Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

How do I use a raise function on python

import math

def divider(number1, number2):
  if number1 <= 0:
    raise ZeroDivisionError("Has to be more than zero")
  return number1 / number2

try:
  firstQ = float(input("Input 1: \n"))
  secondQ = float(input("Input 2: \n"))
except ValueError as err:
  print("ERROR")
else:
  answer = divider(firstQ, secondQ)
  answer = math.ceil(answer)

print("The answer for {} divided by {} is {}!"  .format(firstQ, secondQ, answer))

1 Answer

You are raising it correctly. However, if you would like to actually catch the exception, you would need to put the call to divider within the try: block.