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()
1
  • 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? Commented Mar 24, 2021 at 4:25

2 Answers 2

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')
Sign up to request clarification or add additional context in comments.

7 Comments

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?
I just reformatted your code. This shows you that the last else statement is not at the right level (dangling).
In the system the error is showing up for the first Else statement
@Dreed66 Is the Else capitalized like that in your code? Because it needs to be lowercase.
I gotta tell you, i'm trying everything and still getting the error
|
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

1 Comment

I indented that else statement, and tried sys.exit(). still getting the error on the first else statement

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.