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 trialvikas pal
11,563 Pointswant to make a program
i want to make a program which take a input of a number and then it check if the number is in the variable name lists=[1,2,3,4,5] then print yes if it doesn't exist print no.some brief detail. lists=[1,2,3,4,5] #if these number in input then print yes if no then print no
vikas pal
11,563 Pointsprint('hello')
lists=[1,2,3,4,5]
answer=input('enter')
for item in lists:
if answer==item:
print('yes')
else:
print('no')
1 Answer
jacinator
11,936 Pointsvikas pal, this code should do what you want if I understand you correctly. It takes an input and checks if the input is in my_list
.
my_list = [1, 2, 3, 4, 5]
answer = input('enter ')
if answer in my_list:
print('yes')
else:
print('no')
Steven Parker
229,785 PointsSteven Parker
229,785 PointsWhat aspect of the task is causing an issue? Have you written any code yet? Please give the problem a good-faith attempt and post your code.
Also, can you provide a link to the course challenge or video?