Advertisement
elena_gancedo

Area_perimeter_rectangle

Aug 3rd, 2019
1,213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. from turtle import Turtle
  2. elena = Turtle()
  3.  
  4. def rectArea(length, width):
  5.     return length * width
  6.  
  7. def rectPerimeter(length, width):
  8.     return (length + width) * 2
  9.    
  10. # Write a little
  11. elena.color('blue')
  12. elena.penup()
  13. elena.goto(-60,-10)
  14. elena.write("Let's make a rectangle!")
  15. elena.goto(0,50)
  16. elena.pendown()
  17.  
  18. def draw_rectangle(elena, c):
  19.    elena.color(c)
  20.  
  21.    elena.begin_fill()  
  22.    elena.forward(180)
  23.    elena.left(90)
  24.    elena.forward(130)
  25.    elena.left(90)
  26.    elena.forward(180)
  27.    elena.left(90)
  28.    elena.forward(130)
  29.    elena.left(90)
  30.    elena.end_fill()
  31.    
  32. # Draw the area
  33.    elena.penup()
  34.    elena.goto(-60, 120)
  35.    elena.pendown()
  36.    elena.color("green")
  37.    elena.write("Area of rectangle: " + str(rectArea(200, 200)))
  38. # Draw the perimeter
  39.    elena.penup()
  40.    elena.goto(-100, 100)
  41.    elena.pendown()
  42.    elena.color("purple")
  43.    elena.write("Perimeter of rectangle: " + str(rectPerimeter(300, 100)))
  44.  
  45. draw_rectangle(elena, "magenta")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement