list = [1, 2, 3, 4]
c = input ("c>")
if c in list :
print c
else:
print "not in list"
d = input ("d>")
if d in list 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
list = [1, 2, 3, 4]
c = input ("c>")
if c in list :
print c
list.remove(c)
else:
print "not in list"
d = input ("d>")
if d in list:
print d
else:
print "not in list"
Aucun commentaire:
Enregistrer un commentaire