每场比赛(比赛A和比赛B)都是随机的,每场比赛都有与玩家叠加的赔率,每次玩任何一场比赛,如果你赢了,你赢了1美元,如果你输了,你输了1美元。我想生成一个从 0 到 1 的随机数,如果这个数字小于 0.4 我输了,如果它更大我赢了。这是代码,但它给了我一个错误,你能帮我吗?问题是:玩这个游戏我损失了多少钱?
import random
def testA():
# game A
gameA = random.random()
if gameA>0.4 #error
profitA=profitA+1
end
return profitA
def testB():
#game B
gameB = random.random()
if gameB>0.4
profitA=profitA+1
end
return profitB
def runTests(repititions):
sumA = 0
sumB = 0
for i in range(repititions):
profitA = testA()
profitB = testB()
sumA += profitA
sumB += profitB
return sumA, sumB
repititions = int(raw_input("Repititions: "))
sumA, sumB = runTests(repititions)
print sumA
print sumB