Challenge: Print the Square of a Positive Number
Write a function that prints the square of a positive number if the input is correct; otherwise, display a relevant error message.
We'll cover the following
Write code inside a function that receives a positive number as input and prints its square. If a negative number is entered, then raise an exception, display a relevant error message, and make a graceful exit from the program:
- Input: It should be a positive number as valid input.
- Output: The square of the positive number will be printed. If the number is negative, an exception will be raised and printed on the screen.
Get hands-on with 1400+ tech skills courses.