我试图让我的代码运行10000次。它需要运行10000次。记录每个玩家赢了多少次,每个玩家获得奖金的次数,以及三个玩家共获得奖金的次数。我不知道如何使这项工作,并一直试图找出它。有人能告诉我怎么做吗?我将在下面发布代码
#Part3
#Create a simulation of the game that runs 10,000 times.
#Keep track of how many times each player wins, how many times each player scores the bonus
#how many times all three players earned the bonus.
import random
Spin1 = (random.randint(1,20)*5)
print('Spin1', Spin1)
if (Spin1) > 94 :
Spin2 = 0
if (Spin1) == 100 :
Spin2 = 0
print('Player 1 spun 100! They have won $1,000!')
if (Spin1) < 94:
Spin2 = (random.randint(1,20)*5)
print('Spin2', Spin2)
SpinTotal1 = (Spin1 + Spin2)
print('Player 1 Score = ',SpinTotal1)
if (SpinTotal1) > 100 :
SpinTotal1 = 0
print('Player 1 spun above 100. They have been reset to',SpinTotal1)
import random
Spin1 = (random.randint(1,20)*5)
print('Spin1', Spin1)
if (Spin1) > 94 :
Spin2 = 0
if (Spin1) == 100 :
Spin2 = 0
print('Player 2 spun 100! They have won $1,000!')
if (Spin1) < 94:
Spin2 = (random.randint(1,20)*5)
print('Spin2', Spin2)
SpinTotal2 = (Spin1 + Spin2)
print('Player 2 Score = ',SpinTotal2)
if (SpinTotal2) > 100 :
SpinTotal2 = 0
print('Player 2 spun above 100. They have been reset to',SpinTotal2)
import random
Spin1 = (random.randint(1,20)*5)
print('Spin1', Spin1)
if (Spin1) > 95 :
Spin2 = 0
if (Spin1) == 100 :
Spin2 = 0
print('Player 3 spun 100! They have won $1,000!')
if (Spin1) < 95 :
Spin2 = (random.randint(1,20)*5)
print('Spin2', Spin2)
SpinTotal3 = (Spin1 + Spin2)
print('Player 3 Score = ',SpinTotal3)
if (SpinTotal3) > 100 :
SpinTotal3 = 0
print('Player 3 spun above 100. You have been reset to',SpinTotal3)
if (SpinTotal1 == SpinTotal2) :
SpinOff3 = 0
print('Tie! This results in a Spin Off between Player 1 and 2')
SpinOff1 = (random.randint(1,20)*5)
print('P1 Spin off score =', SpinOff1)
SpinOff2 = (random.randint(1,20)*5)
print('P2 Spin off score =', SpinOff2)
if (SpinTotal1 == SpinTotal3) :
SpinOff2 = 0
print('Tie! This results in a Spin Off between Player 1 and 3')
SpinOff1 = (random.randint(1,20)*5)
print('P1 Spin off score =', SpinOff1)
SpinOff3 = (random.randint(1,20)*5)
print('P3 Spin off score =', SpinOff3)
if (SpinTotal2 == SpinTotal3) :
SpinOff1 = 0
print('Tie! This results in a Spin Off between Player2 and 3')
SpinOff2 = (random.randint(1,20)*5)
print('P2 Spin off score =', SpinOff2)
SpinOff3 = (random.randint(1,20)*5)
print('P3 Spin off score =', SpinOff3)
if (SpinTotal1 > SpinTotal2 and SpinTotal1 > SpinTotal3 and SpinTotal1 > SpinOff2 and SpinTotal1 > SpinOff3):
print('Player 1 is the winner, will recieve $10,000 prize!')
if (SpinTotal1) == 100 :
print('Your total prize is $11,000! Congratulations!')
if (SpinTotal2 > SpinTotal1 and SpinTotal2 >SpinTotal3 and SpinTotal2 > SpinOff1 and SpinTotal2 > SpinOff3):
print('Player 2 is the winner, will recieve $10,000!')
if (SpinTotal2) == 100 :
print('Your total prize is $11,000! Congratulations!')
if (SpinTotal3 > SpinTotal1 and SpinTotal3 > SpinTotal2 and SpinTotal3 > SpinOff1 and SpinTotal3 > SpinOff2):
print('Player 3 is the winner, will recieve $10,000!')
if (SpinTotal3) == 100 :
print('Your total prize is $11,000! Congratulations!')
if (SpinOff1 > SpinTotal1 and SpinOff1 > SpinTotal2 and SpinOff1 > SpinTotal3 and SpinOff1 > SpinOff2 and SpinOff1 > SpinOff3):
print('Player 1 is the winner, $10,000!')
if (SpinOff1) == 100 :
print('Your total prize is $11,000! Congratulations!')
if (SpinOff2 > SpinTotal1 and SpinOff2 > SpinTotal2 and SpinOff2 > SpinTotal3 and SpinOff2 > SpinOff1 and SpinOff2 > SpinOff3):
print('Player 2 is the winner, $10,000!')
if (SpinOff2) == 100 :
print('Your total prize is $11,000! Congratulations!')
if (SpinOff3 > SpinTotal1 and SpinOff3 > SpinTotal2 and SpinOff3 > SpinTotal3 and SpinOff3 > SpinOff1 and SpinOff3 > SpinOff2):
print('Player 3 is the winner, $10,000!')
if (SpinOff3) == 100 :
print('Your total prize is $11,000! Congratulations!')
这是一个类似的游戏,规则较少,只是在所有角色中获得最高分数,并根据玩家获得的分数奖励该玩家,并跟踪每个分数和胜利
这是完整的代码,但我建议您逐个复制函数,测试实际执行的操作,了解如何拆分复杂任务
您应该使代码成为具有所需输入变量的函数。一旦您有了这样的功能,在循环中运行,并将每次运行的输出存储在列表中,以供以后评估:
相关问题 更多 >
编程相关推荐