Challenge
Safe number input
The burn length is typed in by hand, and a typo stops the program with a ValueError. Catch it with try and except, keep asking until the input is a number, then also turn away zero and negative…
Showing 141–150 of 233
Challenge
The burn length is typed in by hand, and a typo stops the program with a ValueError. Catch it with try and except, keep asking until the input is a number, then also turn away zero and negative…
Challenge
Extend the feed parser from "Skip blanks and comments": a faulty sensor sends ERR and float() stops the program. Skip lines that fail to convert and count them, then let one try cover short lines too…
Challenge
…fixed? Six months from now someone will tidy the function, and log=[] looks so much simpler than the None check. Write the test that proves the fix: it has to pass now and fail on the old code. The…
Challenge
…level first, then the values exactly on each threshold and just below them, so a > written instead of >= can't slip through.
Challenge
…tank-status blocks with a list of (name, level) pairs and one loop, keeping the output exactly the same, then add a fourth tank with a single list item and list the low tanks.
Challenge
…lists together with zip(), then add a third list of units and warn when the lists don't have the same length, since zip() quietly stops at the shortest.
Quiz
Free beginner quiz: 15 Python errors to read and fix – NameError, TypeError, ValueError, IndexError, KeyError, IndentationError and ZeroDivisionError.
Quiz
…on return, None, several values, lists, dictionaries and early exit. Instant answers.
Quiz
…on def, return, arguments, default values, *args, scope and docstrings. Instant answers.
Quiz
…add(), update(), remove(), union, intersection, difference and subsets. Instant answers.