[Tutor] Re: My code freezes python. :-)

Derrick 'dman' Hudson dman@dman.ddts.net
Sat Jan 11 19:36:27 2003


--3MwIy2ne0vdjdPXF
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Jan 12, 2003 at 12:22:33AM +0000, Guess Who? Me wrote:
| I got tired of asking questions about things in the tutorial, so I decide=
d=20
| to try to make a program that uses a random number (function call, I thin=
k=20
| its called?) to roll a dice. I messed around with it for a while, and I g=
ot=20
| it to the point where it freezes IDLE when I try to run it. :-) Here it i=
s.

It's not frozen.  It's running, but not doing anything (apparently)
useful.

|    while times > -1 :

We stop when 'times' is less than or equal to -1.  Presumably 'times'
is initially a positive number.

|        times=3Dtimes+1

Here times is incremented.  It gets larger.  Since it started >-1, it
is now moving farther away.  This loop can never end.  Change the line
to
         times =3D times - 1


Since your program deals with user input, there is some more you
should do :
    1)  what if the user says to roll the dice 0 times?  -10 times?

    2)  what if the user says to roll 0 dice >0 times?  How about if
        they say -4 dice?

(Hint: check for conditions like that and print an appropriate error
message instead)

-D

--=20
Stay away from a foolish man,
for you will not find knowledge on his lips.
        Proverbs 14:7
=20
http://dman.ddts.net/~dman/

--3MwIy2ne0vdjdPXF
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj4guEwACgkQO8l8XBKTpRQSkwCfcYn+BDmukpfzXziwkrKIHV67
00oAnj7exf6pthwayZvXDOiVo11GN6yi
=y0nz
-----END PGP SIGNATURE-----

--3MwIy2ne0vdjdPXF--