Advertisement
Fareehausman00

Untitled

Sep 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #rectangles with Tim the turtle
  2. from turtle import Turtle
  3.  
  4. tim = Turtle()
  5.  
  6. def getarea(length, width):
  7. return length * width
  8.  
  9. def getperimeter(length, width):
  10. return 2 * (length + width)
  11.  
  12. def drawrectangle(length, width, col):
  13. tim.color(col)
  14. tim.forward(length)
  15. tim.right(90)
  16. tim.forward(width)
  17. tim.right(90)
  18. tim.forward(length)
  19. tim.right(90)
  20. tim.forward(width)
  21. tim.penup()
  22. tim.goto(5, -15)
  23. tim.color("black")
  24. tim.write("Area " + str(getarea(length, width)))
  25. tim.goto(5, -30)
  26. tim.write("Perimeter " + str(getperimeter(length, width)))
  27.  
  28. import random
  29.  
  30. drawrectangle(random.randint(100, 200), random.randint(40, 100), "dark orchid")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement