samedi 26 août 2017

How to run a calculation until true within a loop python

Hi so a quick question for spyder python 3.6

Say I have a simple while loop or if statement.

import random

from decimal import Decimal

usraccbal = (1000.01)

def rate():
    ratecontents = (random.random() * (1.202 - 0.308) + 0.308)
    return ratecontents

def newconvert(amount, rate):
    a = (amount * rate)
    return a, amount

b = rate()
rate1 = b

c = newconvert(usraccbal, rate1)

newcnvrt = (c[0])

prevusraccbal = (c[1])

#while or if here
if newcnvrt == prevusraccbal or newcnvrt < prevusraccbal:
    #Continue calculating until newcnvrt > prevusraccbal 
    #then update values
else:
    #Update values 
    usraccbal = newcnvrt

As you can see I would like to continue trying to get a newcnvrt which equals more than prevusraccbal either in an if or a while loop. So importantly it is constantly getting a new exchange rate and trying to use that.

The code is actually in a function normally which has root.after(3000,results) and is actioned by a button press

Aucun commentaire:

Enregistrer un commentaire