14.7 Exercises

From Foundations of Python ProgrammingGNU FDL 1.3Original pagePython2 class periods7 exercises5 graded tests

README.md

14.7 Exercises

Read first in the book: 14.3 The Listener Loop, 14.4 Randomly Walking Turtles, 14.5 Break and Continue, 14.6 Infinite Loops.

Exercise 1

1. Using a while loop, create a list numbers that contains the numbers 0 through 35. Your while loop should initialize a counter variable to 0. On each iteration, the loop should append the current value of the counter to the list and the counter should increase by 1. The while loop should stop when the counter is greater than 35.

Open the 01 folder and edit main.py. Run Tests checks it.

Exercise 2

Using a while loop, create a list called L that contains the numbers 0 to 10. (i.e.: Your while loop should initialize a counter variable to 0. On each iteration, the loop should append the current value of the counter variable to L and then increase the counter by 1. The while loop should stop once the counter variable is greater than 10.)

Open the 02 folder and edit main.py. Run Tests checks it.

Exercise 3

Using a while loop, create a list called nums that contains the numbers 0 though 20. (i.e: your while looop should initialize a counter variable on 0. During each iteration, the loop should append the current value of the counter variable to nums and then increase the counter by 1. The while loop should stop once the counter variable is greater than 20)

Open the 03 folder and edit main.py. Run Tests checks it.

Exercise 4

Modify the walking turtle program so that rather than a 90 degree left or right turn the angle of the turn is determined randomly at each step.

Open the 04 folder and edit main.py. This one is not graded, so check it yourself.

Exercise 5

Modify the turtle walk program so that you have two turtles each with a random starting location. Keep the turtles moving until one of them leaves the screen.

Open the 05 folder and edit main.py. This one is not graded, so check it yourself.

Exercise 6

Create a while loop that initializes a counter at 0 and will run until the counter reaches 50. If the value of the counter is divisible by 10, append the value to the list, tens.

Open the 06 folder and edit main.py. Run Tests checks it.

Exercise 7

Use a while loop to iterate through the numbers 0 through 35. If a number is divisible by 3, it should be appended to a list called three_nums.

Open the 07 folder and edit main.py. Run Tests checks it.

For teachers

14.7 Exercises

Students read Foundations of Python Programming's “Exercises” in CS Room and work through its 7 Python coding exercises (5 graded).

  • Time: 2 class periods
  • Tests: 5 in 5 graded exercises, set up for you when you import the lesson

Reading first

Exercises

FolderGradingTests
01Autograded1
02Autograded1
03Autograded1
04Not graded; students check it themselves0
05Not graded; students check it themselves0
06Autograded1
07Autograded1