Combination Function Help

Dave Angel davea at davea.name
Wed Feb 12 18:22:07 EST 2014


 kjakupak at gmail.com Wrote in message:
> 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)
> 
> comb = choices(n, k)
> print comb
> 
> 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: "))
> 
> Still isn't working though..
> 

Still haven't figured how to post a traceback? 

The two lines defining and referencing comb need to be AFTER n and
 k are defined and given values. 

Also, what version of Python are you running?  Version 3.x
 requires parentheses around the arguments to the print function.
 

-- 
DaveA




More information about the Python-list mailing list