This is to be a simple dice game, that rolls two dice, picks a random value, picks the winner or if it's a tie, says tie.
#Lab 7-3 The Dice Game #add libraries needed 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 (p1number, p2number, playerOne, playerTwo, winnerName) #call to display info displayInfo = winnerName endProgram = raw_input ('Do you want to end the program? (Enter yes or no): ') #this function gets the players names def inputNames(): inputNames = raw_input('Please enter your names') playerOne, playerTwo = inputNames (playerOne, playerTwo) return playerOne, playerTwo #this function will get the random values def rollDice(): p1number = random.randit (1, 6) p2number = random.randit (1, 6) if p1number >= p2number: winnerName = playerOne if p1number == p2number: winnerName = 'TIE' else winnerName = playerTwo return winnerName #this function displays the winner def displayInfo(): print 'The winners name is ', winnerName #calls main main()
This post has been edited by JackOfAllTrades: 13 May 2010 - 10:44 AM
Reason for edit:: Added code to post.