Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

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

Python 3.8.2 Shell
File Edit Shell Debug Options Window Help
syonon dio. Teager
D64)] on win32
Type "help", "copyright", "credits" or "license ()" for more information.
>>>
How many steps do you want to move?
5
| |
+-+-+
| |
+-+-+
| |
+-+-+
| |
+-+
+-+
| |
+-+-+
How many steps do you want to move?
3
+-+
| |
+-+-+
| |
+-+-+
| |
+-+
>>>
-----------
|11\1-K1 Colutionl
ROADST
| |
+-+
>>> |
****** **FI
ده
How many steps do you want to move?
1
+-+
-0007
-
] X
Ln: 36 Col: 4
expand button
Transcribed Image Text:Python 3.8.2 Shell File Edit Shell Debug Options Window Help syonon dio. Teager D64)] on win32 Type "help", "copyright", "credits" or "license ()" for more information. >>> How many steps do you want to move? 5 | | +-+-+ | | +-+-+ | | +-+-+ | | +-+ +-+ | | +-+-+ How many steps do you want to move? 3 +-+ | | +-+-+ | | +-+-+ | | +-+ >>> ----------- |11\1-K1 Colutionl ROADST | | +-+ >>> | ****** **FI ده How many steps do you want to move? 1 +-+ -0007 - ] X Ln: 36 Col: 4
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education