'How do I repeat a computation with a decreasing parameter in Python?

I have the following code snippet:

import math
n=800
t=380
a=(0.5**t)*(0.5**(n-t))
m=((math.factorial(n))//(math.factorial(n-t)*math.factorial(t)))
a*m  
print(a*m)

How do I make it so that it repeats for a decreasing t?



Solution 1:[1]

You can use a loop to repeat code several times, e.g.

foo = 10
while foo > 0:
    foo -= 1
    print(foo)

will output

9
8
7
6
5
4
3
2
1
0

Solution 2:[2]

You can use a loop until t reaches some value, like this...

#Import math Library

import math

n, t = 800, 380
a = (0.5**t)*(0.5**(n-t))

while t>0:
    m = ((math.factorial(n))//(math.factorial(n-t)*math.factorial(t)))
    t -= 1
    a *= m

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Someone_who_likes_SE
Solution 2 MK14