Re: Combination Function Help

2014-02-12 Thread Dave Angel
kjaku...@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 c

Re: Combination Function Help

2014-02-12 Thread Mark Lawrence
On 12/02/2014 22:59, kjaku...@gmail.com 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) comb = choices(n, k) print comb print ("Total number of ways of choosing

Re: Combination Function Help

2014-02-12 Thread kjakupak
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

Re: Combination Function Help

2014-02-12 Thread Dave Angel
kjaku...@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) > print ("Total number of ways of choosing %d out of %d courses: " % (n,

Re: Combination Function Help

2014-02-12 Thread Mark Lawrence
On 12/02/2014 15:56, kjaku...@gmail.com 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,

Re: Combination Function Help

2014-02-12 Thread John Ladasky
On Wednesday, February 12, 2014 7:56:05 AM UTC-8, kjak...@gmail.com wrote: [snip] > choices(n, k) > > Changed it like you said, didn't work What are you doing with the value returned by the function, choices()? Right now, you aren't doing anything with it. You are throwing it away. That's the

Re: Combination Function Help

2014-02-12 Thread Joel Goldstick
Y On Feb 12, 2014 11:00 AM, 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) Following line never runs > print ("Total number of ways of choosing %d o

Re: Combination Function Help

2014-02-12 Thread kjakupak
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 =

Re: Combination Function Help

2014-02-12 Thread Mark Lawrence
On 12/02/2014 15:20, kjaku...@gmail.com wrote: So I need to write a function based off of nCr, which I have here: def choices(n, k): if n == k: return 1 if k == 1: return n if k == 0: return 1 return choices(n - 1, k) + choices(n - 1, k - 1) It wor

Combination Function Help

2014-02-12 Thread kjakupak
So I need to write a function based off of nCr, which I have here: def choices(n, k): if n == k: return 1 if k == 1: return n if k == 0: return 1 return choices(n - 1, k) + choices(n - 1, k - 1) It works fine, but then I need to add in so that the user can