我的代码出现问题:
colour = input(" what is your favorite colour? ")
if colour("Red"):
print("I like that colour too.")
else:
print("I prefer red.")
答案 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.")