Python代码询问您最喜欢的颜色有错误

时间:2018-05-01 11:22:32

标签: python

我的代码出现问题:

colour = input(" what is your favorite colour? ")


if colour("Red"):
    print("I like that colour too.")

else:
    print("I prefer red.")

2 个答案:

答案 0 :(得分:5)

这不是你测试字符串相等性的方法。为了安全起见,您可能还想检查不区分大小写。

colour = input("What is your favourite colour?")

if colour.lower() == 'red':
    print("I like that colour too.")

else:
    print("I prefer red.")

答案 1 :(得分:0)

应该是:

colour = input(" what is your favorite colour? ")


if colour=='red':
    print("I like that colour too.")

else:
    print("I prefer red.")