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
Why does it help to differentiate among self-esteem,self-image, and self value
joja [24]

Evaluation of one’s own worth is termed as self-esteem. Each person will take the defeat and pointed out mistake in different manner. One person may shout if somebody points out mistake and another may handle it with smile. Self-esteem plays the role here.

Self image is an imaginary of picture of how an individual is in their own perspective and how the same person in the view of other person’s perspective. This is one of the important traits of the people.

Self-value: Setting a value of one self, analyzing various situations and facts and stamping the seal as either “good” or “bad” is called self-value.

8 0
4 years ago
Read 2 more answers
In the following scenario, which is the least
mario62 [17]

Answer:

Size

Explanation:

Connectivity, they need internet to work.

Speed, they need it to work fast.

Storage, they need space to work.

Size, isn't all that important, unlike the rest.

7 0
3 years ago
Which IDS component is essentially the same as a sniffer in that it runs in conjunction with a network card in promiscuous mode?
Snowcat [4.5K]

Answer:

D. Network tap

Explanation:

A network tap is a hardware device that provides a way to access the data flow across a computer network.

A sniffer is either hardware or software that provides a way to access the data flow across a computer network.

Hence, these two IDS components are very similar.

Cheers.

7 0
3 years ago
Choose the correct function to yield the shown results?
atroni [7]

Answer:

I believe that the answer is float

4 0
3 years ago
Which piece of personal information do websites often require users to enter?
Olin [163]

Answer:

Your Social Security Number

Explanation:

3 0
3 years ago
Other questions:
  • four quantum numbers that could represent the last electron added (using the Aufbau principle) to the Argon atom. A n = 2, l =0,
    14·1 answer
  • What identifies available computers through the internet?
    14·1 answer
  • I have an airsoft pistol and I needed to take it apart to repair it and I lost some screws that were tiny and I dont know what t
    14·1 answer
  • How many pieces are there in a normal laptop??? Good luck and solve carefully
    9·1 answer
  • What is the purpose of OPPA<br>​
    13·1 answer
  • Word documents contain how many sections by default?
    9·1 answer
  • You are going to do a bubble sort on the following list. What are the missing members of the list? Select 3 options.
    14·2 answers
  • How do i work on code with someone else? i use visual studio code. me and a friend wanna make a game together with code. how do
    8·1 answer
  • Who is katie and why is she deleting my answers
    7·2 answers
  • given 2,4,3,-1 as input, what is the output for the following program:total_product = 1 user_value = int(input()) while user_val
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!