Python else:SyntaxError:无效语法
我一点也不知道为什么不管我做什么,我总是收到这个信息。我试过3种不同的平台。这只是代码的最后一半。我只是更新了整个代码,但我想不出来。我知道这很简单,我不得不忽略它。请帮忙 第65行 其他: ^ SyntaxError:无效语法Python else:SyntaxError:无效语法,python,python-3.x,if-statement,Python,Python 3.x,If Statement,我一点也不知道为什么不管我做什么,我总是收到这个信息。我试过3种不同的平台。这只是代码的最后一半。我只是更新了整个代码,但我想不出来。我知道这很简单,我不得不忽略它。请帮忙 第65行 其他: ^ SyntaxError:无效语法 # opening Statement print("Welcome to the Python Voter Registration Application") #continue check preceed = input("
# opening Statement
print("Welcome to the Python Voter Registration Application")
#continue check
preceed = input("Do you wish to continue? (Yes/No)\n")
if preceed.lower() in ['y', 'yes']:
# Name Collection
firstName = input("What is your First Name?\n")
preceed = input("Do you wish to continue? (Yes/No)\n")
if preceed.lower() in ['y', 'yes']:
lastName = input("what is your Last Name?\n")
preceed = input("Do you wish to continue? (Yes/No)\n")
if preceed.lower() in ['y', 'yes']:
# Age Verification
age = int(input("How old are you?\n"))
while age <=17 or age >= 120:
if age <= 17:
print("Sorry you are not old enough to Vote")
ageTryAgain = int(input('How old are you?\n'))
age = ageTryAgain
elif age >= 120:
print("Please enter a valid age")
ageTryAgain = int(input('How old are you?\n'))
age = ageTryAgain
preceed = input("Do you wish to continue? (Yes/No)\n")
if preceed.lower() in ['y', 'yes']:
# Citizen Check
citizen = input('Are you a U.S. Citizen? (Yes/No)\n')
if citizen.lower() in ['y', 'yes']:
preceed = input("Do you wish to continue? (Yes/No)\n")
if preceed.lower() in ['y', 'yes']:
# State Check
state = input('Which State do you live in? ex. AL, CA, IL, ect... \n')
if state.lower() in ['al', 'ak', 'az', 'ar', 'ca', 'co', 'ct', 'de', 'dc', 'fl', 'ga', 'hi', 'id', 'il', 'in', 'ia', 'ks', 'ky', 'la','me', 'md', 'ma','mi', 'mn', 'ms', 'mo', 'mt', 'ne', 'nv', 'nh', 'nj', 'nm','ny', 'nc', 'nd', 'oh', 'ok', 'or', 'pa', 'pr', 'ri', 'sc', 'sd', 'tn', 'tx','ut', 'vt', 'va', 'wa', 'wv', 'wi', 'wy']:
preceed = input("Do you wish to continue? (Yes/No)\n")
if preceed.lower() in ['y', 'yes']:
# Zip Code
zipCode = int(input("Please enter Zipcode\n"))
while zipCode <= 9999 or zipCode >= 100000:
if zipCode <= 9999:
print('Please enter vaild ZipCode')
zipCodeTryAgain = int(input('Please enter Zipcode\n'))
zipCode = zipCodeTryAgain
elif zipCode >= 100000:
print('Please enter vaild ZipCode')
zipCodeTryAgain = int(input('Please enter Zipcode\n'))
zipCode = zipCodeTryAgain
print('Thank you for registering to Vote.\n Here is the information you have entered.')
print('Name (First Last): ' + firstName + " " + lastName)
print('Age: ' + str(age))
print('U.S. Citizen: Yes')
print('State: ' + state)
print('Zipcode: ' + str(zipCode))
print('Thank you for trying the Voter Registration Application.\nYour registration card should be shipped within 3 weeks')
else:
exit()
else:
print('Please enter vaild state next time')
else:
exit()
else:
print('Sorry you can not vote')
else:
exit()
开幕词
打印(“欢迎使用Python选民注册应用程序”)
#继续检查
preced=输入(“是否要继续?(是/否)\n”)
如果在['y','yes']中加上.lower():
#名称集合
firstName=input(“您的名字是什么?\n”)
preced=输入(“是否要继续?(是/否)\n”)
如果在['y','yes']中加上.lower():
lastName=input(“您姓什么?\n”)
preced=输入(“是否要继续?(是/否)\n”)
如果在['y','yes']中加上.lower():
#年龄验证
年龄=int(输入(“您多大?\n”))
当年龄=120时:
如果年龄=120:
打印(“请输入有效年龄”)
ageTryAgain=int(输入('您多大?\n'))
年龄=年龄
preced=输入(“是否要继续?(是/否)\n”)
如果在['y','yes']中加上.lower():
#公民支票
公民=输入('您是美国公民吗?(是/否)\n')
如果公民.lower()在['y','yes']中:
preced=输入(“是否要继续?(是/否)\n”)
如果在['y','yes']中加上.lower():
#状态检查
state=input('您居住在哪个州?例如AL、CA、IL、ect…\n')
如果在[al]、[ak]、[az]、[ar]、[ca]、[co]、[ct]、[de]、[dc]、[fl]、[ga]、[hi]、[id]、[il]、[in]、[ia]、[ks]、[ky]、[la]、[me]、[md]、[ma]、[mi]、[mn]、[ms]、[mo]、[mt]、[ne]、[nv]、[nh]、[nj]、[nm]、[ny]、[nd]、[oh]、[ok]、[pa]、[pr]、[ri]、[sc]、[sd]、[
preced=输入(“是否要继续?(是/否)\n”)
如果在['y','yes']中加上.lower():
#邮政编码
zipCode=int(输入(“请输入zipCode\n”))
zipCode=100000时:
如果zipCode=100000:
打印('请输入有效的ZipCode')
zipcodertryagain=int(输入('请输入Zipcode\n'))
zipCode=zipcodertryagain
打印('感谢您注册投票。\n这是您输入的信息。')
打印('Name(First-Last):'+firstName+“”+lastName)
打印('年龄:'+str(年龄))
打印('美国公民:是')
打印('状态:'+状态)
打印('Zipcode:'+str(Zipcode))
打印('感谢您尝试选民注册应用程序。\n您的注册卡应在3周内寄出')
其他:
退出()
其他:
打印('请下次输入有效状态')
其他:
退出()
其他:
打印('对不起,您不能投票')
其他:
退出()
Python使用空格来构造代码,因此需要正确缩进代码。以下是我对你想要什么的最佳猜测:
from sys import exit
preceed = input("Do you wish to continue? (Yes/No)\n")
if preceed.lower() in ['y', 'yes']:
# Citizen Check
citizen = input('Are you a U.S. Citizen? (Yes/No)\n')
if citizen.lower() in ['y', 'yes']:
preceed = input("Do you wish to continue? (Yes/No)\n")
if preceed.lower() in ['y', 'yes']:
# State Check
state = input('Which State do you live in? ex. AL, CA, IL, ect... \n')
if state.lower() in ['al', 'ak', 'az', 'ar', 'ca', 'co', 'ct', 'de', 'dc', 'fl', 'ga', 'hi', 'id', 'il', 'in', 'ia', 'ks', 'ky', 'la','me', 'md', 'ma','mi', 'mn', 'ms', 'mo', 'mt', 'ne', 'nv', 'nh', 'nj', 'nm','ny', 'nc', 'nd', 'oh', 'ok', 'or', 'pa', 'pr', 'ri', 'sc', 'sd', 'tn', 'tx','ut', 'vt', 'va', 'wa', 'wv', 'wi', 'wy']:
preceed = input("Do you wish to continue? (Yes/No)\n")
if preceed.lower() in ['y', 'yes']:
# Zip Code
while True:
zipCode = int(input("Please enter Zipcode\n"))
if zipCode > 9999 and zipCode < 100000:
break
print('Thank you for registering to Vote.\n Here is the information you have entered.')
print('Name (First Last): ' + firstName + " " + lastName)
print('Age: ' + str(age))
print('U.S. Citizen: Yes')
print('State: ' + state)
print('Zipcode: ' + str(zipCode))
print('Thank you for trying the Voter Registration Application.\nYour registration card should be shipped within 3 weeks')
else:
print('Please enter vaild state next time')
exit()
else:
exit()
else:
print('Sorry you can not vote')
else:
exit()
从系统导入退出
preced=输入(“是否要继续?(是/否)\n”)
如果在['y','yes']中加上.lower():
#公民支票
公民=输入('您是美国公民吗?(是/否)\n')
如果公民.lower()在['y','yes']中:
preced=输入(“是否要继续?(是/否)\n”)
如果在['y','yes']中加上.lower():
#状态检查
state=input('您居住在哪个州?例如AL、CA、IL、ect…\n')
如果在[al]、[ak]、[az]、[ar]、[ca]、[co]、[ct]、[de]、[dc]、[fl]、[ga]、[hi]、[id]、[il]、[in]、[ia]、[ks]、[ky]、[la]、[me]、[md]、[ma]、[mi]、[mn]、[ms]、[mo]、[mt]、[ne]、[nv]、[nh]、[nj]、[nm]、[ny]、[nd]、[oh]、[ok]、[pa]、[pr]、[ri]、[sc]、[sd]、[
preced=输入(“是否要继续?(是/否)\n”)
如果在['y','yes']中加上.lower():
#邮政编码
尽管如此:
zipCode=int(输入(“请输入zipCode\n”))
如果zipCode>9999且zipCode<100000:
打破
打印('感谢您注册投票。\n这是您输入的信息。')
打印('Name(First-Last):'+firstName+“”+lastName)
打印('年龄:'+str(年龄))
打印('美国公民:是')
打印('状态:'+状态)
打印('Zipcode:'+str(Zipcode))
打印('感谢您尝试选民注册应用程序。\n您的注册卡应在3周内寄出')
其他:
打印('请下次输入有效状态')
退出()
其他:
退出()
其他:
打印('对不起,您不能投票')
其他:
退出()
考虑使用早期返回模式以避免深度嵌套的代码:
from sys import exit
citizen = input('Are you a U.S. Citizen? (Yes/No)\n')
if citizen.lower() not in ['y', 'yes']:
print('Sorry you can not vote')
exit(1)
state = input('Which State do you live in? ex. AL, CA, IL, ect... \n')
if state.lower() not in ['al', 'ak', 'az', 'ar', 'ca', 'co', 'ct', 'de', 'dc', 'fl', 'ga', 'hi', 'id', 'il', 'in', 'ia', 'ks', 'ky', 'la','me', 'md', 'ma','mi', 'mn', 'ms', 'mo', 'mt', 'ne', 'nv', 'nh', 'nj', 'nm','ny', 'nc', 'nd', 'oh', 'ok', 'or', 'pa', 'pr', 'ri', 'sc', 'sd', 'tn', 'tx','ut', 'vt', 'va', 'wa', 'wv', 'wi', 'wy']:
print('Please enter vaild state next time')
exit(1)
zipCode = int(input("Please enter Zipcode\n"))
if zipCode < 0 or zipCode > 9999:
print('Please use valid 5 digit zip code')
exit(1)
firstName = "TBD"
lastName = "TBD"
age = "TBD"
print('Thank you for registering to Vote.\n Here is the information you have entered.')
print('Name (First Last): ' + firstName + " " + lastName)
print('Age: ' + str(age))
print('U.S. Citizen: Yes')
print('State: ' + state)
print('Zipcode: ' + str(zipCode))
print('Thank you for trying the Voter Registration Application.\nYour registration card should be shipped within 3 weeks')
从系统导入退出
公民=输入('您是美国公民吗?(是/否)\n')
如果citizen.lower()不在['y','yes']中:
打印('对不起,您不能投票')
出口(1)
state=input('您居住在哪个州?例如AL、CA、IL、ect…\n')
如果state.lower()不在[al]、[ak]、[az]、[ar]、[ca]、[co]、[ct]、[de]、[dc]、[fl]、[ga]、[hi]、[id]、[il]、[in]、[ia]、[ks]、[ky]、[la]、[me]、[md]、[ma]、[mi]、[mn]、[ms]、[mo]、[mt]、[ne]、[nv]、[nh]、[nj]、[nm]、[ny]、[nd]、[oh]、[ok]、[pa]、[pr]、[ri]、[sc
打印('请下次输入有效状态')
出口(1)
zipCode=int(输入(“请输入zipCode\n”))
如果zipCode<0或zipCode>9999:
打印('请使用有效的5位邮政编码')
出口(1)
firstName=“待定”
lastName=“待定”
年龄=“待定”
print('感谢您注册投票。\n以下是信息