每个游戏(gameA和gameB)都是随机的,每个游戏都有与玩家相对的赔率,每玩一次游戏,如果你赢了,你就赢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
你有两个语法错误,一个空格错误,你使用的关键字不存在。你知道吗
所有这些都在
gameB
中重复。你知道吗此外:
profitA
和profitB
在testA
和testB
中没有定义。你知道吗testA
是与testB
相同的代码,这意味着随着时间的推移,它们将返回大约相同的值。你知道吗相关问题 更多 >
编程相关推荐