dimanche 3 juillet 2016

Some problems with input functions and or logic

I am having a simple problem with some input and if statements. I am using a function from this page and my modifications aren't working. This is my code:

def correct(prompt):
    while True:
        try:
            value = int(raw_input(prompt))
        except ValueError:
            print("Enter a number, please!")
            continue

        if (value != 1) or (value != 2):
                print("Enter a value of either 1 or 2, please!")
                continue
        else:
            break
        return value

The problem seems to be at the if statement. The intended behavior is to reject either inputs that aren't 1 or 2. However, it is rejecting all inputs.

Aucun commentaire:

Enregistrer un commentaire