Home > OS >  how do i repeat this equation for decreasing t?- python
how do i repeat this equation for decreasing t?- python

Time:01-20

I'm still new to python but i have this equation


#Import math Library
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  

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

CodePudding user response:

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

CodePudding user response:

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
  •  Tags:  
  • Related