New to programming, same result different program
<p>I'm taking my first course in programming, the course is meant for physics applications and the like. We have an exam coming up, my professor published a practice exam with the following question.</p>

<blockquote>
  <p>The Maxwell distribution in speed v for an ideal gas consisting of particles of mass m at Kelvin temperature T is given by: </p>
</blockquote>

<p>Stackoverflow doesn't use MathJax for formula's, and I can't quite figure out how to write a formula on this site. So, here is a link to <a href="http://www.wolframalpha.com/input/?i=f(v)%20%3D%204*pi*((m%2F(2*pi*k*T))%5E(3%2F2))*(v%5E2)*e%5E(-(m*v%5E2)%2F(2*k*T))" rel="nofollow">WolframAlpha</a>: </p>

<blockquote>
  <p>where k is Boltzmann's constant, k = 1.3806503 x 10-23 J/K.</p>
  
  <p>Write a Python script called maxwell.py which prints v and f(v) to standard output in two column format. For the particle mass, choose the mass of a proton, m = 1.67262158 10-27 kg. For the gas temperature, choose the temperature at the surface of the sun, T = 5778 K.</p>
  
  <p>Your output should consist of 300 data points, ranging from v = 100 m/s to v = 30,000 m/s in steps of size dv = 100 m/s.</p>
</blockquote>

<p>So, here is my attempt at the code. </p>

<pre><code>import math as m
import sys

def f(v):
    n = 1.67262158e-27 #kg
    k = 1.3806503e-23 #J/K 
    T = 5778 #Kelvin
    return (4*m.pi)*((n/(2*m.pi*k*T))**(3/2))*(v**2)*m.exp((-n*v**2)/(2*k*T))

v = 100 #m/s
for i in range(300):
   a = float(f(v))
   print (v, a)
   v = v + 100
</code></pre>

<p>But, my professors solution is:</p>

<pre><code>import numpy as np
def f(v):     
    m = 1.67262158e-27  # kg     
    T = 5778.           # K     
    k = 1.3806503e-23   # J/K    
    return 4.*np.pi * (m/(2.*np.pi*k*T))**1.5 * v**2 * np.exp(-m*v**2/(2.*k*T))

v = np.linspace(100.,30000.,300) 
fv = f(v) 
vfv = zip(v,fv) 
for x in vfv:     
    print "%5.0f %.3e"%x
    # print np.sum(fv*100.)
</code></pre>

<p>So, these are very different codes. From what I can tell, they produce the same result. I guess my question is, simply, why is my code incorrect? </p>

<p>Thank you!</p>

<hr>

<p>EDIT:</p>

<p>So, I asked my professor about it and this was his response. </p>

<blockquote>
  <p>I think your code is fine. It would run much faster using numpy, but the problem didn't specify that you needed numpy. I might have docked one point for not looping through a list of v's (your variable i doesn't do anything). Also, you should have used v += 100. Almost, these two things together would have been one point out of 10.</p>
</blockquote>

<p>1st: Is there any better syntax for doing the range in my code, since my variable i doesn't do anything?</p>

<p>2nd: What is the purpose of v += 100? </p>

<p>Things to be careful about when dealing with numbers is implicit type conversion from floats to ints.
One instance I could figure in your code is that you use (3/2) which evaluates to 1, while the other code uses 1.5 directly. </p>

python algorithm