Python 如何修复此循环?
这是一个游戏,我正在工作,我似乎无法想出如何循环与while循环不使用任何计数或等数字。游戏是僵尸骰子,如果你想知道的话Python 如何修复此循环?,python,python-2.7,Python,Python 2.7,这是一个游戏,我正在工作,我似乎无法想出如何循环与while循环不使用任何计数或等数字。游戏是僵尸骰子,如果你想知道的话 print "If you would like to continue say \"1\" if you don't want to continue say \"2\"." con=raw_input("Do you want to continue?") while con == "1": while dice in range (0,13): # This
print "If you would like to continue say \"1\" if you don't want to continue say \"2\"."
con=raw_input("Do you want to continue?")
while con == "1":
while dice in range (0,13): # This is for when the user wants to continue.
print dice
dice[0] = random.randrange(0,13)
print dice[0];
dice[1] = (raw_input("Roll your First dice"))
dice[1] = random.randrange(0,12)
dice1 = ["brain","brain","brain","brain","shotgun","shotgun","shotgun","shotgun","shotgun","footprint","footprint","footprint"]
print random.choice(dice1)
print dice[1];
dice[2] = raw_input("Roll your Second dice")
dice[2] = random.randrange(0,11)
dice2 = ["brain","brain","brain","brain","shotgun","shotgun","shotgun","shotgun","shotgun","footprint","footprint","footprint"]
print random.choice(dice2)
print dice[2];
dice[3] = raw_input("Roll your Third dice")
dice[3] = random.randrange(0,10)
dice3 = ["brain","brain","brain","brain","shotgun","shotgun","shotgun","shotgun","shotgun","footprint","footprint","footprint"]
print random.choice(dice3)
print dice[3];
# This code is for when the player does not want to continue.
print "You choose \"No\" Second players turn"
import random
dice[1] = raw_input("Roll your First dice")
dice[1] = random.randrange(0,13)
你不会中断循环,因为
con
保持为“1”
你的代码会立即抛出名称错误,因为骰子在你while
循环中将其用作谓词之前没有定义。你在哪里定义骰子?我想他之前也定义过骰子,与问题无关,为什么要用12个值来“掷骰子”,而不是每个值6的2个骰子?对于面向对象编程的未来概念,最好仔细思考这些类型的东西。我认为,这些东西的价值在于它有你想要的答案。