0
mylist = [1, 2, 3, 4]
c = input ("c>")
if c in mylist :
    print c
else:
    print "not in list"

d = input ("d>")
if d in mylist and not c:
    print d
else:
    print "not in list" 

Please can someone tell me why the logic in the second if statement above doesn't work? In my head I'm saying "If d is in the list (therefore a valid choice) and it hasn't already been chosen (c) then print d, otherwise print "not in list".

I have already found a solution using .remove (below) but I don't understand why the other way doesn't work?

Many thanks

mylist = [1, 2, 3, 4]
c = input ("c>")
if c in mylist :
    print c
    mylist.remove(c)
else:
    print "not in list"

d = input ("d>")
if d in mylist:
    print d
else:
    print "not in list" 

0 Answers0