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 "DRY"

I have a quick question. One of the questions on a quiz had this code

first_number = 5
first_result = first_number * first_number
print("The number {} squared is {}".format(first_number, first_result))

second_number = 8
second_result = second_number * second_number
print("The number {} squared is {}".format(second_number, second_result))

I understand this is a repeated code and I know the answer to the multi choice. I went out of my way to try and code this without repeating the code and I ended up with this.

def number(num):
    first_result = num * num
    print("The number {} squared is {}".format(number, first_result))

number(5)
number(9) 

And when I run the code i get this

The number <function number at 0x7f660101be18> squared is 25                                                                                                    
The number <function number at 0x7f660101be18> squared is 81   

Why am I getting the 0x in the first place holder?

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,468 Points

Python functions can be referenced directly. By printing number you are getting the memory location of the function number.

You may want to print the variable num instead.

Post back if you need more help. Good luck!!!