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
Ralph Langdon
721 PointsHaving a hard time calling a Function inside the script. Am able to call it outside the script
It looks like my function only works if I call the data outside the function. Would someone be kind enough to point out my error. Thanks!
Works
def plus10(a): ... return a+10 ... plus10(20) 30
Does not work
def plus10(a): ... return a+10 ... plus10(20) File "<stdin>", line 3 plus10(20) ^ SyntaxError: invalid syntax
Does not work with print either
def plus10(a): ... print a+10 ... plus10(20) File "<stdin>", line 3 plus10(20) ^ SyntaxError: invalid syntax
It looks like print or return does the same thing outside a function
def plus10(a): ... print a+10 ... plus10(20) 30
2 Answers
Ralph Langdon
721 PointsSorry for the silly looking format. This looked normal when I hit submit. Just look at >>> to see when I called the function outside the script
Ralph Langdon
721 PointsLets try this again
Works when plus10 is called outside
def plus10(a): ... return a+10 ... plus10(20) 30
Now when I call plus10 inside the script it breaks
def plus10(a): ... return a+10 ... plus10(20) File "<stdin>", line 3 plus10(20) ^ SyntaxError: invalid syntax