Question
Write a program that asks the user to enter a number. The program should: 1- Catch a python exception if the value entered is not
Write a program that asks the user to enter a number. The program should: 1- Catch a python exception if the value entered is not numerical. In this case, the user is prompted to re-enter a valid number (the program should not exit). 2- Raise and catch a user-defined exception if the value entered contains special characters. In this case, the user is prompted to re-enter a valid number (the program should not exit). 3- Define and implement a function that accepts a numerical string as input, then returns the float value of that string. Make exception handling at the level of the function. 4- Call your function by passing on the value the user entered 5- Loop continuously asking the user if they wish to contiue
Sample Interaction: Please enter a number: hello Caught a python exception. Please re-enter a valid number: /!hi Caught a user-defined exception. Please re-enter a valid number: -20 The absolute value of your number is: 20 Would you like to continue? (yes/no): yes Please enter a number: --10 Caught a user-defined exception. Please re-enter a valid number: ---15 Caught a user-defined exception. Please re-enter a valid number: 12 The absolute value of your number is: 12 Would you like to continue? (yes/no): yes Please enter a number: -5 The absolute value of your number is: 5 Would you like to continue? (yes/no): yes Please enter a number: 5@5 Caught a user-defined exception. Please re-enter a valid number: 12T
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started