[D66] GPT: Can your write a program in python that draws a triangle?

René Oudeweg roudeweg at gmail.com
Sun Dec 18 07:36:54 CET 2022


CAn your write a program in python that draws a triangle?

Certainly! Here is a simple Python program that uses the turtle module
to draw a triangle:

import turtle

# create a turtle object
t = turtle.Turtle()

# move the turtle to the starting position
t.penup()
t.goto(-100, -100)
t.pendown()

# draw the triangle
for i in range(3):
  t.forward(200)
  t.left(120)

# keep the window open until the user closes it
turtle.done()

This program creates a turtle object, moves it to a starting position,
and then uses a for loop to draw a triangle by moving the turtle forward
and turning it left at each iteration. The triangle will be drawn with
sides of length 200, and the internal angles will be 120 degrees,
resulting in an equilateral triangle.

I hope this helps! Let me know if you have any questions.


More information about the D66 mailing list