dimanche 3 janvier 2016

Python 3.x comparing variable to integer

How do I compare the input to a number?

Code:

def Student():
    global Name
    global Class
    while True:
        try:
            Class = int(input('Enter your class number: '))
        except ValueError:
            print('You have not entered a number.')
        if Class == int())
            if Class >= 1 and Class <= 3:
                break
            else:
                 print('You have not entered a valid number.')

The only things that work are when I enter 0 or something that isn't a number.

The problem is that when I enter anything beginning with a number but has letters in it it will say 'You have not entered a number.' and 'You have not entered a valid number.' and when I enter any number that isn't zero it will just tell me to enter cllass number when 1, 2 and 3 are meant to break the loop and any number above 3 should say 'You have not entered a valid number.' and ask again.

Aucun commentaire:

Enregistrer un commentaire