Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import turtle module
- from turtle import Turtle
- #define a function to calculate the circumference of a circle
- def circle_circumference(d):
- return 3.14 * int(d)
- #define a function to calculate the surface area of a rectangle
- def rectangle_surface(length, height):
- return int(length) * int(height)
- def print_color(color):
- return color
- #define the draw a rectangle function and enter variables, such as color,some random elements in there
- def draw_rectangle():
- import random
- name = input("enter turtle name")
- name = Turtle()
- color = input("enter color ")
- name.color(color)
- randx = random.randint(-300, 300)
- randy = random.randint(-300, 300)
- name.penup()
- name.goto(randx, randy)
- length = random.randint(10, 100)
- height = random.randint(10, 100)
- name.pendown()
- name.begin_fill()
- name.forward(length)
- name.right(90)
- name.forward(height)
- name.right(90)
- name.forward(length)
- name.right(90)
- name.forward(height)
- name.end_fill()
- name.color("black")
- name.penup()
- name.goto(int(randx + 0.5 * length), int(randy - 0.5 * height +10))
- name.pendown()
- name.write("surface:" + str(rectangle_surface(length,height)), align = "center")
- name.penup()
- name.goto(int(randx + 0.5 * length), int(randy - 0.5 * height -10))
- name.pendown()
- name.write("color:" + str(print_color(color)), align = "center")
- name.hideturtle()
- #define draw_circle function and enter variables, such as diameter, color,coordinates
- def draw_circle():
- name = input("enter turtle name")
- name = Turtle()
- d = input("enter diameter")
- color = input("enter color")
- x = input("enter x coordinate (300/-300)")
- y = input("enter y coordinate (300/-300)")
- name.penup()
- name.goto(int(x), (int(y)))
- name.pendown()
- name.dot(d , color)
- name.color("black")
- name.write("Circumference: " + str(circle_circumference(d)), align="center")
- name.hideturtle()
- amount = input("How many circles do you want to draw? ")
- for i in range(int(amount)):
- draw_circle()
- amount = input("How many rectangles do you want to draw? ")
- for i in range(int(amount)):
- draw_rectangle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement