Functions CALL AND RESPONSE


#1

def square(n):
"""Returns the square of a number."""
squared = n**2
print "%d squared is %d." % (n, squared)
return squared

Can someone please explain why, if you remove the second modulo, the function does not work. On the print line "%d squared is %d(< this modulo) the whole function does not work,I test this answer on shell 3.5.0 version.

Regards.


#2

Hi @antimatter ,

Because your code is not formatted, it is difficult for other users to read and debug it. After code is been pasted into the editing window for posting, you can format it by selecting it, and then by clicking the </> button above the editing area. This will enable us to see important details, such as the indentation and underscores.

In this line ...

print "%d squared is %d." % (n, squared)

There are two %d format specifiers in the format string, and two expressions in the values tuple, namely n and squared. The number of expressions needs to be the same as the number of format specifiers.


#3

Great! thank you.Well , let me say thank you again because anything less than 20 characters it won't allow me to say thank you in this box I am typing.