如何为 return 个问题创建一个简单的循环?
How can I create a simple loop to return a question?
我正在尝试创建一个循环,询问用户的年龄和邮政编码,一旦它 returns 他们的投票站应该循环回来并再次询问他们的年龄和邮政编码。到目前为止我的代码只要求两个,returns站然后结束。
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.")
我正在尝试创建一个循环,询问用户的年龄和邮政编码,一旦它 returns 他们的投票站应该循环回来并再次询问他们的年龄和邮政编码。到目前为止我的代码只要求两个,returns站然后结束。
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.")