Python 如何检查用户输入的值是否有效?如果输入正确,如何将该值附加到列表中?
希望这有帮助。数量应该是,Python 如何检查用户输入的值是否有效?如果输入正确,如何将该值附加到列表中?,python,python-3.x,input,while-loop,Python,Python 3.x,Input,While Loop,希望这有帮助。数量应该是, Write the item code of the food you wish to buy: this is not on the list How many units of the previous food do want? 56 The item code was inputted correctly Quantity entered is out of range 如果数量order=input(str(“写下你想要购买的食物的项目代码:”) 数量=输
Write the item code of the food you wish to buy: this is not on the list
How many units of the previous food do want? 56
The item code was inputted correctly
Quantity entered is out of range
如果数量order=input(str(“写下你想要购买的食物的项目代码:”)
数量=输入(“您想要多少单位的前一种食物:”)
如果在菜单\u代码中有顺序:
打印(“项目代码输入正确”)
其他:
打印(“项目代码输入错误”)
如果0order==“ff”或“bb”
等被解释为(order==“ff”)或(“bb”)
,并且“bb”
总是计算为True
,那么整个表达式是True
。请阅读列表中的,以及docsRegarding中的操作符中的
您应该阅读Python文档中的比较运算符,并在Python shell中使用它们
Write the item code of the food you wish to buy: this is not on the list
How many units of the previous food do want? 56
The item code was inputted correctly
Quantity entered is out of range
if quantity <= 100:
print("Quantity entered is inside acceptable range")
order = input(str("Write the item code of the food you wish to buy: "))
quantity = input("How many units of the previous food do want::")
if order in menu_codes:
print("The item code was inputted correctly")
else:
print("The item code was inputted incorrectly")
if 0 <= int(quantity) <= 100:
print("Quantity entered is inside acceptable range")
else:
print("Quantity entered is out of range")