0% found this document useful (0 votes)
35 views2 pages

CS125 Introduction To Data Analysis For Social Sciences: Practice Questions For The Midterm Exam

The document contains 6 practice questions for a midterm exam on data analysis in social sciences. The questions cover topics like writing Python programs to count numbers meeting certain criteria, using for loops and finding averages, generating random lists and counting frequencies, extracting lists from strings, working with dictionaries to look up prices and discounts, and formatting names with titles.

Uploaded by

Kemalhan Aydın
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views2 pages

CS125 Introduction To Data Analysis For Social Sciences: Practice Questions For The Midterm Exam

The document contains 6 practice questions for a midterm exam on data analysis in social sciences. The questions cover topics like writing Python programs to count numbers meeting certain criteria, using for loops and finding averages, generating random lists and counting frequencies, extracting lists from strings, working with dictionaries to look up prices and discounts, and formatting names with titles.

Uploaded by

Kemalhan Aydın
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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:

Enter a list of integers (e.g. [1, 2, 3]): [23,11, 14, 54]


The type of input list is: <class 'str'>
The list is: [23, 11, 14, 54]
The type of my list is: <class 'list'>

5. Write a python program that does the following:

• 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.

Item name Price Discount


pencil 2.40 5%
eraser 4.50 10%
sharpener 7.80 20%
crayon 3.00 10%
notebook 8.60 25%

• Displays the dictionary.

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)}

Enter an item name: eraser

Enter an item name: crayon

Enter an item name: notebook


Total price to pay: 13.2

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

Enter name: Alara Baykuş


Enter title: Ms.
Official Name: Baykuş, Ms. Alara

Enter name: STOP


Program complete....

Sample Run 2:
Enter name: Halil Altin
Enter title: Mr.
Official Name: Altin, Mr. Halil

Enter name: quiT


Program complete....

You might also like