Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Goals: Developing problem-solving skills, checking validity of input, and using

ID: 3889073 • Letter: G

Question

Goals: Developing problem-solving skills, checking validity of input, and using multi-branched decision structures. Do not use lists (arrays), tuples or dictionaries.

Problem: You are going to develop a program that will allow the user to draw polygons with different number of sides using different pen colors, and with different lengths of the sides. Your program should prompt the user to enter the number of sides which should be a whole number from 3 to 12 inclusive. Robustly check that the user entered a value in that range (you do not have to check that the user entered a whole number because you should have stored the input as a whole number). Next provide the user a menu of at least 10 colors (e.g. 1 for blue, 2 for yellow etc.). Robustly check that the selected a correct choice. Next ask the user if he/she wants a small, medium or large polygon and robustly confirm that he/she enters a correct choice. Then draw a polygon with the selected size (for small use a side length of 20, for medium use length of 50, and for large use a length of 90), color, and number of sides. Use a pen size of 6 for the drawing. Finally ask the user if he/she would like to create a new polygon. If so, clear the turtle window, and ask the user to enter the choices again. The user should be able to draw as many polygons as he/she would like.

*Do not use any concepts beyond Chapter 4 of Python Fourth Edition by Tony Gaddis (i.e. no functions).

*Do not use any breaks please, as breaks are not aloud to be used in my course

Explanation / Answer

import turtle

def myTurtle():
sidesofpolygon = raw_input("desired number of sides of a polygon: " )
shapes = raw_input("polygon shape: " )
num_sides = int(sidesofpolygon)
shapes = int(shapes)
window = turtle.Screen()
window.bgcolor("green")

polygon = turtle.Turtle()
polygon.penup()
polygon.goto(300, 200)
polygon.pendown()
side_length = 60
angle = 360.0
n = 0

for j in range(0, shapes):
    polygon.forward(side_length)
    for i in range(num_sides):
        polygon.pencolor("black")
        polygon.forward(side_length)
        polygon.right(angle)
    n += side_length  
window.exitonclick()
if __name__ == '__main__':
myTurtle()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote