+ 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?
2 odpowiedzi
+ 2
Thanks
+ 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