In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of January 4th
(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).
When b is zero, the function catches the respective exception and returns the string
"Error: Division by 0!"
. Additonally, if an argument is not a number in the function call, the function should also catch the equivalent error and returns the string "Error: Unsupported type(s) for division!"
".
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 b can be given as strings | This scenario will also raise an exception |
Example Function Calls | Example Output |
print(division(10, 2)) print(division("10", 2)) print(division(10, 0)) print(division(10, "b")) |
10/2 = 5.0 Error: Unsupported type(s) for division! Error: Division by 0! Error: Unsupported type(s) for division! |