Code Lab BetaBUILD. RUN. DISCOVER.

Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.

Challenges / 02

Guard Parse.

About 5–10 minutes
Your lesson
Write parse_score(text): try int(text); except ValueError: raise ValueError("not an int"). If the number is outside 0..100, raise ValueError("out of range"). Otherwise return the number. Print parse_score("80"). In try/except print the messages for parse_score("x") and parse_score("150"). Expected: 80 not an int out of range

Links early rules with try/except and raise messages.

challenge_02.pyPYTHON
Loading the runtime… The first launch may take a little longer.
… 0/20000
CHECKSSTANDBY
01ValueError for non-int
02ValueError for range
03console is 80 / not an int / out of range
…0/10000
ConsoleWrite the code. Bring it online.
›
Calculators BG — 50+ free online calculators | Калкулатори БГ