问蟒蛇早餐菜单

时间:2016-06-15 21:12:40

标签: python-3.x

'meals = ("Juice", "Milk", "Bread")
name = input("What do you want in a breakfast? ")
if meals =='bread''milk''juice':
print("I love it ")

否则:     打印(“我不想要它”)'

1 个答案:

答案 0 :(得分:0)

您需要将用户输入(即存储在变量name中的字符串与meals(字符串元组)进行比较。要比较这两者,您需要包含in逻辑运算符:

name = input("What do you want in a breakfast? ") if name in meals: print("i love it") else: print("i dont want it")

但是,要使此代码起作用,用户输入必须始终大写。下一次,提出问题并说明您想要的结果,而不是仅仅发布代码。