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
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images