【发布时间】:2014-11-01 01:40:48
【问题描述】:
当我在下面运行我的代码时,我得到了平局和玩家二的结果,但玩家一显示为 NO NAME。无法弄清楚为什么当我输入名称时 playerOne 变量没有改变。新手程序员希望对我的工作有所帮助。
import random
#the main function
def main():
print
#initialize variables
endProgram = 'no'
playerOne = 'NO NAME'
playerTwo = 'NO NAME'
#call to inputName
playerOne, playerTwo = inputNames(playerOne, playerTwo)
#while loop to run program again
while endProgram == 'no':
winnerName = 'NO NAME'
#initialize variables
p1number = 0
p2number = 0
#call to roll dice
winnerName = rollDice(playerOne, playerTwo, winnerName)
#call to display info
winnerName = displayInfo(winnerName)
endProgram = raw_input ('Do you want to end the program? (Enter yes or no): ')
#this function gets the players names
def inputNames(playerOne, playerTwo):
playerOne = raw_input('Player one enter name ')
playerTwo = raw_input('Player two enter name ')
return playerOne, playerTwo
#this function will get the random values
def rollDice(winnerName, playerOne, playerTwo):
p1number = random.randint (1, 6)
p2number = random.randint (1, 6)
if (p1number == p2number):
winnerName = 'TIE'
elif (p1number > p2number):
winnerName = playerOne
else:
winnerName = playerTwo
return winnerName
#this function displays the winner
def displayInfo(winnerName):
print 'The winners name is ', winnerName
#calls main
main()
【问题讨论】:
-
抱歉 -- StackOverflow 不是一个通用的调试服务。现在,如果您已将问题缩小到特定问题或疑问(最好使用最少的复制器 - 请参阅 stackoverflow.com/help/mcve),那么我们将在更好的地方提供帮助。
标签: python python-2.7