1.6. ExercisesΒΆ

  1. Evaluate the following numerical expressions in your head, then use the active code window to check your results:

    1. 5 ** 2
    2. 9 * 5
    3. 15 / 12
    4. 12 / 15
    5. 15 // 12
    6. 12 // 15
    7. 5 % 2
    8. 9 % 5
    9. 15 % 12
    10. 12 % 15
    11. 6 % 6
    12. 0 % 7
    1. 5 ** 2  = 25
    2. 9 * 5 = 45
    3. 15 / 12 = 1.25
    4. 12 / 15 = 0.8
    5. 15 // 12 = 1
    6. 12 // 15 = 0
    7. 5 % 2 = 1
    8. 9 % 5 = 4
    9. 15 % 12 = 3
    10. 12 % 15 = 12
    11. 6 % 6 = 0
    12. 0 % 7 = 0
  1. What is the order of the arithmetic operations in the following expression. Evaluate the expression by hand and then check your work.

    2 + (3 - 1) * 10 / 5 * (2 + 3)
    
  1. Create a turtle and assign it to a variable. When you print its type, what do you get?

  1. data-2-6: Turtle objects have methods and attributes. For example, a turtle has a position and when you move the turtle forward, the position changes. Think about the other methods shown in the summary above. Which attibutes, if any, does each method relate to? Does the method change the attribute?

  1. Write a program to draw a shape like this:

    ../_images/star.png
  1. On a piece of scratch paper, trace the following program and show the drawing. When you are done, press run and check your answer.

  1. Write a program to draw some kind of picture. Be creative and experiment with the turtle methods provided in the Python documentation for this module.

Next Section - 2. Expressions and Evaluation