CS125 Introduction To Data Analysis For Social Sciences: Practice Questions For The Midterm Exam
CS125 Introduction To Data Analysis For Social Sciences: Practice Questions For The Midterm Exam
1. Write a Python program to count and display those numbers between 280 and 3500 which are
divisible by 7 and are a multiple of 4.
2. Write a for loop that finds the average of 6 values entered by the user. If the user enters a negative
number stop inputting values, and do not include the negative value in the average.
3. Write a python script to create a list with 10 elements that are randomly generated integers between
the interval [1-20] (inclusive). Then find and display how many times each number appears in the
list. Do not repeat a value that has already been displayed. [Hint: you may use the count() function
to count the number of occurrences of a given list element. E.g. my_list.count(3) counts the
number of occurrences of the number 3 in my_list.]
Sample Run:
The list is: [16, 1, 2, 16, 15, 3, 3, 3, 14, 1]
The number 16 appears 2 times.
The number 1 appears 2 times.
The number 2 appears 1 times.
The number 15 appears 1 times.
The number 3 appears 3 times.
The number 14 appears 1 times.
4. Write a python script to extract the elements of an integer list from a given input string and create a
list of integers. E.g. the user enters the string '[1, 2, 3]’ and the list my_list = [1, 2, 3]
is created. Make sure the type of my_list is a list. See sample run.
Sample Run:
• Creates a dictionary containing the names of 5 items (as keys) and the prices and discount
percentages for the items as a tuple associated with each key. The dictionary data is provided in
the table below.
1
• Retrieves 3 item names from the user and calculates and displays the total price to be paid for
those items. (Note: the associated discount percentage should be applied to each item’s price.)
Sample Run:
Dictionary is:
{'pencil': (2.4, 0.05), 'eraser': (4.5, 0.1), 'sharpener': (7.8, 0.2),
'crayon': (3.0, 0.1), 'notebook': (8.6, 0.25)}
6. Write a program that inputs the names and titles of people and displays the formal name in the
format 'surname, title name. Assume that each name has at most one surname. Stop inputting when
the user enters stop or quit for the name (not case sensitive). The user may enter a maximum of
15 names.
Sample Run 1:
Enter name: Mert Yiğit Samsun
Enter title: Prof.
Official Name: Samsun, Prof. Mert Yiğit
Sample Run 2:
Enter name: Halil Altin
Enter title: Mr.
Official Name: Altin, Mr. Halil