Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python turtle problem

Blue

New Coder
I'm new to this so sorry if I'm doing this wrong.
I keep getting this error and not sure how to fix it.
file:///C:/Users/Ava%20Garay/Desktop/Error.JPG

Python:
while True:
    askQuestion = input( 'Pick between a dog or a cat: ' )
    
    if askQuestion == "cat":
        print( 'Good choice!' )
        break
    elif askQuestion == "dog":
        print( 'Too bad! you get a cat. ' )
        break
    else:
        print( 'Please choose between a dog or a cat' )
    
askQuestion = input( 'pick a color for your cat! \nChoose Blue, red, or yellow: ' )
penSize = input( 'Please pick a pen size 1 through 100: ' )
penPace = input( 'Lastly, pick a pen speed, 1 through 100: ' )

import turtle

s = turtle.getscreen()

window = turtle.Screen()
window.bgcolor("white")
turtle.color(askQuestion)
turtle.pensize(penSize)
turtle.speed(penPace)


turtle.right(0)
turtle.forward(50)
turtle.left(45)
turtle.forward(30)
turtle.left(-90)
turtle.forward(35)
turtle.right(46)
turtle.forward(40)
turtle.right(-40)
turtle.forward(20)
turtle.left(-60)
turtle.forward(40)
turtle.left(-30)
turtle.forward(20)
turtle.right(-30)
turtle.forward(20)
turtle.right(-50)
turtle.forward(40)
turtle.right(15)
turtle.forward(40)
turtle.right(-50)
turtle.forward(10)
turtle.right(60)
turtle.forward(50)
turtle.right(-85)
turtle.forward(30)
turtle.left(65)
turtle.forward(30)
turtle.left(45)
turtle.forward(50)
turtle.right(30)
turtle.forward(30)
turtle.right(50)
turtle.forward(40)
turtle.right(70)
turtle.forward(35)
turtle.right(73)
turtle.forward(10)
turtle.left(-105)
turtle.forward(33)
turtle.left(78)
turtle.forward(30)
turtle.right(-45)
turtle.forward(20)
turtle.right(-30)
turtle.forward(55)
turtle.left(-55)
turtle.forward(40)
turtle.left(-59)
turtle.forward(210)
turtle.right(93)
turtle.forward(60)
turtle.right(50)
turtle.forward(10)
turtle.right(-45)
turtle.forward(45)
turtle.right(15)
turtle.forward(30)
turtle.right(-50)
turtle.forward(20)
turtle.right(-30)
turtle.forward(20)
turtle.left(-30)
turtle.forward(40)
turtle.left(-60)
turtle.forward(20)
turtle.right(-35)
turtle.forward(45)
turtle.right(46)
turtle.forward(35)
turtle.left(-90)
turtle.forward(30)
turtle.right(-40)
turtle.forward(20)
 
this might anger you alot cuz i think the reason is you just forgot to import the turtle module. all you do is put import turtle at the top and it should work. its just a small mistake
 
Can you try once again to upload the picture, or maybe write what it says on the picture? Now, there is just a file path to the file you tried to upload, but we cannot access it as we do not have access to your computer.
Please use the "Attach files" button under the message composer, find the picture and click on open in order to be able to upload it.

I've copied and ran your code to test and I guess you get this error message?
Traceback (most recent call last):
File "C:/Users/%user%/OneDrive/Desktop/cf-test.py", line 27, in <module>
turtle.speed(penPace)
File "<string>", line 8, in speed
File "C:\Users\%user%\AppData\Local\Programs\Python\Python311\Lib\turtle.py", line 2171, in speed
elif 0.5 < speed < 10.5:
TypeError: '<' not supported between instances of 'float' and 'str'

So, the problem is with the penPace variable. It expects an integer/float but it is assigned a string. The solution is simply to specify that the input should be taken as an integer/float. Let's go with integer.

So instead of
Python:
penPace = input( 'Lastly, pick a pen speed, 1 through 100: ' )

# it should be

penPace = int(input( 'Lastly, pick a pen speed, 1 trough 100: '))
 
I took your project a step further. The dog is a little big for the screen as it was what I was using to familiarize myself with turtle. I've not shrunk it down for the tkinter window.

play.py
Python:
import tkinter as tk
import turtle
import drawings

class Window:
    def __init__(self, parent):
        parent.columnconfigure(0, weight=1)
        parent.rowconfigure(0, weight=1)
        parent.geometry('800x670+300+300')
        parent.resizable(False, False)
        self.parent = parent

        container = tk.Frame(parent)
        container.grid(column=0, row=0, sticky='news')
        container.grid_columnconfigure(0, weight=2)
        container.grid_columnconfigure(1, weight=3)
        container.grid_rowconfigure(0, weight=3)
        container.grid_rowconfigure(1, weight=3)
        
        left = tk.Frame(container)
        left.grid(column=0, row=0, sticky='news', padx=5, pady=5)
        left.grid_columnconfigure(0, weight=3)
        left.grid_rowconfigure(0, weight=3)

        right = tk.Frame(container)
        right.grid(column=1, row=0, sticky='news', padx=5, pady=5)
        right.columnconfigure(0, weight=3)
        right.rowconfigure(0, weight=3)

        self.listbox = tk.Listbox(left)
        self.listbox.grid(column=0, row=0, sticky='news')
        for item in ('fish', 'cat', 'dog', 'smiley'):
            self.listbox.insert('end', f' {item.title()}')

        self.canvas = tk.Canvas(right, bg='green', width=500, height=600)
        self.canvas.grid(column=0, row=0, sticky='news')

        self.screen = turtle.TurtleScreen(self.canvas)
        self.pointer = turtle.RawTurtle(self.screen, shape='arrow')
        self.pointer.up()
        self.pointer.hideturtle()
        self.pointer.setx(45)
        self.pointer.sety(-60)

        btn_container = tk.Frame(container)
        btn_container.grid(column=0, columnspan=2,row=1, sticky='new', padx=5, pady=5)
        btn_container.grid_columnconfigure(0, weight=3, uniform='btns')
        btn_container.grid_columnconfigure(1, weight=3, uniform='btns')
        
        self.clear_btn = tk.Button(btn_container, text='Clear')
        self.clear_btn.grid(column=0, row=0, sticky='news')

        self.exit_btn = tk.Button(btn_container, text='Exit')
        self.exit_btn.grid(column=1, row=0, sticky='news')


class Controller:
    def __init__(self, window):
        
        self.window = window

        self.window.parent.bind('<<ListboxSelect>>', self.draw)
        self.window.clear_btn['command'] = self.clear
        self.window.exit_btn['command'] = self._exit

    def clear(self):
        self.window.pointer.reset()
        self.window.pointer.hideturtle()

    def _exit(self):
        self.window.parent.destroy()

    def draw(self, event):
        for index in self.window.listbox.curselection():
            item = self.window.listbox.get(index).lower()
        self.window.pointer.reset()
        self.window.pointer.speed(10)
        
        match item.strip():
            case 'smiley':
                drawings.smiley(self.window.pointer)

            case 'cat':
                drawings.cat(self.window.pointer)

            case 'fish':
                drawings.fish(self.window.pointer)

            case 'dog':
                drawings.dog(self.window.pointer)
            
            case _:
                print('nothing')

if __name__ == '__main__':
    root = tk.Tk()
    Controller(Window(root))
    root.mainloop()

drawings.py
Python:
def dog(turtle):
    turtle.penup()
    turtle.setpos(180, 180)
    turtle.pendown()
    turtle.setheading(180)
    turtle.right(30)
    turtle.circle(360,60)

    turtle.setheading(240)
    turtle.forward(150)

    turtle.setheading(190)
    turtle.forward(280)

    turtle.circle(120, 160)
    turtle.forward(220)

    turtle.setheading(350)
    turtle.heading()
    turtle.circle(60, 5)
    turtle.setheading(360)
    turtle.forward(200)

    # Neck back
    turtle.circle(150, 130)
    turtle.penup()
    turtle.home()
    turtle.setpos(180, 180)
    turtle.pendown()
    turtle.setheading(-60)
    turtle.heading()
    turtle.forward(600)
    turtle.penup()

    turtle.home()
    turtle.setpos(-25, -250)
    turtle.pendown()
    turtle.right(60)
    turtle.forward(300)
    turtle.penup()


    # Ear
    turtle.home()
    turtle.setpos(40, 225)
    turtle.pendown()
    turtle.right(90)
    turtle.forward(300)
    turtle.circle(70, 180)
    turtle.forward(260)
    turtle.penup()

    turtle.setpos(-550, -25)
    turtle.pendown()
    
    turtle.fillcolor('firebrick')
    turtle.begin_fill()
    turtle.circle(40, 360)
    turtle.end_fill()

    # Mouth
    turtle.penup()
    turtle.setpos(-625, -150)
    turtle.pendown()
    turtle.fillcolor('black')
    turtle.right(90)
    turtle.forward(380)
    turtle.circle(80, 50)
    turtle.penup()
    turtle.home()

    # Eye
    turtle.setpos(-248, 65)
    turtle.pendown()
    turtle.right(-15)
    turtle.forward(110)

    turtle.setheading(90)
    turtle.heading()
    turtle.left(30)
    turtle.forward(90)
    turtle.penup()
    turtle.goto(-170, 125)
    turtle.pendown()
    turtle.circle(25, 360)
    turtle.hideturtle()

def fish(pointer):
    pointer.penup()
    pointer.setpos(-150, 50)
    pointer.pendown()
    pointer.setheading(360)
    pointer.circle(-80, -180)
    pointer.right(0)
    pointer.forward(-250)
    pointer.setheading(15)
    pointer.forward(150)
    pointer.setheading(-70)
    pointer.forward(120)
    pointer.setheading(90)
    pointer.forward(300)
    pointer.setheading(70)
    pointer.forward(-120)
    pointer.setheading(-15)
    pointer.forward(-180)
    pointer.setheading(0)
    pointer.forward(-220)
    pointer.penup()
    pointer.setpos(-180, -10)
    pointer.pendown()
    pointer.fillcolor('black')
    pointer.begin_fill()
    pointer.circle(15, 360)
    pointer.end_fill()
    pointer.penup()
    pointer.setpos(-120, 10)
    pointer.right(180)
    pointer.pendown()
    pointer.circle(50, -180)
    pointer.penup()
    pointer.setpos(-110, -100)
    pointer.pendown()
    pointer.circle(60, 180)
    pointer.hideturtle()

def cat(pointer):
    # Head
    pointer.penup()
    pointer.goto(50, -200)
    pointer.pendown()
    pointer.circle(180, 360)
    pointer.penup()

    # Left ear
    pointer.goto(-110, 68)
    pointer.pendown()
    pointer.setheading(75)
    pointer.forward(140)
    pointer.setheading(-55)
    pointer.forward(78)
    pointer.penup()

    # Right ear
    pointer.goto(-110, 68)
    pointer.setheading(0)
    pointer.forward(320)
    pointer.pendown()
    pointer.setheading(-75)
    pointer.forward(-140)
    pointer.setheading(55)
    pointer.forward(-78)
    pointer.penup()

    # Eyes
    pointer.home()
    pointer.goto(40, 28)
    pointer.pendown()
    pointer.right(-90)
    pointer.circle(55, 180)
    pointer.penup()

    pointer.home()
    pointer.goto(160, 28)
    pointer.pendown()
    pointer.right(-90)
    pointer.circle(55, 180)
    pointer.penup()

    # Nose
    pointer.home()
    pointer.setpos(80, -40)
    pointer.pendown()
    pointer.left(90)
    pointer.circle(40, 180)
    pointer.penup()
    pointer.setpos(80, -40)
    pointer.pendown()
    pointer.setheading(-140)
    pointer.forward(50)
    pointer.setheading(140)
    pointer.forward(50)
    pointer.penup()

    pointer.setpos(-77, -70)
    pointer.setheading(-90)
    pointer.pendown()
    pointer.circle(60, 180)
    pointer.penup()
    pointer.setpos(163, -70)
    pointer.setheading(90)
    pointer.pendown()
    pointer.circle(60, -180)
    pointer.penup()

    pointer.setpos(65, -60)
    pointer.setheading(15)
    pointer.pendown()
    pointer.forward(150)
    pointer.penup()
    pointer.setpos(65, -60)
    pointer.setheading(0)
    pointer.pendown()
    pointer.forward(150)
    pointer.penup()
    pointer.setpos(65, -60)
    pointer.setheading(-15)
    pointer.pendown()
    pointer.forward(150)
    pointer.penup()

    pointer.setpos(22, -60)
    pointer.setheading(170)
    pointer.pendown()
    pointer.forward(140)
    pointer.penup()
    pointer.setpos(22, -60)
    pointer.setheading(180)
    pointer.pendown()
    pointer.forward(140)
    pointer.penup()
    pointer.setpos(22, -60)
    pointer.setheading(190)
    pointer.pendown()
    pointer.forward(140)
    pointer.penup()
    pointer.hideturtle()

def smiley(pointer):
    # Body
    pointer.penup()
    pointer.goto(50, -200)
    pointer.pendown()
    pointer.fillcolor('yellow')
    pointer.begin_fill()
    pointer.circle(180, 360)
    pointer.end_fill()
    pointer.penup()

    # Eyeball
    pointer.goto(-30, 0)
    pointer.pendown()
    pointer.fillcolor('white')
    pointer.begin_fill()
    pointer.circle(40, 360)
    pointer.penup()

    pointer.goto(120, 0)
    pointer.pendown()
    pointer.circle(40, 360)
    pointer.end_fill()
    pointer.penup()

    # Pupil
    pointer.goto(-32,28)
    pointer.pendown()
    pointer.fillcolor('black')
    pointer.begin_fill()
    pointer.circle(12, 360)
    pointer.penup()

    pointer.goto(120, 28)
    pointer.pendown()
    pointer.circle(12, 360)
    pointer.end_fill()
    pointer.penup()

    # Mouth
    pointer.goto(-53, -73)
    pointer.pendown()
    pointer.fillcolor('#333')
    pointer.begin_fill()
    pointer.right(90)
    pointer.circle(100, 180)
    pointer.goto(-53, -73)
    pointer.end_fill()
    pointer.penup()

    # Tongue
    pointer.goto(10, -120)
    pointer.pendown()
    pointer.right(180)
    pointer.fillcolor('red')
    pointer.begin_fill()
    pointer.circle(40, 180)
    pointer.end_fill()
    pointer.penup()
    pointer.hideturtle()
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom