-1

This is an extremely easy question for Python. It's very basic Python as I'm still a beginner... to take a number, use a function and square it:

import math
nmb = int(raw_input("Enter a number to be squared: "))
def square(nmb):
    y = math.pow(nmb,2)
    return y
print str(nmb) + " squared is equal to " + str(square)

I've jiggered it around a few times, but the end result always prints something like "5 squared is equal to function square at 0x02BC87B0" instead of the result

I feel like I'm missing something really obvious, as my understanding of functions is still quite basic, but any pointers would set me on my way!

aunteth
  • 29
  • 3

2 Answers2

1

You are passing the function square, not the return value of a call to square, to str. You want this:

print str(nmb) + " squared is equal to " + str(square(nmb))
chepner
  • 497,756
  • 71
  • 530
  • 681
-3

Write a python3 function sqrt(n) that returns the square of its numeric parameter n.

import math
num = int(raw_input("Enter a number to be squared: "))
def square(num):
    y = math.pow(num,2)
    return y
print str(num) + " squared is equal to " + str(square(num))
Javad
  • 2,033
  • 3
  • 13
  • 23
  • I doubt that you should answer a beginner question 6 years ago without major improvements than another answer. – adamkwm Apr 20 '22 at 09:38
  • This answer is severely confused: It talks about python3, while the question (and the answer!) use python2. (old `print` syntax, `raw_input`). Also, why are you talking about `sqrt`, when the question is about `square`? Apart from that, this question is a bad copy of @chepner's answer with the explanation missing. – Sören Apr 23 '22 at 19:50