如何解决这些问题
•CherryB声明两次,首先声明为4个整数的列表,然后声明为整数。 •CherriesT也有同样的问题 •游戏没有定义
import random
#Identify players
players = ['1', '2', '3', '4']
#Identify cherry trees
CherriesT = [10, 10, 10, 10]
#Identify Buckets
CherryB = [0, 0, 0, 0]
#Action result from each spin
spinChoice = [1, 2, 3, 4, -2, -2, -10]
#Number of cherries in the tree
CherriesT = 10
#How to win
winnerindex = 0
turns = 0
while CherryB < 10:
for player in players:
randNum = random.randint(0,6)
PlayIn = players.index(player)
print PlayIn
spinResult = spinChoice[randNum]
print spinResult
CherriesT [PlayIn] = CherriesT [PlayIn] - spinResult
print CherriesT [PlayIn]
CherryB[PlayIn] = CherryB[PlayIn] + spinResult
#Check number of cherries is between 0 and 10
if CherryB[PlayIn] < 0:
CherryB[PlayIn] = 0
if CherriesT[PlayIn] > 10:
CherriesT[PlayIn] = 10
play = play + 1
if CherryB[PlayIn] == 10:
winnerindex = PlayIn
break
for player in players:
if players.index(player)<=winnerindex:
print player + " played " + str(play) + " times. Number of Cherries in"+player+"'s bucket:"+ str(CherryB[players.index(player)])
else:
print player + " played " + str(play-1) + " times. Number of Cherries in"+player+"'s bucket:"+ str(CherryB[players.index(player)])
print players[winnerindex] + " won after " + str(play) + " plays."
提前谢谢
一开始我不明白,但我想我解决了你的问题 随机导入
相关问题 更多 >
编程相关推荐