Question
Description You've been provided with some starter code that handles the menu for you (for the most part), you'll just have to fill in a
Description
You've been provided with some starter code that handles the menu for you (for the most part), you'll just have to fill in a few holes to get that working as expected. In terms of the rest of the functionality, you'll be drawing simple shapes.
The challenge for this assignment is to explore lists and dictionaries but also to use functions effectively to reduce code duplication, simplify your application, and reduce another developer's intellectual overhead when they need to understand your application. As professionals, none of us work in a vacuum, it is important to develop code that other developers can easily read, understand, and modify as necessary. It is rare that someone who was around for the beginning of the development of a software product will also be there later in the process - they will often have been promoted or got a better paying job at another company! It is estimated that the "average" length of time at a job in our industry is less than one year - this doesn't mean people are getting fired - it usually means they are moving on to something bigger and better! So before you leave, you have to make sure you've left your code in a state that another developer can "jump in" and make necessary modifications.
As you develop your code, use iterative practices - just get small pieces working and gradually build up to the full working system. Also, it can be very beneficial to temporarily comment-out or wait to develop any user interface elements. Think about it this way - while you're trying to make the the square work correctly, you don't want to delay your iterative process by having to type in the menu option and size of the square. Instead, just call the square method directly with a hard-coded value until you get that one working, then test it with another value and then finally integrate it into the UI.
I HIGHLY recommend that you follow this iterative approach to developing code anytime you sit down to work on your challenges, assignments, or professional projects! Write a few lines of code, save, run, and test thoroughly! By reducing the amount of changes you make each time, this reduces the likely places for new bugs - if you only added 3 lines, any bugs are probably in those 3 lines! Anytime your code is in a running state, commit your changes to github (or whatever code versioning system you're using) and push your code to the remote repository. If you're working directly in Mimir, it is saving your state everytime you run the tests.
Functional Design
Effective functions are ones that either reduce intellectual overhead by pulling out large blocks of code that accomplish a single task and replacing them with a descriptive function name (like printMenu()) OR pulling out blocks of code that are reusable by other applications or the current application (like sort()). We'll see examples of both of these in this assignment.
To make good, reusable functions, we need to make effective use of parameters - these allow us to provide customization data to a function so that it can do something different each time it runs. We've seen a good example of this in the promptForInteger() function that was provided for you in one of the challenges - this function allows us to easily ask the user for a bounded number with appropriate messages.
Great functions do ONE simple task and do that one task VERY well! Think of functions as your own personal butler - you send the function off to do a specific task with specific instructions (parameters!), trust that it will do the task conscientiously, efficiently, and effectively, and then bring you back the result (return value!) without needing any more interaction from you. Generally, a function should be more than just one line of code in its "block" - but sometimes, one-liners can be useful if they simplify a complex mathematical function (like summations, averages, compound interest, etc.). A good rule of thumb is that a function should fit on a single "screen" of code - this allows the developer to see the whole function at once. While this isn't always possible, it is a reasonable goal as it reduces intellectual overhead.
You will need to demonstrate effective use of the following functions:
- promptForInteger - requests an integer from the user within a certain range and repeats the request until a valid number is received
- ask the user for a ranged (minimum to maximum) integer using a custom message
- If the user does not provide an acceptable value, it should print an error message and accept another value
- drawX functions - for each shape that you will draw, you will need a function that just draws the shape, these must accept the appropriate size information as parameters (hint: if all these do is draw the shape, you will be able to reuse them multiple times to draw other shapes!)
- other helpful functions - I've left a few opportunities for you to determine helpful functions of your own design. Hint: Look for repeated or copied code that performs the same action in different places in your code or big chunks of uninteresting code that you could pull out into a function (hint: menus......) - can you combine these into a function with parameters? Sometimes it doesn't make sense - remember that our goal of introducing functions is to make it easier to understand the code, not harder!
Starter Code
You've been provided with starter code that includes all of the output statements and the promptForInteger method.
Requirements
Your application must:
- Print a menu of shapes to draw from which the user will select
- Ask the user what size of shape to draw
- Print the name of the shape and its selected size
- Draw the shape
- Repeat the process until the user elects to quit
- Print a goodbye message
Shapes
When drawing the shapes, to receive full design credit, you will need to use list comprehensions.
Each shape will be drawn with simple asterisks based on their size. Some of your shapes should reuse other shapes. If you are creative with your parameters, you can effectively have one of the two shapes skip a row so that they can be put together with the right number of rows (diamond, hourglass and house).
Square
Drawing Square of size 5 ***** ***** ***** ***** *****
Right Triangle
Drawing Right Triangle of size 5 * ** *** **** *****
Isosceles Triangle
Drawing Isosceles Triangle of size 5 * *** ***** ******* *********
Inverted Isosceles Triangle
Drawing Inverted Isosceles Triangle of size 5 ********* ******* ***** *** *
Diamond
Isosceles and inverted isosceles triangles
Drawing Diamond of size 5 * *** ***** ******* ********* ******* ***** *** *
Hourglass
Inverted isosceles and isosceles triangles
Drawing Hourglass of size 5 ********* ******* ***** *** * *** ***** ******* *********
House
Isosceles triangle and square
Drawing House of size 5 * *** ***** ******* ********* ********* ********* ********* ********* ********* ********* ********* *********
Example Output
****************************** 1 - Draw a Square 2 - Draw a Right Triangle 3 - Draw an Isosceles Triangle 4 - Draw a Flipped Isosceles Triangle 5 - Draw a Diamond 6 - Draw an Hourglass 7 - Draw a House 8 - Quit ****************************** Please select from the menu (1 to 8)? What size should we use for your shapes (1 to 20)? Drawing Square of size 5 ***** ***** ***** ***** ***** ****************************** 1 - Draw a Square 2 - Draw a Right Triangle 3 - Draw an Isosceles Triangle 4 - Draw a Flipped Isosceles Triangle 5 - Draw a Diamond 6 - Draw an Hourglass 7 - Draw a House 8 - Quit ****************************** Please select from the menu (1 to 8)? What size should we use for your shapes (1 to 20)? Drawing Right Triangle of size 5 * ** *** **** ***** ****************************** 1 - Draw a Square 2 - Draw a Right Triangle 3 - Draw an Isosceles Triangle 4 - Draw a Flipped Isosceles Triangle 5 - Draw a Diamond 6 - Draw an Hourglass 7 - Draw a House 8 - Quit ****************************** Please select from the menu (1 to 8)? What size should we use for your shapes (1 to 20)? Drawing Isosceles Triangle of size 5 * *** ***** ******* ********* ****************************** 1 - Draw a Square 2 - Draw a Right Triangle 3 - Draw an Isosceles Triangle 4 - Draw a Flipped Isosceles Triangle 5 - Draw a Diamond 6 - Draw an Hourglass 7 - Draw a House 8 - Quit ****************************** Please select from the menu (1 to 8)? Thank you, Goodbye!
Starter Code::
def promptForInteger(min, max, message, errorMsg): response = int(input(message)) while (response < min or response > max): response = int(input(errorMsg)) return response
'''****************************** 1 - Draw a Square 2 - Draw a Right Triangle 3 - Draw an Isosceles Triangle 4 - Draw a Flipped Isosceles Triangle 5 - Draw a Diamond 6 - Draw an Hourglass 7 - Draw a House 8 - Quit ******************************'''
#"Please select from the menu (1 to 8)? ", #"Your response must be number between 1 and 8, try again. "
#"What size should we use for your shapes (1 to 20)? ", #"Your response must be number between 1 and 20, try again. ")
#"Drawing Square of size " #"Drawing Right Triangle of size " #"Drawing Isosceles Triangle of size " #"Drawing Inverted Isosceles Triangle of size " #"Drawing Diamond of size " #"Drawing Hourglass of size " #"Drawing House of size " #"Thank you, Goodbye!"
Step 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