Computer Science, asked by ADITTT007, 7 months ago

Write a python program to draw a square using turtle graphics. Please fast

Answers

Answered by ItzAditt007
3

Write the code given below:-

\rule{200}2

>> import turtle

>> a = turtle.Turtle()

>> s = turtle.getscreen()

>> s.fd(200)

>> s.rt(90)

>> s.fd(200)

>> s.rt(90)

>> s.fd(200)

>> s.rt(90)

>> s.fd(200)

It will draw a square which looks like this:-

\setlength{\unitlength}{20} \begin{picture}( 0 , 0 ) \put( 1 , 1){ \line( 0 , 1){4}}\put( 1 , 1){ \line( 1 , 0){4}}\put( 5 , 1){ \line( 0 , 1){4}}\put( 1 , 5){ \line( 1 , 0){4}}\put(2, 0.5){$ \rm{side = 200}$} \end{picture}

\rule{200}2

ExplanaTion:-

  • Import turtle will import the all attributes available in turtle.

  • a = turtle.Turtle() will define a as the turtle.

  • s = turtle.getscreen() will open turtle screen and define s as the screen of the turtle.

  • s.fd(200) will move the pen 200 units forwards.

  • s.rt(90) will rotate the pen at 90°.

Some more atributes of turtle graphics:-

  • Backward:- bk(length)

  • Rotate left:- lt(angle)

  • To undo:- a.undo()

  • Clear screen:- s.clear()

  • Background colour:- s.bgcolor(req. colour)

  • To draw circle:- a.circle(radius)
Similar questions