[Tutor] Why doesn't it choose a new number each time?
Alan Gauld
alan.gauld at btinternet.com
Wed Feb 14 01:07:06 CET 2007
"Nathan Pinno" <falcon3166 at hotmail.com> wrote
> I wrote a rock, paper, scissors game and every time you play
> without exiting, it chooses the same number. How can I fix this
> problem? The relative code is below:
I can't see anything obvious, can you be more specific. Which
number does it always choose(I assume you mean the choice()
call?) or does it choose a different number to stick on each time?
And have you tried putting a debug print statement after the call
to choice, just to see what you get out?
Just some thoughts,
Alan G.
[code]
# -*- coding: cp1252 -*-from random import *
print "Welcome to Rock, Paper, or Scissors!"print "by Nathan
Pinno"print "© 2007. All rights reserved."printwhile 1: answer =
int(raw_input("Would you like to play a game? 1 for yes and 2 for no.
")) if answer == 1: compchoice = choice(range(3))
humanchoice = int(raw_input("Enter 1 for rock, 2 for paper, and 3 for
scissors. ")) if compchoice == 1: print "AI chose
rock." if humanchoice == 1: print "You chose
rock. Tie game." elif humanchoice == 2:
print "You chose paper. You win!" elif humanchoice == 3:
print "You chose scissors. You lost!" else:
print "That's not an option. Choose again." elif compchoice ==
2: print "AI chose paper." if humanchoice == 1:
print "You chose rock. You lost!" elif humanchoice == 2:
print "You chose paper. Tie game." elif humanchoice == 3:
print "You chose scissors. You win!" else:
print "That's not an option. Choose again." else:
print "AI chose scissors." if humanchoice == 1:
print "You chose rock. You win!" elif humanchoice == 2:
print "You chose paper. You lost!" elif humanchoice == 3:
print "You chose scissors. Tie game." else:
print "That's not an option. Choose again." elif answer == 2:
break else: print "That's not an option."print
"Goodbye."[/code]
Thanks,
Nathan Pinno
--------------------------------------------------------------------------------
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list