Hi This will solve your purpose: Yes we can write in better way also : ------------------------------ #The Dice Game #add libraries needed import random
#the main function def main(): print #initialize variables playerOne = 'No Name' playerTwo = 'No Name' endProgram ="no" #call to inputNames playerOne, playerTwo = inputNames(playerOne, playerTwo) #while loop to run program again while endProgram == 'no': #call to rollDice winnersName = rollDice(playerOne, playerTwo) #call to displayInfo print "Winner is ", winnersName endProgram = raw_input('Do you want to end program? (Enter yes or no): ') #this function gets the players names def inputNames(playerOne, playerTwo): playerOne = raw_input("Enter Name") playerTwo = raw_input("Enter Name") return playerOne, playerTwo #this function will get the random values def rollDice(playerOne, playerTwo): p1number = random.randint(1, 6) p2number = random.randint(1, 6) #this function displays the winner if p1number == p2number: winnerName = "TIE" elif p1number > p2number: winnerName = playerOne else: winnerName = playerTwo return winnerName if __name__ == "__main__": # calls main main() On Sun, May 11, 2014 at 8:46 AM, Glen Chan <gchan...@msn.com> wrote: > Hello, I am a student trying to figure out Python. I am getting errors > that I don't know how to fix. What do you do after you get the error > message and something is highlighted? Does that have to be deleted? Anyway, > here is what I mean... > > > #>>> The Dice Game > #add libraries needed > import random > #the main function > def main(): > print > #initialize variables > playerOne = 'No Name' > playerTwo = 'No Name' > > #call to inputNames > playerOne, playerTwo = inputNames(playerOne, playerTwo) > #while loop to run program again > while endProgram == 'no': > #initialize variables > winnersName = 'NO NAME' > p1number = 0 > p2number = 0 > #call to rollDice > winnerName = rollDice(p1number, p2number, playerOne, playerTwo, > winnerName) > > #call to displayInfo > winnerName > endProgram = raw_input('Do you want to end program? (Enter yes or > no): ') > > > > #this function gets the players names > def inputNames(playerOne, playerTwo): > playerOne = raw_input("Enter Name") > playerTwo = raw_input("Enter Name") > > return playerOne, playerTwo > #this function will get the random values > def rollDice(p1numer, p2numer, playerOne, playerTwo, winnerName): > p1number = random.randint(1, 6) > p1number = random.randint(1, 6) > > #this function displays the winner > > if p1number == p2number: > winnerName = "TIE" > elif p1number > p2number: > winnerName = playerOne > else: > winnerName = playerTwo > return winnerName > > # calls main > main() > > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor