while within while

Tony aclarke11 at yahoo.co.uk
Sun Oct 28 06:12:54 CET 2007


On Oct 27, 7:11 pm, Shawn Minisall <trekker... at comcast.net> wrote:
> snip
>
> import random
>
> def main():
>
>     #define and initialize variables
>     #choice as int
>     choice = 0
>     #weapon choice as int
>     weaponchoice = 0
>     #number of wins
>     win = 0
>     #number of loses
>     lose = 0
>     #number of ties
>     tie = 0
>     #number of rounds
>     rounds = 0
>     #play again loop
>     again = "no"
>
snip

In Python, you usually don't need to define your variables in advance.
Choice is determined as a number by your use of input() and the
response of the user, and in other code it could later be changed to
another type. So your initial declaration was unnecessary.'Dynamic
typing' its called, one of the joys of the language compared to  Java,
C etc.. So not doing that would make your code a bit simpler, one less
thing to worry about

Tony




More information about the Python-list mailing list