Advanced Even or Odd

After writing the last post I wondered what would happen if the user didn't enter a number. It caused a value error, so I wrote another script that starts a function, catches the error, prints Please enter a valid number and restarts the function. Hope this helps someone.


def evenodd():
    #Checks if character entered is a valid number
    try:
        #Accepts user input and converts the string to an integer
        x = int(input('Enter an integer: '))
    except ValueError:
        #If fails check then print message and restart the program.
        print('Please enter a valid number')
        evenodd()

    #Uses modulo operator to check the remainder after dividing user input by 2
    if x%2 == 0:
        #If the remainder is 0 then the number is even
        print('')
        print('Even')
    else:
        #If the remainder is not 0 then the number is odd
        print('')
        print('Odd')

evenodd()