Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Simple python question. How do I make the values in my list read in an input. I know this is prob too basic for u guys but I need to figure this out

1

This is my work and it wont read the items inside my list. What should I do?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading