vendredi 28 septembre 2018

Voting If/Else/Elif

New to Python (and to StackOverflow). Trying to figure out how to get this to execute properly. While the program itself executes fine, I'd like it to not have the extra step in there. What I mean by that is that if it fails the first statement, I'd like to to terminate and print the message associated with the else statement.

def main():

# init
messageOne = 'You are too young to vote.'
messageTwo = 'You can vote.'
messageThree = 'You need to register before you can vote.'

# input
age = int(input('Please enter your age: '))
registration = input('Are you registered to vote(Y/N)?: ')

# calculate / display
if age >= 18:
    if registration.upper() == "Y":
        print(messageTwo)
    else:
        print(messageThree)
else:
    print(messageOne)

main()

Aucun commentaire:

Enregistrer un commentaire