Windows,Spyder,Python 3.6
您好,我正在逐步处理此代码,并且我继续为计算获取null值。我在它之前执行相同的计算,当我自己打印变量时,它们没有空值。我正在处理的代码如下。运行代码时得到的结果是trd1()函数的值不断改变,但trd2()函数的值是0.0。我找了答案,但似乎找不到相关的答案?
import random
#define variables
amt1 = (1000)
amt2 = (1000)
prevAmt1 = ()
prevAmt2 = ()
#create random exchange rates
def exRt1():
return round(random.random() * (1.399 - 1.001) + 1.001, 3)
def exRt2():
return round(random.random() * (0.999 - 0.699) + 0.699, 3)
#assign exchange rates to variables
rate1 = exRt1()
rate2 = exRt2()
#create a conversion function
def convert(amount, exchange_rate):
return amount * exchange_rate
#create trade functions
def trd1(amount1,exRt2):
trd1Amt = convert(amount1, exRt2())
print(trd1Amt)
return trd1Amt
trd1(amount1,exRt2)
def trd2(amount2,exRt1):
trd2Amt = convert(amount2, exRt1())
print(trd2Amt)
return trd2Amt
trd1(amount2,exRt1)