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 on or before Friday February 7, it is fair game for the exam. If you have a specific question about whether a topic could be part of the exam, please come to ask me.
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.
Programs
- what are their main components
- difference between a program and an algorithm
Values, Variables, Expressions and Assignments
- different types of values you can find in a Python program
- type conversion
- variables: what they are, what they store, Python rules for their names
- variable naming schemes: CamelCase and snake_case
- expressions: what they are, how they are evaluated
- assignments: what they are, what they look like
Input and Output
- input and print statements and how to use them
- how to use formatted output - do not memorize all the codes, but have a general idea of what the format specification looks like
Math with Python
- types of numbers, their strengths and limitations
- operators for numbers
- order of operations
- from float to int: truncating, Python rounding and how to round up the way we are used to
- the math library and how to use it (no need to memorize all the functions in it)
Strings in Python
Removed from test material.
Practice Problems
- Are the following valid names (as far as Python is concerned) for a variable?
- 10more
- uu123___qwerqwerqwerq
- __1212__1212
- IMSCREAMING
- @comp115
- variable!
- Practice using camel case and snake case for variable names consisting of any 2 or 3 words of your choice.
- What is the type or each of the following expressions?
- 5
- 4.5
- "a number"
- True
- [1,2,3]
- 2 * 5
- 2 + 5.0
- 54 / 9
- 35 % 3
- float(3) + 5
- To what value would Python evaluate each of the following expressions?
- 3 * 5
- 40 / 8
- 40 // 8
- 2 ** 5.0
- int(2.3) + 5
- float(7) * 2
- int(-6.5)
- round(-6.5)
- int(-7.5)
- round(-7.5)
- Knowing that sin and cos are functions in the math library, and that pi and e are constants in the math library, write a Python expression that would calculate the following
- $\cos(x + y)$
- $e^{2\pi}$
- $\frac{n+1}{n-1}$
- $\sin(a^5 + b^5)$
- Determine what would be printed on screen as a result of executing the following code:
userInput1 = int(input("Please enter an integer: "))
userInput2 = float(input("Please enter a floating-point number: "))
calc1 = userInput1 ** 2
calc2 = userInput1 / 5
calc3 = userInput2 * 3
print("The first value is", calc1)
print("The second value is {0:3.1f} calculated from {1}".format(calc2, userInput1))
print("The last value is {0:3.1f}".format(calc3))
Assume that the user enters the value 11 and 3.1 as input.
- A gas station sells diesel at $2.799 per gallon. Write a program that asks the user how many gallons of diesel they would like to buy and displays the amount. The amount displayed should be rounded to the closest cent, with the 0.5cent rounded up.