0

如何修复此代码中的 while 循环,使其仅在 18 时起作用age,如果小于 18 则打印错误消息,并使程序即使在错误的邮政编码后继续运行?

这是我的代码:

print "VOTER ELIGIBILITY AND POLLING STATION PROGRAM"
print
print
age= int(raw_input("Enter your age (Type ' 0 ' to exit program) :"))
while age != 18:
    print "ineligible"
    age= int(raw_input("Enter your age (Type ' 0 ' to exit program) :"))
    if age != 0:
        zipcode= int(raw_input("Enter your residence's zip code:"))

        if zipcode == 93305:
            print "Your polling station is 123 Panorama Drive."
        elif zipcode == 93306:
            print "Your polling station is 6143 Fairfax Drive."
        elif zipcode ==93307:
            print "Your polling station is 21121 B Street."
        elif zipcode ==93308:
            print "Your polling station is 863 Desmond Ct."
        elif zipcode == 93309:
            print "Your polling station is 7332 Del Canto Ct."
        else:
            print "Error-unknown zip code"

raw_input("\nRun complete.Press the Enter key to exit.")    
4

1 回答 1

0

尝试类似:

age = get_age();

while ( age != 0 ) {
    if ( age >= 18 ) ...
    else ...

    age = get_age();
}

exit
于 2013-02-10T03:44:17.823 回答