CSCI120 - Final Exam Study Guide

Last updated: Friday 6th December 2024, 8:10 PT, AD


Final Exam format

Topics to be studied for the final exam:

Python variables, data types and simple processing using 
input, selection and repetition statements.
Python Operator Precedence, Python Lists and Strings, 
List and String methods, Functions, Variable Scope, 
Docstrings, Files, 
Sequential(Linear) Search and Binary Search Algorithms.

 
The topics of String Formatting, File Exception Handling,
Object Oriented Programming, Sorting and Complexity, 
Recursion and Games programming are not on the final exam.


CLICK HERE FOR A LIST OF FINAL EXAM TOPICS IN ORDER OF PRESENTATION ON THE COURSE


Example exam questions for Python 3 Programming:





1.  What is the output of this Python 3 program?

x = 17 / 2 % 2 * 3**3
print (x)
 

Answer:

13.5

(not sure why the answer is 13.5? - you need to study operator precedence.



 
2.  What is the output of this Python 3 program?

print (7 > 10)
print (4 < 16) 
print (4 == 4) 
print (4 <= 4)  
print (4 != 4)  



Answer: 

False
True
True
True
False


 

3.  What is the output of this Python 3 program?


num1 = 5
if num1 >= 91:
    num2 = 3
else:
    if num1 < 6:
        num2 = 4
    else:
        num2 = 2
x = num2 * num1 + 1
print (x,x%7)



Answer: 
21     0







4. Name and give an example of the three types of error
that might be contained in a Python program.

Answer:

syntax error - mis-spelling a keyword
logic error - multiplying when you meant to divide
run-time - an attempt to divide by zero




5. What is an algorithm?


Answer: a written description of the steps to solve a problem.



6. What is a computer program?

Answer: the implementation of an algorithm



7. What is the data type of a value such as 3.142?

Answer: float



8. What is the data type of a value such as 3?

Answer: int



9. What is the data type of a value such as "anne was here"?

Answer: string


10.  What is the output when the following code is executed?

list1 = [2,4,6,8,10,12,14,16,18,20] 
print (list1[0:1],list1[5:7])

Answer:
[2] [12, 14]








11.  What is the output when the following code is executed?

list1 = [1,2,3]
list1 = list1 * 2
print (list1)

Answer:
[1, 2, 3, 1, 2, 3]







12.  What is the output when the following code is executed?

s1 = 'spamandeggs'
x = s1.find('and')
print (x)
print (s1[0:1],s1[5:7])

Answer:
4 
s nd








13.  What is the output when the following code is executed?

s = 'one\ntwo\tthree'
print (s)
print (len(s))

Answer:
one
two	three 
13







14.  What is the output when the following code is executed?

list2 = ["B","C","A"]
list2.extend(["X","Y"]) 
list2.reverse()
list2.append("S")
list2.sort() 
list2.reverse()
print (list2)

Answer:
['Y', 'X', 'S', 'C', 'B', 'A']



15. What is the output when the following code is executed?

f = open("x.txt","w") 
f.write("Where did\nI put my\nloaf\nof bread") 
f.close() 
f = open("x.txt","r") 
string = f.readline()
string = f.readline()
str1 = string.strip()
print(str1)
string = f.readline()
str2 = string.strip()
print(str2)
f.read(4)
string = f.readline()
str3 = string.strip()
print(str3)
print(str2.upper())
print(len(str1))


Answer:

I put my
loaf
read
LOAF
8





Final Exam format

Good Luck!