我正在尝试为课堂做作业,但它比需要的要困难得多,但我这样做是为了学习。
任何人都可以看到我的代码有问题吗?
我做了一些简单的搜索并尝试了一些修复,但我一定错过了一些基本的东西。
另外,我似乎无法将我的“新”列表中的所有项目相加。环顾四周后我仍然无法弄清楚这一点。正如主题所说,我对此很陌生,因此非常感谢任何帮助。
# define variables
new = []
items = float()
tax = float()
final = float()
subtotal = float()
# welcome and set rules of entering numbers
print("Welcome! Sales tax is 7%. Enter your five items, one (1) at a time.")
# gathering input for items
for _ in range(5):
_ += 1
# define condition to continue gathering input
test = True
while test: # test1 will verify integer or float entered for item1
items = input("Enter the price of item without the $: ")
try:
val = float(items)
print("Input amount is :", "$"+"{0:.2f}".format(val))
test1 = False
except ValueError:
try:
val = float(items)
print("Input amount is :", "$"+"{0:.2f}".format(val))
test = False
except ValueError:
print("That is not a number")
new.append(items)
# define calculations
subtotal = sum(new)
tax = subtotal * .07
final = subtotal + tax
# tax & subtotal
print("Subtotal: ", "$"+"{0:.2f}".format(subtotal))
print("Tax: ", "$"+"{0:.2f}".format(tax))
print("Tare: ", "$"+"{0:.2f}".format(final))
侃侃无极
万千封印
梵蒂冈之花
MMTTMM
相关分类