【发布时间】:2022-09-29 02:46:18
【问题描述】:
下面是一个正在运行的程序示例:
Welcome to the Fast Freight Shipping Company shipping rate program.
This program is designed to take your package(s) weight in pounds and
calculate how much it will cost to ship them based on the following rates.
2 pounds or less = $1.10 per pound
Over 2 pounds but not more than 6 pounds = $2.20 per pound
Over 6 pounds but not more than 10 pounds = $3.70 per pound
Over 10 pounds = $3.80 per pound
Please enter your package weight in pounds: 1
Your cost is: $ 1.10
Would you like to ship another package <y/n>? y
Please enter your package weight in pounds: 5
Your cost is: $ 11.00
Would you like to ship another package <y/n>? y
Please enter your package weight in pounds: 52
Your cost is: $ 197.60
Would you like to ship another package <y/n>? y
Please enter your package weight in pounds: 8
Your cost is: $ 29.60
Would you like to ship another package <y/n>? y
Please enter your package weight in pounds: 3
Your cost is: $ 6.60
Would you like to ship another package <y/n>? t
Invalid Input
Would you like to ship another package <y/n>? y
Please enter your package weight in pounds: 10
Your cost is: $ 37.00
Would you like to ship another package <y/n>? n
Thank you for your purchase, your total charge is $ 282.90
Goodbye!
这是我到目前为止所拥有的:
charges = 0
answer = \"yes\"
while (answer == \"yes\"):
packageWeight = eval (input (\"Enter weight of package: \"))
answer = input (\"Do you have more items to input? <yes/no>? \")
if (packageWeight <=2):
charges = (packageWeight * 1.10)
print (\"The cost is: $\",charges)
elif (packageWeight >2) and (packageWeight<=6):
charges= (packageWeight * 2.20)
print (\"The cost is: $\", charges)
elif (packageWeight >6)and (packageWeight<=10):
charges = (packageWeight * 3.70)
print (\"The cost is: $\", charges)
else :
charges = (packageWeight * 3.80)
print (\"The cost is: $\", charges)
message = \"Thank you for your purchase, your total charge is $\"
sum= charges+charges
message += format(sum, \',.2f\')
print(message)
print(\"Goodbye!\")
我如何找到所有费用的总和?我怎样才能让第二个问题出现在成本之后?
所以它会显示:
Enter weight of package: 3
The cost is: 6.60
Do you have more items to input? yes/no
标签: python