while within while
J. Cliff Dyer
jcd at sdf.lonestar.org
Sat Oct 27 15:35:07 EDT 2007
Shawn Minisall wrote:
> K I've since fixed the UnboundLocalError: local variable 'ai' referenced
> before assignment error, I forgot to include decision = (1, 2, 3) inside
> " " for each number.
>
>
You mean like decision = ("1", "2", "3") ? I don't think that would
have caused the error you reported. You probably changed something else
as well.
> Now when I run it, I get this..
>
> >>> main()
> READY TO PLAY ROCK, PAPER, SCISSORS???
>
> Please choose from the following menu:
> 1. See the rules
> 2. Play against the computer
> 3. Play a two player game
> 4. Exit
> Please enter your choice here: 2
>
> =====================
> you choose scissors
>
> I choose
>
> YOU LOSE!
>
> Rounds Won: 0
>
> Rounds Lost: 1
>
> Rounds Tied: 0
>
>
> Would you like to play again? y
> Please choose from the following menu:
> 1. See the rules
> 2. Play against the computer
> 3. Play a two player game
> 4. Exit
> Please enter your choice here: 2
>
> Please choose a weapon from the following menu:
> 1. Rock
> 2. Paper
> 3. Scissors
> Please choose a weapon: 1
>
> and then the weapon submenu repeats over and over.
>
> It's also like the program is ignoring
>
> if ai == "1":
> ai = "rock"
> if ai == "2":
> ai = "paper"
> if ai == "3":
> ai = "scissors"
>
> since it says I choose ________
>
>
Lo and behold: it *is* ignoring that block. Why? Or in other words
what set of conditions have to be true in order to reach that block?
Which one of them is false? (Hint: Check your while loops, and your
initialization variables.)
Also, Why not use decision = ('rock', 'paper', 'scissors')?
Cheers,
Cliff
More information about the Python-list
mailing list