Challenge
Safe number input
…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 lengths.
Showing 1–10 of 50
Challenge
…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 lengths.
Challenge
…lines that fail to convert and count them, then let one try cover short lines too and print each error.
Challenge
…only if fuel_needed(-5) raises ValueError : call it in try , set a variable to True in except ValueError: , and assert it after. Then print: All checks passed Leave the function as it is. The hidden…
Challenge
…rows the way the file does. Check the sensor first, then try the conversion. Flag the limits After the count, check every valid reading against its sensor's range in LIMITS . Collect each one outside…
Challenge
…were checked twice and they are working. The code has a try and an except , so it can't crash, but the bug is hiding somewhere inside it. Predict what the program prints, find out what the except is…
Challenge
The telemetry pipeline is now split into parse_row() and check_limits(). Write assert tests for both, good rows, rejected rows and readings right at a limit, so that each of three planted bugs makes…
Article Mini projects
…CELESTIAL BODY DATA") name = input("Name: ") while True: try: mass_str = input("Mass in kg (e.g. 5.972e24): ") mass = float(mass_str) if mass <= 0: print("Mass must be positive!") continue break…
Article Mini projects
…"All fields are required!") return try: astronaut_id = int(astronaut_id) heart_rate = int(heart_rate) weight = float(weight) except ValueError: messagebox.showerror("Error", "Invalid input types!")…
Article Mini projects
…event log""" if not self.log_file.exists(): return [] try: with open(self.log_file, 'r') as f: events = json.load(f) # Verify chain integrity for i, event in enumerate(events): # Reconstruct the…
Challenge
…raises ValueError with the reason for anything else. Then try every command and print OK and the result, or REJECTED , the command in quotes and the reason: OK ('burn', 12.5) OK ('burn', 3.0) OK…