## Maths symbol

### Maths symbol

I'm not a mathematician and I don't understand how to interpret the three dots between multiplication symbols; x...x in this formula for equating possible combinations:

$Image$

Can somebody tell me how to interpret it please?
Hypernova

Posts: 18
Joined: Mon Jun 10, 2013 12:23 am

### Re: Maths symbol

Moved to the bar, because this is not a Python question.

They're ellipses, implying that there is more in between but that the pattern should be recognizable. So the whole thing is the product of all the parts with denominators (k, k-1, k-2, k-3, ..., 3, 2, 1) and the numerator has its own pattern.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.

micseydel

Posts: 1436
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

### Simple math code

Where am I going wrong here? If n=4 and k=2, I can only get 12 where 6 is the solution. I'm using this equation to find the number of possible combinations ;
$Image$

Here's my code:
Code: Select all
`def choose(n,k):   a=((n-k+2)/2)   c=((n-k+1)/1)   b=n/k   for i in range(1,k-1):      b=b*((n-i)/(k-i))   return (int(b*a*c))Running choose(4, 2) … Error: choose(4, 2) has wrong value 12, expected 6`

BTW, this is a graded exercise for learning python and I included the error report.

Edit: Sorry, I didn't realize this had been moved
Hypernova

Posts: 18
Joined: Mon Jun 10, 2013 12:23 am

### Re: Maths symbol

Don't bother with a and c here. Just initialize a variable to 1, and then multiply it by each part of your product. My function body is 4 lines, including initialization, loop header, loop body and return statement. Try simplifying your code, and if you still have a question after doing so, post your simplified code.

When I wrote this function, I took advantage of the associative property, as a hint for simpler code.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.

micseydel

Posts: 1436
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

### Re: Maths symbol

Yeah you're right. I realized I was getting double the required amount because my code was wrong, and I was getting 36 when i corrected it, so I then thought I was multiplying 6 by 6 and getting 36 and kinda guessed that I was doing the same thing twice and multiplying it together. So I removed the a and b part and pretty much instantly solved it. Thanks.
Hypernova

Posts: 18
Joined: Mon Jun 10, 2013 12:23 am