Online Compiler Python

import time import random print("🎯 Real Code Running on iPhone!") print("=" * 30) # Simple motion detector simulation for i in range(10): motion = random.randint(0, 100) if motion > 70: print(f"🔴 High motion detected: {motion}%") elif motion > 30: print(f"🟡 Medium motion: {motion}%") else: print(f"🟢 Low motion: {motion}%") time.sleep(0.5) print("✅ Done!")
This code simulates a motion detector by generating random numbers and printing color-coded alerts. It runs 10 times with a half-second pause between each reading.

- The `random.randint(0, 100)` creates a random percentage value each loop iteration, and the `if/elif/else` structure sorts it into three categories. Think about what happens when `motion` is exactly 70 or exactly 30 — does the current logic handle those boundary values the way you intend?
- The `time.sleep(0.5)` controls the pacing, but notice the loop runs exactly 10 times regardless of what values appear. Consider how you might make the loop stop early if a critical motion level is detected — what condition would you add?