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 the end of "if" statements, 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 1,
Strings
- Delimiters, how to use them, how to have delimiter characters inside a string
- operators on strings
- Accessing specific characters and slices
- String 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)
Objects and Graphics
- Rough (very rough) idea of what an object is
- If I describe one or two of the objects that we have used in the graphics library in a way similar to the way they are described in graphics.pdf, you should be able to use it
Functions
- the syntax of a function definition
- how to use input parameters in a function
- how to use a return statement
Practice Problems
- Explain why there are so many string delimiters.
- Suppose you want to only ever use the single quote as a string delimiter. Explain how you would write strings that contain the single quote as a character.
- Suppose that the assignment
myString = "a completely random string"
was just executed. What value would Python give to each of the following expressions:
- myString[20:-1]
- myString[20::-1]
- myString[:5]
- myString[1:15:3]
Find a slice of the string contained in myString
that would evaluate to the following values:
- Write a function that takes two input parameters, a number of feet and a number of inches that, together, describe someone's height, and outputs a floating-point number that correspond that height in meters. Remember that there are 2.54 centimeters in an inch, 12 inches in a foot and 100 centimeters in a meter.
- Determine what would be printed on screen by the following snippets of code:
def aPrintingFunction():
print("I'm printing stuff!")
print("all done")
def headAndTail(inputString):
s = inputString[:2] + inputString[-2:]
return s
print(headAndTail("Supercalifragilisticexpialidocious"))
- Write a program that creates a graphic window that is 300 pixels wide and 200 pixels high. In the window, draw a 100 x 100 yellow square with a black outline, and inside it, draw a red circle with a black outline whose center is the center of the square such that the perimeter of the circle barely touches the sides of the square.
- An coffee shop sells coffee online at 13.99 a pound plus the cost of shipping. Each order ships for 1.15 per pound, plus a 2.50 fixed cost. A 3% state tax is also applied before the cost of shipping is added. Write a function that takes the weight of an order as its input parameter and returns the cost of the order.
- Write a function that takes a string containing many words as its input parameter and returns the number of words contained in the string. To do this the string method
count
should be useful, look it up in the Python Documentation.
- Write a function that, like in the previous problem, takes a string containing many words as its input parameter and returns the average length of the words containined in the string. For this, you will need the function
len
, which takes a string as its input parameter and returns the length of the string.