Question

Python 3 **11.40 (Guess the capitals) Write a program that repeatedly prompts the user to enter...

Python 3

**11.40

(Guess the capitals) Write a program that repeatedly prompts the user to enter a capital for a state. Upon receiving the user input, the program reports whether the answer is correct. Assume that 50 states and their capitals are stored in a two- dimensional list, as shown in Figure 11.13. The program prompts the user to answer all the states’ capitals and displays the total correct count. The user’s answer is not case sensitive. Implement the program using a list to represent the data in the following table.

Alabama  Montgomery
Alaska  Juneau
Arizona  Phoenix
...  ...

A two-dimensional list stores states and their capitals.

Here is a sample run:

What is the capital of Alabama? Montogomery
The correct answer should be Montgomery
What is the capital of Alaska? Juneau
Your answer is correct
What is the capital of Arizona? ...
...
The correct count is 35
0 0
Add a comment Improve this question Transcribed image text
Answer #1

PYTHON Code:

#Added 10 state capitals to the list for testing
#You can add more state capitals
capitals=[["Alabama","Montgomery"],["Alaska","Juneau"],["Arizona","Phoenix"],
["Arkansas","Little Rock"],["California","Sacramento"],["Colorado","Denver"],
["Connecticut","Hartford"],["Delaware","Dover"],["Florida","Tallahassee"],
["Georgia","Atlanta"]]
correctcount=0
  
for i in range(len(capitals)):
cap=input("What is the capital of "+capitals[i][0]+"? ")
if cap.lower() == capitals[i][1].lower():
correctcount+=1
print("Your answer is correct")
else:
print("The correct answer should be",capitals[i][1])
  
print("The correct count is",correctcount)
  

1 ovouw #Added 10 state capitals to the list for testing #You can add more state capitals capitals=[[Alabama, Montgomery]

Output:

What is the capital of Alabama? Montogomery The correct answer should be Montgomery What is the capital of Alaska? Juneau You

Add a comment
Know the answer?
Add Answer to:
Python 3 **11.40 (Guess the capitals) Write a program that repeatedly prompts the user to enter...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C# windows forms program to create a States and Capitals guessing game. A method...

    Write a C# windows forms program to create a States and Capitals guessing game. A method in your program should generate a random number between 1 and 50. Your program should use this number to represent one of the 50 U.S states and then display the name of that state. The user will guess the capital of that state. Another method in your program should get the users answer and check to see whether it is correct. Yet another method...

  • Write a Python program that prompts the user to enter integer values for each of two...

    Write a Python program that prompts the user to enter integer values for each of two lists. It then should displays whether the lists are of the same length, whether the elements in each list sum to the same value, and whether there are any values that occur in both lists.

  • Program must be in Python 3. Write a program that prompts the user to enter two...

    Program must be in Python 3. Write a program that prompts the user to enter two strings and then displays a message indicating whether or not the first string starts with the second string. Your program must satisfy the following requirements. 1. Your program must include a function called myStartsWith that takes two string parameters. This function returns True if the rst string starts with the second string and returns False otherwise. 2. Your program must include a main function...

  • (PYTHON) Write a program that prompts the user to enter the number of students and each student's score

    USE PYTHON 3Write a program that prompts the user to enter the number of students and each student's score, and displays the highest and second- highest scores.

  • C++, data structure Write a program that plays a game called "guess the state, guess the...

    C++, data structure Write a program that plays a game called "guess the state, guess the capital". How do you play? The program randomly selects a state or a state capital. The program asks the player to guess the state's capital (or the capital's state). The program reads the user's guess; and, tells the user if its guess is right, or if the guess is wrong, tells the user that its guess is wrong and displays the correct answer. Before...

  • what code in python 3 would I use for this? Write a program that prompts the...

    what code in python 3 would I use for this? Write a program that prompts the user to guess a number between 0 and 10. Your program then picks a random number and tells the user whether their guess is too high, too low or right on! Don't forget to give the user an error if their number is below 0 or above 10. Don't forget to document your code.

  • Python Programming Q.3) Write a program that repeatedly asks the user to enter words until they...

    Python Programming Q.3) Write a program that repeatedly asks the user to enter words until they enter a period ("."). Your program should then print all of the words they entered including the period) on a single line separated by spaces. For example, Enter some words (. to stop): > hello > world hello world.

  • For this lab, write a program that lets the user enter a state and the program...

    For this lab, write a program that lets the user enter a state and the program returns that state's capital, stored in a dictionary Requirements: Start by hard coding in all of the states and their capitals the user should be able to enter the name of a state or ask for all states to be printed (one key/value pair per line) If the state is in the dictionary, print its state capital in the form: "The capital of Vermont...

  • 1) Write a Python program that prompts the user to enter the current month name and...

    1) Write a Python program that prompts the user to enter the current month name and prints the season for that month. Hint: If the user enters March, the output should be "Spring"; if the user enters June, the output should be "Summer". 2 )Write a Python program using the recursive/loop structure to print out an equilateral triangle below (double spacing and one space between any two adjacent asterisks in the same row).          *      * * * *...

  • Write a program that prompts the user to enter a binary string and displays the corresponding...

    Write a program that prompts the user to enter a binary string and displays the corresponding decimal integer value. For example, binary string ‘10001’ is 17 (1*24 +0*23 +0*22 +0*2 + 1 = 17) A sample run : Enter a binary: 10001 17 Enter second integer: 110 6 Use python.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT