所以我输入3作为我的眼睛颜色(绿色),它显示“你是一个乐观的人”,而不是“你是一个好奇的人”。为什么会这样?它不是应该显示其他的吗
eyeList = ["blue", "brown","green","hazel","grey","none"]
print(eyeList)
eyecolor = int(input("Pick your eye color: "))
if eyecolor == 1 or 2:
print("you are a optimistic person")
else:
print("you are a curious person")
personality
可能是string
,使用int(input(...))
获得int
int
与string
进行比较==
,而不是=
if
或elif
之后都需要冒号:
类似的方法可能会奏效:
有三个问题:
a)输入作为字符串,您需要在
int
中转换它b)检查语法错误,应该是两个等号
==
c)跳过
if
结尾处的:
固定代码:
Python语法:
您只是缺少每个条件之后的冒号(
:
)此外,要检查某物是否等于其他某物,必须使用
==
。单个=
执行赋值最后,不能将整数与字符串进行比较(
input()
函数返回字符串)。要执行此操作,请将字符串转换为整数:最后提示:您的控制台为您提供了有关代码错误的有用提示。听他们说
相关问题 更多 >
编程相关推荐