Question
You are to write a program that uses a dictionary to implement a guessing game involving U. S. states and their capital cities. The dictionary
You are to write a program that uses a dictionary to implement a guessing game involving U. S. states and their capital cities. The dictionary will contain the names of the states as keys and the corresponding capital cities as values. A function (loadDictionary) will create a dictionary by reading state information from a file. The file is formatted so each line of the file contains a state name followed by a comma followed by the capital city name. The main function will get the state dictionary from the loadDictionary function. Main will repeatedly ask the user to select a state. If the user enters the name of a state that is in the dictionary, the user is then asked to enter the name of the capital of that state. If the state the user entered is not in the dictionary, a random state is selected from the dictionary and the user is asked for the name of that states capital. In either case, the state selected from the dictionary is removed from the dictionary so it cannot be selected again. The capital city entered by the user is compared to the dictionary value for that states capital. The user is informed whether their answer was correct, and if not, the correct answer is displayed. The number of capitals guessed and the number correct are also displayed after each round. The game ends when the dictionary is empty. Note: the pop( ) and popitem( ) functions should be used to get key:value pairs from the dictionary. These functions remove items from the dictionary. Program Requirements 1. Write a function that creates the dictionary from the data in the file provided. 2. Write the main function which gets the dictionary from the function in step 1. Create the loop that asks for a state, gets user input, removes an item from the dictionary, asks for the capital city, and displays the results and the statistics. The loop terminates when the dictionary is empty. Note: please it has to be coded in python 3.6
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started