Combination Function Help

John Ladasky john_ladasky at sbcglobal.net
Wed Feb 12 11:24:40 EST 2014


On Wednesday, February 12, 2014 7:56:05 AM UTC-8, kjak... at 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 beginning of your problem.

In your own program, you have two other working examples of functions which return and use values.  You should study these.  

The first, and easier function call for you to understand is the call to int().  You call it twice.  The first time, you ASSIGN the name "n" to the value returned by int().  The second time, you assign the name "k" to the value returned by another run of int().

Assigning the names to the values returned by the function calls is what allows you to work with those values later, on other lines of your program.  Without assigning n and k, attempting to call choices(n,k) would generate an error.

If int() was written in Python (it probably isn't; most of the Python core is written in C) and you looked at int()'s source code, it would have a "return" statement in it, just like your choices() does.

Does that help you to see how you should modify the last line of your program, and what you might do after that?

There's a second function call in your program as well: you call input().  This function call would be harder for a beginner to understand, because it happens to be nested inside the int() function call.  Let's take the simpler one first.



More information about the Python-list mailing list