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.
If you want to see the short video I recorded about the test, click here.
In addition to all concepts from Test 2,
Functions
Decisions
- the general syntax of an if statement, with all possible variants (with or without elif, with or without else)
- how to trace a program that include if statements
- how to use if statements to solve simple problems
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)
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]
- Write a program that asks the user for an input string and prints the string on screen without modifications if the string contains an even number of characters, and prints the reverse of the string if it contains an odd number of characters.
- The following is a (silly) large if statement:
a = int(input("Enter a first number "))
b = int(input("Enter a second number "))
c = int(input("Enter a third number: "))
if a > b:
if b > c:
print("Spam")
else:
print("Parrot")
elif b > c:
print("Cheese Store")
if a >= c:
print("Cheddar")
elif a < b:
print("Gouda")
elif c == b:
print("Swiss")
else:
print("Trees")
if a == b:
print("Chestnut")
else:
print("Birch")
print("Done")
Show what would be printed on screen for each of the following inputs:
- 3, 4, 5 (meaning the user enters 3, then 4, then 5)
- 3, 3, 3
- 5, 4, 3
- 3, 5, 2
- 5, 4, 7
- 3, 3, 2
You can copy-paste all this code in Wing101 if you wish to test your answer.
- Other practice problems TBA