Hi I am having problems with this code please help. PS all your help so far ha really helped me so thank you!!!
import random
def whiles():
myRand = round(random.random() * (0.909 - 0.101) + 0.101, 3)
print ("myrand Initial", myRand)
amt = 1000
amt2 = 0
while myRand > 0:
# def trade1():
myRand = round(random.random() * (0.909 - 0.101) + 0.101, 3)
# print (myRand)
if (myRand > 0.5):
print ("my usd rate", myRand)
trd1 = amt * myRand
print ("trade1 =", trd1)
amtPrev = amt
def myRandom2():
myRand2 = round(random.random() * (1.909 - 1.101) + 1.101, 3)
print ("my nzd rate", myRand2)
if (trd1 * myRand2 < amtPrev):
myRand2 = round(random.random() * (1.909 - 1.101) + 1.101, 3)
print ("my nzd rate", myRand2)
else:
trd2 = trd1 * myRand2
print ("trade2 =", trd2)
myRandom2()
else:
print ("error less than 0.5")
whiles()
Ok so what i am trying to do is in the second if statement if (trd1 * myRand2 < amtPrev) I would like to then go back a few steps to the myRand2 underneath def myrandom2() and essentially run myRandom2 again until I have a value which = (trd1 * myRand2 > amtPrev). I am not sure if i need to do the functions trade1 and trade2? to do this. If i do end up with a value where trd2 > amtPrev i would then like to do the function trade1 again and make sure that the next trd1 amount = more than the last trd2 amount and then run the while loop infinitely im almost there but am stuck at the end.
Thanks for your help
Aucun commentaire:
Enregistrer un commentaire