1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
borishaifa [10]
4 years ago
7

Write a program that creates a map containing the U.S. states as keys, and their capitals as values. (Use the Internet to get a

list of the states and their capitals.) The program should then randomly quiz the user by displaying the name of a state and ask the user to enter that state’s capital. The program should keep a count of the number of correct and incorrect responses. (As an alternative to the U.S. states, the program can use the names of countries and their capitals.) -Python

Computers and Technology
1 answer:
seraphim [82]4 years ago
8 0

Answer:

Here is the Python program:

import random  #  to generate random numbers

def quiz():  #method quiz to ask state's capital

   capitals={"Washington":"Olympia","Oregon":"Salem",\

                   "California":"Sacramento","Ohio":"Columbus",\

                   "Nebraska":"Lincoln","Colorado":"Denver",\

                   "Michigan":"Lansing","Massachusetts":"Boston",\

                   "Florida":"Tallahassee","Texas":"Austin",\

                   "Oklahoma":"Oklahoma City","Hawaii":"Honolulu",\

                   "Alaska":"Juneau","Utah":"Salt Lake City",\

                   "New Mexico":"Santa Fe","North Dakota":"Bismarck",\

                   "South Dakota":"Pierre","West Virginia":"Charleston",\

                   "Virginia":"Richmond","New Jersey":"Trenton",\

                   "Minnesota":"Saint Paul","Illinois":"Springfield",\

                   "Indiana":"Indianapolis","Kentucky":"Frankfort",\

                   "Tennessee":"Nashville","Georgia":"Atlanta",\

                   "Alabama":"Montgomery","Mississippi":"Jackson",\

                   "North Carolina":"Raleigh","South Carolina":"Columbia",\

                   "Maine":"Augusta","Vermont":"Montpelier",\

                   "New Hampshire":"Concord","Connecticut":"Hartford",\

                   "Rhode Island":"Providence","Wyoming":"Cheyenne",\

                   "Montana":"Helena","Kansas":"Topeka",\

                   "Iowa":"Des Moines","Pennsylvania":"Harrisburg",\

                   "Maryland":"Annapolis","Missouri":"Jefferson City",\

                   "Arizona":"Phoenix","Nevada":"Carson City",\

                   "New York":"Albany","Wisconsin":"Madison",\

                   "Delaware":"Dover","Idaho":"Boise",\

                   "Arkansas":"Little Rock","Louisiana":"Baton Rouge"}

#dictionary of states along with their capitals    

   quit=False   #exit option

   print ("Welcome to the States capitals quiz game!")  

   wrong_ans = False   # boolean variable for incorrect answer

   while not quit and len(capitals)>0:  

#loop continues until all state capitals are finished and user presses q

       choice = random.choice(list(capitals.keys()))  

#choice variable stores randomly generated list of pick

       right_ans = capitals.get(choice)  #stores correct answer

       print ("\nWhat is the capital city of",choice,"?")

       user_ans = input("Your guess:  ")  #answer entered by user

       if user_ans.lower()=='q':  #if user presses q to quit

           quit=True  #quit value become true

           print("The quiz is over! Bubye!")  

#displays the above message and quits the program

       elif user_ans.lower()==right_ans.lower():  #if user enters correct guess

           print ("Right Answer! \n")  # displays this message

       else:  #if user enters wrong guess

           print ("Wrong Answer!\n")  #displays wrong answer message

           print ("The right answer is ",right_ans)  #prints right capital

           wrong_ans = True          

quiz()       #calls quiz function to begin with the quiz

Explanation:

The program has a dictionary that contains the US states as keys and their capitals as values. The program asks the user to enter the capital of a random state. This state is selected randomly from the list of states using random function and keys() method is used to display list of all keys in the capital states dictionary. The while loop starts which keeps asking the user to guess the capital of states. This loop ends when the user types q to quit the program or all the capitals of the states are covered. Now the user guess is compared to the right answer, if the user has correctly guessed the capital then the Right answer message is displayed otherwise Wrong answer is displayed. After Wrong answer message the correct answer  is displayed and the quiz starts again until the user enters q to exit. When the user types q the message: The quiz is over! Bubye! is displayed and the programs exits.

You might be interested in
Which statements describe the use of styles in Word? Check all that apply.
algol [13]

Answer:

can be used to make word docments look the same

Explanation:

4 0
3 years ago
Read 2 more answers
What is used to configure data sources for applications that require access to a database?
Radda [10]
A network is used to configure data sources for applications that require access to a database?
6 0
4 years ago
You have informed your users that you need to bring the machine down at the end of the day to perform routine maintenance. Howev
PSYCHO15rus [73]

Answer:

shutdown -h +15 It is time for a shutdown!

Explanation:

In a work environment where there is an admin and users connected to the server when the admin wants to Give a 15-minute delay to allow users enough time to save their work data and logout from the system. the command above shuts down after 15 minutes delay and notifies the user with "It is time to shut down!".

8 0
4 years ago
Can I have help on this
never [62]

the answer is the seconf one


6 0
3 years ago
Read 2 more answers
Which of the following is the best reason to use a macro?: *
marin [14]

Answer:c)You want to automate a repetitive task to save time

Explanation: Macro is the program that is utilized when there is a requirement of a task or operation to be repeated in a automatic way.This helps in saving the time without commanding the same operation to take place manually.

This program works by taking the into and generating the preset output sequence. Other options are incorrect because it does not help in email functions, correction of the citation in documents or generation of the table.Thus, the correct option is option(c).

7 0
3 years ago
Other questions:
  • I plugged my phone up into a charger, the charger sparked and i unplugged my phone and now it wont charge at all, does anyone kn
    13·1 answer
  • The internet connects millions of computers connected through millions of ____ worldwide.
    9·1 answer
  • To hide gridline when you display or print a worksheet
    14·1 answer
  • Windows _____ is a system notification utility and gives quick access to settings for items like screen brightness and network c
    8·1 answer
  • The concept/theory where computer generated animation (especially humans) that is TOO life-like they become uncomfortable to us
    15·2 answers
  • The HTTP protocol operates at which layer?
    7·1 answer
  • The post-closing trial balance shows the balances of only the ____ accounts at the end of the period.
    12·1 answer
  • Every single device can be connected to every other device on network, making the network mesh. This statement is True or False?
    8·1 answer
  • What was software for modems that connected through phone lines called?
    6·1 answer
  • Michelle has defined a custom object by creating an object literal. She wants to access the properties of the custom object. Mic
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!