Student Instructions | Week 1 | Topics: Objects, Types, Variables, Bindings, Arithmetic
Oregon State University | ENGR 103 | Dr. Cheng Li
Log into Spyder/Jupyter. Confirm Python 3.x is running. Introduce yourself to your neighbor โ you'll pair up for Part 3.
Follow along and type each snippet yourself. Do NOT copy-paste.
Type and run this code:
# Your first Python program
print('Hello, Living Systems!')
print('ENGR 103 โ Python for Bio/Env Engineering')
print('My name is: YOUR_NAME_HERE')Run the script. Change the last line to print your actual name.
Type and run this code:
# Sensor data from a water quality probe
pH_value = 7.42 # float
do_mg_per_L = 8.15 # float โ dissolved oxygen
temp_celsius = 22.3 # float
cell_count = 1500000 # int โ cells per mL
station_id = 'WQ-01' # str
is_calibrated = True # bool
print(type(pH_value))
print(type(cell_count))
print(type(station_id))
print(type(is_calibrated))What type is each variable? Run it and confirm. Then add two more variables of your own.
Type and run this code:
# Microbial Fuel Cell power calculation
voltage_V = 0.45 # Volts
current_A = 0.020 # Amperes
power_W = voltage_V * current_A
power_mW = power_W * 1000
efficiency = 0.35
useful_mW = power_mW * efficiency
print('Voltage:', voltage_V, 'V')
print('Power:', power_mW, 'mW')
print('Useful power:', useful_mW, 'mW')Change voltage to 0.52 V and current to 0.018 A. What is the new power?
Work in pairs. You are analyzing a small array of 5 microbial fuel cells (MFCs). Each MFC has a measured voltage and current. Your task: write a Python script that computes power for each unit and totals up the array output.
Type and run this code:
# MFC array โ measured values
mfc_1_V, mfc_1_I = 0.45, 0.020 # Volts, Amps
mfc_2_V, mfc_2_I = 0.38, 0.015
mfc_3_V, mfc_3_I = 0.52, 0.025
mfc_4_V, mfc_4_I = 0.41, 0.018
mfc_5_V, mfc_5_I = 0.49, 0.022Copy this starter data into your script.
1. Calculate power (in mW) for each MFC.
2. Calculate total array power.
3. Calculate average power per unit.
4. Calculate daily energy if array runs 12 hours (in Wh).
5. Print a formatted report using f-strings:
MFC-1: V=0.45 V, I=20.0 mA, P=9.00 mW
...
Total Power: XX.XX mW
Average Power: XX.XX mW
Daily Energy: X.XXXX WhIf you finish early, try this extension on your own.
Type and run this code:
# E. coli doubling time = 20 minutes
# How many cells after 2 hours starting from 1 cell?
doubling_time_min = 20
start_cells = 1
time_min = 120 # 2 hours
# YOUR CODE HERE
# Hint: doublings = time / doubling_time
# cells = start * (2 ** doublings)Fill in the calculation and print: 'After 2 hours: X cells'
Show your TA your completed script for Part 2. TA will verify output and mark attendance. Discuss: what surprised you? What questions do you have for Monday?