## 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.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
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.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
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