2015-12-03 56 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() 

这一个完美运行,对原单我错过了其他几件事情太