Lab 01: Python Fundamentals#
Topics Covered:
Setting up and verifying your Anaconda environment
Basic Python math operations for engineering calculations
1. Demonstration#
1.1 Environment Setup and Verification#
Before we begin calculations, let’s verify that your environment is properly configured.
# Verify Python version and environment
import sys
# Check that key packages are installed
import pandas as pd
import numpy as np
import matplotlib
1.2 Basic Python Math Operations#
Python can perform mathematical calculations using basic arithmetic operators. Let’s explore how to use them for engineering calculations.
Example 1.2.1: Scientific Notation#
For very large or very small numbers, Python uses scientific notation with the e symbol.
# Scientific notation: 1.5e6 means 1.5 × 10⁶
avogadro = 6.022e23 # Avogadro's number
electron_mass = 9.109e-31 # kg
gas_constant = 8.314 # J/(mol·K)
Example 1.2.2: Power Calculations#
Syntax:
base ** exponentBuilt-in operator for exponentiation.
Works with integers, floats, and complex numbers.
Returns the same type as the input when possible.
2 ** 3 # 8 (int)
2.0 ** 3 # 8.0 (float)
2 ** 0.5 # 1.4142135623730951 (float)
(1+2j) ** 2 # (-3+4j) (complex)
2 ** -1 # 0.5
import math
# Compare ** operator vs math.pow()
print("Comparing ** and math.pow():")
print(f"2**3 = {2**3}")
print(f"pow(2, 3) = {pow(2, 3)}")
print(f"math.pow(2, 3) = {math.pow(2, 3)}")
Comparing ** and math.pow():
2**3 = 8
pow(2, 3) = 8
math.pow(2, 3) = 8.0
# Cube root example using fractional exponents
print("\nCube Root Example:")
volume_sphere = 113.1 # m³
# For a sphere: V = (4/3)πr³, so r = (3V/4π)^(1/3)
pi = 3.14159
Cube Root Example:
1.3. Chemical Engineering Applications#
Example 1.3.1: Ideal Gas Law#
Calculate pressure using the ideal gas law:
where:
n = 50.0 mol
R = 8.314 J·mol⁻¹·K⁻¹
T = 373.15 K (100 °C)
V = 0.5 m³
# # Calculate pressure of gas in a reactor
Example 1.3.2: Reynolds Number Calculation#
Determine whether the flow is laminar or turbulent using the Reynolds number:
where:
ρ = 1000 kg/m³ (density of water)
v = 2.5 m/s (velocity)
D = 0.1 m (pipe diameter)
μ = 0.001 Pa·s (dynamic viscosity)
Determination criteria:
Re < 2300 → Laminar flow
2300 ≤ Re ≤ 4000 → Transitional flow
Re > 4000 → Turbulent flow
# # Reynolds number for water flowing in a pipe
Example 1.3.3: Mass Balance - Dilution Calculation#
Calculate the final concentration (\(C_2\)) using the dilution equation:
where:
C₁ = 12.0 mol/L (initial concentration)
V₁ = 0.250 L (initial volume)
V₂ = 1.000 L (final volume after dilution)
# # Dilute a concentrated solution
Practice Problems#
Now it’s your turn! Solve the following problems in the cells below. Make sure to:
Show your work with comments
Use appropriate variable names
Format your output professionally
Include units in your output
Problem 1: Pipe Flow Calculation#
Water flows through a circular pipe with a diameter of 0.15 m at a velocity of 3.2 m/s.
Calculate:
The cross-sectional area of the pipe (A = π × (D/2)², use π = 3.14159)
The volumetric flow rate (Q = A × v) in m³/s
Convert the flow rate to L/min (1 m³ = 1000 L, 1 min = 60 s)
Format your output to show all results with appropriate decimal places and units.
# Your solution here
Problem 2: Pressure Drop in a Pipe#
Calculate the pressure drop in a horizontal pipe using the Darcy-Weisbach equation:
ΔP = f × (L/D) × (ρv²/2)
Where:
f = 0.025 (friction factor, dimensionless)
L = 100 m (pipe length)
D = 0.2 m (pipe diameter)
ρ = 1000 kg/m³ (fluid density)
v = 3.0 m/s (fluid velocity)
Calculate:
The pressure drop ΔP in Pa
Convert to kPa and to psi (1 psi = 6894.76 Pa)
Format your results with appropriate units.
# Your solution here
Problem 3: Friction Factor Calculation#
For turbulent flow in smooth pipes, the Blasius correlation is used to estimate the friction factor:
where Re is the Reynolds number.
Given:
Reynolds number (Re) = 25,000
Tasks:
Calculate the friction factor
Verify that both methods give the same answer
Format your output to clearly show:
The Reynolds number
The friction factor calculated with
math.pow(),pow(), and**A statement confirming they are equal
# Your solution here