1.6. ExercisesΒΆ
-
Evaluate the following numerical expressions in your head, then use the active code window to check your results:
5 ** 2
9 * 5
15 / 12
12 / 15
15 // 12
12 // 15
5 % 2
9 % 5
15 % 12
12 % 15
6 % 6
0 % 7
5 ** 2 = 25
9 * 5 = 45
15 / 12 = 1.25
12 / 15 = 0.8
15 // 12 = 1
12 // 15 = 0
5 % 2 = 1
9 % 5 = 4
15 % 12 = 3
12 % 15 = 12
6 % 6 = 0
0 % 7 = 0
-
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)
-
Create a turtle and assign it to a variable. When you print its type, what do you get?
-
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?
-
Write a program to draw a shape like this:
-
On a piece of scratch paper, trace the following program and show the drawing. When you are done, press
run
and check your answer.
-
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.