2015-12-03 59 views
-1
def purchace(): 
    total=0 
    while keepgoing == ("y" or "Y"): 

    item= float(input("Enter price of the item") 
    if (item<=100): 
     dis=(.15*item) 
     price=(item-dis) 
    else: 
     dis=(.25*item) 
     price=(item-dis) 
    total+= item 
    keepgoing = raw_input("Do you want to add more items? (y/n)") 

print("Your total is ",total)      
print("Thank you") 

def main(): 
    purchase() 
main() 

第6行存在語法錯誤「if(item < = 100):」它特別強調在冒號「:」,是不是如何使if在Python中的語句?我應該繼續在while循環之前定義嗎?Python While循環(檢查行6)

+0

你'而情況也是錯誤的。 (「y」,「Y」):'。 – chepner

回答

2

你錯過了上一行的關閉右括號:

item = float(input("Enter price of the item")) 
+0

另外,請注意,你在這段代碼中使用了很多不必要的括號。你不需要他們進行簡單的分配和表達。 – Prune

+0

哇真的嗎?我至少檢查了3次......謝謝! – Jefa

+0

已注意。然而,這就是教授教我們的方式 – Jefa

1
def purchase(): 
total=0 
keepgoing = "y" 
while keepgoing == ("y" or "Y"): 

    item= float(input("Enter price of the item: ")) 
    if (item<=100): 
     dis=(.15*item) 
     price=(item-dis) 
    else: 
     dis=(.25*item) 
     price=(item-dis) 
    total+= price 
    keepgoing = raw_input("Do you want to add more items? (y/n)") 

print("Your total is ",total)      
print("Thank you") 

def main(): 
    purchase() 
main() 

這一個完美運行,對原單我錯過了其他幾件事情太