Anda di halaman 1dari 1

COMP102-Programing I

Assignment 04
Submit one .py file with all the scripts that answer the following questions. Your file
name should be Name_RollNumber.py.

Submit before 16th Dec, 2018. 11:45PM

Disclaimer: Zero tolerance on plagiarism

Question 1: Take 3 sets as input, merge them in one set and find the average.

Question 2: Write a program that keeps a dictionary in which both keys and values are strings—
names of students and their course grades. Prompt the user of the program to add or remove
students, to modify grades, or to print all grades. The printout should be sorted by name and
formatted like this:
Carl: B+
Joe: C
Sarah: A
Francine: A

Questions 3: Write a program that asks a user to type in two strings and that prints
• the characters that occur in both strings.
• the characters that occur in one string but not the other.
• the letters that don’t occur in either string. (Create a set of all characters a-z, A-Z
and then proceed with the solution)
Use the set function to turn a string into a set of characters.

Question 4: A multiset is a collection in which each item occurs with a frequency. You might have
a multiset with two bananas and three apples, for example. A multiset can be implemented as a
dictionary in which the keys are the items and the values are the frequencies. Write Python
functions union, intersection, and difference that take two such dictionaries and return a dictionary
representing the multiset union, intersection, and difference. In the union, the frequency of an item
is the sum of the frequencies in both sets. In the intersection, the frequency of an item is the
minimum of the frequencies in both sets. In the difference, the frequency of an item is the
difference of the frequencies in both sets, but not less than zero.

Question 5: Write a program that reads the data from


https://www.cia.gov/library/publications/the-world-factbook/rankorder/rawdata_2004.txt into a
dictionary whose keys are country names and whose values are per capita incomes. Then the
program should prompt the user to enter country names and print the corresponding values. Stop
when the user enters quit.

Anda mungkin juga menyukai