所以我看過所有相關的問題,似乎無法找到特定於我的程序的答案。我必須有兩個玩家擲骰子游戲,擲出一個隨機數並宣佈獲勝者。截至目前,該程序運行時,它說: 獲獎者是: 輸入播放器1名: 輸入玩家名稱2:在Python中隨機骰子游戲
這裏是我的代碼:
import random
def main():
print "You are now playing Dice Roll!!"
endProgram = 'no'
playerOne = 'NO NAME'
playerTwo = 'NO NAME'
playerOne, playerTwo = inputNames(playerOne, playerTwo)
while endProgram == 'no':
winnnerName = 'NO NAME'
p1number = '0'
p2number = '0'
playerOne,playerTwo = inputNames(playerOne,playerTwo)
winnerName =()
winnerName = rollDice(p1number, p2number, playerOne, playerTwo, winnerName)
displayInfo = winnerName
endProgram = raw_input('Do you want to end program? (Enter yes or no): ')
def inputNames(playerOne,playerTwo):
playerOne = raw_input('Enter player one name:')
playerTwo = raw_input('Enter player two name:')
return playerOne, playerTwo
def rollDice(p1number, p2number, playerOne, playerTwo, winnerName):
p1number = random.randint(1,6)
p2number = random.randint(1,6)
if p1number == p2number:
print "TIE!!!!"
elif p1number > p2number:
print winnnerName
else:
p1number < p2number
print winnnerName
return winnerName
print "The winner is:",winnerName
main()
我不是在找答案只是指導走向正確的道路。 在此先感謝。
是的,這些論據似乎讓我很不高興。我迷失在他們需要的地方,以及我真正擁有他們的地方。你爲我解決了很多困惑。我要去修理我的代碼了!謝謝! – Matt331
不客氣!順便說一下,我還糾正了其他一些問題。您首先測試了變量'winnerName ==「NO NAME」',但讓我們假裝一名玩家將此作爲玩家名稱。每次他贏的時候都會說這是平局。所以我將它定義爲'winnerName = None',並用'winnerName是None'對其進行測試。 – mjorissen