添加while循环中的输入用户值



我是一个完全的初学者,正在做作业。包裹的不同重量有不同的价格,用户必须能够输入包裹的数量及其单个重量,程序必须告知所有包裹的总价。这就是我到目前为止所得到的,(我不知道是什么,但似乎有点不对劲(我似乎不知道如何使总价成为包裹所有不同价格的总和(p.s不允许用于循环(。感谢任何帮助或建议,并提前表示感谢。

parcel = int(input("How many parcels do you want to send?"))
i = 1
while i < parcel+1:
print("State the weight for parcel",i,":")
weight = int(input())
if (i == parcel):
break
i += 1
if weight < 2:
price = 30
elif weight == 2 or weight < 6:
price = 28
elif weight == 6 or weight < 12:
price = 25
elif weight >= 12:
price = 23
tot_price = 
print("The total price will be:",tot_price)
# All prices of each parcel
list_of_prices = []
# Ask the user to input the number of parcels
parcel_count = int(input("How many parcels do you want to send? "))
count = 1
# Loop through the number of parcels, asking for the weight of each
while count <= parcel_count+1:
weight = int(input(f"Please input the weight for parcel {count}: "))
if weight < 2:
price = 30
elif 2 <= weight < 6:
price = 28
elif 6 <= weight < 12:
price = 25
elif weight >= 12:
price = 23
list_of_prices.append(int(price))      # add the price to the list
count += 1
# sum() adds up all the numbers in the list of prices
total_price = sum(list_of_prices)
print("The total price will be:", total_price)

相关内容

  • 没有找到相关文章

最新更新