Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #rectangle - print area and perimeter
- from turtle import Turtle
- eric = Turtle()
- def rectangle_area(l,h):
- return l*h
- def rectangle_perimeter(l,h):
- return 2*l + 2*h
- def draw_rectangle(t_name,col,l,h):
- t_name.color(col)
- t_name.penup()
- t_name.fillcolor(col)
- t_name.begin_fill()
- t_name.pendown()
- t_name.forward(l)
- t_name.left(90)
- t_name.forward(h)
- t_name.left(90)
- t_name.forward(l)
- t_name.left(90)
- t_name.forward(h)
- t_name.end_fill()
- t_name.penup()
- t_name.goto(l/2,(h/2)+10) # position text depending on size of rectangle
- t_name.color("black")
- t_name.write("area: " + str(rectangle_area(l,h)), align="center")
- t_name.penup()
- t_name.goto(l/2,(h/2)-10) # position text depending on size of rectangle
- t_name.color("black")
- t_name.write("perimeter: " + str(rectangle_perimeter(l,h)), align="center")
- t_name.hideturtle()
- length = input("what is the length? ")
- length = int(length)
- height = input("height")
- height = int(height)
- draw_rectangle(eric,"red", length, height)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement