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

Python

Dorota Parzych
Dorota Parzych
5,706 Points

error: 'tuple' object is not callable

Hi, I have got an error in my code...

I wanted to write a program that accepts a sequence of numbers separated by commas and generates their list and tuples.

Then it 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

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: ")

if searched_number in tuple:
  print("True")
else:
  print("False")

1 Answer

Steven Parker
Steven Parker
230,248 Points

The code shown above runs without an error. Did you perhaps post the wrong code?

One thing in it is rather odd, though:

number = print("")

This statement prints an empty line but doesn't assign "number" with anything useful. And "number" isn't used later in the code.

Dorota Parzych
Dorota Parzych
5,706 Points

I have no idea what this line is doing in my code, ​to be honest, haha

number = print("")

anyway, I am sending you a link down here... link: https://w.trhou.se/b53o9stw21 cause anyway it shows:

Input some comma-separated numbers: 1,2,3
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-64-f0bb55ad848d> in <module>()
      4 values = input("Input some comma seprated numbers : ")
      5 a_list = values.split(",")
----> 6 a_tuple = convert(list)
      7 
      8 #print("List: ",a_list,"Tuple: ", a_tuple)

<ipython-input-64-f0bb55ad848d> in convert(list)
      1 def convert(list):
----> 2     return tuple(list)
      3 
      4 values = input("Input some comma seprated numbers : ")
      5 a_list = values.split(",")

TypeError: 'tuple' object is not callable
Steven Parker
Steven Parker
230,248 Points

This is what I get when I run it:

Input some comma seprated numbers : 1,2,3                                                        
list :  ['1', '2', '3']                                                                          
Tuple :  ('1', '2', '3')                                                                         

Please enter the number you are looking for: 2                                                   
True

But you're clearly running different code, because in your output sample the prompt says "comma-separated" but in the snapshot it is "comma seprated".