我想在python 3.5.2中添加,但我有一個未指定數量的變量。我必須使用非常基本的功能;我不能使用list
。我無法弄清楚如何在沒有list
的情況下將每個新變量加在一起。當我運行代碼時,它會添加最後輸入的price1
,即-1
。我需要使用-1
來告訴程序總計所有變量。如何將未指定數量的變量添加到一起?
count = 0
while (True):
price1 = int(input("Enter the price of item, or enter -1 to get total: "))
count += 1
if (price1 ==-1):
subtotal = (price1 +) #this is where I"m having trouble
#at least I think this is the problem
tax = (subtotal*0.05)
total = (subtotal + tax)
print("Subtotal: . . . . . ", subtotal)
print("Tax: . . . . . . . . ", tax)
print("Total: . . . . . . . .", total)
break
你的問題不清楚,你期待什麼確切的輸出? –
我正在嘗試獲取小計。我想如果我能得到,我不能弄清楚總機智的稅收。 – John