Call and Response


#1



https://www.codecademy.com/en/courses/python-beginner-c7VZg/1/2?curriculum_id=4f89dab3d788890003000096#


Hi, I do not know why besides my square function returns the variable squared, in the result windows I get None

I think it should return the value of the variable


def square(n):
    """Returns the square of a number."""
    squared = n**2
    print "%d squared is %d." % (n, squared)
    return squared
    
# Call the square function on line 9! Make sure to
# include the number 10 between the parentheses.

square(10)


#2

it does, but then you need to store the response in a variable:

x = square(10)
print x

or call print directly on the function to print what the function returned:

print square(10)

#3

Ok I get it! However I just want to mention that in my Windows shell for example I did get the output 100 instead of None again ...And the same in Jupyter

Does it have to deal with the version of Python? In my Windows Shell I have Canopy and in Jupyter Anaconda 3


#4

yea, the python IDLE is so friendly to output what the function returns

if you where to make a script (lets say test.py) and run this in CMD using the python interpreter:

python test.py

what the function returns is not printed.

I have no idea about Jupyter


#5

Yes! you are right! I just did what you say and Indeed I have to print the result in order to see it

Thanks


#6

yep, in codecademy you write script (just like your test.py), you don't work in the python IDLE, as you can see, there is the difference between script and IDLE


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.