Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66047

Re: Combination Function Help

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Combination Function Help
Date 2014-02-12 15:40 +0000
References <bd88bd17-76d0-43de-9649-daa9ef86155e@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.6760.1392219671.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 12/02/2014 15:20, kjakupak@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 works fine, but then I need to add in so that the user can have an input box for n and k.
>
> 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)
>
> n_input = int(input("Number of courses you like: "))
> k_input = int(input("Number of courses you can register for: "))
>
> The above doesn't return any value at all. And then I need it to print the total number of ways of choosing k out of n courses, which I only have:
>
> print ("Total number of ways of choosing %d out of %d courses: " % (n_input, k_input))
>
>
> So basically I need help figuring out why it won't return any value and how to print that final value.
>

Actually calling choices with n_input and k_input as inputs might help 
your cause.

-- 
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.
http://www.avast.com

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Combination Function Help kjakupak@gmail.com - 2014-02-12 07:20 -0800
  Re: Combination Function Help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-12 15:40 +0000
    Re: Combination Function Help kjakupak@gmail.com - 2014-02-12 07:56 -0800
      Re: Combination Function Help Joel Goldstick <joel.goldstick@gmail.com> - 2014-02-12 11:21 -0500
      Re: Combination Function Help John Ladasky <john_ladasky@sbcglobal.net> - 2014-02-12 08:24 -0800
      Re: Combination Function Help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-12 16:55 +0000
      Re: Combination Function Help Dave Angel <davea@davea.name> - 2014-02-12 13:38 -0500
        Re: Combination Function Help kjakupak@gmail.com - 2014-02-12 14:59 -0800
          Re: Combination Function Help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-12 23:15 +0000
          Re: Combination Function Help Dave Angel <davea@davea.name> - 2014-02-12 18:22 -0500

csiph-web