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 Python Basics Functions and Looping Reviewing Functions

Im 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
Jimmy Sweeney
5,649 Points

It 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.

Thanks 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))

I 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
Jimmy Sweeney
5,649 Points

Changing the variable inside the function to "result" definitely makes more sense. Glad you got it figured out!