Exception | SoloLearn: Learn to code for FREE!

+1

Exception

y=[int(i) for i in input().split()] print(y) def factorial(x): if x==0 or x==1: return 1 else: return x*factorial(x-1) def coef_binom(n,k): if k >n: print("Error:k>n") else: return factorial(n)/(factorial(k)*factorial(n-k)) print(coef_binom(y[0],y[1])) Hi, I want to use an exception if k >n. How I do modify this code?

4/3/2019 12:46:19 PM

Silvio Petix

2 Answers

New Answer

+2

+2

For example: raise ValueError (or whatever Error you want to use.) Here's a list to choose from (and you can also make your own). https://docs.python.org/3/library/exceptions.html