I have got a problem in my code and i cant see it

basically i have got the python turtle graphics and i draw something with a turtle called charlie. And i have a eraser that draws with white over charlies graphic. And than i have something that brings charlie back to the start. I also made a 3 times loop where all three things are included.
So, when i run the loop, charlie draws something and the eraser “erases” it. then charlie draws something again but this and the third time the eraser goes over it but doesnt “erase” it. There is not a single penup in the entire eraser code.
Code: https://replit.com/@vades52460/textadventure280823#main.py

Hi @vades52460 , welcome to the forums!
Can you try this code:

import turtle

charlie = turtle.Turtle()

def house(schildkröte, seitenlänge):
  charlie.shape("turtle")
  charlie.color("red")
  charlie.speed("slow")
  charlie.pendown()
  charlie.pensize(3)
  charlie.forward(30)
  charlie.penup()
  charlie.forward(40)
  charlie.pendown()
  charlie.forward(30)
  charlie.left(90)
  charlie.forward(100)
  charlie.left(90)
  charlie.forward(100)
  charlie.left(90)
  charlie.forward(100)
  charlie.left(90)
  charlie.left(180)
  charlie.color("green")
  charlie.forward(100)
  charlie.right(90)
  charlie.backward(30)
  charlie.right(90)
  charlie.forward(100)
  charlie.left(90)
  charlie.forward(30)
  charlie.left(90)
  charlie.forward(100)
  charlie.right(90)
  charlie.backward(30)
  charlie.penup()
  charlie.backward(50)
  charlie.pendown()

ring = turtle.Turtle()
ring.color("white")

def eraser():
  ring.shape("circle")
  ring.color("blue")
  ring.pendown()
  ring.speed("slow")
  ring.pensize(3)
  ring.forward(100)
  ring.left(90)
  ring.forward(100)
  ring.left(90)
  ring.forward(100)
  ring.left(90)
  ring.forward(100)
  ring.right(90)
  ring.forward(100)
  ring.right(90)
  ring.backward(30)
  ring.right(90)
  ring.forward(100)
  ring.left(90)
  ring.forward(30)
  ring.right(90)

def back_to_place(schildkröte, seitenlänge):
  charlie.forward(80)
  charlie.right(90)
  charlie.forward(100)

def muster():
  for i in range(3):
    house(charlie, 100)
    eraser()
    back_to_place(charlie, 100)
  
muster()


The code actually messed it up a bit more. I used the turtle.clear function and it worked pretty well.
Thank you tho for trying to help me:)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.