dimanche 28 mai 2017

python If and in statement

so i'm writing a code that is checking if input is in two seperate places. one being a dictionary and another being a list. my code is something like this:

a_list = ['north', 'south', 'east', 'west']
a_dictionary = {'north', 'south'}

action = input(">>")
action = action.lower().pop(0)
if action in a_list and action in a_dictionary:
    print("you move %s." % action)
else:
     print("you are confused.")

obviously this is a simplified version of what i have but that is the mainly what i'm doing. my problem is that it only seems to be checkin the first in statement and will 'move' even when both conditions aren't met. or if the positions are swapped it will use the else statement everytime. i also tried this:

if action in a_list:
    if action in a_dictionary:
        print("you move %s." % action)
    else:
        print("you are confused.")

didn't seem to help. just uses else statement.

Aucun commentaire:

Enregistrer un commentaire