# [Tutor] Question on listing cards, then deleting one or more items by user's choice.

luke rabidpoobear at gmail.com
Wed Aug 10 07:14:01 CEST 2005

```>Say I deal 5 cards, and then list them. How would I print the list of
cards, with the numbers >of each card(the position in the list)? Then delete
a certain card or cards, based upon the >user's choice?.

hope this points you in the right direction Nathan.
-Luke

#start of program
#------------------------------
alist = ["1","2","3","4","5"]
avar = ''
while 1:
if len(alist) == 0:
break
for item in range(len(alist)):
print "item at list index ", item, " == ", alist[item]
avar = raw_input("type -1 to exit or type the index of the item  you want
to remove ")
try:
avar = int(avar)
if avar == -1:
break
elif avar > len(alist):
print "oops error. indexOutOfRange"
else:
del(alist[avar])
except ValueError:
print "oops error. please enter an integer value."
#--------------------------------------------------

And the output:
#------------------------
item at list index  0  ==  1
item at list index  1  ==  2
item at list index  2  ==  3
item at list index  3  ==  4
item at list index  4  ==  5
type -1 to exit or type the index of the item  you want to remove 0
item at list index  0  ==  2
item at list index  1  ==  3
item at list index  2  ==  4
item at list index  3  ==  5
type -1 to exit or type the index of the item  you want to remove 3
item at list index  0  ==  2
item at list index  1  ==  3
item at list index  2  ==  4
type -1 to exit or type the index of the item  you want to remove 2
item at list index  0  ==  2
item at list index  1  ==  3
type -1 to exit or type the index of the item  you want to remove 0
item at list index  0  ==  3
type -1 to exit or type the index of the item  you want to remove -1

<snip siggy>

```