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

3. Write a program on python that asks the user for a color, a line width, a lin

ID: 3787551 • Letter: 3

Question

3. Write a program on python that asks the user for a color, a line width, a line length and a shape.Assume that the user will specify a that is either a line, a triangle, or a square. Use turtle graphics to draw the shape that the user requests of the size, color, line width and line length that the user requests. For example, if these are the user choices for color, width,line length and shape what color? blue whatline width? 25 whatline length? 100 line, triangle or square? triangle

Python code no for loop

only if and elif

thank you

Explanation / Answer

import turtle s = turtle.Screen() t = turtle.Turtle() length = None while not length: try: length = float(input('Enter your preferred turtle line length: ')) except ValueError: print('You need to enter a number') width = None while not width: try: width = int(input('Enter your preferred turtle line width: ')) except ValueError: print('You need to enter a positive integer') else: if width < 1: print('You need to enter a positive integer') width = None color = None while not color: color = input('Enter your preferred turtle line color: ') try: t.pencolor(color) except: print('You need to enter a color that I know.') color = None shape = None while not shape: shape = input('Specify whether you want to draw a line, triangle, or square: ') if shape.lower() not in ['line', 'triangle', 'square']: shape = None print('I only draw lines, triangles and squares!') t.pensize(width) if shape == 'line': t.forward(length) elif shape == 'triangle': t.forward(length) t.right(120) t.forward(length) t.right(120) t.forward(length) else: t.forward(length) t.right(90) t.forward(length) t.right(90) t.forward(length) t.right(90) t.forward(length) s.exitonclick()
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