banner



How To Draw A Square On Python

Draw Square and Rectangle in Turtle – Python

Prerequisite: Turtle Programming Nuts
turtle is an inbuilt module in Python. It provides drawing using a screen (cardboard) and turtle (pen). To draw something on the screen, nosotros need to move the turtle (pen). To motility turtle, there are some functions i.e forward(), backward(), etc.

Drawing Square:

Python3

import turtle

t = turtle.Turtle()

southward = int ( input ( "Enter the length of the side of the Square: " ))

t.frontward(s)

t.left( 90 )

t.frontward(due south)

t.left( 90 )

t.forrad(s)

t.left( ninety )

t.forward(due south)

t.left( 90 )

Input :

100

Output :

Second arroyo (Using Loop) :

Python3

import turtle

t = turtle.Turtle()

s = int ( input ( "Enter the length of the side of foursquare: " ))

for _ in range ( 4 ):

t.forward(south)

t.left( xc )

Input :

100

Output :

Cartoon Rectangle:

Python3

import turtle

t = turtle.Turtle()

50 = int ( input ( "Enter the length of the Rectangle: " ))

w = int ( input ( "Enter the width of the Rectangle: " ))

t.forward(l)

t.left( ninety )

t.forrad(westward)

t.left( xc )

t.forward(l)

t.left( 90 )

t.forrad(w)

t.left( ninety )

Input :

100 120

Output :

2d arroyo (Using Loop) :

Python3

import turtle

t = turtle.Turtle()

l = int ( input ( "Enter the length of the Rectangle: " ))

w = int ( input ( "Enter the width of the Rectangle: " ))

for _ in range ( 4 ):

if _ % 2 = = 0 :

t.forward(l)

t.left( 90 )

else :

t.frontward(w)

t.left( xc )

Input :

100 120

Output :

Since every bit of at present, you must accept learned how to depict various basic geometrical illustrations like circle, foursquare, rectangle. And so, permit's implement this knowledge to build something which you tin can really employ in building games like let's describe a human being using the basic knowledge of geometrical knowledge.

Here the code for this implementation:-

Python3

import turtle

def draw_dream():

window = turtle.Screen()

window.bgcolor( "white" )

draw_Scarlett()

window.exitonclick()

def draw_Scarlett():

brad = turtle.Turtle()

brad.shape( "turtle" )

brad.color( "blood-red" )

draw_head(brad)

draw_body(brad)

draw_arm(brad)

draw_leg1(brad)

draw_leg2(brad)

def draw_head(brad):

brad.circle( sixty )

brad.speed( three )

brad.right( 60 )

def draw_body(brad):

num = 0

while num < 3 :

brad.frontwards( 150 )

brad.right( 120 )

brad.speed( ane )

num + = one

def draw_arm(brad):

brad.forward( 60 )

brad.left( 60 )

brad.forward( lx )

brad.backward( 60 )

brad.correct( lx )

brad.backward( 60 )

brad.right( lx )

brad.forward( 60 )

brad.right( sixty )

brad.forward( 60 )

brad.astern( 60 )

brad.left( 60 )

brad.frontward( 90 )

def draw_leg1(brad):

brad.left( 120 )

brad.forward( 40 )

brad.right( 120 )

brad.frontward( 120 )

draw_foot1(brad)

def draw_leg2(brad):

brad.color( "red" )

brad.correct( 180 )

brad.forward( 120 )

brad.right( 60 )

brad.forrard( lxx )

brad.correct( 60 )

brad.forward( 120 )

draw_foot2(brad)

def draw_foot1(brad):

brad.colour( "blue" )

num = 0

while num < 4 :

brad.forward( 20 )

brad.correct( 90 )

num + = 1

def draw_foot2(brad):

brad.color( "blue" )

num = 0

while num < 4 :

brad.forward( xx )

brad.left( 90 )

num + = 1

draw_dream()

Output:


Source: https://www.geeksforgeeks.org/draw-square-and-rectangle-in-turtle-python/

Posted by: wilketherechat.blogspot.com

0 Response to "How To Draw A Square On Python"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel