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

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
231,096 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
231,096 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
231,096 Points

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