Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #rectangles with Tim the turtle
- from turtle import Turtle
- tim = Turtle()
- def getarea(length, width):
- return length * width
- def getperimeter(length, width):
- return 2 * (length + width)
- def drawrectangle(length, width, col):
- tim.color(col)
- tim.forward(length)
- tim.right(90)
- tim.forward(width)
- tim.right(90)
- tim.forward(length)
- tim.right(90)
- tim.forward(width)
- tim.penup()
- tim.goto(5, -15)
- tim.color("black")
- tim.write("Area " + str(getarea(length, width)))
- tim.goto(5, -30)
- tim.write("Perimeter " + str(getperimeter(length, width)))
- import random
- drawrectangle(random.randint(100, 200), random.randint(40, 100), "dark orchid")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement