Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. # error in the area of the rectangle
  2. from turtle import Turtle
  3.  
  4. Tina = Turtle()
  5.  
  6. x = input("Enter the distance on the axis x that you want your rectangle to be drawn: ")
  7. y = input("Enter the distance on the axis y that you want your rectangle to be drawn: ")
  8. width = input("Enter width: ")
  9. height = input("Enter height: ")
  10. color = input("What color do you want your rectangle?: ")
  11. def rectangle_area(width, height):
  12. return width * height # error: can't multiply sequence by non-int of type 'str'
  13. def rectangle_perimeter(width, height):
  14. return (width + height)*2
  15.  
  16. def draw_rectangle(name, x, y, width, height, color):
  17. name.hideturtle() # to hide the turtle
  18. name.penup() # to move the invisible turtle to a position given by the input
  19. name.goto(0, 0) # begin at the centre of the screen
  20. name.pendown()
  21. name.color(color)
  22. name.begin_fill() # to fill in the rectangle with colour
  23. name.forward(width) # to begin drawing the rectangle, it can be all left or all right
  24. name.left(90)
  25. name.forward(height)
  26. name.left(90)
  27. name.forward(width)
  28. name.left(90)
  29. name.forward(height)
  30. name.left(90)
  31. name.end_fill() # to end the fill in with the colour given in the input
  32. name.penup() # to move the invisible turtle to begin writing the perimeter
  33. name.goto(0, -50) # error: it does not let me write (x, y - 10), it says it is a concatenate of str and int
  34. name.pendown()
  35. name.color("green")
  36. name.write("Rectangle of perimeter " + str(rectangle_perimeter(width, height)), align="center")
  37. name.penup() # to move the invisible turtle to begin writing the area
  38. name.goto(0, 50) # error: it does not let me write (x, y + 10), it says it is a concatenate of str and int
  39. name.pendown()
  40. name.color("green")
  41. name.write("Rectangle of area " + str(rectangle_area(width, height)), align="center")
  42.  
  43. draw_rectangle(Tina, x, y, width, height, color)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement