0

I am working on a deduct amount function and it should raise a run time error if a < b in value:

here is my code

def deduct_amount(a, b):
    try:
        b - a < 0
    except ValueError:
        print(a + ' can not be less than' + b)
    else:
        c = a - b
        return c


deduct_amount(8, 12)


I know my try statement is faulty. how can I throw a value error if a is less than b

Ada_lovelace
  • 503
  • 2
  • 4
  • 16

1 Answers1

5

A try/except block is to catch an exception. You want to raise an exception:

if a > b:
   raise ValueError("a must be less than b")
Jab
  • 25,138
  • 21
  • 72
  • 111