PYTHON
Write a program that prints steps. Take in a single positive integer which will be used as the number of steps in your staircase. The program only accepts integers greater than or equal to 1 and less than 1000. The program will always run only once for each user input.
Additional Requirements:
1. The very first step in the staircase will be left aligned and for each subsequent level the step will move above and to the right of the prior step.
2. There are no spaces after the right of any of the steps.
3. The bottom most row ends without a new line.
4. Here is the py file you should add your code to, this should be the only file you submit.
5. Format your code as provided in the starter code provided below.
6. The user prompt for a size will be: "Please input your staircase size:"
7. Perform a function call within the exception handling logic (Your function that contains the code to run the program should be within a try/except block - see comments in the starter code).
8. Raise and Handle the following exceptions:
- A custom exception called "IntegerOutOfRangeException" when the user provides an integer value that is not within the valid integer range. ("That staircase size is out of range.")
- A custom exception called "NoStaircaseSizeException" when the user provides a staircase size of 0. ("I cannot draw a staircase with no steps.")
- In ValueError for user input that are not integers. ("Invalid staircase value entered.")
9. The error messages for the above exceptions should be the same as above and printed to the shell.
10. The program should continue to run and request a new input until the user types the word "DONE"
getUserInput()
- Should read input from the user via the built-in Python input function with the prompt "Please input your staircase size:"
- Should return the value from the function as an int (if possible) or as the string DONE
- Should raise a ValueError for any non-numeric input (other than the word DONE)
printSteps(stepCount)
- Should take the number of steps, passed in as stepCount, as an int input parameter
- Should create a string containing the staircase based on the input stepCount and return that string as the result of the function
- Should raise a custom exception called IntegerOutOfRangeException when the user provides an integer value that is not within the valid integer range of 1 <= stepCount < 1000.
- Should raise a custom exception called NoStaircaseSizeException when the user provides an integer value of 0 for the number of steps.
- NOTE: it is confusing, but realize that although the function is named printSteps, you should not need any print statements inside this function
runProgram()
- Should run continuously in a loop that gets user input, creates a staircase, prints it to the console, repeat
- Should print the staircase returned by printSteps to the console
- Should terminate by calling return with the value "Done Executing" when the user enters the word DONE (case-sensitive) instead of a number for the steps
- Should catch the ValueError raised by getUserInput and print the error string "Invalid staircase value entered." and then continue looping
- Should catch the IntegerOutOfRangeException raised by printSteps and print the error string "That staircase size is out of range." and then continue looping
- Should catch the NoStaircaseSizeException raised by printSteps and print the error string "I cannot draw a staircase with no steps." and then continue looping
- Should not terminate the program when ValueError, IntegerOutOfRangeException or NoStaircaseSizeException are raised.
Other
- You will need to define custom exceptions for this assignment. They should be defined at the "top-level" in the module (i.e. not inside a function) so that their scope is visible to all functions. A custom exception can be defined as follows:
class MyCustomException(Exception):
pass
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images
- 1. Write a pyrhon program that prints out a classic hangman stick figure. The program should ask the user to enter a number from 1-6 and the corresponding hangman should be printed. The value the user inputs corresponds to the number of incorrect guesses in a real hangman game and so the completeness of the hangman will correspond to the number of ‘incorrect guesses’ inputted by the user (e.g., if the user enters 1, then only the head of the hangman will be printed; full example below). Example:Enter a number from 1-6: 1O Enter a number from 1-6: 2O|Enter a number from 1-6: 3O\||Enter a number from 1-6: 4O\|/|Enter a number from 1-6: 5O\|/|/Enter a number from 1-6: 6O\|/|/ \ 2. Modify your program from problem 1 so that the user input is checked to be a validsingle digit (1-6) before printing the corresponding hangman. If the input is not valid, theninstead of a hangman the following message should be printed “Invalid input: you must enter asingle number from 1-6.” Example:Enter a…arrow_forwardA retail company assigns a $5000 store bonus if monthly sales are more than $100,000; otherwise a $500 store bonus is awarded. Additionally, they are doing away with the previous day off program and now using a percent of sales increase to determine if employees get individual bonuses. If sales increased by at least 4% then all employees get a $50 bonus. If they do not, then individual bonuses are 0. Step 7: The final step in completing the pseudocode is to call all the modules with the proper arguments. Complete the missing lines. Module main () //Declare local variables Declare Real monthlySales Declare Real storeAmount Declare Real empAmount Declare Real salesIncrease //Function calls Call getSales(monthlySales) Call getIncrease(salesIncrease) Call ______________(_______________, _____________) Call ______________(_______________, _____________) Call ______________(_______________, _____________) End Modulearrow_forwardA rod is used to hang a load (force) of 1000 N.There are 4 ingredients with their respective strengths.Create a program to create a bar diameter table, if using the 4 materials.Example: Copper Steel Material. Aluminum. Bronze Strength(N/mm2) 2000. 1600. 1400. 1700Rod Diameter: Ingredient. Copper Steel. Aluminum. BronzeDiameter. (mm) …. …. …. …..Note: Strength is the maximum stress the material can withstandStress S = force/sectional area S=force/A A = force/SmaxCross-sectional area A = 3.14 x d2 /4 d = root(4xA/3.14)Instructions: Make a list to store the ingredient names and strengths Create in a python programarrow_forward
- python Write a program that prompts the user to enter the number of study hours of a student and the average of the student. Then the program is checking the following:- If the average of the student is greater than 4 and the number of hours is less than 26, then the program should display "You have a chance".- Otherwise, the program should display "You do not have a chance".arrow_forwardPython. Use decimal module to ensure answer is accurate.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education