如何列出收据的价格清单?

时间:2016-10-26 13:34:34

标签: python

我已经尝试了一段时间让我的收据显示我列出的所有价格,使用sum()显示小计,并在我的价格旁边做一个美元符号。到目前为止,我收到了很多收据,但无法解决这个问题。到目前为止,这是我的代码:

price = []

headphones = int(input("Enter price of Headphones: ") )
while(True):
    price = int(input("Enter price of Headphones: "))
    if (price == -1):
       break
apple= int(input("Enter price of  Apple: ") )
while(True):
    price = int(input("Enter price of  Apple: "))
    if (price == -1):
      break
pen = int(input("Enter price of Pen: ") )
while(True):
    price = int(input("Enter price of Pen: "))
    if (price == -1):
       break
mouse = int(input("Enter price of  Mouse: ") )
while(True):
    price = int(input("Enter price of  Mouse: "))
    if (price == -1):
       break
paper = int(input("Enter price of amount for Paper: ") )
while(True):
    price = int(input("Enter price of amount for Paper: "))
    if (price == -1):
       break
cookies = int(input("Enter price of Cookies: ") )
while(True):
    price = int(input("Enter price of Cookies: "))
    if (price == -1):
       break
bananas = int(input("Enter price of Bananas: ") )
while(True):
    price = int(input("Enter price of Bananas:"))
    if (price == -1):
       break
bread = int(input("Enter price of Bread: ") )
while(True):
    price = int(input("Enter price of Bread: "))
    if (price == -1):
       break

subtotal = headphones + apple + pen + mouse + paper + cookies + bananas + bread
tax = int(subtotal * 0.065)
total = subtotal + tax

a = headphones
b = apple
c = pen
d = mouse
e = paper
f = cookies
g = bananas
h = bread
w = subtotal

y = w * .065
v = y+w

print("Target Recipt".center(80, "-"))
print("-".center(80, "-"))

print("Headphones                        $:   ".center(0, ), headphones)
print("Apple                             $:   ".center(0, ), apple)
print("Pen                               $:   ".center(0, ), pen)
print("Mouse                             $:   ".center(0, ), mouse)
print("Paper                             $:   ".center(0, ), paper)
print("Cookies                           $:   ".center(0, ), cookies)
print("Bananas                           $:   ".center(0, ), bananas)
print("Bread                             $:   ".center(0, ), bread)

print("-".center(80, "-"))
print()
print()
print("Subtotal".center(37, ), w)
print("Tax".center(37, ), y)
print()
print("Total".center(37, ), v)
print()
print()
print('Have a wonderful day!'.center(80, "-"))

我似乎无法弄清楚我做错了什么。我知道我应该使用它:

prices = []

while(True):
    p = float(input("Enter a price" ))
    prices.append(p)

for i in range(len(prices)):
    print(prices[i])

0 个答案:

没有答案