I found this picture on 9gag and I decided to write a python code to see if this is true
However, when I run the following python code, I got a different result from what I got from Wolfram Alpha
import numpy as np
import matplotlib.pyplot as plt
def f(x):
return (18111/2)*(x**4) - 90555*(x**3) + (633885/2)*(x**2) - 452773*x + 217331
for i in range(0,5):
print f(i)
Output:
217331
0
-7
-40
-129
217016
And here's the link to my Wolfram Alpha query link
Notice that I copied and pasted my equation string directly from my Python code to Wolfram alpha and it seems to interpreted correctly. So I highly doubt that the fault is within my Python code.
In Python 2.x,
int / int
returns aint
. (truncate number below decimal point)To get the number you want, you need to use
float
.Or, you can change the behavior using
from __future__ import ...
statement:BTW, to iterate from 1 to 5. you need to use
range(1, 6)
, notrange(0, 5)
.