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
Debora [2.8K]
2 years ago
7

Write a program that creates a dictionary containing the U.S. states as keys and their abbreviations as values. The program shou

ld then randomly quiz the user by displaying the abbreviation and asking the user to enter that state's name. The program should keep a count of the number of correct and incorrect responses, as well as which abbreviation the user missed. You should include the following: Mainline logic and functions Error handling Dictionaries
Computers and Technology
1 answer:
AleksandrR [38]2 years ago
6 0

Answer:

Explanation:

The following program is written in Python. It creates a loop that keeps creating a random number to randomly choose a State abbreviation from the dictionary. Then it asks the user what the state is. If the user gets the answer correct it prints out "Correct" and adds 1 point to the correct variables. Otherwise it prints "Incorrect" and adds 1 point to the incorrect variable. Finally, printing out the final amount of correct and incorrect responses. The program was tested and the output can be seen below.

import random

states = {"AL":"Alabama","AK":"Alaska","AZ":"Arizona","AR":"Arkansas","CA":"California","CO":"Colorado","CT":"Connecticut","DE":"Delaware","FL":"Florida","GA":"Georgia","HI":"Hawaii","ID":"Idaho","IL":"Illinois","IN":"Indiana","IA":"Iowa","KS":"Kansas","KY":"Kentucky","LA":"Louisiana","ME":"Maine","MD":"Maryland","MA":"Massachusetts","MI":"Michigan","MN":"Minnesota","MS":"Mississippi","MO":"Missouri","MT":"Montana","NE":"Nebraska","NV":"Nevada","NH":"New Hampshire","NJ":"New Jersey","NM":"New Mexico","NY":"New York","NC":"North Carolina","ND":"North Dakota","OH":"Ohio","OK":"Oklahoma","OR":"Oregon","PA":"Pennsylvania","RI":"Rhode Island","SC":"South Carolina","SD":"South Dakota","TN":"Tennessee","TX":"Texas","UT":"Utah","VT":"Vermont","VA":"Virginia","WA":"Washington","WV":"West Virginia","WI":"Wisconsin","WY":"Wyoming"}

keys_list = list(states)

correct = 0

incorrect = 0

while True:

   randNum = random.randint(0, 49)

   abbr = keys_list[randNum]

   answer = input("Enter The State name of " + abbr + ": ")

   if answer.lower() == states[abbr].lower():

       print("Correct")

       correct += 1

   else:

       print("Incorrect")

       incorrect += 1

   again = input("Play again? y/n ")

   if again.lower() == 'n':

       break

print("Correct: " + str(correct))

print("Incorrect: " + str(incorrect))

You might be interested in
What is returned by the code: range (5, 100, 25) ?
Nataly [62]
You would have to add them up need more info on the returned video
6 0
3 years ago
Read 2 more answers
Help with what the awnser is
wariber [46]
Flute on a boot ;) hope i helped

8 0
3 years ago
When typing an outline, you can move a point from a lower level to a higher level by changing the list level from the outline me
Arte-miy333 [17]
A shift+Tab
I hope it’s work
6 0
2 years ago
What are web services?
nekit [7.7K]

So far the most general and convincing definition is to say that Web Services are the set of applications or technologies with the ability to interoperate on the Web. These technologies exchange data between them in order to offer services.


7 0
3 years ago
How long is the bachelor's program at Eth Zurich? 3 or 4 years?
natulia [17]
The bachelor's program at Eth Zurich is 3 years.
I hope this helps!
:-)
4 0
3 years ago
Other questions:
  • A. True
    5·1 answer
  • To under a clip art you must do the following.
    14·1 answer
  • The _____ handles the instructions for your computer to start up before the operating system is loaded.
    11·1 answer
  • Write a program that displays the following menu:
    8·1 answer
  • Which of the following is a requirement for the Safety Data Sheet (SDS)?​
    5·1 answer
  • Help me out with this .....
    10·1 answer
  • Words that have a special meaning in a programming language are called
    13·1 answer
  • Que es un programa de ordenador?
    10·1 answer
  • Which is a basic job requirement for a career in corrections services?
    13·1 answer
  • you are setting up an active directory environment for a business that has three locations and 300 users. you want the users to
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!