EXTREME NOOB, lists?

skeetor skeetornospam at bellsouth.net
Fri Sep 1 21:30:03 EDT 2000


Ok, apparently I was unclear.  This language is still unfamiliar to me...
please help me.
I want to combine all the elif statements with the if statement to say.
"if a is equal to any number in list x then print a's range"

here's what I have.

a = input ("which dice: ")
def dice_numbers(a):
     a = a + 1
     b = range(1, a)
     print b
if a == 4:
     dice_numbers (a)
elif a == 6:
     dice_numbers (a)
elif a == 8:
     dice_numbers (a)
elif a == 10:
     dice_numbers (a)
elif a == 12:
     dice_numbers (a)
elif a == 20:
     dice_numbers (a)
elif a == 100:
     dice_numbers (a)
else:
     print ("try again")



"Calvelo Daniel" <dcalvelo at pharion.univ-lille2.fr> wrote in message
news:8oo08p$72$2 at netserv.univ-lille1.fr...
> skeetor <skeetornospam at bellsouth.net> wrote:
> : I am trying to compare an input number with several numbers in a list,
and
> : then to print the range of that number. for example:  I have it ask for
a
> : number, and i reply with 4.  I want it to check to see if 4 is in the
list
> : and if so print the range.   I have solved the problem by writing out
the
> : argument for each number in the list... but it is very long.   I hope i
have
> : explained this accurately.  and please i am still a retarded four year
> : old... so talk slowely and use small words.  thanks.
>
> It's built into lists.
>
> >>> a = [ 3, 1, 4, 1, 5, 9, 2, 6 ]
> >>> a.index( 1 )
> 1
> >>> a.index( 9 )
> 5
> >>> a[ a.index( 4 ) ]
> 4
>
> Read the tutorial in parallel to whatever you are doing. Even if you don't
> get it exactly, at least you will have a vague idea of the possibilities.
>
> HTH, DCA
>
> -- Daniel Calvelo Aros
>      calvelo at lifl.fr





More information about the Python-list mailing list