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
Dorota Parzych
5,706 Pointsquest with tuples...
I wanted to write a program that accepts a sequence of numbers separated by commas and generates their list and tuples and checks if a given value is in a given list of numbers. E.g: 4 -> [1,4,3,7]: true -10 -> [1,4,3,7]: false
but in the end, the output is... ...far from intended and I am not sure what I have done wrong
values = input("Input some comma seprated numbers : ")
list = values.split(",")
tuple = tuple(list)
print('list : ',list)
print('Tuple : ',tuple)
number = print("")
searched_number = input("Please enter the number you are looking for: ")
for searched_number in tuple:
print("True")
else:
print("False")
thanks in advance!
1 Answer
Chris Freeman
Treehouse Moderator 68,468 PointsIt appears you want to use if instead of for in the last statement.
By using for you are looping through all the values in the tuple and printing True
Dorota Parzych
5,706 PointsDorota Parzych
5,706 Pointsok ... but now it shows me an error "'tuple' object is not callable"
Chris Freeman
Treehouse Moderator 68,468 PointsChris Freeman
Treehouse Moderator 68,468 PointsBe careful of assigning
tuple = tuple(...)as this overwrites the definition of thetupletype!