python - 无效的文字 python 算命先生
问题描述
def My_Fortune():
color = int(input("Select a Color: red, blue, yellow, or green: "))
if color == "red":
number = int(input("Select a number: 1, 3, 5, or 7: "))
if number == 1:
print("You will be forever alone")
elif number == 3:
print("You will get very lucky very soon")
elif number == 5:
print("The police will be searching for you shortly")
elif number == 7:
print("You will get you dream job")
else:
print("Invalid Request")
我得到 int() 的无效文字,基数为 10:'red'
解决方案
您正在尝试将颜色输入“红色”转换为 int:
color = int(input("Select a Color: red, blue, yellow, or green: "))
将其更改为
color = input("Select a Color: red, blue, yellow, or green: ")
推荐阅读
- python - 如何使用python脚本打印一行今天日期的excel表?
- c++ - 如何纠正 C++ 中的 malloc 错误?附加字符时
- jquery - 如何将参数传递给 AJAX 以加载 Datatable?
- javascript - 如何在输入零之前继续接收数字并计算用户输入的正数和负数总数。在文本字段中
- heroku - Heroku - 使用身份验证循环无法在站点上登录
- vue.js - 刷新页面时,Vue 3路由器链接没有活动类
- javascript - chrome.scripting.executeScript - 意外属性:“参数”
- google-sheets - 输入日期到书面形式
- ejabberd - 带书签的 muc 房间不会加载到前端应用程序上
- rust - 存储 Fn 闭包的返回值