这是一个Python中的票务供应商的程序。
在我添加time.sleep
函数之前,它工作正常。
这是我的代码:
import time
spaces = 61
def init():
global spaces
if spaces > 1:
print("Welcome to OCR's car park!")
print("The number of spaces remaining is "+ str(spaces-1) +".")
print("What are the last three letters on your number plate?")
numplate = input()
if len(numplate) != 3:
print("These letters are invalid.")
time.sleep(1)
init()
elif numplate.isalpha():
print("It's £3.45 for a ticket. Enter how much money you want to insert. Type 'cancel' to cancel.")
confirm = input()
if confirm == "cancel":
print("Payment cancelled.")
time.sleep(3)
init()
if int(confirm) < 345:
print("You don't have enough money.")
time.sleep(1)
init()
print("£" +str(confirm)+ " inserted.")
time.sleep(2)
if float(confirm)> 345:
print("Taking change...")
time.sleep(3)
confirm = float(confirm)-345
print("Change due: £" +str(len(confirm[0]))+ "." +str(len(confirm[1]))+str(len(confirm[2]))
time.sleep(1)
print("Printing ticket. Please wait.")
time.sleep(5)
print("Thank you for choosing OCR's car park!")
spaces -= 1
print("")
print("")
print("|-----|")
print("| "+str(numplate.upper())+"|")
print("|-----|")
print("")
print("")
init()
else:
print("These letters are invalid.")
time.sleep(1)
init()
elif spaces < 2:
print("No More Spaces.")
init()
每次运行时,都会显示一个弹出式提示'invalid syntax'
,它始终指向time.sleep(1)
功能。
答案 0 :(得分:2)
错误发生在你的下一行。
print("Change due:£"str(len(confirm[0]))+"."+str(len(confirm[1]))+str(len(confirm[2]))
缺少一个右括号。只需添加一个右括号。