On python
a) Create a dictionary with 5 to 10 key-values so that state is the key and its capital is the value. Print the dictionary and its length.
b) Create and print a list of states and a list of capitals.
c) Ask the user for a state's name. Check to see if the state's name exists in the list of states. If it does, look up the state's name in the dictionary and print out its capital. If it doesn't notify the user.
# part a dictionary = {"AP":"amaravathi", "karnataka":"bangaluru", "thamilnadu":"chennai", "state1":"capital1", "state2":"capital2"} # part b print("states:",list(dictionary.keys())) print("capitals:",list(dictionary.values())) # part c state = input("Enter state: ") if state in dictionary.keys(): print("Capital of",state,"is",dictionary[state]) else: print(state,"not in the dictionary")
Get Answers For Free
Most questions answered within 1 hours.