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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -