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
Which of the following situations is least likely fair use
kolezko [41]

Answer:

Is there more to the question or is that it?

8 0
3 years ago
Read 2 more answers
What is the purpose of a mutator?
choli [55]

Answer:

To change the value of private or protected members.

Explanation:

Mutator also known as setters are the member function or method in class that is used to set or change the value of private or protected members. Mutator does not return any values. They are very important in Object Oriented Programming.

3 0
4 years ago
True or False: In Google Cloud IAM: if a policy applied at the project level gives you Owner permissions, your access to an indi
vekshin1

Answer:

The following statement is False.

Explanation:

When any user or person using IAM platform of the Google Cloud that give permission to the user for the particular granular access. It provides user control by setting IAM policies of what access to which services.

That's why it not restricted to view if the user applies for the restrictive rules to that resources.

8 0
3 years ago
Choose all items that represent characteristics of HTML attributes.
OLga [1]

Answer:

- Used to include additional information in an element

- May be required for certain elements

- Consist of a keyword followed by an equals sign and additional information in quotes

Explanation:

<a href="website link goes here">    <---- example element with an attribute.

- You can see the <a> element which creates a link requires a "href" (which means "Hypertext Reference", basically a fancy way of saying a link to another page) attribute for the source of the link.

- The keyword "href" is followed by an equals and wrapped in quotes.

- Can be used to include additional information, like how you can use the keyword "alt" with an <img> tag to add text that shows up when you hover over it.

----------------------------------------------------------------------------------------------------------

In response to the other answers:

- The attribute itself is not wrapped in angle brackets, though it does sit within them. It is the *element* that is wrapped in angle brackets.

- The attributes are not added to the end (closing) tag, they are added to the opening tag.

3 0
3 years ago
Read 2 more answers
7d2b:00a9:a0c4:0000:a772:00fd:a523:0358
motikmotik

Answer:

yh3iuskjldnsjfhbcgfihekwfhei3wh8hfefbgp

Explanation:

6 0
3 years ago
Other questions:
  • Are mechanical keyboards more expensive than membrane keyboards?
    9·2 answers
  • How can an installation be a tool for community building?
    9·1 answer
  • 10^4+10-2=<br>10^4+10-2=
    12·2 answers
  • Which of the following is a scam where perpetrators promise high pay for working on different projects like wooden calendars, pa
    13·1 answer
  • Which of the following is not a compilation error? Group of answer choices a. Placing a semicolon at the end of the first line o
    13·1 answer
  • I have to write this in Java, but i've never even learned it before and i'm completely lost
    12·1 answer
  • What is data and imformation?​
    6·1 answer
  • Select the word or phrase from the drop-down menu to complete each sentence. File names consist of a ______ and a file extension
    10·1 answer
  • Which of the following is a software tool used to manage data for a project in a logical and hierarchical order?
    13·1 answer
  • A computer professional's job involves analyzing computer systems for
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!