7.15 Chapter Assessment
From Foundations of Python ProgrammingGNU FDL 1.3Original pagePython2 class periods8 exercises7 graded tests
7.15 Chapter Assessment
Check your understanding
Exercise 1
Write one for loop to print out each character of the string my_str on a separate line.
Open the
01folder and editmain.py. Run Tests checks it.
Exercise 2
Write one for loop to print out each element of the list several_things. Then, write another for loop to print out the TYPE of each element of the list several_things. To complete this problem you should have written two different for loops, each of which iterates over the list several_things, but each of those 2 for loops should have a different result.
Open the
02folder and editmain.py. Run Tests checks it.
Exercise 3
Write code that uses iteration to print out the length of each element of the list stored in str_list.
Open the
03folder and editmain.py. Run Tests checks it.
Exercise 4
Write a program that uses the turtle module and a for loop to draw something. It doesn't have to be complicated, but draw something different than we have done in the past. (Hint: if you are drawing something complicated, it could get tedious to watch it draw over and over. Try setting .speed(10) for the turtle to draw fast, or .speed(0) for it to draw super fast with no animation.)
Open the
04folder and editmain.py. This one is not graded, so check it yourself.
Exercise 5
Write code to count the number of characters in original_str using the accumulation pattern and assign the answer to a variable num_chars. Do NOT use the len function to solve the problem (if you use it while you are working on this problem, comment it out afterward!)
Open the
05folder and editmain.py. Run Tests checks it.
Exercise 6
addition_str is a string with a list of numbers separated by the + sign. Write code that uses the accumulation pattern to take the sum of all of the numbers and assigns it to sum_val (an integer). (You should use the .split("+") function to split by "+" and int() to cast to an integer).
Open the
06folder and editmain.py. Run Tests checks it.
Exercise 7
week_temps_f is a string with a list of fahrenheit temperatures separated by the , sign. Write code that uses the accumulation pattern to compute the average (sum divided by number of items) and assigns it to avg_temp. Do not hard code your answer (i.e., make your code compute both the sum or the number of items in week_temps_f) (You should use the .split(",") function to split by "," and float() to cast to a float).
Open the
07folder and editmain.py. Run Tests checks it.
Exercise 8
Write code to create a list of numbers from 0 to 67 and assign that list to the variable nums. Do not hard code the list.
Open the
08folder and editmain.py. Run Tests checks it.
For teachers
7.15 Chapter Assessment
Students read Foundations of Python Programming's “Chapter Assessment” in CS Room and work through its 8 Python coding exercises (7 graded).
- Time: 2 class periods
- Tests: 7 in 7 graded exercises, set up for you when you import the lesson
Exercises
| Folder | Grading | Tests |
|---|---|---|
01 | Autograded | 1 |
02 | Autograded | 1 |
03 | Autograded | 1 |
04 | Not graded; students check it themselves | 0 |
05 | Autograded | 1 |
06 | Autograded | 1 |
07 | Autograded | 1 |
08 | Autograded | 1 |