Advertisement
farrismp

1.10.1

Apr 24th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. from turtle import Turtle
  2.  
  3. tina = Turtle()
  4.  
  5. # function to draw rectangle
  6. # x and y are the starting co-ordinates
  7. # w and h are the width and height of the rectangle
  8. def draw_rectangle(t, x, y, w, h):
  9. t.penup()
  10. t.goto(x, y)
  11. t.pendown()
  12. t.forward(w)
  13. t.right(90)
  14. t.forward(h)
  15. t.right(90)
  16. t.forward(w)
  17. t.right(90)
  18. t.forward(h)
  19. t.penup()
  20. t.goto(x, (y+10))
  21. t.pendown
  22. t.write("Area of rectangle is " + str(rect_area(w, h)))
  23. t.goto(x, (y+30))
  24. t.write("Perimeter of rectangle is " + str(perim_rect(w, h)))
  25. t.hideturtle()
  26.  
  27. # perimeter of square is
  28. def perim_rect(w, h):
  29. return (2 * w) + (2 * h)
  30.  
  31. def rect_area(w, h):
  32. return (w * h)
  33.  
  34. draw_rectangle(tina, -200, 200, 50,100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement