在Python 2.7中工作。在python中迭代的問題
我希望能夠輸入一個數字,並返回x和y的所有值集合,以完成方程win_percentage = observed。
def Rlog5(observed):
z = float(observed)/1000
for x in range(350, 650, 1):
y = 1000 - x
win_percentage = (float(x)-(float(x)*float(y)))/(float(x)+float(y)-(2*(float(x)*float(y))))
if win_percentage = observed:
print (z, float(x), float(y))
當我運行該功能時,我什麼也沒有。沒有錯誤,但沒有值(我嘗試過,沒有浮點數的x,但我認爲它需要它們,因爲win_percentage應該是浮點數)。最無奈的是,我有這樣的代碼,基本上做同樣的事情,並能正常工作:
def solve(numNuggets):
for numTwenties in range(0, numNuggets/20 + 1):
for numNines in range(0, (numNuggets - numTwenties*20)/9 + 1):
numSixes = (numNuggets - numTwenties*20 - numNines*9)/6
totNuggets = 20*numTwenties + 9*numNines + 6*numSixes
if totNuggets == numNuggets:
print (numSixes, numNines, numTwenties)
我知道這種一個新手的問題,但我在我無計可施......
你不可能有'如果win_percentage =觀察:'因爲這是一個'SyntaxError',你需要''==不是'='。 – agf