Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Python program to draw a polygon with various number of sides by: Import turtle Import math In the main() function: Set a variable

  1. Write a Python program to draw a polygon with various number of sides by:
    1. Import turtle
    2. Import math
    3. In the main() function:
      1. Set a variable for the line length to the value 800
      2. Set a variable for the number of sides (start with 3 sides)
      3. Create a turtle (call it what you want)
      4. Set the fill color to "PeachPuff". (To see all the possible colors you can use with a turtle, look at the page (https://www.tcl.tk/man/tcl8.4/TkCmd/colors.htm)
      5. Begin filling
        1. Use a for loop to draw the specified number of sides
        2. Move the turtle forward line length divided by the number of sides
        3. Turn the turtle right or left by the correct angle so that the polygon has the correct number of sides
      6. End filling
      7. Use turtle.mainloop()
    4. Try changing the number of sides as well as the line length to verify that your program will change the polygon appropriately. The number of sides should change as well as the size of the poly should be proportionally about the same size.
  2. Copy the Python program to a new program. Change the copy so that the loop is a while loop instead of a for loop.
  3. Create a new Python program to draw a circle WITHOUT USING THE circle() FUNCTION:
    1. import the turtle and math libraries as you did before
    2. In the main() function:
      1. Set a variable for the radius to be 100
      2. Create a turtle
      3. Set the turtle to work in radians (using the radians() function)
      4. Raise the pen
      5. Set a variable for the time to be 0.0
      6. Move the turtle to the coordinates (radius * math.cos(time), radius * math.sin(time))
      7. Set the pen down
      8. Set the fill color to whatever you would like
      9. Begin filling
      10. Using a while loop that will execute until time is 2*math.pi
        1. Increment the time by one fourth pi
        2. Move the turtle to the coordinates (radius * math.cos(time), radius * math.sin(time))
      11. End filling
      12. Use turtle.mainloop()
  4. Modify the above program to decrease how much you increment time (for example one eighth pi). Keep decreasing the increment until the same looks like a circle.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions