Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from turtle import Turtle
- tina = Turtle()
- # function to draw rectangle
- # x and y are the starting co-ordinates
- # w and h are the width and height of the rectangle
- def draw_rectangle(t, x, y, w, h):
- t.penup()
- t.goto(x, y)
- t.pendown()
- t.forward(w)
- t.right(90)
- t.forward(h)
- t.right(90)
- t.forward(w)
- t.right(90)
- t.forward(h)
- t.penup()
- t.goto(x, (y+10))
- t.pendown
- t.write("Area of rectangle is " + str(rect_area(w, h)))
- t.goto(x, (y+30))
- t.write("Perimeter of rectangle is " + str(perim_rect(w, h)))
- t.hideturtle()
- # perimeter of square is
- def perim_rect(w, h):
- return (2 * w) + (2 * h)
- def rect_area(w, h):
- return (w * h)
- draw_rectangle(tina, -200, 200, 50,100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement