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 trialSammy Godreau
459 PointsSquaring.py Challenge
How do I call a new function and pass it a new variable? I am on part two of the challenge and I created a function that squares a number entered.
def square(number):
return(number * number)
2 Answers
Alexander Davison
65,469 PointsTo call a function with an argument, just put the argument between the parens. e.x.:
def square(number):
return number * number
# The below line calls the function "square", but it doesn't do anything with
# the returned value:
square(3)
If you merely call square
, however, it will only return the value 3
. What happens to 3
? Well, it isn't being used, or stored within a variable, so it's kind of just floating in space. To assign it to a variable, you could write this:
result = square(3)
I hope this helps!
Jose Alvarez
382 Pointson the next step it is asking to store the value from the function call but im not sure how to do that i tried this but its not working import math
def square(number): return (number * number)
result = square(number)
square(3)
Sammy Godreau
459 PointsSammy Godreau
459 Pointsyes it does thank you so much!
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsIf it helped, remember to provide a "Best Answer"