1. I have worked through the following presentation, attempting all challenges.
2. Why will the following code produce an error and fail to create any molecules on the screen?
import turtle
def draw_circle(turtle, color, size, x, y):
turtle.penup()
turtle.color(color)
turtle.fillcolor(color)
turtle.goto(x,y)
turtle.begin_fill()
turtle.pendown()
turtle.circle(size)
turtle.penup()
turtle.end_fill()
turtle.pendown()
tommy = turtle.Turtle()
tommy.shape("turtle")
tommy.speed(500)
#create variables
xaxis=-150
yaxis=150
offset=30
for i in range(5):
draw_circle(tommy, "green", size, xaxis, yaxis-offset*i)
draw_circle(tommy, "green", size, xaxis+offset*i, yaxis-120)
3. The following code produces a green molecule on the screen, but we want a red one. What one thing needs to change?
import turtle
def draw_circle(turtle, color, size, x, y):
turtle.penup()
turtle.color(color)
turtle.fillcolor(color)
turtle.goto(x,y)
turtle.begin_fill()
turtle.pendown()
turtle.circle(size)
turtle.penup()
turtle.end_fill()
turtle.pendown()
tommy = turtle.Turtle()
tommy.shape("turtle")
tommy.speed(500)
#create variables
colour="red"
size=30
xaxis=-150
yaxis=130
offset=30
draw_circle(tommy, "green", size, xaxis, yaxis)
draw_circle(tommy, "colour", size, xaxis, yaxis)
draw_circle(tommy, red variable, size, xaxis, yaxis)
draw_circle(tommy, colour="red", size, xaxis, yaxis)
draw_circle(tommy, colour, size, xaxis, yaxis)
4. The last two lines of this program should print two green molecules on the screen (separate from each other) but this is not happening. Why?
import turtle
def draw_circle(turtle, color, size, x, y):
turtle.penup()
turtle.color(color)
turtle.fillcolor(color)
turtle.goto(x,y)
turtle.begin_fill()
turtle.pendown()
turtle.circle(size)
turtle.penup()
turtle.end_fill()
turtle.pendown()
tommy = turtle.Turtle()
tommy.shape("turtle")
tommy.speed(500)
#create variables
colour="red"
size=30
xaxis=-150
yaxis=130
offset=30
draw_circle(tommy, "green", size, xaxis, yaxis)
draw_circle(tommy, "green", size, xaxis, yaxis)
Because both molecules have been created in the same location (on top of each other)
Because the size of the molecules are too great
Because both molecules have the same offset value, which means they will not move
Because the colour variable has been assigned incorrectly
5. Look carefully at the following code. What will be printed to the screen?
import turtle
def draw_circle(turtle, color, size, x, y):
turtle.penup()
turtle.color(color)
turtle.fillcolor(color)
turtle.goto(x,y)
turtle.begin_fill()
turtle.pendown()
turtle.circle(size)
turtle.penup()
turtle.end_fill()
turtle.pendown()
tommy = turtle.Turtle()
tommy.shape("turtle")
tommy.speed(500)
#create variables
size=4
xaxis=-150
yaxis=150
offset=30
for i in range(5):
draw_circle(tommy, "green", size, xaxis, yaxis-offset*i)
draw_circle(tommy, "green", size, xaxis+offset*i, yaxis-120)
draw_circle(tommy, "green", size, xaxis+120, yaxis-offset*i)
An X shape
A square
A U shape
A triangle
6. On what line is the user being asked for input (e.g. to enter the value to be stored in a variable)
7. What is wrong with this for loop?
8. What will the output of this for loop be?
for i in range(2,8):
print(i)
1,2,3,4,5,6,7
2,8
2,3,4,5,6,7
2,7
9. What will the output of this for loop be?
for i in range(5):
print(i)
1,2,3,4
4
1,4,1,4
0,1,2,3,4
10. This code should produce a vertical line of green molecules, but doesn't. What one thing on the last line needs to be changed?
import turtle
def draw_circle(turtle, color, size, x, y):
turtle.penup()
turtle.color(color)
turtle.fillcolor(color)
turtle.goto(x,y)
turtle.begin_fill()
turtle.pendown()
turtle.circle(size)
turtle.penup()
turtle.end_fill()
turtle.pendown()
tommy = turtle.Turtle()
tommy.shape("turtle")
tommy.speed(500)
#create variables
size=4
xaxis=-150
yaxis=150
offset=30
for i in range(6):
draw_circle(tommy, "green", size, xaxis, yaxis-offset*1)
draw_circle(tommy, "green", size, xaxis, yaxis-offset*i)
Nothing needs to change, it would work fine
draw_circle(tommy, "green", size+i, xaxis, yaxis-offset*1)
draw_circle(tommy, "green", size, xaxis, yaxis +offset*1)