loops - python:compare values with other values in dictionary -
as per this link
now have randomly choose state question , compare answer capital, if user provides right answer loop must exit.
i have dictionary with
{'state': ['alabama', 'alaska', 'arizona', 'arkansas', 'california'], 'capital': ['montgomery', 'juneau', 'phoenix', 'little rock']}
something might work (not tested), assumes states , capitals 1 1 , in right order
import random random_state = random.choice(your_dict.get('state') index = your_dict.get('state').index(random_state) answer = your_get_answer_method() #returns answer, process if needed (lower ... etc) if your_dict.get('capital')[index] == answer: #do stuff here
Comments
Post a Comment