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 trialPatrick Brusven
14,520 PointsIm trying to create a function for the quiz question with code smell, but cannot get it to return anything.
my code
def base_number ( number): first_result = base_number * base_number print("the number {} squared is {}" .format(base_number, first_result))
number 5 number 8
2 Answers
Jimmy Sweeney
5,649 PointsIt looks like you create a variable "first_result" within your function but then you assign that variable to "base_number * base_number". However, "base_number" is the name of your function, not the argument you pass into the function. First_result should equal number * number. Also, fix the format string. Change base_number to number.
Also, I think the name of your function ought to be "square" because you function will square whatever number you pass into it.
Patrick Brusven
14,520 PointsI figured it out, I was not calling the function correctly.
def square(number): result = number * number print("The number {} squared is {}".format(number, result))
square(5) square(8)
Thanks.
Jimmy Sweeney
5,649 PointsChanging the variable inside the function to "result" definitely makes more sense. Glad you got it figured out!
Patrick Brusven
14,520 PointsPatrick Brusven
14,520 PointsThanks for chiming in James. I think I've cleaned up the function to your callouts. I want to run the function using the integers 5 and 8 but cannot get it to work.
def square (number): first_result = number * number print("The number {} squared is {}." .format(number, first_result))