以下代码是上周作业的程序。任务是创建一个程序,您可以作为出纳输入信息,它将根据输入的信息为您汇总所有信息。本周任务的一部分是增强它,以便程序可以使用while循环处理多个项目。此改进程序应输出所有项目的总数
这是教授正在寻找的结果的一个例子
Original ticket price: $100
Is this item reduced?y
Is this item taxable?y
Here is your bill
Orginal Price $100.00
Reduced Price $25.00
Final Price $75.00
7% Sales Tax $5.25
Total amount due $80.25
Original ticket price: $75
Is this item reduced?y
Is this item taxable?n
Here is your bill
Orginal Price $75.00
Reduced Price $18.75
Final Price $56.25
7% Sales Tax $0.00
Total amount due $56.25
Total amount due is $136.50
# Enter constants for sale & salesTax
SALE = .25
SALES_TAX = .07
# Enter the ticket price of the item
origPrice = float(input('Original ticket price or 0 to quit: $'))
# Is the item reduced? Y/y or N/n - use if/elif to determine salePrice
reduced = input('Is this item reduced?')
if reduced == 'Y' or reduced == 'y':
salePrice = origPrice * SALE
elif reduced == 'N' or reduced == 'n':
salePrice = 0.00
# Enter constant for finalPrice = origPrice - salePrice
finalPrice = origPrice - salePrice
# Is the item taxable? Y/y or N/n - use if/elif to determine tax
taxable = input('Is this item taxable?')
if taxable == 'Y' or taxable == 'y':
tax = finalPrice * SALES_TAX
elif taxable == 'N' or taxable == 'n':
tax = 0.00
# Enter all Print Statements
print('Here is your bill')
print('Orginal Price $', format(origPrice, ',.2f'),sep='')
print('Reduced Price $', format(salePrice, ',.2f'),sep='')
print('Final Price $', format(finalPrice, ',.2f'),sep='')
print('7% Sales Tax $', format(tax, ',.2f'),sep='')
print('Total amount due $', format(finalPrice + tax, ',.2f'),sep='')
总是很高兴看到人们学习编程。Python是一个很好的语言,有大量的资源。话虽如此,请检查下面的代码,如果您有兴趣看到它运行,请单击下面的链接。它是一本GoogleColab笔记本,它几乎是一个用浏览器开发的python环境
链接Colab:https://colab.research.google.com/drive/1S64fGVM1rQTv05rJBlvjOVrwHQFm8faK?usp=sharing
塞纳里奥一号:![OrgPrice: 100](https://i.stack.imgur.com/BIZlO.png)
欢迎来到StackOverflow!从教授给您的示例输出来看,似乎您需要使用break条件将当前代码(不包括常量声明)包装在
while True
循环中,但还需要添加另一个名为totalAmountDue
的变量。每次添加新项目时,此变量都将更改。如果要应用更改,则应如下所示:这是编辑版本的输出:
如果您想了解python中while循环的更多信息,可以查看以下链接:https://www.w3schools.com/python/python_while_loops.asp
相关问题 更多 >
编程相关推荐