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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!