Python is a high-level and general-purpose programming language. According to the TIOBE index and CodeEval, it is one of most popular programming languages. Part of the reason that it is a popular choice for scientists and engineers is the language versatility, online community of users, and powerful analysis packages such as Numpy and Scipy. This course uses Python 2.7 because of compatibility with the scientific computing packages although the newer 3.x versions are making progress with compatibility.
There are several resources for learning Python online. For a good start, look at Code Academy (Python track) or view the documentation at Python.org. For users with a foundation in MATLAB, there are excellent resources that demonstrate equivalent Python (Numpy) commands.
Option #1: Install Python
The following instructions are for the Windows OS. The Python base program should be installed first and then the other packages can be installed in any order with the utility PIP or by downloading the installer package from the appropriate web-site.
Option #3: Anaconda (includes most packages)
The iPython platform installation instructions are given here. Some platforms like MacOS typically include Python pre-installed but may be missing some of the packages such as Numpy.
Manage Python Packages
"Hello, World!" Tutorial
The following tutorial is a "Hello, World!" (introductory) example of writing a simple Python script, running the script in debug mode, and basic programming constructs.
This same tutorial is also show in a MATLAB introduction.
Non-Ideal Gas Equation
R = 0.0821 # L-atm/K T = 500 # K V = 5 # L/mol Pc = 37.2 # atm Tc = 132.5 # K a = 0.427 * pow(R,2) * pow(Tc,2.5) / Pc b = 0.0866 * R * Tc / Pc # Compute in atm P_ig = R * T / V P_rk = R * T / (V-b) - a/(V*(V+b)*pow(T,0.5)) # Convert to Pascals P_ig = P_ig * 101325 P_rk = P_rk * 101325 print("The ideal gas pressure: " + str(P_ig) + " Pa") print("The Redlich-Kwong pressure: " + str(P_rk) + " Pa")
comments powered by Disqus