Write a python program to draw a square using turtle graphics. Please fast
Answers
Answered by
3
Write the code given below:-
>> 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:-
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