DanielHannon

Draw square with same area as a given circle

Feb 13th, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. from math import pi
  2. from math import sqrt
  3. import turtle
  4.  
  5. radius = int(raw_input("What radius would you like the circle to be(The Bigger the better)? "))
  6. turtle.penup()
  7. turtle.color("red")
  8. turtle.sety(-radius)
  9. turtle.pendown()
  10. turtle.circle(radius)
  11. areaofcircle = (radius*radius) * pi
  12. sideofsquare = sqrt(areaofcircle)
  13. print sideofsquare
  14. turtle.color("blue")
  15. halfsquare = sideofsquare/2
  16. turtle.penup()
  17. turtle.setx(0)
  18. turtle.sety(-halfsquare)
  19. turtle.pendown()
  20. turtle.forward(halfsquare)
  21. turtle.left(90)
  22. for i in range(4):
  23.     turtle.forward(sideofsquare)
  24.     turtle.left(90)
  25.  
  26. turtle.write("side of square is %s" %(sideofsquare))
Advertisement
Add Comment
Please, Sign In to add comment