Question

On python a) Create a dictionary with 5 to 10 key-values so that state is the...

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.

Homework Answers

Answer #1
# 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")

Know the answer?
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
Similar Questions
Write a Python program to create a dictionary from two lists without losing duplicate values. If...
Write a Python program to create a dictionary from two lists without losing duplicate values. If there is more values in the key list, then provided key should return an empty set if there is no match. (Hint: use defaultdict) Example: class_list = ['Class-V', 'Class-VI', 'Class-VII', 'Class-VIII','Class-IX'] id_list = [1, 2, 2, 3] Output: assuming you store the values in a data structure named temp print(temp["Class-V"]) # {1} print(temp["Class-IX"]) # set() can you please try and do on google colab
Create a new dictionary called quantities using {} format like. Complete the following: Put these values...
Create a new dictionary called quantities using {} format like. Complete the following: Put these values (quantity, price) in your quantities dictionary: "baskets": (4, 2.49) "boxes": (2, 1.95) "bags": (5, 1.29) "crates": (3, 5.99) Print the quantities dictionary Loop through each key in quantities. For each key, print out the key along with its corresponding quantity. Print the answer in the following format: baskets: 4 boxes: 2 bags: 5 crates: 3 Print the total number of items (should be 14)....
PYTHON Ask the user for a value N (0 ≤ N < 10) Create a 2-D...
PYTHON Ask the user for a value N (0 ≤ N < 10) Create a 2-D list in an N X N structure with integers 1-(N*N) Print the list created Reverse the list such that (1) each list in the 2D list is reversed and (2) the order of each list in the outer list is reversed (see example) Print the reversed list Example Execution What size 2D list would you like to create? N> 3 The original list is:...
Write a program that sorts the content of a map by Values. Before we start, we...
Write a program that sorts the content of a map by Values. Before we start, we need to check the explanation of Java Map Interface and Java LinkedHashMap. This program can be implemented as follows: 1. Create a LinkedHashMap class <String (Country), String(Capital)> that stores Capitals of FIVE countries. 2. Use sortMap() for receiving content of the created class of LinkedHashMap and reorder it in a sorted Map. (sort in natural order). 3. You need to transfer the map into...
Using python 3.5 or later, write the following program. A kidnapper kidnaps Baron Barton and writes...
Using python 3.5 or later, write the following program. A kidnapper kidnaps Baron Barton and writes a ransom note. It is not wrriten by hand to avoid having his hand writing being recognized, so the kid napper uses a magazine to create a ransom note. We need to find out, given the ransom note string and magazine string, is it possible to given ransom note. The kidnapper can use individual characters of words. Here is how your program should work...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm to work along with a worked exercise from Chapter 5. Use two different looping strategies for different purposes. Prior Task Completion: 1. Read Chapter 05. 2. View Chapter 05’s video notes. 3. As you view the video, work along with each code sample in PyCharm using the Ch 5 Iteration PPT Code Samples.zip. Important: Do not skip the process of following along with the...
Create a currency class, up to 5 individual currencies, with four attributes - currency name, whole...
Create a currency class, up to 5 individual currencies, with four attributes - currency name, whole parts and fractional parts and fractional's name such that 100 fractional parts equals 1 whole part, e.g. Pound, 1, 55, pence or Euro, 3, 33, cent. Define overloaded operators to add or subtract different currency objects - care should be taken that you can only perform these operation on objects of the same currency. Also, take care that fractional parts roll into whole parts....
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all user information from a given input file. The input file contains information of a user in following order: username, first name, last name, password, account number and account balance. Information is separated with ‘|’. o username is a unique information, so no two users will have same username. Sample input file: Username eaglebank has password 123456, account number of BB12 and balance of $1000....
So, i have this code in python that i'm running. The input file is named input2.txt...
So, i have this code in python that i'm running. The input file is named input2.txt and looks like 1.8 4.5 1.1 2.1 9.8 7.6 11.32 3.2 0.5 6.5 The output2.txt is what i'm trying to achieve but when the code runs is comes up blank The output doc is created and the code doesn't error out. it should look like this Sample Program Output 70 - 510, [semester] [year] NAME: [put your name here] PROGRAMMING ASSIGN MENT #2 Enter...
Instructions: Step 1: Create UNF Relation from a User View. The goal here is to create...
Instructions: Step 1: Create UNF Relation from a User View. The goal here is to create a single relation for the data found in the user view. The method used is: •   Examine the user view •   Identify all attributes •   Describe the user view using DBDL Here is an example of a user view. This reports lists the customers of the Premiere Corporation. Premiere Corporation Customer List CustNo   Name   Street   City   State   ZipCode   SalesRepNo 124    Sally Adams   482...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT