samedi 30 juin 2018

false if statements being called/variable not being assigned?

I wasn't too sure what to call this post.

Anyways, what I'm trying to do is assign 'diff' to a user input, and if 'diff' is not average or advanced, recall the function so that the user can (hopefully) enter average or advanced.

However, no matter what I input, it will always recall the function, even if the input is 'average' or 'advanced'.

Code -

def choices():
    global diff
    diff = input("Choose a difficulty: Average/Advanced ")
    diff = diff.lower()
    x = 0
    while x > 1:
        if diff == 'average':
            print('Difficulty set to average.')
            x = x + 1
        elif diff == 'advanced':
            print('Difficulty set to advanced.')
            x = x + 1

    if diff != 'average' or 'advanced':
        print('Your input is invalid. Please try again.')
        choices()

choices()

The same thing is also happening for another decision I have that is similar to this, but I figured that there's no point in putting it down if it follows the same logic.

Sorry if this is a stupid question. I'm only a beginner.

Aucun commentaire:

Enregistrer un commentaire