0

I am stuck in using multiple parameter through function. I have two files:

1.py

import function
x=2
y=5
print function.power(x,y)

function.py

import math
def power(*x)
return math.pow(x,x)

Whenever i try to pass multiple parameter to power function, it is giving following error:

Traceback (most recent call last):

File "C:\Examples\1.py", line 33, in

print function.power(x,y)

File "c:\Examples\function.py", line 11, in power

return math.pow(x,x)

TypeError: a float is required

1
  • 1
    This code has at least 2 syntax errors in addition to what you are asking Commented Jan 31, 2013 at 5:18

2 Answers 2

3

I think you want:

def power(*x):
    return math.pow(*x)

This is a form of argument unpacking. within the power function, x is a tuple which can then be unpacked when passed to another function.

Sign up to request clarification or add additional context in comments.

Comments

0

that's because *x is actually making x a list.

You really want to make function.py be:

import math
def power(*x)
    return math.pow(x[0],x[1])

Why do you really want to know how to do this though? It obviously can't be to pointlessly wrap the math.pow function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.