0

I'm not sure at all why I keep getting this message no matter what i do. I've tried in 3 different plateforms. This is just the last half of the code. I just updated with the whole code and can't figure it out. I know it's something simple, and i have to be overlooking it. PLEASE HELP!!

Line 65 Else: ^ SyntaxError: Invalid Syntax

    # 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()
Dreed66
  • 25
  • 1
  • 5
  • this is my first python class. So i'm brand new too it, but i'm learning that spacing is huge when it comes to Python. So do i need to space "print" more? – Dreed66 Mar 24 '21 at 04:25

2 Answers2

1

Python uses whitespace to structure your code, so you need to indent your code correctly. Here my best guess as to what you want:

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()

Consider using the early return pattern to avoid deeply nested code:

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')
Allan Wind
  • 23,068
  • 5
  • 28
  • 38
  • this is my first python class. So i'm brand new too it, but i'm learning that spacing is huge when it comes to Python. So do i need to space "print" more? – Dreed66 Mar 24 '21 at 04:26
  • I just reformatted your code. This shows you that the last else statement is not at the right level (dangling). – Allan Wind Mar 24 '21 at 04:27
  • In the system the error is showing up for the first Else statement – Dreed66 Mar 24 '21 at 04:30
  • @Dreed66 Is the `Else` capitalized like that in your code? Because it needs to be lowercase. – duckboycool Mar 24 '21 at 04:32
  • I gotta tell you, i'm trying everything and still getting the error – Dreed66 Mar 24 '21 at 04:46
  • You had a weird white space after the first preceed that I removed. I also rewrote you zip input logic. The condition ` zipCode > 9999 and zipCode < 100000` is not valid logic. My zip code, for instance, is 02180. It now breaks on firstName and lastName not being defined but that's a entirely different problem that what you asked about. – Allan Wind Mar 24 '21 at 05:03
  • What coding software would you recommend to write the code on? – Dreed66 Mar 24 '21 at 18:55
0

else statement before " print('Sorry you can not vote') " need the proper indentation. and if it's giving syntax error, the exit() you using might be not imported. try sys.exit(). Hope this will be helpful

KLAS R
  • 52
  • 7
  • I indented that else statement, and tried sys.exit(). still getting the error on the first else statement – Dreed66 Mar 24 '21 at 04:35