Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Draws a circle, rectangle and star showing size and perimeter
- from turtle import *
- def circle_area(r):#Returns circles area
- return 3.14 * r * r
- def circle_circumference(r):#Returns circles circumference
- return 3.14 * 2 * r
- def draw_circle(r, col):#Draws circle
- penup()
- goto(-150,0)
- color(col)
- dot(r*2)
- penup()
- goto(-150,5)
- color("black")
- write("Area: " + str(circle_area(r)), align="center")
- penup()
- goto(-150,-5)
- pendown()
- color("black")
- write("Circumference: " + str(circle_circumference(r)), align="center")
- def rectangle_area(l,h):#Returns rectangles area
- return l * h
- def rectangle_perimeter(l,h):#Returns rectangles perimeter
- return l * 2 + h * 2
- def drawrectangle(c,l,h):#Draws rectangle
- color(c)
- length = l
- height = h
- penup()
- goto(-l/2,h/2)
- pendown()
- begin_fill()
- forward(length)
- right(90)
- forward(height)
- right(90)
- forward(length)
- right(90)
- forward(height)
- right(90)
- end_fill()
- penup()
- goto(0,5)
- pendown()
- color("black")
- write("Area: " + str(rectangle_area(l,h)), align="center")
- penup()
- goto(0,-5)
- pendown()
- color("black")
- write("Perimeter: " + str(rectangle_perimeter(l,h)), align="center")
- def star_perimeter(s):#Returns stars perimeter
- return s * 10
- def draw_star(s,c):#Draws star
- size = s
- color(c)
- angle = 150
- penup()
- goto(200,20)
- begin_fill()
- for side in range(5):
- forward(size)
- right(angle)
- forward(size)
- right(72 - angle)
- end_fill()
- penup()
- goto(175,0)
- pendown()
- color("black")
- write("Perimeter: " + str(star_perimeter(s)), align="center")
- return
- draw_circle(100, "blue")
- drawrectangle("green", 100, 200)
- draw_star(100,"pink")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement