[Tutor] Simple Python Program

bob gailer bgailer at gmail.com
Sat Jul 31 20:35:03 CEST 2010


On 7/31/2010 12:00 AM, Jason MacFiggen wrote:
> Can anyone tell me how to fix the errors I am getting if possible? I'm 
> quite new and so confused...
I could give lots of diagnostic advice and detail. There is so much 
wrong with this program.

I suggest you discard it, back up and start with the simplest possible 
statement of the problem which is:
print a number randomly chosen from (0,1,2)

Then write the simplest possible program to do this one time; no loops 
or functions.
The entire program could then be written in 2 lines of code. Run it, fix 
it if it does not work. Once you have success -

Add (one at a time) various features:
- roll dice to select winner
- player names
- repetition

Continue to avoid writing functions. They are not necessary for such a 
simple program.

The final product will have less than 15 statements.

> also how do I display the winner under the displayInfo function?
> import random
>
> def main():
>     print
>
>     playerOne, playerTwo = inputNames(playerOne, PlayerTwo)
>
>     while endProgram == 'no':
>
>         endProgram == no
>         playerOne = 'NO NAME'
>         playerTwo = 'NO NAME'
>
>         winnerName = rollDice(p1number, p2number, playerOne, 
> playerTwo, winnerName)
>         winnerName = displayInfo
>
>         endProgram = raw_input('Do you want to end program? (Enter yes 
> or no): ')
>
> def inputNames(playerOne, PlayerTwo):
>
>     p1name = raw_input("Enter your name.")
>     p2name = raw_input("Enter your name.")
>     return playerOne, playerTwo
>
> def random(winnerName):
>
>     p1number = random.randint(1, 6)
>     p2number = random.randint(1, 6)
>
>     if p1number > p2number:
>         playerOne = winnerName
>     elif p1number < p2number:
>         playerTwo = winnerName
>     else p1number == p2number:
>         playerOne, playerTwo = winnerName
>
> def displayInfo():
>
>     #how do I display winner?
>
> main()
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>    


-- 
Bob Gailer
919-636-4239
Chapel Hill NC

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100731/fcf66ff4/attachment-0001.html>


More information about the Tutor mailing list