Question
PYTHON for beginners. I need help with part 4. Thank you. **4. Driver code: Loop to call the getSize function, the getNumSides function, and the
PYTHON for beginners. I need help with part 4. Thank you.
**4. Driver code: Loop to call the getSize function, the getNumSides function, and the drawPolygon function to keep drawing polygons, until the user chooses a size of 0. Each time that a new polygon is drawn, the previous polygon should be cleared from screen.**
This is my unfinished code:
#1. def drawPolygon (t, n, length): t.color ("blue") t.begin_fill () t.fillcolor("blue") for i in range(n): t.lt(360) t.fd(length) t.end_fill() #2. def getSize (): length = int(input ("Enter size of polygon (50-150): ")) if length == 0: return length while 50>length or length>150: print ("Error: size must be between 50 and 150") length = int(input ("Enter size of polygon (50-150): ")) return length
#3. def getNumSides (): n =int(input ("Enter number of sides of polygon (3-10): ")) while 3 >n or n>10: print ("Error: sides must be between 3 and 10") n =int(input ("Enter number of sides of polygon (3-10): ")) return n
#4. from turtle import* import time t=Turtle ()
length=getSize () n = getNumSides ()
if length == 0: bye () while length >0: drawPolygon (t, n, length) time.sleep(3) t.reset()
fills the polygon with the same color as the border. You can choose a color for the polyg on 2. getSize function input: nothing return: the size that the user enters The function prompts the user and reads in the size of the polygon. The function checks that the input size is either 0 or is a number between 50 and 150, inclusive. Otherwise it keeps prompting the user until it gets a valid size 3. getNurmsides function input: nothing return the number of sides that the user enters The function prompts the user and reads in the number of sides for the polygon. The function checks that the input number is between 3 and 10, inclusive, otherwise it keeps prompting the user until it gets a valid number. 4. Driver code Loop to call the getsize function, the getNumsides funcion, and the draw Polygon function to keep drawing polygons, until the user chooses a size of 0. Each time that a new polygon is drawn, the previous polygon should be dearedfrom saeen. Example output, with input error: Enter size of polygon (50-150) 40 Error: size must be between 50 and 150 Enter size of polygon (50-150) 200 Error size must be between 50 and 150 Enter size of polygon (50-150) 50 Enter number of sides of polygon (3-10): 8 Enter size of polygon (50-150) 90 Enter number of sides of polygon (3-10) 2 Error: size must be between 3 and 10 Enter number of sides of polygon (3-10) 12 Error size must be between 3 and 10 Enter number of sides of polygon (3-10) 5 Enter size of polygon (S0-150) -2 Error: size must be between 50 and 150 Enter size of polygon (50-150) 0 fills the polygon with the same color as the border. You can choose a color for the polyg on 2. getSize function input: nothing return: the size that the user enters The function prompts the user and reads in the size of the polygon. The function checks that the input size is either 0 or is a number between 50 and 150, inclusive. Otherwise it keeps prompting the user until it gets a valid size 3. getNurmsides function input: nothing return the number of sides that the user enters The function prompts the user and reads in the number of sides for the polygon. The function checks that the input number is between 3 and 10, inclusive, otherwise it keeps prompting the user until it gets a valid number. 4. Driver code Loop to call the getsize function, the getNumsides funcion, and the draw Polygon function to keep drawing polygons, until the user chooses a size of 0. Each time that a new polygon is drawn, the previous polygon should be dearedfrom saeen. Example output, with input error: Enter size of polygon (50-150) 40 Error: size must be between 50 and 150 Enter size of polygon (50-150) 200 Error size must be between 50 and 150 Enter size of polygon (50-150) 50 Enter number of sides of polygon (3-10): 8 Enter size of polygon (50-150) 90 Enter number of sides of polygon (3-10) 2 Error: size must be between 3 and 10 Enter number of sides of polygon (3-10) 12 Error size must be between 3 and 10 Enter number of sides of polygon (3-10) 5 Enter size of polygon (S0-150) -2 Error: size must be between 50 and 150 Enter size of polygon (50-150) 0Step 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