Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from turtle import Turtle
- from random import *
- tina = Turtle()
- def circle_area(r):
- return 3.14159 * r * r
- def circle_circumference(r):
- return 3.14159 * 2 * r
- def draw_circle(t_name, r, col):
- t_name.color(col)
- t_name.dot(2 * r)
- t_name.penup()
- t_name.goto(0,5) #Assumes circle is at 0,0.
- t_name.pendown()
- t_name.color("black")
- t_name.write("Area: " + str(circle_area(r)), align="center")
- t_name.penup()
- t_name.goto(0,-5)
- t_name.pendown()
- t_name.color("black")
- t_name.write("Circumference: " + str(circle_circumference(r)), align="center")
- def area_rectangle(x,y):
- rec_area = x * y
- return rec_area
- def perimeter_rectangle(x,y):
- rec_perimeter = 2 * (x + y)
- return rec_perimeter
- def draw_rectangle(t_name,x,y,col):
- t_name.hideturtle
- t_name.color(col)
- t_name.penup()
- t_name.goto(-x/2,y/2)
- t_name.pendown()
- t_name.begin_fill()
- t_name.goto(x/2,y/2)
- t_name.goto(x/2,-y/2)
- t_name.goto(-x/2,-y/2)
- t_name.goto(-x/2,y/2)
- t_name.end_fill()
- t_name.penup()
- t_name.goto(0,5) #Assumes rectangle is at 0,0.
- t_name.pendown()
- t_name.color("black")
- t_name.write("Area: " + str(area_rectangle(x,y)), align="center")
- t_name.penup()
- t_name.goto(0,-5)
- t_name.pendown()
- t_name.color("black")
- t_name.write("Circumference: " + str(perimeter_rectangle(x,y)), align="center")
- draw_rectangle(tina,50,70,"blue")
- #draw_circle(tina,25,"red")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement