This is my work and it wont read the items inside my list. What should I do?
CodePudding user response:
Should be:
if bag in notallowed:
CodePudding user response:
Your if
condition is wrong. You should check if the bag
is in a lit, `notallowed'.
The error message means, you are trying to check if ['gun', 'knife']
is in gun
, which is impossible. The error is saying that the left of in
should be a character (but you used a list), because right of in
is a string.
bag = input("What is inside your bag?")
notallowed = ['gun', 'knife']
if bag in notallowed: # This line is fixed
print("now way")
else:
print("You may pass")
The code result:
What is inside your bag?gun
now way # It prints correctly now.