mardi 5 mai 2020

How to do a Loop with umbrals and replace in Python?

n = 50
inflation = list()
for i in range(n):
        if n > i:
            inflation.append(np.random.uniform(-5, 5))
plt.plot(inflation, label = 'inflation')
plt.legend(loc='best')
plt.show() 

I want to do a loop that permits me to replace the value. I have this code: So, when the cumulated inflation will be higher than an umbral, in this case 10 I want to adjust my value c by cumulated inflation that is b, c + c*b, and start again replacing the value of b in 0 and cumulating until reach higher than my umbral and print all times that b was higher than the umbral.

a = 10
b = 0
c = 5000
for i in range(len(inflation)):
        if b < a:
            b = b + inflation[i]
        elif b == a or b > a:
            print('Acumulated Inflation: ', b, "Period: ", i)
            c = c + c*b
            b = 0
            print('Adjusted Pension in period',str(i),": ",c)
            if b < a:
                 b = b + inflation[i]                
            #repeat until n = 50.

This code does not work but my idea, I think have this conception.




Aucun commentaire:

Enregistrer un commentaire