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."""
#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.
Get Answers For Free
Most questions answered within 1 hours.