IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Python: I'm overlooking something obvious.
This code:

import random\nrandom.seed()\n\ndef rolldice(numdice):\n    result=0\n    rolls=[]\n    for n in range(1,numdice):\n        roll=random.randint(1,6)\n        rolls.append(roll)\n        if result < roll:\n            result = roll\n        elif roll==6:\n            result+=1\n    return [result,rolls]


Is giving me this error:

>>> dice.rolldice(4)\nTraceback (most recent call last):\n  File "<interactive input>", line 1, in ?\n  File "dice.py", line 7, in rolldice\n    for n in range(1,numdice):\nNameError: global name 'randint' is not defined


Yes, I know that randint is not defined somehow, but that's in a module that comes by default with Python, not in something I control. If I understand properly, importing random should result in all random functions being initialized, no?
apt-get install godlike-powers
New Works For Me.
Python 2.3.4 (#2, Dec  3 2004, 13:53:17) \n[GCC 3.3.5 (Debian 1:3.3.5-2)] on linux2\nType "help", "copyright", "credits" or "license" for more information.\n>>> import dice\n>>> dice.rolldice(4)\n[4, [4, 2, 2]]\n


What version of Python?

Incidentally, please do yourself and other future programmers who might have to look at your code, and put some whitespace around your operators:
import random\nrandom.seed()\n\ndef rolldice(numdice):\n    result = 0\n    rolls = []\n    for n in range(1, numdice):\n        roll = random.randint(1, 6)\n        rolls.append(roll)\n        if result < roll:\n            result = roll\n        elif roll == 6:\n            result += 1\n    return [result, rolls]

This has been a PSA (programming style analism).
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Funky. 2.4.1, ActiveState installer.
Also works fine from the command line version - only from the PythonWin Interactive Window does it puke.

Thanks!
apt-get install godlike-powers
Expand Edited by inthane-chan Aug. 10, 2005, 01:59:34 PM EDT
     Python: I'm overlooking something obvious. - (inthane-chan) - (2)
         Works For Me. - (admin) - (1)
             Funky. 2.4.1, ActiveState installer. - (inthane-chan)

___oO0Oo___play Zarathustra chords___oO0Oo___
64 ms