Combination Function Help

Mark Lawrence breamoreboy at
Wed Feb 12 17:55:10 CET 2014

On 12/02/2014 15:56, kjakupak at wrote:
> def choices(n, k):
>      if k == 1:
>          return n
>      if n == k:
>          return 1
>      if k == 0:
>          return 1
>      return choices(n - 1, k) + choices(n - 1, k - 1)
>      print ("Total number of ways of choosing %d out of %d courses: " % (n, k))
> n = int(input("Number of courses you like: "))
> k = int(input("Number of courses you can register for: "))
> choices(n, k)
> Changed it like you said, didn't work

Changed it like who said?  I'm assuming myself, but with no context you 
can't always tell.  Also, stating "didn't work" is often useless to us. 
  What didn't work?  Why didn't it work?  Here it's obvious, you're 
throwing away the return value from your function call.  Either save the 
return value and print it or add the function call directly to your 
original print call.

My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

This email is free from viruses and malware because avast! Antivirus protection is active.

More information about the Python-list mailing list