【发布时间】:2018-03-05 14:00:30
【问题描述】:
价格 = { “1”:1000, “2”:2000, “3”:3000, “4”:4000, “5”:5000, }
def get_total_challan_cost(): total_price = 0
while True:
challan_type = input("Enter the Challan Type: ")
if challan_type == "":
break
price = prices[challan_type]
total_price += price
print("The price for Challan is: {}".format(price))
print("")
print("Total price: {}".format(total_price))
定义主(): # 生成 machine_cost、diesel_cost 等的代码 ...
# machine_cost = ...?
# diesel_cost = ...?
challan_cost = get_total_challan_cost()
# print(machine_cost + diesel_cost + challan_cost + ...)
如果 name == "main": 主要()
到这里就OK了
现在我在新行中打印以下内容 打印(get_total_challan_cost) 它应该只给出总挑战成本,而不需要再次输入
【问题讨论】:
-
只有一个输入?其他输入的总和?
-
您能否具体说明您想要求和的内容以及预期的输出?
-
我假设 OP 意味着
while循环的每次迭代 -
该程序将迭代直到我们输入空格
-
输入查伦类型:1查伦价格为:1000 输入查伦类型:4查伦价格为:4000 输入查伦类型:5查伦价格为:5000
标签: python python-3.x