Question

Python Write the contents of the function below. It should build a dictionary with keys and...

Python

Write the contents of the function below. It should build a dictionary with keys and
values. For each such entry, it must enter two rows from the keyboard. The first line should
constitute the key to be stored in a form with only capital letters. The user enters the value on
the next row. This should be stored as an integer. If you enter a blank line as the key, the lock should
end and the dictionary is returned.

def read_uppercase_keys_and_ints():

"""Reads two lines per entry, one with key, one with value, stores all entries in a dictionary, which is returned.

Keys are stored as UPPERCASE only, values as ints. Input is stopped by entering an empty line as key."""

Homework Answers

Answer #1
#funtion
def read_uppercase_keys_and_ints():
  dic = {}
  while(True):
    #user input for key
    key = input("Enter the key:")
    #if key is not blank line then if condition will execute otherwise breaks
    if(key!=''):
      key = key.upper() #key in uppercase
      #user input for value of key 
      value = int(input("Enter value for key:")) 
      dic[key] = value
    else:
      break
  return dic #returns dictionary


#function call and prints the dictionary
content = read_uppercase_keys_and_ints()
print(content)

Output::

Note:: if any query please comment i will solve.

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 with correct indentation that creates a dictionary containing the U.S. states as keys...
Write a Python  program with correct indentation that creates a dictionary containing the U.S. states as keys and their abbreviations as values. The program should then randomly quiz the user by displaying the abbreviation and asking the user to enter that state's name. The program should keep a count of the number of correct and incorrect responses, as well as which abbreviation the user missed. You should include the following: Mainline logic and functions Error handling Dictionaries A file is attached...
Please create a python module named homework.py and implement the functions outlined below. Below you will...
Please create a python module named homework.py and implement the functions outlined below. Below you will find an explanation for each function you need to implement. When you are done please upload the file homework.py to Grader Than. Please get started as soon as possible on this assignment. This assignment has many problems, it may take you longer than normal to complete this assignment. This assignment is supposed to test you on your understanding of reading and writing to a...
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...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
Attention:- Your code should follow all the below instruction. Specification The file has entries like the...
Attention:- Your code should follow all the below instruction. Specification The file has entries like the following Barnstable,Barnstable,1 Bourne,Barnstable,5 Brewster,Barnstable,9 ... This code should create a dictionary where the county is the key and then total number of cases for the country is the value. The code should print the name of the county with the highest number of cases along with the total cases. The code must only use below 3 functions open_file_read cases_dictionary_create highest_cases This code must read...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...