python - Can not figure out what is going wrong with this coding -


i trying figure out why not getting correct answer coding in python. here code far:

def main():     base = input('enter integer base: ')     exponent = input('enter integer exponent: ')     print(base,'to power', exponent,'equals', power)  def power(base, exponent):     if exponent <= 1:        return base     else:        return base * power(base, exponent - 1) main() 

when run program 2 , 5 (base, exponent) this:

enter integer base: 2 enter integer exponent: 5 2 power 5 equals <function power @ 0x03ddc300> >>>  

my question this: why getting "function power @ 0x03ddc300" or similar answers instead of correct answer of 32?

you need call function power proper integer arguments correct output.

print(base,'to power', exponent,'equals', power(int(base), int(exponent))) # call function `power` 

without this, power return callable.

in [1]: def some_func():    ...:     return 2     ...:   in [2]: print some_func # print function without calling  <function some_func @ 0x601a050> # returns callable  in [3]: print some_func() # call function 2 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -