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]
3 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]3 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
A large number of consecutive IP addresses are available starting at 198.16.0.0. Suppose that four organizations, Able, Baker, C
san4es73 [151]
K k k k k k k. K k k kk. K kk
4 0
3 years ago
List three examples of observations of earth by remote-sensing satellites
topjm [15]
Calipso

CloudSat

Aqua


Hope this helps. Brainliest please
3 0
4 years ago
The sun emits invisible _____> A) electromagnetic waves B) Waves C) Radiation D) Wavelength E) Ultraviolet Light
SIZIF [17.4K]

Answer:

Ultra violet light.

Explanation:

7 0
3 years ago
Which attributes does not come in tag?
Ne4ueva [31]

Answer:

length is your answer

Explanation:

Have a great day! ^-^

can you me as brainliest if its right? i need 10000 points and 35 brainliest's to rank up to genius

4 0
3 years ago
Read 2 more answers
Write a function index(elem, seq) that takes as inputs an element elem and a sequence seq and returns the index of the first occ
Delicious77 [7]

Answer:

def index(elem, seq):

   for i in range(len(seq)):

       if elem == seq[i]:

           return i

   

   return len(seq)

print(index(5, [4, 10, 8, 5, 3, 5]))

Explanation:

Create a function named index that takes elem and seq as parameters

Create a for loop that iterates through the seq. If elem is equal to the item in the seq, return the i, index of the item.

If the elem is not found in the seq, this means nothing will be returned in the loop, just return the length of the seq, len(seq)

Call the function with given parameters and print the result

Note: Since 5 is in the list in the example, the index of the 5 which is 3 will be returned

5 0
4 years ago
Other questions:
  • How to tell if screen or screen protector is cracked?
    5·2 answers
  • An essential skill today is knowing how to cite sources properly. Creative Commons has a system of licenses and tools for creato
    11·1 answer
  • "Select the computing device that uses a limited version of an operating system and uses a web browser with an integrated media
    12·1 answer
  • You create a new three-way mirror storage space. You format the storage space by using ReFS. Which two features can you use on t
    13·1 answer
  • The traditional UNIX scheduler enforces an inverse relationship between priority numbers and priorities: the higher the numbe1~
    6·1 answer
  • Identify which statement explains why a programmer would break a logic problem into steps.
    13·2 answers
  • import java.util.Scanner; public class ArraySum { public static void main(String[] args) { Scanner scnr = new Scanner(System.in)
    9·1 answer
  • What do flowcharts communicate to programmers ?
    10·1 answer
  • How does porter’s competitive forces model help companies develop competitive strategies using information systems?
    13·1 answer
  • Can someone please entertain me and talk right now, because I'm just so bored that I may lose my mind.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!