Studio 1 โ€” Python Basics: Types, Variables & Your First Script

ENGR 103 โ€” Week 1

๐Ÿ“‹ Contents

Studio Overview0:00โ€“0:10 โ€” Welcome & Setup Check0:10โ€“0:35 โ€” Part 1 โ€” Codedex Warmup (Guided)0:35โ€“1:10 โ€” Part 2 โ€” Practical Lab: MFC Power Audit1:10โ€“1:25 โ€” Part 3 โ€” Extension Challenge (Individual)1:25โ€“1:30 โ€” Wrap-Up & TA Check-Off

Student Instructions | Week 1 | Topics: Objects, Types, Variables, Bindings, Arithmetic

Oregon State University | ENGR 103 | Dr. Cheng Li

Studio Overview

0:00โ€“0:10 โ€” Welcome & Setup Check

Log into Spyder/Jupyter. Confirm Python 3.x is running. Introduce yourself to your neighbor โ€” you'll pair up for Part 3.

0:10โ€“0:35 โ€” Part 1 โ€” Codedex Warmup (Guided)

Follow along and type each snippet yourself. Do NOT copy-paste.

Exercise 1A โ€” Hello, Living Systems

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')
โœ๏ธ Your Task:

Run the script. Change the last line to print your actual name.

Exercise 1B โ€” Variables & Types

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))
โœ๏ธ Your Task:

What type is each variable? Run it and confirm. Then add two more variables of your own.

Exercise 1C โ€” Arithmetic with Sensor Data

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')
โœ๏ธ Your Task:

Change voltage to 0.52 V and current to 0.018 A. What is the new power?

0:35โ€“1:10 โ€” Part 2 โ€” Practical Lab: MFC Power Audit

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.

Starter Data

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.022
โœ๏ธ Your Task:

Copy this starter data into your script.

Tasks to complete

โœ๏ธ Your Task:
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 Wh

1:10โ€“1:25 โ€” Part 3 โ€” Extension Challenge (Individual)

If you finish early, try this extension on your own.

Bacterial Growth Calculator

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)
โœ๏ธ Your Task:

Fill in the calculation and print: 'After 2 hours: X cells'

1:25โ€“1:30 โ€” Wrap-Up & TA Check-Off

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?