SHARE
TWEET

return_values

Grafundzijus Apr 26th, 2019 (edited) 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from turtle import Turtle
  2. import random
  3.  
  4. raphaelo = Turtle()
  5.  
  6. def rect_perimeter(length, height):
  7.     return length * 2 + height * 2
  8.  
  9. def rect_area(length, height):
  10.     return length * height
  11.  
  12.  
  13. def draw_rectangle(name, color):
  14.     length = random.randint(50,300)
  15.     height = random.randint(50,200)
  16.     x = random.randint(0, 100)
  17.     y = random.randint(0, 100)
  18.  
  19.     name.penup()
  20.     name.goto(x, y)
  21.     name.pendown()
  22.     name.color(color)
  23.     name.begin_fill()
  24.     name.forward(length)
  25.     name.right(90)
  26.     name.forward(height)
  27.     name.right(90)
  28.     name.forward(length)
  29.     name.right(90)
  30.     name.forward(height)
  31.     name.end_fill()
  32.    
  33.     name.penup()
  34.     name.backward(height/2)
  35.     name.right(90)
  36.     name.forward(length/2)
  37.     name.right(90)
  38.     name.forward(10)
  39.     name.pendown()
  40.     name.color("black")
  41.     name.write("Area: " + str(rect_area(length, height)), align = "center")
  42.    
  43.     name.penup()
  44.     name.backward(20)
  45.     name.pendown()
  46.     name.color("black")
  47.     name.write("Perimeter: " + str(rect_perimeter(length, height)), align = "center")
  48.  
  49.  
  50. draw_rectangle(raphaelo, "green")
  51. draw_rectangle(raphaelo, "yellow")
  52. draw_rectangle(raphaelo, "red")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top