In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of January 3rd
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #11 exercise sheet]
In this problem you should submit a function as described. Inside the function do not print anything that was not asked!
Neo has just begun his training aboard the Nebuchadnezzar. Morpheus sits across from him, a faint smile on his face.
"Neo," he begins, "you've taken the red pill and awakened to the truth, but the Matrix is not
just a world of code: it's a world of errors."
"Errors?" Neo asks.
"Yes," Morpheus replies. "Errors are glitches in the system. Unchecked, they can crash
your programs or, in the Matrix, your mind."
Write a function division(a,b) that,
that given two numbers a and b returns the string "a/b = (a/b)" (note that you don't need to round: just return the result of a/b as a string in the respective position).
If one of the arguments is not a number in the function call, the function should catch that as an exception and return the string "Error: Unsupported type(s) for division!"". Additionally, even if both arguments are numbers, if b is zero, the function should catch the respective exception and return the string "Error: Division by 0!". No other error types will occur.
The following limits are guaranteed in all the test cases that will be given to your program:
| -1000 ≤ a, b ≤ 1000 | Numbers a and b | |
| a and/or b can be non numbers | This scenario will raise an exception |
| Example Function Calls | Example Output |
print(division(10, 2))
print(division("10", 2))
print(division(10, [1,2]))
print(division("10", 0))
print(division(10, 0))
print(division(10, 0.0))
print(division(10.0, 2.0))
|
10/2 = 5.0 Error: Unsupported type(s) for division! Error: Unsupported type(s) for division! Error: Unsupported type(s) for division! Error: Division by 0! Error: Division by 0! 10.0/2.0 = 5.0 |