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.
PYTHON
Write a
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
!["This functions asks the user for the number of steps
they want to climb, gets the value provided by the user
and returns it to the calling function. This function will
raise any exceptions related to none integer user inputs.''
def getUserInput():
#your code belongs here
"This function takes the number of steps as an input parameter,
creates a string that contains the entire steps based on the user input
and returns the steps string to the calling function. This function will raise
any exceptions resulting from invalid integer values.
| | |
def printSteps (stepCount):
#your code belongs here
'''This function kicks off the running of your program. Once it starts
it will continuously run your program until the user explicitly chooses to
end the running of the program based on the requirements. This function returns
the string "Done Executing" when it ends. Additionally, all exceptions will be
handled (caught) within this function.'''
def runProgram():
#your code belongs here
'''Within this condition statement you are to write the code that kicks off
your program. When testing your code the code below this
if
should be the only code not in a function and must be within the if
statement. I will explain this if statement later in the course.''
__name__ == _main__":
"1
#your code belongs here](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F340b67e9-d1cc-42a7-9225-2cca127f9e9c%2F2a0ef344-810b-4e37-b6c6-ed238ee6b0ef%2F5xqaul5_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)