Tom_Jung

Untitled

Jan 23rd, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. from turtle import Turtle
  2. tom = Turtle()
  3.  
  4. def rect_area(width, height):
  5. return width * height
  6.  
  7. def rect_perimeter(width, height):
  8. return 2*width + 2*height
  9.  
  10. def draw_rectangle(tom, width, height, color):
  11.  
  12. tom.color(color)
  13. tom.forward(height)
  14. tom.left(90)
  15. tom.forward(height)
  16. tom.left(90)
  17. tom.forward(width)
  18. tom.left(90)
  19. tom.forward(height)
  20. tom.left(90)
  21. tom.forward(width)
  22. tom.penup()
  23.  
  24. tom.color("black")
  25. tom.goto(-50,100)
  26. tom.write("Area: " + str(rect_area(width, height)), align = "center" )
  27. tom.goto(-50, 80)
  28. tom.write("Perimeter: " + str(rect_perimeter(width,height)), align = "center")
  29. tom.hideturtle()
  30. draw_rectangle(tom,500,200, "blue")
Advertisement
Add Comment
Please, Sign In to add comment