python3.6中的无限while循环

2024-09-27 07:28:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一些值,比如amt1, amt2val1 = .75, val2 = 1.25。我想这样做:

假设amt1是1000,我乘以val1.1000*.75=750,然后把这个量赋给amt2,所以amt2 = amt1 * val1。在

然后用amt2乘以val2,所以750*1.25=937。在

如果amt2 * val2的乘积小于amt1,则再次进行整个计算,直到val2的值导致总和大于amt1。在

我也希望,如果它真的等于,然后再做整个事情,但是像这样的倒数值。我真的不知道如何实现这一点,甚至不知道如何正确地提出这个问题。在

# -*- coding: utf-8 -*-
"""
Created on Sun Jul 23 00:57:28 2017

@author: Anwar Goulouh
"""

def infiniteloop():
#   TRADE1
#   define an amount to trade first myAmt1, define what base currency is 
#   and currency to trade to nzd and usd, define exchange rates for both,
#   once i have completed the second trade I would like to do trade 1 again
#   only the myAmt1 will be the value in myResult2
myAmt1 = int(10000)
print ("My Amount 1 = $",myAmt1)
myVar1 = "nzd"
myVar2 = "usd"
#   Iwould like these following two values to be either a webrequest from 
#   google or random decimals for myVar1ExRate value will always be 1 an the 
#   second will be something between 0.701 and 0.909 so need to figure out 
#   how to generate the random number also for now i will use hardcoded 
#   values
myVar1ExRate = int(1.00)
myVar2ExRate = float(0.7565)
print ("ex rates", myVar1,myVar2,"NZD ExRate =", myVar1ExRate,"USD ExRate 
=",myVar2ExRate,)
#   do first trade
print ("do first trade $",myAmt1, "* USD Ex Rate",myVar2ExRate,)
myAmt2 = int(myAmt1*myVar2ExRate)
print ("My Amount 2 =$",myAmt2)
#   TRADE2
#   I then attempt to trade the full amount of myAmt2 back from USD to NZD 
#   and make a profit to do this the 
#   the exchange rate of the NZD must be above a certain amount otherwise
#   it will result in a loss i do not know how to correctly code the if 
#   statement for this but will make an attempt the idea is that it runs 
#   infinitely.
#   So...
#   I then switch the values of myVar1 and my Var2 as follows and put them 
#   to new vars so I can use them again i also need to define the previous 
#   amount of MyAmt1
myVar1Prev = (myVar1)
myVar2Prev = (myVar2)
myAmt1Prev = (myAmt1)
#   I now perform the switch
myVar1 = (myVar2Prev)
myVar2 = (myVar1Prev)
print ("New currencies", myVar1, myVar2)
#   add the new exchange rates
myNewExRate1 = int(1)
myNewExRate2 = float(1.2523)
print ("New ex rates", myVar1,myVar2,"USD ExRate =", myNewExRate1,"NZD 
ExRate =",myNewExRate2,)
#   now i need to do an if statement and if it fails then try again until 
#   MyNewExRate2 has a value which equals a profit
if  myAmt1Prev == (myAmt1Prev < myAmt2 * myNewExRate2):
    myNewAmt2 = int(myAmt1Prev < myAmt2 * myNewExRate2)
    print ("the Amount is less than$", myAmt1Prev)
else
    myAmt1Prev == (myAmt1Prev > myAmt2 * myNewExRate2):
    myNewAmt2 = int(myAmt1Prev > myAmt2 * myNewExRate2)
    print ("you made a profit$", myAmt1Prev)      
#   once this is all done say if myNewExrate had been 1.4565 and i had 
#   successfully made a profit I want to then put the new amount I had made 
#   in the else statement to myAmt1 then do the if statement again to see if 
#   i would make a profit trading back to USD and so on forever
#   I should be able to get this to run infinitely but am unsure how to code 
#   it effeciently and correctly  I dont know?????

infiniteloop()

Tags: andthetoifbedowillint

热门问题