151,699 views
7 votes
7 votes
Write a python code to generate the following shape

Write a python code to generate the following shape-example-1
User Nisaa
by
2.6k points

1 Answer

22 votes
22 votes

Hello, you should first install the library of PyTurtle. You can type in terminal if you've GNU/Linux.

  • sudo apt-get install -y python3-wxgtk4.0

And then, you can use this code. Good luck!

import turtle

# Defining instance of turtle

pen = turtle.Turtle()

wn = turtle.Screen()

#Initial position is setting

pen.penup()

pen.setposition(-275.0,-150.0)

pen.pendown()

#Red diamond shape

pen.color("red")

pen.left(60)

pen.forward(200)

pen.left(60)

pen.forward(200)

pen.left(120)

pen.forward(200)

pen.left(120)

pen.forward(200)

pen.right(120)

pen.forward(200)

pen.right(120)

pen.forward(200)

pen.right(120)

pen.forward(200)

#Go to draw circle

pen.color("white")

pen.right(90)

pen.forward(170)

pen.left(90)

pen.forward(175)

#Draw circle

pen.color("black")

pen.circle(175)

#Go to green diamond

pen.color("white")

pen.forward(175)

pen.left(90)

pen.forward(175)

pen.right(90)

#Draw green diamond

pen.color("green")

pen.forward(200)

pen.left(120)

pen.forward(200)

pen.left(120)

pen.forward(200)

pen.left(60)

pen.forward(200)

pen.left(120)

pen.forward(200)

pen.left(120)

pen.forward(200)

#Always-on-display

wn.mainloop()

Write a python code to generate the following shape-example-1
User Herbertusz
by
3.0k points