我正在尝试创建一个循环,询问用户他们的年龄和他们的邮政编码,一旦它返回他们的投票站,它应该循环回来再次询问他们的年龄和邮政编码。到目前为止,我的代码只询问了两个,返回工作站然后完成。
print("VOTER ELIGIBILITY AND POLLING STATION PROGRAM\n\n")
ageMinimum = 18
exitVal = 0
zipCode = 0
zipCodeTemp = 0
age = int(input("Enter your age (Type '0' to exit the program): "))
while age < ageMinimum and age != exitVal:
print("You are not eligible to vote")
age = int(input("Enter your age (Type '0' to exit the program): "))
if age == exitVal:
input("\nRun complete. Press the Enter key to exit.")
if age != exitVal:
zipCode = int(input("Enter your residence's Zip Code: "))
if age != exitVal and zipCode == ...:
print("Your polling station is ...")
elif age != exitVal and zipCode == ...:
print("Your polling station is ...")
elif age != exitVal and zipCode == ...:
print("Your polling station is ...")
elif age != exitVal and zipCode == ...:
print(" Your polling station is ...")
elif age != exitVal and zipCode == ...:
print("Your polling station is ...")
elif zipCode != zipCodeTemp:
print("Error – unknown zip code")
这应该可以解决您遇到的任何问题:
print("VOTER ELIGIBILITY AND POLLING STATION PROGRAM\n\n")
ageMinimum = 18
exitVal = 0
zipCode = 0
zipCodeTemp = 0
while True:
age = int(input("Enter your age (Type '0' to exit the program): "))
while age < ageMinimum and age != exitVal:
print("You are not eligible to vote")
if age == exitVal:
input("\nRun complete. Press the Enter key to exit.")
exit()
if age != exitVal:
zipCode = int(input("Enter your residence's Zip Code: "))
if age != exitVal and zipCode == ...:
print("Your polling station is ...")
elif age != exitVal and zipCode == ...:
print("Your polling station is ...")
elif age != exitVal and zipCode == ...:
print("Your polling station is ...")
elif age != exitVal and zipCode == ...:
print(" Your polling station is ...")
elif age != exitVal and zipCode == ...:
print("Your polling station is ...")
elif zipCode != zipCodeTemp:
print("Error – unknown zip code")
else:
print("Some sort of error has occured.")