Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

Jesse Busby
Jesse Busby
966 Points

I need help on regards to the following code challange.

The first one requires that I figure out how to square it. I can't either because math is not defined or that you can't use (number ^ 2), and I do not know why.

import math

number = input("number plz..  ")

def square(number):
    return math.sqrt(int(number))

new_number = square(number)
print(new_number)

2 Answers

Steven Parker
Steven Parker
216,165 Points

An easy way to square a number is to multiply it by itself. For example:

square_of_num = num * num

I prefer exponentiation syntax (**) to square numbers:

squared_number = number**2
Steven Parker
Steven Parker
216,165 Points

Good point, the ^ symbol is not used in Python for exponentiation but ** is.

Jesse Busby
Jesse Busby
966 Points

Thank you all, this has been holding me back a few days!

And all I had to change was 2 Characters?!?

Steven Parker
Steven Parker
216,165 Points

I find the most common errors (at least my own) are caused by a single character. :stuck_out_tongue_winking_eye: