Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Python program that allows the user to choose between drawing a rectangle or a circle and draw that shape. The user selects the

Write a Python program that allows the user to choose between drawing a rectangle or a circle and draw that shape. The user selects the color, the placement of the shape and its size. The interaction follows as below.

1. The user is first prompted to enter r for drawing a rectangle and anything else for drawing a circle.

2. The program first prompts for and reads in the x and y coordinates of the bottom left corner of the rectangle (that is, if the user wanted to draw a rectangle) or the x and y coordinates of the center of the circle (that is, if the user wanted to draw a circle).

3. The program then prompts for and reads in the width and height of the rectangle (that is, if the user wanted a rectangle) or the radius of the circle (that is, if the user wanted a circle).

4. The program then prompts for and reads in the fill color: b for blue and anything else for red.

5. The program then draws the chosen shape in the chosen color. The outline of the shape has the same color as the fill color. The program must not prompt for anything that is not called for by the above list or the interactions given later. Also, no displays other than the circle or the rectangle should be made.

Write Python code using turtle graphics that solves the problem. To get a filled circle, put the turtle.circle(radius) command between turtle.begin_fill() and turtle.end_fill(). Make sure that the program prompts for the input and displays the shape as specified.

Debug your code as necessary until it complies with all requirements. The Python code should prompt for user input and display results as given in the sample interactions below. This program lets the user specify a circle or a rectangle to be drawn. The user uses the letter r for rectangle and anything else for a circle. The user then specifies the location and dimensions of the shape. Finally, the user will enter the fill color (b for blue and anything else for red)

Enter the shape type (r for rectangle; anything else for circle): e

Enter x-coord of circle's center: 30

Enter y-coord of circle's center: 10

Enter circle's radius: 150

Enter the fill color (b for blue; anything else for red): b

This program lets the user specify a circle or a rectangle to be drawn. The user uses the letter r for rectangle and anything else for a circle. The user then specifies the location and dimensions of the shape. Finally, the user will enter the fill color (b for blue and anything else for red)

Enter the shape type (r for rectangle; anything else for circle): r

Enter x-coord of rectangle's bottom-left corner: 20

Enter y-coord of rectangle's bottom-left corner: 10

Enter rectangle's width: 100

Enter rectangle's height: 200

Enter the fill color (b for blue; anything else for red):

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_2

Step: 3

blur-text-image_3

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

Database And Expert Systems Applications Dexa 2021 Workshops Biokdd Iwcfs Mlkgraphs Al Cares Protime Alsys 2021 Virtual Event September 27 30 2021 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Anna Fensel ,Jorge Martinez-Gil ,Lukas Fischer

1st Edition

3030871002, 978-3030871000

More Books

Students also viewed these Databases questions

Question

Develop a program for effectively managing diversity. page 303

Answered: 1 week ago

Question

List the common methods used in selecting human resources. page 239

Answered: 1 week ago