Search code examples
pythonintegerturtle-graphicspython-turtle

How to use integers in write command in turtle module python


I want to use integers in the write command.

import turtle
t=turtle.Turtle()
a=0
b=0
t.write(a,':',b)

When I run this code it shows these errors:

Traceback (most recent call last):
  File "C:\Users\Drukker\AppData\Local\Programs\Python\Python39\Among_us.py", line 5, in <module>
    t.write(a,':',b)
  File "C:\Users\Drukker\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 3432, in write
    end = self._write(str(arg), align.lower(), font)
AttributeError: 'int' object has no attribute 'lower'

Does anyone know a fix for this? Thanks


Solution

  • You are not calling the write function properly.

    The syntax of the function is:

    turtle.write(arg, move=False, align=’left’, font=(‘Arial’, 8, ‘normal’))

    Your arguments have to be passed as one parameter, so I believe what you are trying to do is:

    t.write(str(a) + ':' + str(b))