Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何检查用户输入的值是否有效?如果输入正确,如何将该值附加到列表中?_Python_Python 3.x_Input_While Loop - Fatal编程技术网

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代码中有顺序:
打印(“项目代码输入正确”)
其他:
打印(“项目代码输入错误”)

如果0
order==“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")