當我開發我的第一個代碼時,遇到了一個問題,我用break
命令試圖在程序出現錯誤時重新啓動程序。python「break」error:break outside loop
看看代碼,也許你會更好理解。
Name = str(input("Please enter Your Name:"))
Age = input("Please enter your age: ")
if Age != int():
print ("Error! Check the age")
break
elif Age == int():
continue
Height = input("Please enter your height: ")
if Height != int():
print ("Error! Check the Height")
break
elif Height == int():
continue
if Age == int() and Age >= 18 and Height == int() and Height >= 148:
print("You're able to drive a car " + (Name))
elif Age == int() and Age < 18 and Height == int() and Height > 148:
print("You're not able to drive a car " + (Name))
elif Age and Height != int() :
print ("Error! , Age or Height are not numbers")
錯誤:
"C:\Users\Ghanim\Desktop\Coding\Documents\Projects\Python\Project1\Project1.py", line 6 break ^ SyntaxError: 'break'
outside loop
您的代碼縮進似乎被破壞。 – Moberg
在這裏看看如何檢查一個變量是否包含一個數字:https://stackoverflow.com/questions/3501382/checking-whether-a-variable-is-an-integer-or-not – Moberg