Answered step by step
Verified Expert Solution
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
- 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 for the line length to the value 800
- Set a variable for the number of sides (start with 3 sides)
- Create a turtle (call it what you want)
- 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)
- Begin filling
- Use a for loop to draw the specified number of sides
- Move the turtle forward line length divided by the number of sides
- Turn the turtle right or left by the correct angle so that the polygon has the correct number of sides
- End filling
- Use turtle.mainloop()
- 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.
- Copy the Python program to a new program. Change the copy so that the loop is a while loop instead of a for loop.
- Create a new Python program to draw a circle WITHOUT USING THE circle() FUNCTION:
- import the turtle and math libraries as you did before
- In the main() function:
- Set a variable for the radius to be 100
- Create a turtle
- Set the turtle to work in radians (using the radians() function)
- Raise the pen
- Set a variable for the time to be 0.0
- Move the turtle to the coordinates (radius * math.cos(time), radius * math.sin(time))
- Set the pen down
- Set the fill color to whatever you would like
- Begin filling
- Using a while loop that will execute until time is 2*math.pi
- Increment the time by one fourth pi
- Move the turtle to the coordinates (radius * math.cos(time), radius * math.sin(time))
- End filling
- Use turtle.mainloop()
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started