Try Except#

Part 1#

What is the output of the following code?

def divide_two_numbers(x, y):
    result = x / y
    return result
try:
    result = divide_two_numbers({{ params_vars_a }},{{ params_vars_b }})
    print(result)
except NameError:
    print("A NameError occurred.")
except ValueError:
    print("A ValueError occurred.")
except ZeroDivisionError:
    print("A ZeroDivisionError occurred.")

Answer Section#

  • A ZeroDivisionError occurred.

  • Output of: result

  • A ValueError occurred

  • A NameError occurred

Attribution#

Problem is licensed under the CC-BY-NC-SA 4.0 license.
The Creative Commons 4.0 license requiring attribution-BY, non-commercial-NC, and share-alike-SA license.