AECO Specific Example - 30 - Aug - 2025 Input-Output, Variables, Expressions

Next Topic(s):

Created:
30th of August 2025
09:13:28 AM
Modified:
30th of August 2025
09:22:15 AM

AECO Site Calculations — Python Practice (Float & Decimal)

Learning Objectives

  • Translate formulas to robust code: convert the given units to SI, apply the correct relation, and report in requested units.
  • Use IS-2 compliant rounding: apply ties-to-even via either round(x, n) or Decimal.quantize(..., ROUND_HALF_EVEN).
  • Validate inputs: check non-negativity, prevent zero denominators, and warn about implausible magnitudes.
  • Show hand-calculation trails: LaTeX blocks with aligned “=” for transparency.
  • Offer two program variants: a simple float version and a precise Decimal version suitable for AECO calculations.
🧭

Tip: Prefer Decimal when exact decimal rounding matters. Convert inputs to SI before applying formulas; round only for display.

Instructions to Students

Enter only numbers (no unit text) in the specified units. Each program validates inputs, prevents zero denominators, converts to SI internally, and rounds using ties-to-even. The Decimal variants use quantize(..., rounding=ROUND_HALF_EVEN) for explicit control.

Reminder: Python’s built-in round(x, n) also uses ties-to-even. Decimal makes rounding intent explicit and consistent for AECO workflows.

Problem 1 — Resistance via Ohm’s Law

A portable cutter on site draws a current [I] (A) from a supply at [V] (V). Using Ohm’s law, compute the resistance [R] in ohms.

$$ R\ =\ \frac{V}{I} $$

Report: R to 2 decimal places in Ω.

$$ \begin{aligned} R &= \frac{V}{I} \\ &= \frac{230}{4.6} \\ &= 50.00\ \Omega \end{aligned} $$
# Problem 1 (float)
V = float(input("Enter supply voltage V in volts (V): ").strip())
I = float(input("Enter current I in amperes (A): ").strip())

if I == 0.0:
    print("Current cannot be zero for R = V/I.")
else:
    if V < 0.0 or I < 0.0:
        print("WARNING: Expected V >= 0 and I >= 0.")
    R = V / I
    R_out = round(R, 2)  # ties-to-even
    print(f"Resistance R = {R_out:.2f} ohm")
    if R <= 0.0 or R > 1e6:
        print("WARNING: Check units/values (R unusually small/large).")

 

 

 

# Problem 1 (Decimal)
from decimal import Decimal, getcontext, ROUND_HALF_EVEN
getcontext().prec = 28  # working precision

V = Decimal(input("Enter supply voltage V in volts (V): ").strip())
I = Decimal(input("Enter current I in amperes (A): ").strip())

if I == Decimal("0"):
    print("Current cannot be zero for R = V/I.")
else:
    if V < Decimal("0") or I < Decimal("0"):
        print("WARNING: Expected V >= 0 and I >= 0.")
    R = V / I
    R_out = R.quantize(Decimal("0.01"), rounding=ROUND_HALF_EVEN)
    print(f"Resistance R = {R_out} ohm")
    if R <= Decimal("0") or R > Decimal("1e6"):
        print("WARNING: Check units/values (R unusually small/large).")
  • Sample input: V = 230, I = 4.6
  • Expected output: Resistance R = 50.00 ohm

Problem 2 — Capacitance of a Plate Sensor

A simple plate sensor in a precast yard has relative permittivity (er), plate area [A] in cm^2, and separation [d] in mm. With ε0 = 8.854×10^-12 F/m, compute capacitance [C] in nF.

$$ C\ =\ \varepsilon_0\,\varepsilon_r\,\frac{A}{d} \qquad A(\text{m}^2)=A_{\text{cm}^2}\times10^{-4},\quad d(\text{m})=d_{\text{mm}}\times10^{-3} $$

Report: C to 3 decimal places in nF.

Steps:

  1. Convert geometry to SI.
  2. Apply C = ε0 er (A/d).
  3. Convert to nF: C(nF) = C(F) × 10^9.
  4. Round to 3 dp and report units.
$$ \begin{aligned} A(\text{m}^2) &= 25 \times 10^{-4} &&= 2.5\times10^{-3} \\ d(\text{m}) &= 2 \times 10^{-3} &&= 2.0\times10^{-3} \\ C(\text{F}) &= \varepsilon_0\,\varepsilon_r\,\frac{A}{d} &&= (8.854\times10^{-12})\times 2.5 \times \frac{2.5\times10^{-3}}{2.0\times10^{-3}} \\ &= (8.854\times10^{-12})\times 2.5 \times 1.25 &&= 2.766875\times10^{-11} \\ C(\text{nF}) &= C(\text{F})\times10^{9} &&= 0.02766875 \\ C_{\text{reported}} &= \text{round to 3 dp (ties-to-even)} &&= 0.028\ \text{nF} \end{aligned} $$
# Problem 2 (float)
er    = float(input("Enter relative permittivity er (dimensionless): ").strip())
A_cm2 = float(input("Enter plate area A in cm^2: ").strip())
d_mm  = float(input("Enter separation d in mm: ").strip())

eps0 = 8.854e-12  # F/m
A_m2 = A_cm2 * 1e-4
d_m  = d_mm  * 1e-3

if d_m == 0.0:
    print("Separation cannot be zero.")
else:
    if er <= 0.0 or A_cm2 <= 0.0 or d_mm <= 0.0:
        print("WARNING: Expected er > 0, A > 0 cm^2, d > 0 mm.")
    C_F  = eps0 * er * (A_m2 / d_m)
    C_nF = C_F * 1e9
    C_out = round(C_nF, 3)  # ties-to-even
    print(f"Capacitance C = {C_out:.3f} nF")
    if C_nF <= 0.0 or C_nF > 1e6:
        print("WARNING: Check units/values (C unusually small/large).")

 

 

 

# Problem 2 (Decimal)
from decimal import Decimal, getcontext, ROUND_HALF_EVEN
getcontext().prec = 34

er    = Decimal(input("Enter relative permittivity er (dimensionless): ").strip())
A_cm2 = Decimal(input("Enter plate area A in cm^2: ").strip())
d_mm  = Decimal(input("Enter separation d in mm: ").strip())

eps0 = Decimal("8.854e-12")  # F/m
A_m2 = A_cm2 * Decimal("1e-4")
d_m  = d_mm  * Decimal("1e-3")

if d_m == Decimal("0"):
    print("Separation cannot be zero.")
else:
    if er <= Decimal("0") or A_cm2 <= Decimal("0") or d_mm <= Decimal("0"):
        print("WARNING: Expected er > 0, A > 0 cm^2, d > 0 mm.")
    C_F  = eps0 * er * (A_m2 / d_m)
    C_nF = C_F * Decimal("1e9")
    C_out = C_nF.quantize(Decimal("0.000"), rounding=ROUND_HALF_EVEN)
    print(f"Capacitance C = {C_out} nF")
    if C_nF <= Decimal("0") or C_nF > Decimal("1e6"):
        print("WARNING: Check units/values (C unusually small/large).")
  • Sample input: er = 2.5, A = 25, d = 2
  • Expected output: Capacitance C = 0.028 nF

Problem 3 — Induced Voltage across an Inductor (Linear Ramp)

An inductor of inductance [L] (in mH) carries current changing linearly from [I1] to [I2] (A) over time [Delta t] (in ms). Compute induced voltage [V] (V).

$$ V\ =\ L\,\frac{\Delta I}{\Delta t} \qquad L(\text{H})=L_{\text{mH}}\times10^{-3},\ \Delta t(\text{s})=\Delta t_{\text{ms}}\times10^{-3},\ \Delta I=I_2-I_1 $$

Report: V to 2 decimal places in V.

$$ \begin{aligned} L(\text{H}) &= 10\times10^{-3} &&= 0.010 \\ \Delta t(\text{s}) &= 20\times10^{-3} &&= 0.020 \\ \Delta I &= 2.0 - 0.5 &&= 1.5 \\ V &= L\,\frac{\Delta I}{\Delta t} &&= 0.010 \times \frac{1.5}{0.020} \\ &&&= 0.75\ \text{V} \\ V_{\text{reported}}&= \text{round to 2 dp (ties-to-even)} &&= 0.75\ \text{V} \end{aligned} $$
# Problem 3 (float)
L_mH  = float(input("Enter inductance L in mH: ").strip())
I1    = float(input("Enter initial current I1 in A: ").strip())
I2    = float(input("Enter final current I2 in A: ").strip())
dt_ms = float(input("Enter time interval Delta t in ms: ").strip())

L_H  = L_mH * 1e-3
dt_s = dt_ms * 1e-3
dI   = I2 - I1

if dt_s == 0.0:
    print("Time interval cannot be zero.")
else:
    if L_mH <= 0.0 or dt_ms <= 0.0:
        print("WARNING: Expected L > 0 mH, Delta t > 0 ms.")
    V = L_H * (dI / dt_s)
    V_out = round(V, 2)
    print(f"Induced voltage V = {V_out:.2f} V")

 

 

 

# Problem 3 (Decimal)
from decimal import Decimal, getcontext, ROUND_HALF_EVEN
getcontext().prec = 34

L_mH  = Decimal(input("Enter inductance L in mH: ").strip())
I1    = Decimal(input("Enter initial current I1 in A: ").strip())
I2    = Decimal(input("Enter final current I2 in A: ").strip())
dt_ms = Decimal(input("Enter time interval Delta t in ms: ").strip())

L_H  = L_mH * Decimal("1e-3")
dt_s = dt_ms * Decimal("1e-3")
dI   = I2 - I1

if dt_s == Decimal("0"):
    print("Time interval cannot be zero.")
else:
    if L_mH <= Decimal("0") or dt_ms <= Decimal("0"):
        print("WARNING: Expected L > 0 mH, Delta t > 0 ms.")
    V = L_H * (dI / dt_s)
    V_out = V.quantize(Decimal("0.01"), rounding=ROUND_HALF_EVEN)
    print(f"Induced voltage V = {V_out} V")
  • Sample input: L = 10, I1 = 0.5, I2 = 2.0, Delta t = 20
  • Expected output: Induced voltage V = 0.75 V

Problem 4 — Energy Stored in a Capacitor

A DC link capacitor with capacitance [C] (in microfarads, uF) is charged to [V] (V). Compute the stored energy [E] in joules.

$$ E\ =\ \tfrac{1}{2}\,C\,V^{2} \qquad C(\text{F})=C_{\mu \mathrm{F}}\times10^{-6} $$

Report: E to 3 decimal places in J.

$$ \begin{aligned} C(\text{F}) &= 47\times10^{-6} &&= 4.7\times10^{-5} \\ V^{2} &= 12^{2} &&= 144 \\ E &= \tfrac{1}{2}\,C\,V^{2} &&= \tfrac{1}{2}\times (4.7\times10^{-5}) \times 144 \\ &&&= 0.003384\ \text{J} \\ E_{\text{reported}}&= \text{round to 3 dp (ties-to-even)} &&= 0.003\ \text{J} \end{aligned} $$
# Problem 4 (float)
C_uF = float(input("Enter capacitance C in microfarads (uF): ").strip())
V    = float(input("Enter voltage V in volts (V): ").strip())

C_F = C_uF * 1e-6

if C_F < 0.0 or V < 0.0:
    print("WARNING: Expected C >= 0 uF and V >= 0 V.")
E = 0.5 * C_F * (V ** 2)
E_out = round(E, 3)
print(f"Stored energy E = {E_out:.3f} J")

 

 

 

# Problem 4 (Decimal)
from decimal import Decimal, getcontext, ROUND_HALF_EVEN
getcontext().prec = 34

C_uF = Decimal(input("Enter capacitance C in microfarads (uF): ").strip())
V    = Decimal(input("Enter voltage V in volts (V): ").strip())

C_F = C_uF * Decimal("1e-6")

if C_F < Decimal("0") or V < Decimal("0"):
    print("WARNING: Expected C >= 0 uF and V >= 0 V.")
E = (Decimal("0.5") * C_F * (V ** 2))
E_out = E.quantize(Decimal("0.000"), rounding=ROUND_HALF_EVEN)
print(f"Stored energy E = {E_out} J")
  • Sample input: C = 47, V = 12
  • Expected output: Stored energy E = 0.003 J

Problem 5 — Acceleration with Friction (Newton’s Laws)

A horizontal force [F] (N) pulls a precast panel of mass [m] (kg) across rollers. The kinetic friction coefficient is [mu]. Take g = 9.81 m/s^2. Assuming motion occurs, compute acceleration [a] in m/s^2.

$$ a\ =\ \frac{F\ -\ \mu\,m\,g}{m} $$

Report: a to 3 decimal places in m/s^2.

$$ \begin{aligned} \mu m g &= 0.15 \times 200 \times 9.81 &&= 294.3 \\ F - \mu m g &= 600 - 294.3 &&= 305.7 \\ a &= \frac{F - \mu m g}{m} &&= \frac{305.7}{200} \\ &&&= 1.5285\ \text{m/s}^2 \\ a_{\text{reported}} &= \text{round to 3 dp (ties-to-even)} &&= 1.528\ \text{m/s}^2 \end{aligned} $$
# Problem 5 (float)
F  = float(input("Enter pulling force F in newtons (N): ").strip())
m  = float(input("Enter mass m in kilograms (kg): ").strip())
mu = float(input("Enter kinetic friction coefficient mu (dimensionless): ").strip())

g = 9.81
if m == 0.0:
    print("Mass cannot be zero.")
else:
    if m < 0.0 or F < 0.0 or mu < 0.0 or mu > 1.0:
        print("WARNING: Expected F >= 0 N, m > 0 kg, 0 <= mu <= 1.")
    a = (F - mu * m * g) / m
    a_out = round(a, 3)
    print(f"Acceleration a = {a_out:.3f} m/s^2")

 

 

 

# Problem 5 (Decimal)
from decimal import Decimal, getcontext, ROUND_HALF_EVEN
getcontext().prec = 34

F  = Decimal(input("Enter pulling force F in newtons (N): ").strip())
m  = Decimal(input("Enter mass m in kilograms (kg): ").strip())
mu = Decimal(input("Enter kinetic friction coefficient mu (dimensionless): ").strip())

g = Decimal("9.81")

if m == Decimal("0"):
    print("Mass cannot be zero.")
else:
    if m < Decimal("0") or F < Decimal("0") or mu < Decimal("0") or mu > Decimal("1"):
        print("WARNING: Expected F >= 0 N, m > 0 kg, 0 <= mu <= 1.")
    a = (F - mu * m * g) / m
    a_out = a.quantize(Decimal("0.000"), rounding=ROUND_HALF_EVEN)
    print(f"Acceleration a = {a_out} m/s^2")
  • Sample input: F = 600, m = 200, mu = 0.15
  • Expected output: Acceleration a = 1.528 m/s^2