Classify CPU usage as OK, warning or critical
Problem statement
Some decisions have more than two outcomes. CPU usage isn't just "fine" or "not fine," it's usually graded into bands: under 70% is fine, 70-89% is a warning, 90% and up is critical. Checking three ranges needs more than one if, it needs elif ("else if") to chain the checks together, only running one of them.
Common mistake: using separate if statements instead of elif.
Wrong:if usage >= 90: print("critical")if usage >= 70: print("warning")With usage = 95, both conditions are true, so this prints both "critical" and "warning", when only one label should apply. elif fixes this by only checking the next condition when the previous one was false, so exactly one branch ever runs.
Your task: given cpuUsage = 82, classify it as "OK" (under 70), "warning" (70-89), or "critical" (90 and up), and print the result.
Expected output:
warningApproach
Check the highest band first, or the lowest first, either order works as long as each check only runs when the ones before it were false:
cpu_usage = 82
if cpu_usage >= 90:
status = "critical"
elif cpu_usage >= 70:
status = "warning"
else:
status = "OK"
print(status)