[Tutor] Help with Python

jitendra gupta jitu.icfai at gmail.com
Mon May 12 16:08:21 CEST 2014


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 <gchan401 at 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 at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140512/7689ae5f/attachment-0001.html>


More information about the Tutor mailing list