Challenge
Log formatter function
…f-string into format_log(t, level, msg), a function that returns the line instead of printing it, then fix the alignment of every log line with one change inside the function.
Showing 11–20 of 78
Challenge
…f-string into format_log(t, level, msg), a function that returns the line instead of printing it, then fix the alignment of every log line with one change inside the function.
Example
Return can be used to exit function early when a condition is met.
Challenge
…the name as local, fix it by passing the count in and returning the new one, then write a fuel function the same way.
Challenge
Write validate_cargo(item), which returns a list of everything wrong with a cargo record: missing fields and a negative mass, then a cargo ID that doesn't match the CG- and four digits format. An…
Challenge
…what crew.sort() gives back and store it, as text, in sort_returns . Then sort on a line of its own, print crew[0] , and store that name in first_after_sort . Remove any lines you added before you…
Quiz
…beginner quiz on Python functions: 15 questions on def, return, arguments, default values, *args, scope and docstrings. Instant answers.
Challenge
…to it. Predict the crash, find out what input() really returns, fix it with int(), then write a packing tool that reads two numbers.
Challenge
…calculation into a function distance_km(a, b) that returns the distance between two (x, y, z) points, and use it for all three waypoints. The output must stay exactly the same: To waypoint A: 193.0 km…
Article Python Fundamentals
…to write your own Python functions, from your first def to return values, default parameters and scope, with runnable examples, common mistakes and six practice projects.
Challenge
Add a docstring to fuel_needed() that says what it returns and what the reserve means, then add type hints for its parameters and return value; the tests read both from the function itself.