"Oscar Benjamin" wrote in
Then you want operator.pow:
import operator
operator.pow(3, 2)
9
math.pow is basically the (double)pow(double, double) function from
the underlying C library. operator.pow(a, b) is precisely the same as
a**b.
So how is operator.pow() different from just pow()?
"Dave Angel" wrote
One other test:
diff = set(map(int, result1)).symmetric_difference(set(result2))
if diff:
print diff
print len(diff)
shows me a diff set of 15656 members. One such member:
135525271560688054250931600108742713928222656250
"Chris Angelico" wrote in
First, are you aware that ** will return int (or sometimes long on
2.7.3), while math.pow() will return a float? That may tell you why
you're seeing differences. That said, though, I wasn't able to
replicate your result using 2.7.3 and 3.3.0 both on Windows - always
"Dave Angel" wrote in message
On 02/21/2013 02:33 PM, Schizoid Man wrote:
However, there is an important inaccuracy in math.pow, because it uses
floats to do the work. If you have very large integers, that means some
of them won't be correct. The following are some exampl
Hi there,
I run the following code in Python 3.3.0 (on a Windows 7 machine) and Python
2.7.3 on a Mac and I get two different results:
result1 = []
result2 = []
for a in range(2,101):
for b in range(2,101):
result1.append(math.pow(a,b))
result2.append(a**b)
result1 = list(set(
"Schizoid Man" wrote in message
news:kejcfi$s70$1...@dont-email.me...
So for values of s=60 and k=50, the first code returns 0.1823215567939546
(on the PC), whereas the second returns 0.0 (on the Mac). This this
expression is evaluated in the numerator, it never returns a divid
Ah, there may well be something in that. Definitely post the code and
outputs; chances are someone'll spot the difference.
Ok, I *think* I found the source of the difference:
This is the base code that runs fine in v 3.3.0 (the output is correct):
def Numer(s, k):
return math.log(s / k)
s =
If your input has no decimal point in it, eval (or input) will return
an integer, not a float. Other than that, I can't see any obvious
reason for there to be a difference. Can you put together a simple
script that demonstrates the problem and post it, along with the exact
input that you're giving
Highly unlikely. I'd say impossible, unless you type a different value for
x
of course. By the time the input() function returns, the result is already
a float. Wrapping it in float() again cannot possibly change the value. If
you have found a value that does change, please tell us what it is.
T
raw_input() takes a line from the keyboard (handwave) and returns it
as a string.
input() in 2.X takes a line from the keyboard and evaluates it as a
Python expression.
float() takes a string, float, int, etc, and returns the
nearest-equivalent floating point value.
What's the input you're givi
"Chris Angelico" wrote in message
news:mailman.1289.1359801291.2939.python-l...@python.org...
On Sat, Feb 2, 2013 at 9:27 PM, Schizoid Man
wrote:
The quantity s is input with the following line: s = input("Enter s: ")
To get rid of the compile error, I can cast this a
I have a program that performs some calculations that runs perfectly on
Python 2.7.3. However, when I try to execute it on Python 3.3.0 I get the
following error:
numer = math.log(s)
TypeError: a float is required
The quantity s is input with the following line: s = input("Enter s: ")
To
Gabriel Genellina wrote:
> En Sun, 02 Mar 2008 08:25:49 -0200, Schizoid Man <[EMAIL PROTECTED]> escribi�:
>
>> Lorenzo Gatti wrote:
>>> On Mar 1, 3:39 pm, Schizoid Man <[EMAIL PROTECTED]> wrote:
>>>> As in variable assignment, not homework assignment!
Lorenzo Gatti wrote:
> On Mar 1, 3:39 pm, Schizoid Man <[EMAIL PROTECTED]> wrote:
>> As in variable assignment, not homework assignment! :)
>>
>> I understand the first line but not the second of the following code:
>>
>> a, b = 0, 1
>> a, b = b, a + b
As in variable assignment, not homework assignment! :)
I understand the first line but not the second of the following code:
a, b = 0, 1
a, b = b, a + b
In the first line a is assigned 0 and b is assigned 1 simultaneously.
However what is the sequence of operation in the second statement? I;m
15 matches
Mail list logo