Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
vikas pal
11,563 Pointshow to use it
why if i use something like that "answer=input('> ')" then i use answer with "IN' then in always return false.for example:
print('hello')
lists=[1,2,3,4,5]
answer=input('enter')
for item in lists:
if answer==item:
print('yes')
else:
print('no')
1 Answer
Kristian Gausel
14,661 PointsBecause input / raw_input (for python 2) returns a string. and:
"1" == 1 # == False
#while:
int("1") == 1 # == True
So try this:
print('hello')
lists = [1,2,3,4,5]
answer = int(input('enter')) #This is the only line that changed
for item in lists:
if answer == item:
print('yes')
else:
print('no')
vikas pal
11,563 Pointsvikas pal
11,563 Pointsthank so much you clear my doubt .thank you :--)))))))).yipeeeeeeeeeeeee