views:

88

answers:

2

Why is python telling me "TypeError: pow expected 2 arguments, got 3" despite it working in IDLE (sometimes it tells me that in IDLE as well)? im simply doing pow(a,b,c). my program is very short and i do not change the definition of pow at any time since i need to use it for some exponentiation.

NOTE: This is the pow from __builtin__, not Math

A: 

http://docs.python.org/release/2.6.5/library/functions.html

pow(x, y[, z]) Return x to the power y; if z is present, return x to the power y, modulo z (computed more efficiently than pow(x, y) % z). The two-argument form pow(x, y) is equivalent to using the power operator: x**y.

The arguments must have numeric types. With mixed operand types, the coercion rules for binary arithmetic operators apply. For int and long int operands, the result has the same type as the operands (after coercion) unless the second argument is negative; in that case, all arguments are converted to float and a float result is delivered. For example, 10*2 returns 100, but 10*-2 returns 0.01. (This last feature was added in Python 2.2. In Python 2.1 and before, if both arguments were of integer types and the second argument was negative, an exception was raised.) If the second argument is negative, the third argument must be omitted. If z is present, x and y must be of integer types, and y must be non-negative. (This restriction was added in Python 2.2. In Python 2.1 and before, floating 3-argument pow() returned platform-dependent results depending on floating-point rounding accidents.)

Perhaps you're violating the bold portion?

Amber
no. im sure that all the values are positive integersedit: yep. a,b,c = 9, 4, 225
calccrypto
+4  A: 

Built-in pow takes two or three arguments. If you do from math import * then it is replaced by math's pow, which takes only two arguments. My recommendation is to do import math, or explicitly list functions you use in import list. Similar issue happens with open vs. os.open.

sdcvvc
ah... maybe that's why. thanks!!!!!err... would an import from another file affect it? im importing another program i wrote which also has `from math import *`
calccrypto
@calccrypto: If you're importing the another program with `from p import *` then yes. Use `import p` or list explicitly `from p import [...]`.
sdcvvc
You could also do `pow3 = pow` `from math import *` `pow3(a,b,c)`
Mark Ransom