Python While 循环(检查第 6 行)
Python While loop (check line 6)
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):”有一个语法错误,它特别突出显示在冒号“:”上,python 中的 if 语句不就是这样写的吗?我应该在 while 循环之前定义继续吗?
您缺少上一行的右括号:
item = float(input("Enter price of the item"))
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()
这个运行完美,在原来的我也搞砸了一些其他的事情
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):”有一个语法错误,它特别突出显示在冒号“:”上,python 中的 if 语句不就是这样写的吗?我应该在 while 循环之前定义继续吗?
您缺少上一行的右括号:
item = float(input("Enter price of the item"))
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()
这个运行完美,在原来的我也搞砸了一些其他的事情