Question: Problem 1. Make a Dictionary (5 points) Write a function make_dictionary(number) that takes input from the user such as name and major separated by a
Problem 1. Make a Dictionary (5 points)
Write a function make_dictionary(number) that takes input from the user such as name and major separated by a comma and creates a dictionary with keys corresponding to names and values corresponding to majors. The parameter number is an integer that controls how many entries should be added to the dictionary. Your function should work with the following code:
if __name__ == '__main__: d = make_dictionary(3) print(d)
Save the main code and your function in a file named majors.py. You can test your code with input files such as ex1:
python3 dictionary.py < ex1
The contents of the file ex1:
Alice, Anthropology Bob, Biology Carol, Chemistry
Note: The input file may contain less or more lines.
The function should return the following dictionary if the file ex1 is used:
{'Alice': 'Anthropology', 'Bob': 'Biology', 'Carol': 'Chemistry'} Please upload your file majors.py here.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
