2017-06-11 51 views
0

的代碼都運行良好。我有增值稅部分的麻煩例如,它會說不含增值稅的價格爲£100,則增值稅爲£20,但是當他們加在一起這讓£153我不是很確定它得到來自 我的第二個問題是,我嘗試添加一個循環,所以我會問你要制定出另一個價格,然後如果他們說是整個程序再次重新啓動不能得到正確的號碼,我的增值稅

length = int(raw_input("what is the length of all you walls added together? 
")) 
while 2 > length or length > 26: 
    length = int(raw_input("what is the height of all you walls added 
    together? ")) 
else: 
    print ("okay") 
height = int(raw_input("what is the length of all you walls added together? 
")) 
while 1 > height or height > 6: 
    height = int(raw_input("what is the height of your room? ")) 
else: 
    print ("okay") 
area = height*length 
paint = raw_input("what paint would you like to use luxury paint, Standard 
quality, Economy quality? ") 
if paint == "LP" or "lp" or "luxery paint": 
    LP = 2 
    answer = LP*area  
if paint == "SQ": 
    SQ = 1.25 
    answer = SQ*area  
if paint == "EQ": 
    EQ = 0.55 
    answer = EQ*area 
undercoat = raw_input("would you like an undercoat?") 
if undercoat == "yes": 
    undercoat = area*0.55 
    novat = answer + undercoat 
elif undercoat == "no": 
    novat = answer 
percentage = (novat/100.00)*20 
print percentage 
cost = (novat + percentage) 
print "Interior Decorator" 
print "invoice" 
print "the price will be "+ unichr(163) + str(answer) +"(excluding vat)" 
print "the vat will be "+ unichr(163) + str(percentage) 
print "your grand total is " + unichr(163) + str(cost) 

感謝您的幫助

+1

您正在使用哪個調試器來單步執行程序和檢查值產生的? – lit

+0

在Python中啓動調試的簡單方法是粘貼這個pdb行:'import pdb; pdb.set_trace()'就在代碼沒有做到你期望的之前,並且在它運行之前檢查變量(例如'print(foo)')。 –

回答

0

關於錯誤的價值觀:

眼看cost = (novat + percentage)。打印價格時,您不應該使用novat變量而不是answer

關於通過另一個執行循環:

你可以在你的代碼中提取類的實例的方法和循環:

def main_logic(): 
    # The code you have above 

while True: 
    main_logic() 
    run_again = raw_input("would you like to run again? ") 
    if run_again != "yes": 
     break