I'm trying to make a game where the user is asked to guess a country based on it's capital which is selected at random from a list of dictionaries (similar to the link at bottom). Guessing 10 countries in total, if they guess correctly they get 1 point, with 10 points in total. I've imported a variable 'countries' that contains a list of dictionaries like the following:
[{'capital': 'Andorra la Vella', 'code': 'AD', 'continent': 'Europe', 'name': 'Andorra', 'timezones': ['Europe/Andorra']}, {'capital': 'Kabul', 'code': 'AF', 'continent': 'Asia', 'name': 'Afghanistan', 'timezones': ['Asia/Kabul']},
So how do I print a random choice from a specific key name? In this case, any 'capital' from any of the dictionaries.
Python-Dictionary states and capital game
Aucun commentaire:
Enregistrer un commentaire