I tried my best to list the topics for the exam but I may have forgotten one or two. Your default assumption should be that if I covered it in class before files, it is fair game for the exam.
I will add practice problems as I find new interesting questions, so come back to this page every few days, more practice problems may have appeared.
In addition to all concepts from Test 2,
Lists
- operators on lists
- Accessing specific characters and slices, in particular, difference between accessing an element and doing a slice that includes only one element
- Differences between lists and strings
- List methods, what they look like, how to use them (you do not need to remember all of them, but if I describe one to you, you should be able to use it)
Repetition
- Syntax for the
while
loop and for
loop
- Interactive loop, sentinel loop and counting loop, and how to use them to make a loop end at the desired time
- Accumulator pattern and how to use it to make the loop execute a simple task
- Be able to keep track of values of variables during the execution of a loop
- Be able to use loops to solve simple problems
Practice Problems
- Finish any lab exercises that you did not have time to complete during lab time. Remember, I added a whole page of exercise for the week of Fall break during which we did not have lab.
- Suppose that the assignment myList = ["fish", 3, 5.0, 1729, [7,8,9], 10, 39, 67] was just executed. What value would Python give to each of the following expressions:
- myList[0]
- myList[4]
- myList[2:6]
- myList[0:1]
- myList[1:7:2]
- myList[0][3]
- myList[4][::2]
- myList[:3:-3]
Find a slice of the list in myList
that would evaluate to the following value:
- [3, 5.0, 1729]
- [8,9]
- [39]
- "ish"
- [10, [7,8,9], 1729]
- Determine what would be printed by each of the following pieces of code:
- Assume the user enters the number 30 while running the following:
myList = [5, 17, 45, 30, 29, 18]
lookFor = int(input("Enter a number: "))
i = 0
while i < len(myList) and myList[i] != lookFor:
i = i + 1
print(i)
- What would be printed by the program of the previous question if the user entered 19.
-
for i in range(5):
print("*"*i)
-
for i in range(5):
print("{0:_>5}".format("*"*i))
-
myList = [1,2,3,4,5]
for i in range(len(myList)):
if myList[i] == 4:
myList[i] = 1729
print(myList)
-
currentValue = 2
while currentValue < 100:
print(currentValue)
currentValue = 2 * currentValue + 5
print("DONE")