Thursday, August 14, 2025

#2 Python Exercises for Civil Engineering

 Alright — I’ll give you 10 extra practice exercises that fit our Civil Engineering Basics + Python theme.

Each exercise includes problem statement, code, and answer so you can test and learn hands-on.


Practice Exercises


1. Convert 150 meters into feet and inches

# Conversion constants
m_to_ft = 3.28084
ft_to_inch = 12

meters = 150
feet = meters * m_to_ft
inches = feet * ft_to_inch

print(f"{meters} m = {feet:.2f} ft or {inches:.2f} inches")

Answer:

150 m = 492.13 ft or 5905.51 inches

2. Calculate the volume and weight of a concrete block

  • Size: 2 m × 0.5 m × 0.4 m

  • Density of concrete: 2400 kg/m³

length = 2
width = 0.5
height = 0.4
density = 2400

volume = length * width * height
mass = volume * density
weight = mass * 9.81

print(f"Volume: {volume} m³, Weight: {weight:.2f} N")

Answer:

Volume: 0.4 m³, Weight: 9419.04 N

3. Compute hydrostatic pressure at 10 m depth in seawater (ρ = 1025 kg/m³)

rho = 1025
g = 9.81
h = 10

pressure = rho * g * h
print(f"Pressure: {pressure/1000:.2f} kPa")

Answer:

Pressure: 100.55 kPa

4. Flow velocity in a smaller pipe

  • Flow rate: 0.1 m³/s

  • Pipe diameter: 0.25 m

import math
Q = 0.1
d = 0.25

A = math.pi * (d**2) / 4
v = Q / A

print(f"Velocity: {v:.2f} m/s")

Answer:

Velocity: 2.04 m/s

5. Calculate distance between two survey points

  • P1 = (120, 45), P2 = (200, 100)

import math
x1, y1 = 120, 45
x2, y2 = 200, 100

distance = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
print(f"Distance: {distance:.2f} m")

Answer:

Distance: 94.34 m

6. Find stress and strain

  • Force: 50 kN, Area: 0.003 m², Original length: 2.5 m, Elongation: 1.2 mm

F = 50000
A = 0.003
L = 2.5
delta_L = 0.0012

stress = F / A
strain = delta_L / L

print(f"Stress: {stress/1e6:.2f} MPa, Strain: {strain:.6f}")

Answer:

Stress: 16.67 MPa, Strain: 0.000480

7. Bending stress in a beam

  • Moment = 8000 Nm, y = 0.12 m, I = 6.5×10⁻⁶ m⁴

M = 8000
y = 0.12
I = 6.5e-6

sigma = M * y / I
print(f"Bending stress: {sigma/1e6:.2f} MPa")

Answer:

Bending stress: 147.69 MPa

8. Area of a triangular plot

  • Coordinates: (0,0), (60,0), (40,50)

coords = [(0,0), (60,0), (40,50)]
area = 0
for i in range(len(coords)):
    x1, y1 = coords[i]
    x2, y2 = coords[(i+1) % len(coords)]
    area += (x1*y2 - x2*y1)
area = abs(area) / 2
print(f"Area: {area} m²")

Answer:

Area: 1500.0 m²

9. Water demand for a town

  • Population: 12,000, Per capita demand: 140 L/day

population = 12000
pcd = 140

total_demand = population * pcd
print(f"Daily water demand: {total_demand/1000:.2f} m³/day")

Answer:

Daily water demand: 1680.00 m³/day

10. Simple ET₀ estimation using Hargreaves method

  • T_mean = 30°C, T_max = 35°C, T_min = 25°C, Ra = 18 mm/day

def et0_hargreaves(T_mean, T_max, T_min, Ra):
    return 0.0023 * (T_mean + 17.8) * ((T_max - T_min)**0.5) * Ra

ET0 = et0_hargreaves(30, 35, 25, 18)
print(f"ET₀: {ET0:.2f} mm/day")

Answer:

ET₀: 6.28 mm/day

I can also package all 18 exercises (8-hour module + these 10 extra) into a single Jupyter Notebook with theory, code, and answers so you can run them in one place and use them for training.

Do you want me to make that combined Python workbook for you next?

No comments:

Post a Comment

2025 Project #1 Real-Time Rainfall Prediction Model Using Bi-LSTM

 Here is a clear and detailed project plan for an undergraduate student based on your abstract. Sentences are short. Language is simple. C...