jeudi 17 novembre 2016

Python: if true, ignore Variable from now on

I have an assignment which forces me to ignore certain variables if a condition is fullfilled. Basically I'm asking the user for an input and tell him the Valid choices he has, but after a while that originally valid choice is no longer valid anymore. I thought about doing something like this

while True:
    choice = input('You can choose between: ', Choice1, Choice2, Choice3)
    if choice == Choice1:
        Choice1Counter +=1
        break
    elif choice == Choice2:
        Choice2Counter +=1
        break
    elif choice == Choice3:
        Choice2Counter +=1
        break
    else:
        choice = input('You can choose between: ', Choice1, Choice2, Choice3)
        continue

with this I would first of all 'force' a valid choice and if the input is a valid choice I would add 1 to the Counter of that choice. should the Counter hit its limit I thought about doing something like this

if Choice1Chounter == 4:
    #ignore Choice 1 for the rest of the Programm or until Choice1 is reset

This should then basically mean that Choice1 is ignored by the program, which would look a bit like this (in my mind)
choice = Input('You can choose between: ', Choice1, Choice2, Choice3)

With that it should basically "print" out the following when running the Programm after Choice1Counter hits ist limit
You can choose between: Choice2 Choice3

I have 8 Valid Inputs and can't really define all 8! combinations of them, so i thought about this, but can't find a command that just ignores a variable for the rest of the Program. Any Kind of help is appreciated, if you have any further questions I will try to answer asap. Thank you in anticipation!

Aucun commentaire:

Enregistrer un commentaire