python - Input statements just keep going in a loop
问题描述
Hi i am albert i am learning python, in this block of code i wrote i intend it to print the total, but the input statements just keep going in a loop
print("this program prints your invoice")
while True:
ID = input("item identification: ")
if ID == "done":
break
if len(ID) < 3:
print("identification must be at least 3 characters long")
exit(1)
break
try:
Quantity = int(input("quantity sold: "))
except ValueError:
print("please enter an integer for quantity sold!!!")
exit(2)
if Quantity <= 0:
break
print("please enter an integer for quantity sold!!!")
exit(3)
try:
price = float(input("price of item"))
except ValueError:
print("please enter a float for price of item!!")
exit(4)
if price <= 0:
print("please enter a positive value for the price!!!")
exit(5)
break
cost = 0
total = cost + (Quantity*price)
print(total)
解决方案
我想你需要这个
cost = 0
total = cost + (Quantity*price)
print(total)
在while循环内。否则,完全跳过循环。
推荐阅读
- java - JAVA中相同变量的一元增量运算符的奇怪表达式评估顺序
- node.js - 我如何检查从角度传递到服务器的数据到 node.js
- javascript - 如果长度大于 Jquery 隐藏 Div 元素
- python-3.x - pytorch中使用cnn的二元分类模型
- javascript - 如何遍历包含键和值的数组以在 ReactJS 中发送对 Axios.get 参数的请求?
- javascript - 在使用 JS 的特定行数后显示“阅读更多”按钮
- python - scp 来自 Debian 中 Python 的目录
- django - 如何使用 Django Rest Framework 在同一函数中传递两个查询集
- eclipse - 空项目上的 Eclipse web.xml 中的错误
- javascript - 注销后停用服务人员