Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Goals: using loops and turtle graphics Problem: You are going to create a Python program that will draw a regular polygon (one with each side

Goals: using loops and turtle graphics Problem:

You are going to create a Python program that will draw a regular polygon (one with each side of the same length and each angle of the same size) with number of sides between 3 and 12 as chosen by the user. Your code should prompt the user to enter the number of sides he/she would like to see. Use a while loop to robustly (repeatedly) confirm that the number of sides is in the range of 3 and 12 including 3 and 12. (A message should be output to the user stating what is wrong and the user should be prompted to enter a new value.) Next use either a for loop or a while loop and turtle to draw the polygon with side of 60 pixels and a color other than black. Use a pen size of 6. The angle to turn left or right may be calculated as 360 divided by the number of sides. For example, the angle for a 12-sided polygon is 360/12 or 30. The angle for 6-sided polygon is 60 degrees. An example of a 12-sided polygon using a pen color of orange and a 6-sided polygon using a pen color of dark sea green is given below. Think about which commands should be repeated and which commands should not be repeated. Do not put commands that do not need to be repeated inside a loop.

This program should contain three functions (one main and two other functions).

image text in transcribed

The main function will contain input and calls to your other functions

You should create value-returning function to robustly confirm that the user's input is between 3 and 12 inclusive. This function should accept 1 parameter and return 1 value that is between 3 and 12 inclusive

The other function is void function that accepts one parameter for the number of sides of the polygon and will use a for loop to output the polygon. This function should contain all the turtle commands. Nothing should be returned to the function call from this function.

Your main function should prompt the user to enter a value between 3 and 12 for the number of sides of the polygon. Next your main function should call the function to check the input. Finally your main function should call the function to draw the polygon.

Import turtle before all your programmer built functions.

Do not use the same variable name in multiple functions.

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

Recommended Textbook for

More Books

Students also viewed these Databases questions