Real examples of AI-generated STEM errors — annotated with what went wrong, why, and what to learn from it. Use for the error hunt breakout activities. Click each card to expand.
Use these for the Workshop 2 "Code Error Hunt" breakout. Each snippet has a subtle bug the AI introduced.
"Write a Python function that calculates the range of a projectile given initial velocity (m/s) and launch angle (degrees). Use the standard range equation."
import math
def projectile_range(velocity, angle):
"""Calculate the range of a projectile.
velocity: initial velocity in m/s
angle: launch angle in degrees
Returns: range in meters
"""
g = 9.81 # acceleration due to gravity
range_m = (velocity ** 2 * math.sin(2 * angle)) / g
return round(range_m, 2)
# Example: 20 m/s at 45 degrees
print(projectile_range(20, 45)) # Expected: ~40.77 m
math.sin() expects radians, but the angle is passed in degrees. math.sin(2 * 45) computes sin(90) in radians (≈ 0.894), not sin(90°) which equals 1.0. The output is 36.49 instead of the correct 40.77. It's close enough to look plausible — which makes it dangerous. angle_rad = math.radians(angle)
range_m = (velocity ** 2 * math.sin(2 * angle_rad)) / g
"Write a Python function that takes a list of daily temperatures and returns the average, minimum, and maximum."
def temp_stats(temperatures):
"""Return average, min, and max temperature."""
total = 0
for temp in temperatures:
total += temp
average = total / len(temperatures)
minimum = min(temperatures)
maximum = max(temperatures)
return {
"average": round(average, 1),
"min": minimum,
"max": maximum
}
# Test with a week of data
week = [72, 68, 75, 80, 77, None, 73]
print(temp_stats(week))
None (a common real-world scenario — a sensor goes offline, a student misses a reading). The function crashes with TypeError: unsupported operand type(s) for +=: 'int' and 'NoneType'. The AI wrote clean code for clean data but real data is rarely clean.def temp_stats(temperatures):
clean = [t for t in temperatures if t is not None]
if not clean:
return {"average": None, "min": None, "max": None}
average = sum(clean) / len(clean)
return {"average": round(average, 1), "min": min(clean), "max": max(clean)}
"Write a function that classifies a pH value as acidic, neutral, or basic."
def classify_ph(ph):
"""Classify pH as acidic, neutral, or basic."""
if ph < 7:
return "acidic"
if ph == 7:
return "neutral"
if ph > 7:
return "basic"
# Test
print(classify_ph(6.8)) # acidic ✓
print(classify_ph(7.0)) # neutral ✓
print(classify_ph(7.2)) # basic ✓
print(classify_ph(-1)) # acidic? 🤔
print(classify_ph(15)) # basic? 🤔
== 7 for "neutral" is scientifically misleading — water at different temperatures has pH ≠ 7.0, and the "neutral" range in practice is roughly 6.5-7.5.def classify_ph(ph):
if ph < 0 or ph > 14:
return "invalid (pH must be 0-14)"
if ph < 6.5:
return "acidic"
if ph <= 7.5:
return "approximately neutral"
return "basic"
AI-generated STEM explanations that sound right but contain subtle inaccuracies.
CRAFT PD Series · UCF DRACO Lab & School of Teacher Education