Advertisement
khrislewis

Return Values

Dec 13th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #Draws a circle, rectangle and star showing size and perimeter
  2. from turtle import *
  3. def circle_area(r):#Returns circles area
  4. return 3.14 * r * r
  5. def circle_circumference(r):#Returns circles circumference
  6. return 3.14 * 2 * r
  7. def draw_circle(r, col):#Draws circle
  8. penup()
  9. goto(-150,0)
  10. color(col)
  11. dot(r*2)
  12. penup()
  13. goto(-150,5)
  14. color("black")
  15. write("Area: " + str(circle_area(r)), align="center")
  16. penup()
  17. goto(-150,-5)
  18. pendown()
  19. color("black")
  20. write("Circumference: " + str(circle_circumference(r)), align="center")
  21. def rectangle_area(l,h):#Returns rectangles area
  22. return l * h
  23. def rectangle_perimeter(l,h):#Returns rectangles perimeter
  24. return l * 2 + h * 2
  25. def drawrectangle(c,l,h):#Draws rectangle
  26. color(c)
  27. length = l
  28. height = h
  29. penup()
  30. goto(-l/2,h/2)
  31. pendown()
  32. begin_fill()
  33. forward(length)
  34. right(90)
  35. forward(height)
  36. right(90)
  37. forward(length)
  38. right(90)
  39. forward(height)
  40. right(90)
  41. end_fill()
  42. penup()
  43. goto(0,5)
  44. pendown()
  45. color("black")
  46. write("Area: " + str(rectangle_area(l,h)), align="center")
  47. penup()
  48. goto(0,-5)
  49. pendown()
  50. color("black")
  51. write("Perimeter: " + str(rectangle_perimeter(l,h)), align="center")
  52. def star_perimeter(s):#Returns stars perimeter
  53. return s * 10
  54. def draw_star(s,c):#Draws star
  55. size = s
  56. color(c)
  57. angle = 150
  58. penup()
  59. goto(200,20)
  60. begin_fill()
  61. for side in range(5):
  62. forward(size)
  63. right(angle)
  64. forward(size)
  65. right(72 - angle)
  66. end_fill()
  67. penup()
  68. goto(175,0)
  69. pendown()
  70. color("black")
  71. write("Perimeter: " + str(star_perimeter(s)), align="center")
  72. return
  73. draw_circle(100, "blue")
  74. drawrectangle("green", 100, 200)
  75. draw_star(100,"pink")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement