0% found this document useful (0 votes)
28 views4 pages

Allowed: String/List Note Sheet & One Side of One 8.5 by 11 Inch Paper With Hand Written Notes

This document provides instructions for a midterm exam in CSC 201. It includes 10 multiple choice and short answer questions testing Python concepts like data types, operators, strings, lists, files, and loops. Students are allowed to use a note sheet and handwritten notes for reference while taking the exam.

Uploaded by

Hồng Hiếu
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)
28 views4 pages

Allowed: String/List Note Sheet & One Side of One 8.5 by 11 Inch Paper With Hand Written Notes

This document provides instructions for a midterm exam in CSC 201. It includes 10 multiple choice and short answer questions testing Python concepts like data types, operators, strings, lists, files, and loops. Students are allowed to use a note sheet and handwritten notes for reference while taking the exam.

Uploaded by

Hồng Hiếu
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/ 4

CSC 201—Fall 2019 Name: ______________________________________

Midterm 1—Part 1—60 points of 100 total points


Allowed: String/List note sheet & one side of one 8.5 by 11 inch paper with hand written notes

1. (1 pt each) Write True or False

________ a. If data = ['Today', 'is', 'Wednesday'], then len(data) is 16, the number of characters in the list.

________ b. Python is a case sensitive programming language.

________ c. If num = 16, then num // 3 = 5 and num % 3 = 1.

________ d. If average = 315.87342, then the statement print(f'Average: {average:.5f}') will output
Average: 315.87
________ e. To generate a random integer from 1 to 6 inclusive use the expression random.randrange(1, 7).

2. (1 pt) If you want to use the sqrt function from the math module in your Python code, what statement do you need to
include first?

________________________________

3. (1 pt each) Decide whether each is a valid or invalid identifier for a Python variable. Circle valid or invalid.

a. midterm1Score valid invalid c. quiz%Score valid invalid

b. 2nd_place_score valid invalid d. my_dog's_name valid invalid

4. (2 pts each) Evaluate each Python expression and give its resulting value. Make sure to give a value of the appropriate
type (such as including a .0 at the end of a float).

a. 20 – 15 % 2 * 4 b. 2 * 3 ** 2 + 5 c. 7 / 2 + 7 // 2

5. (4 pts) What is the difference between what is stored in the variable data when the two code snippets execute?
Describe what is stored including its type (int, float, str, or list).

f_in = open("information.txt", "r") f_in = open("information.txt", "r")


data = f_in.readline() data = f_in.readlines()
6. (8 pts) Give the value and type of each variable requested. The type should be int, float, str (string), or list.
a = 'Halloween is coming'
b = "jack o'lanterns"
c = ['ghosts', 'goblins', 'witches', 'black cats']

value type

d = a[5] + b[-2] d _________________________________ ____________

e = a.split() e _________________________________ ____________

f = c[:2] f _________________________________ ____________

g = b.find('a') g _________________________________ ____________

h = len(a) h _________________________________ ____________

j = b[g:8] j _________________________________ ____________

k = c[2] k _________________________________ ____________

m = a[4] * 3 m _________________________________ ____________

7. (4 pts each) Write what will be printed to the console when each of the following snippets of code is executed. Be
very clear with spacing, line breaks, etc. Write your final answer clearly in each box.

a. a = 12
b = 7
c = a + b
b = b + 2
a = a - b
c = c + a
print(a)
print(b)
print(c)

b. value = 10
for num in range(1, 12, 3):
print(num)
value = value + num
print(value)
c. animal = 'antelope'
stop = len(animal) - 2
for i in range(1, stop):
part = animal[:i]
print(part)
print(animal)

d. x = 12
y = 16
if x > y:
print('A')
if x % 2 == 0:
print('B')
elif y % 2 == 0:
print('C')
else:
print('D')
print('E')

e. x = 4
y = 0
if x > 0:
print('A')
if y < 0:
print('B')
elif y > 0:
print('C')
print('D')
else:
print('E')
if y < 0:
print('F')
elif y > 0:
print('G')
else:
print('H')
print('I')
print('J')
On the next two problems you will be writing code. Indention within your code must be clear.
8. (6 pts) Write code using a loop to generate 100 random numbers each random number from 10 to 50 inclusive. Output
each random number generated and the maximum of those numbers. See sample output.
Sample Output

21
32
14
41
.
. continue to output
. the numbers
.
.
Maximum: 47

9. (6 pts) Each line of a file "data.txt" contains a one-word name followed by two integer test scores separated by spaces
(see sample below for sample lines in the file). Write code to read through the file and print each name followed by
the average of its two test scores in the console window (see sample output).
data.txt output

Smith 80 90 Smith 85.0


King 85 92 King 88.5
Fitzgerald 72 66 Fitzgerald 69.0
Donner 76 81 Donner 78.5
. .
. .
. .

You might also like