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
kvv77 [185]
3 years ago
10

Write a program that creates a dictionary 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 asking 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.)
Computers and Technology
1 answer:
Dima020 [189]3 years ago
7 0

Answer:

  1. import random  
  2. states = {
  3.    "Alabama": "Montgomery",
  4.    "California": "Sacramento",
  5.    "Florida": "Tallahassee",
  6.    "Hawaii": "Honolulu",
  7.    "Indiana": "Indianapolis",
  8.    "Michigan": "Lansing",
  9.    "New York": "Albany",
  10.    "Texas" : "Austin",
  11.    "Utah" : "Salt Lake City",
  12.    "Wisconsin": "Madison"
  13. }
  14. correct = 0
  15. wrong = 0
  16. round = 1
  17. while(round <= 5):
  18.    current_state = random.choice(list(states))
  19.    answer = input("What is the capital of " + current_state + ": ")
  20.    
  21.    if(answer == states[current_state]):
  22.        correct += 1
  23.    else:
  24.        wrong += 1
  25.    
  26.    round += 1
  27. print("Correct answer: " + str(correct))
  28. print("Wrong answer: " + str(wrong))

Explanation:

The solution code is written in Python 3.

Line 3 -14

Create a dictionary of US States with capital as each of their corresponding value. Please note only ten sample states are chosen here.

Line 16 - 18

Create variables to track the number of correct and inaccurate response and also round counter.

Line 19 - 28

Set the while condition to enable user to play the quiz for five questions and use random.choice to randomly pick a state from the dictionary and prompt user to input the capital of selected stated.

If the answer matched with the capital value of the selected state, increment the correct counter by one. Otherwise the wrong counter will be incremented by one. Increment the round counter by one before proceed to next round.

Line 30 - 31

Print the number of correct responses and wrong responses.

You might be interested in
Before installing any software, it's always important to back up your system and to create a BLANK, which enables you to go back
g100num [7]
Whats the question supposed to be so I can answer it?
8 0
3 years ago
Read 2 more answers
FS EVERFI:
Snowcat [4.5K]

Answer:

A) work study program

Explanation:

Because you need experience and scholarships don't always pay, so this is the best choice.

6 0
2 years ago
Read 2 more answers
When a field is declared static there will be ________. Group of answer choices two reference copies of the field for each metho
anygoal [31]

Answer: one field copy gets generated in memory

Explanation:

When a field is declared static,it will become common for entire class instances. Single copy of field that gets created for the particular class where numerous instances present in that class can use it by sharing .

  • Other options are incorrect because  two copy of reference does not gets created as it only supports single copy.
  • Copy of the field for every class is not generated by static field.All method and instances use  only one field copy for the whole class.
  • Thus the correct answer is creation of only one field copy in memory for static field.

7 0
3 years ago
The information of an management information system comes from?
Debora [2.8K]

A management information system is a computer system consisting of hardware and software that serves as the backbone of an organization's operations

5 0
2 years ago
Generally speaking, what is a “best practice"?
miss Akunina [59]

Answer:

What’s up, I’m currently in this class, and I was wondering if it’s easy or hard?

Explanation:

3 0
3 years ago
Other questions:
  • What is the portrait mode?
    5·2 answers
  • PowerPoint Presentation on What type of device will she use to display her presentation and explain it to the rest of the childr
    13·2 answers
  • "When an interrupt or a system call transfers control to the operating system, a kernel stack area separate from the stack of th
    11·1 answer
  • Encapsulation is the process of “packaging” information prior to transmitting it from one location to another. true or false
    14·1 answer
  • In a CSS document, within what must you enclose properties and values when you define a rule for a specified selector?
    13·1 answer
  • Write a script that will read from a file x and y data points in thefollowing format:
    9·1 answer
  • Anna's computer has slowed down. How might she improve her computer's performance? Select one of the options below as your answe
    10·1 answer
  • Who when and why developed python​
    9·2 answers
  • Read the steps in the process of making a video.
    5·2 answers
  • Digital rights include the right to
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!