首页 > 解决方案 > 无效的文字 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'

标签: python

解决方案


您正在尝试将颜色输入“红色”转换为 int:

color = int(input("Select a Color: red, blue, yellow, or green: "))

将其更改为

color = input("Select a Color: red, blue, yellow, or green: ")

推荐阅读