Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from turtle import Turtle
- elena = Turtle()
- def rectArea(length, width):
- return length * width
- def rectPerimeter(length, width):
- return (length + width) * 2
- # Write a little
- elena.color('blue')
- elena.penup()
- elena.goto(-60,-10)
- elena.write("Let's make a rectangle!")
- elena.goto(0,50)
- elena.pendown()
- def draw_rectangle(elena, c):
- elena.color(c)
- elena.begin_fill()
- elena.forward(180)
- elena.left(90)
- elena.forward(130)
- elena.left(90)
- elena.forward(180)
- elena.left(90)
- elena.forward(130)
- elena.left(90)
- elena.end_fill()
- # Draw the area
- elena.penup()
- elena.goto(-60, 120)
- elena.pendown()
- elena.color("green")
- elena.write("Area of rectangle: " + str(rectArea(200, 200)))
- # Draw the perimeter
- elena.penup()
- elena.goto(-100, 100)
- elena.pendown()
- elena.color("purple")
- elena.write("Perimeter of rectangle: " + str(rectPerimeter(300, 100)))
- draw_rectangle(elena, "magenta")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement