Final Review Worksheet: CMSC 201 Spring 2019 Name
Final Review Worksheet: CMSC 201 Spring 2019 Name
1. Suppose you know myInt is an integer and intString is a string representing an integer. For
example, myInt is 3 and intString is '24'. Write a function that takes them both in, and prints
out the arithmetic sum of the two. In the example given, 27 would be printed.
9. The code below has seven errors for you to find and correct.
11. Write code that continuously takes input from the user using a while loop, and adds that input
to the end of a list. When they enter "quit" the program should print the list twice (once in the
given order, and once in reverse) before terminating.
13. Write a function that uses recursion to find the maximum number in a list.
14. Write a function that creates and returns a 2D list, where the contents count up, while the size of
the “inner” lists goes down in size. For example, with an input of 4, the list would look like
[ [1, 2, 3, 4], [5, 6, 7], [8, 9], [10] ]
15. Write a function that takes in an integer and determines if it is a power of 2, returning True or
False. (Powers of 2 include 1, 2, 4, 8, 16, 32, 64, etc.)
17. Study with friends! Write up and test a piece of code for one of problems above. Then, remove
some of the pieces and replace them with blanks. Give it to your friend to fill in, and have them
do the same for you. Or, you could add in some errors to the code, and challenge them to fix it.
18. For each of the short programs below, circle and explain any errors you find. (There may be
more than one in a single statement! A statement may also be error-free.) You can assume that
variables are initialized and contain what their names indicate (e.g., int1 is an integer, etc.)
c. def printStatement(num1):
print( str(num1) * int(num1) )
def main():
print( printStatement(5) )
19. More debugging – the code below has eight errors.
22. Given an example of each of the following types of errors: syntax, runtime, and logic.
23. You should also know the following concepts, topics, and/or how to code them:
a. File I/O
i. Including how to use split() and strip() correctly
b. Selection Sort, Bubble Sort, and Quicksort
i. (Don’t need to code them, but should know how they work and their run times)
c. Linear search and binary search (again, should know how they work and their run times)
d. Creating and printing 2D and 3D lists
e. Creating, updating, and removing elements of a dictionary
f. Recursion!
i. (If you skipped or didn’t understand Labs 11 or 12, you should look at them)
g. Recursion!
The final covers more topics, and more difficult topics (recursion, 3D lists, file I/O,
searching and sorting) than either of the midterms. It will be a more difficult exam!