Write a python script to calculate nCr using functions.. | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

Write a python script to calculate nCr using functions..

20th Nov 2016, 7:45 AM
Neilvarghese Abrha
Neilvarghese Abrha - avatar
2 Réponses
+ 5
Samuel is right. In the end, you just need to write print nCr(x,y) where x,y can be anything but x>y of course.😜
23rd Nov 2016, 6:28 AM
Tamoghna Saha
+ 2
import operator as op def nCr(n, r): r = min(r, n-r) if r == 0: return 1 numer = reduce(op.mul, xrange(n, n-r, -1)) denom = reduce(op.mul, xrange(1, r+1)) return numer // denom
20th Nov 2016, 7:58 AM
Samuel Neo
Samuel Neo - avatar