Challenge
Read the traceback
…line just above it is where it happened. Fill in error_type , crash_function and crash_line at the end of the program, then fix the bug on that line so the program prints: Average: 695.0 K Fix the…
Showing 21–30 of 73
Challenge
…line just above it is where it happened. Fill in error_type , crash_function and crash_line at the end of the program, then fix the bug on that line so the program prints: Average: 695.0 K Fix the…
Challenge
…are written. Investigate and modify Investigate. Store the type of the readings in reading_type : int , float , str or bool . Modify. The readings arrive as text, so leave the two lines that set them…
Challenge
code[0] = "X" stops with a TypeError, because Python strings can't be changed. Predict the crash, find out what methods and slices really give, build a new string instead, then swap a letter in the…
Challenge
…whole items rather than parts of text, then normalise IDs typed by hand and print a clear cleared or not-cleared message.
Challenge
…settings over a copy of the defaults, check each value's type and range and report every problem in one go, then wrap it all in a load_config() that never crashes, even on broken JSON.
Article Mini projects
…ValueError: messagebox.showerror("Error", "Invalid input types!") return conn = sqlite3.connect('space_station.db') cursor = conn.cursor() cursor.execute("INSERT INTO medical_records (astronaut_id…
Challenge
Write parse_command(), which turns typed commands such as burn 12.5 or set mode safe into tuples and raises ValueError with a reason for anything malformed, then run a whole batch of commands and…
Challenge
…can last part of a second, like 12.4. When you press Run, type the number in the console. When you check, the tests type it for you. What the burn leaves The flight director also wants to know what…
Article Python Fundamentals
…Control says: "All systems go!"') # Using different quote types print('Captain\'s log: Day 1') # Using backslash to escape single quote # Including special characters print("Temperature…
Example
Tuples have only two methods: count() for counting and index() for searching.