[Tutor] Entering a list of numbers

doubletwist@spack.nu doubletwist@spack.nu
Mon, 5 Jun 2000 06:42:59 -0700 (PDT)


I am quite new to python as well as programming in general.
I've decided that for my first sort of 'assignment' to attempt to create a
python program for playing yahtzee. [Text at first, later perhaps to
attempt it graphically]

I'm still fairly early in the program but have gotten stuck. I created a
function to do the initial roll of the dice with no problem.
Now I'm trying to make a function for the input of which dice the user
wants to roll again. [ie enter which dice [1-6] they want to re-roll]

I'd like to have the user just enter the numbers separated by commas. The
only way I've figured out to do it is have the input entered into a tuple,
then transcribed to a list, but if they just enter one number [and thus no
comma] the conversion to a list fails with:
	
	
	Traceback (innermost last):
  	File "temp.py", line 40, in ?
    	rerolled = rollagain()
  	File "temp.py", line 25, in rollagain
    	while count < len(entered):
	TypeError: len() of unsized object

Is there an easier way of doing this? Or would I just be better off using
a loop of some sort and just having them enter each number followed by a
return?

My code as it stands follows... the function is called with :

rerolled = rollagain()

Thanks,
Doubletwist

---CODE BELOW----

def rollagain():
        elist = []
        entered = ()
        count = 0
        print "Which dice would you like to re-roll?"
        print "Separate with commas. Enter 99 to keep all dice"
        entered = input()
        while count < len(entered):
                elist.append(entered[count])
                count = count + 1
        return elist