Sythra
All tracks

Advanced · 4 labs

Crash-Proof Sythra: Try / Except

Parse messy learner input and recover from errors with try and except — so Sythra never crashes on bad data.

Total labs

4

Completed

0

Remaining

4

Progress

0%

In this track

Labs

0 / 4 done

Lab 01Easy

Safe XP Parser

XP fields sometimes arrive as invalid text from forms. Write safe_xp(text). Return int(text) on success. On ValueError return 0. Examples - safe_xp("42") → 42 - safe_xp("abc") → 0 - safe_xp("") → 0 - safe_xp("-5") → -5

Not started · 0%

Start →
Lab 02Easy

Missing Profile Field

Learner profiles may be missing optional fields. Write get_profile_field(profile, field). Return str(profile[field]) when present. On KeyError return "N/A". Examples - get_profile_field({"name": "Asha"}, "name") → "Asha" - get_profile_field({}, "level") → "N/A" - get_profile_field({"xp": 10}, "streak") → "N/A"

Not started · 0%

Start →
Lab 03Medium

Safe Accuracy Calculator

Quiz accuracy is correct divided by total, as a percent rounded to 1 decimal. Write safe_accuracy(correct, total). On success return round(correct / total * 100, 1). ZeroDivisionError (total is 0) → 0.0 TypeError (bad types for division) → None Use separate except blocks for ZeroDivisionError and TypeError. Examples - safe_accuracy(8, 10) → 80.0 - safe_accuracy(1, 3) → 33.3 - safe_accuracy(5, 0) → 0.0 - safe_accuracy("5", 10) → None

Not started · 0%

Start →
Lab 04Hard

Retry with else and finally

Sythra loads the first valid integer from a list of raw inputs and logs every attempt. Write load_first_valid(inputs, log). Try int() on each item in order. On success use else on the try block and return (value, tries) where tries is the 1-based attempt number. If no item converts, return (None, tries) where tries is how many you tried. Use finally to append the string checked to log on every attempt (success or failure). Examples - load_first_valid(["x", "2"], []) → (2, 2) and log ["checked", "checked"] - load_first_valid(["bad"], []) → (None, 1) and log ["checked"] - load_first_valid([], []) → (None, 0) and log []

Not started · 0%

Start →