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:
Optional Extra Challenge:
Answer:
Explanation:
state_capital is the hardcoded dictionary. while loop is used to ask the user again and again to try.
2 options are given to the user. To search for capital or to print all state and capitals.
state_capital={
'Alabama': 'Montgomery',
'Alaska': 'Juneau',
'Arizona':'Phoenix',
'Arkansas':'Little Rock',
'California': 'Sacramento',
'Colorado':'Denver',
'Connecticut':'Hartford',
'Delaware':'Dover',
'Florida': 'Tallahassee',
'Georgia': 'Atlanta',
'Hawaii': 'Honolulu',
'Idaho': 'Boise',
'Illinios': 'Springfield',
'Indiana': 'Indianapolis',
'Iowa': 'Des Monies',
'Kansas': 'Topeka',
'Kentucky': 'Frankfort',
'Louisiana': 'Baton Rouge',
'Maine': 'Augusta',
'Maryland': 'Annapolis',
'Massachusetts': 'Boston',
'Michigan': 'Lansing',
'Minnesota': 'St. Paul',
'Mississippi': 'Jackson',
'Missouri': 'Jefferson City',
'Montana': 'Helena',
'Nebraska': 'Lincoln',
'Neveda': 'Carson City',
'New Hampshire': 'Concord',
'New Jersey': 'Trenton',
'New Mexico': 'Santa Fe',
'New York': 'Albany',
'North Carolina': 'Raleigh',
'North Dakota': 'Bismarck',
'Ohio': 'Columbus',
'Oklahoma': 'Oklahoma City',
'Oregon': 'Salem',
'Pennsylvania': 'Harrisburg',
'Rhoda Island': 'Providence',
'South Carolina': 'Columbia',
'South Dakoda': 'Pierre',
'Tennessee': 'Nashville',
'Texas': 'Austin',
'Utah': 'Salt Lake City',
'Vermont': 'Montpelier',
'Virginia': 'Richmond',
'Washington': 'Olympia',
'West Virginia': 'Charleston',
'Wisconsin': 'Madison',
'Wyoming': 'Cheyenne'
}
option = 'y'
while(option=='y'):
print('1. Search for a state')
print('2. Print all state and capitals')
n = input('Choose an option(1/2): ')
if(n=='1'):
name = input('Enter state name: ')
if name in state_capital:
print('The capital of', name, 'is', state_capital[name])
else:
print(name, 'is not in the list.')
elif(n=='2'):
for k, v in state_capital.items():
print(k, ":", v)
option = input('Would you like to try again?(y/n) ')
Output:
1. Search for a state
2. Print all state and capitals
Choose an option(1/2): 1
Enter state name: Australia
Australia is not in the list.
Would you like to try again?(y/n) y
1. Search for a state
2. Print all state and capitals
Choose an option(1/2): 1
Enter state name: California
The capital of California is Sacramento
Would you like to try again?(y/n) y
1. Search for a state
2. Print all state and capitals
Choose an option(1/2): 2
Montana : Helena
Michigan : Lansing
Georgia : Atlanta
New Mexico : Santa Fe
North Carolina : Raleigh
South Dakoda : Pierre
Wisconsin : Madison
Virginia : Richmond
Wyoming : Cheyenne
Hawaii : Honolulu
Vermont : Montpelier
Alabama : Montgomery
South Carolina : Columbia
California : Sacramento
Nebraska : Lincoln
Delaware : Dover
Mississippi : Jackson
Illinios : Springfield
Kansas : Topeka
Minnesota : St. Paul
Oklahoma : Oklahoma City
Washington : Olympia
Massachusetts : Boston
Utah : Salt Lake City
Neveda : Carson City
Maine : Augusta
Missouri : Jefferson City
New Jersey : Trenton
Arizona : Phoenix
Louisiana : Baton Rouge
New Hampshire : Concord
Idaho : Boise
Rhoda Island : Providence
Pennsylvania : Harrisburg
Iowa : Des Monies
West Virginia : Charleston
Oregon : Salem
Connecticut : Hartford
Arkansas : Little Rock
Florida : Tallahassee
Alaska : Juneau
North Dakota : Bismarck
Tennessee : Nashville
Maryland : Annapolis
New York : Albany
Texas : Austin
Kentucky : Frankfort
Colorado : Denver
Ohio : Columbus
Indiana : Indianapolis
Would you like to try again?(y/n) n
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
For this lab, write a program that lets the user enter a state and the program...
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...
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...
In C++ Write a program that lets the user enter at least 10 values into an array. The program then display the largest and smallest values stored in the array.
Write a program that lets the user enter at least 10 values into an array. The program should then display the largest and smallest values stored in the array. Do it in C++
Python: Write a program that lets the user enter a string and displays the letter that appears most frequently in the string, ignore spaces, punctuation, and Upper vs Lower case. Create a list to hold letters based on the length of the user input Convert all letters to the same case Use a loop to check for each letter in the alphabet Have a variable to hold the largest number of times a letter appears, and replace the value when...
Write a "PYTHON" program to prompt the user to enter a fist name, last name, student ID and GPA. Create a dictionary with the data. Print out the data. Then remove the GPA and print again.
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...
Starting out with python 4th edition Write program that lets the user enter in a file name (numbers.txt) to read, keeps a running total of how many numbers are in the file, calculates and prints the average of all the numbers in the file. This must use a while loop that ends when end of file is reached. This program should include FileNotFoundError and ValueError exception handling. Sample output: Enter file name: numbers.txt There were 20 numbers in the file....
Write a program in C++ that lets the user enter the total rainfall for each of 12 months into an array of doubles. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Input validation: Do not accept negative numbers for monthly rainfall figures.
PYTHON: write a program that lets the user enter a sting and displays te character that appears most frequently in the string. A space can be the most frequent in the string, but do not include it for the count. (Please make it as simple as possible, I just started learning python)