Skip to main content

Section 4.17 Chapter Assessment

Check your understanding

Checkpoint 4.17.1.

Write one for loop to print out each character of the string my_str on a separate line.

Checkpoint 4.17.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.

Checkpoint 4.17.3.

Write code that uses iteration to print out the length of each element of the list stored in str_list.

Checkpoint 4.17.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.)

Checkpoint 4.17.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!)

Checkpoint 4.17.6.

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.

Checkpoint 4.17.7.

    Given the following output, frame, and arrow indicators, what happens in the next step?
  • 0 is printed
  • Not quite, as shown, 0 has already printed
  • 1 is printed
  • Not quite, The next line to execute is at the top of the for loop, not the print
  • The variable i checks for the end of the loop
  • Correct! The code needs to check the list and see if there is anything left to do (line 1). Once it realizes it still has numbers to process, the loop continues.
  • An error is thrown
  • Not quite, this code runs properly, try it yourself.

Checkpoint 4.17.8.

    :
    The red arrow is still pointing to line 6 but we can see in the global frame that j is β€˜o’. Why is the next line to execute line 6?
  • Because ’o’ gets printed twice
  • Not quite, there is no reason for ’o’ to print again
  • Because the loop starts again
  • Not quite, once a loop finishes running in its entirety, it can’t hop back up to run again
  • Because the code is checking for another iteration
  • Correct! The code needs to check in the list and see if there is anything left to do (line 6). Once it realizes there isn’t, the code block completes
  • Because there is an error in the code
  • Not quite, this code runs properly, try it yourself.

Checkpoint 4.17.9.

The next line that the interpreter evaluates first before considering execution is shown with the red arrow (line 4).
Give the number (integer value only) for the line of code that will fully execute next?
You have attempted of activities on this page.