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

TypeError: number() takes 0 positional arguments but 1 was given

What is wrong with my code?

def number():
    answer = number + number
    print(number)

number(2)
number(3)
number(0)



I keep getting this error:

treehouse:~/workspace$ python Practice.py                                                                                                            
Traceback (most recent call last):                                                                                                                   
  File "/home/treehouse/workspace/Practice.py", line 5, in <module>                                                                                  
    number(2)                                                                                                                                        
TypeError: number() takes 0 positional arguments but 1 was given

1 Answer

def number():
    answer = number + number
    print(number)

In the line def number():, the function does not have any parameters. If you want your function to accept an argument, you could change the first line to be def number(number):. Then, in your third line, the value for your parameter number will be printed out.

If you want the line answer = number + number to have a visible effect on your program, you could change your third line to print(answer) to print out the value for number + number.

Thank you!