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
In a(n) ____________________ device, the movement of electrons performs essentially the same functions as gears and wheels in me
lana66690 [7]

Answer:

Electronic computing.

Explanation:

8 0
2 years ago
A dual looped Fibre Channel drive system is theoretically capable of transferring data at a rate of _____.
Anna007 [38]

Answer:200 MBps

Explanation: Fibre channel are those channel that work with the data transfer protocol at the rate of high speed.They work on the connection that are based on the links and loops or share any other form of point to point connection.

It is measured that theoretically the speed of the dual looped FC is supposed to be 200 MBps rate having the two loop form connection.

4 0
3 years ago
What is the best way to ensure personal privacy with regard to online information?
Alenkinab [10]
A) only post it via an anonymizer is my guess
7 0
3 years ago
A major concern about ESP claims is that proponents explain both the positive and negative findings. By explaining the negative
4vir4ik [10]

Answer: Falsifiability

Explanation: Falsifiability is the term that is defined as the evaluation of any particular hypothesis or theory to be proven wrong .This feature gives the access that the theory can be tested and have more accurate claims .

The ESP(Extrasensory perception) theory  can also have feature of being falsifiable because the experiments and test lead to the issue that the negative effects of the theory are not certain which might occur due to simple observation of effects.

5 0
4 years ago
Large Format Camera holds:
Leviafan [203]
Film 4x5 because it is bigger than 120 mm because mm is 120 of 1000th
5 0
3 years ago
Other questions:
  • A file named numbers.txt contains an unknown number of lines, each consisting of a single positive integer. Write some code that
    9·1 answer
  • An employee has contacted the IT Support call center where you work. They are complaining that they are unable to access any web
    14·1 answer
  • A(n) _________ website contains factual information, such as libraries, encyclopedias, dictionaries, guides, and other types of
    8·1 answer
  • The Start menu on Windows computers changes based on actions performed by their users. True False
    15·2 answers
  • Cell phones replacing fixed line phones is an example of:
    12·1 answer
  • Assume that we have an application with a total of 500,000 instructions where 20% of them are the load/store instructions with a
    14·1 answer
  • A _____ is an example of a systems program. A. command interpreter B. web browser C. text formatter D. database system
    10·1 answer
  • Which keys should you press to insert a comment in OpenOffice Writer?
    15·2 answers
  • Someone please help will mark as brainliest
    8·2 answers
  • Which of the following enables robots to do things such as understand itself, walk, talk, and develop skills?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!