Okay, so here is the exercise I'm trying to complete. Create a turtle object in turtle graphics in a coin field, with each coin an object itself. Make the turtle randomly move while simultaneously collecting/eating coins(in my while loop, I used the random generator). As the turtle collects a coin, the turtle gets bigger and the coins should dissapear from the screen(also in my while loop, I made the shapesize increase,the coin it contacted white). When the turtle leaves the coin field boundaries, the turtle should stop and a score should be printed (in my while loop, I have two conditionals for this and I increased the score in the while loop).
The problem is, I keep getting errors, that I don't understand, which means I don't know if my code works or not. So can you help me by spotting the error(s) and seeing if my code works? Thanks.
The problem is, I keep getting errors, that I don't understand, which means I don't know if my code works or not. So can you help me by spotting the error(s) and seeing if my code works? Thanks.
Code:
from turtle import *
from random import *
s = Screen()
s.setup(560,560)
s.title("A turtle collecting coins!!")
s.tracer(False)
writer = Turtle(visible = False)
writer.penup()
writer.goto(0, -275)
coins = []
for i in range(-4,5):
for j in range(-4, 5):
c = Turtle(shape="circle")
c.color("", "orange")
c.shapesize(0.5)
c.goto(40*i, 40*j)
coins.append(c)
s.tracer(True)
Molly=Turtle(shape="turtle")
Molly.color("","green")
Molly.shapesize(1)
Molly.goto(-175,-175)
score=0
while True:
Molly.fd(randint(10,30))
if Molly.distance(c)<15:
c.color("","white")
Molly.shapesize+=1
score+=1
Molly.rt(randint(0,360))
if Molly.distance(c)<15:
c.color("","white")
Molly.shapesize+=1
score+=1
Molly.bk(randint(10,30))
if Molly.distance(c)<15:
c.color("","white")
Molly.shapesize+=1
score+=1
Molly.bk(randint(10,30))
if Molly.distance(c)<15:
c.color("","white")
Molly.shapesize+=1
score+=1
Molly.lt(randint(0,360))
if Molly.distance(c)<15:
c.color("","white")
Molly.shapesize+=1
score+=1
if Molly.xcor()<-175 or >175:
write("Score:"+str(score),align="center",font=("Courier",14,bold))
break
if Molly.ycor()<-175 or >175:
write("Score:"+str(score),align="center",font=("Courier",14,bold))
break
Comment