Python please: Write a square_root() function that takes a number and returns the square root. The square_root() function throws a ValueError object with the message "Exception: Negative input for square root entered." when the number is negative. Complete the main() program that reads a number from a user, calls the square_root() function, and outputs the returned value from the square_root() function. Use a try-except block to catch any ValueError object thrown by the square_root() function and output the exception message. If the user enters something other than an integer, the program throws a ValueError object with the message "invalid literal for int() with base 10: " and 'user_input'. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print('{:.2f}'.format(your_value)) Example: If the input is 100 the output is 10.00 Example: If the input is -55 the output is Exception: Negative input for square root entered. Example: If the input is abc the output is invalid literal for int() with base 10: 'abc'
Python please:
Write a square_root() function that takes a number and returns the square root.
The square_root() function throws a ValueError object with the message "Exception: Negative input for square root entered." when the number is negative.
Complete the main() program that reads a number from a user, calls the square_root() function, and outputs the returned value from the square_root() function.
Use a try-except block to catch any ValueError object thrown by the square_root() function and output the exception message. If the user enters something other than an integer, the program throws a ValueError object with the message "invalid literal for int() with base 10: " and 'user_input'.
Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print('{:.2f}'.format(your_value))
Example: If the input is
100
the output is
10.00
Example: If the input is
-55
the output is
Exception: Negative input for square root entered.
Example: If the input is
abc
the output is
invalid literal for int() with base 10: 'abc'
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images