Challenge
Silent branch
…returns None for Scrub because that branch sets a variable but never returns it. Predict the last line, find which statuses give None, make every path return, then write a function where every path…
Showing 21–30 of 53
Challenge
…returns None for Scrub because that branch sets a variable but never returns it. Predict the last line, find which statuses give None, make every path return, then write a function where every path…
Example
The global keyword allows modifying a global variable inside a function.
Challenge
…landing site as a (lat, lon) tuple, unpack it into two variables in one line and print both to four decimals, then show it the way maps do, with N, S, E and W.
Challenge
…thousands. Investigate and modify Investigate. Find the variable that holds a distance in a different unit and store its name, as text, in odd_one_out . Then convert it: one mile is 1.609344 km. Store…
Example
Namespaces isolate variables. Modules and functions create their own namespaces.
Example
The nonlocal keyword gives access to variables in the enclosing function.
Example
F-strings are a modern way to format text in Python. Insert variables directly into text.
Challenge
…each value to the type it should have, into the new variables named in the comments, then print each new value and its type: altitude_km: 408 <class 'int'> speed_kms: 7.66 <class 'float'> crew: 3…
Example
Return statement returns a value from function. Function can perform calculations and give result.
Article Python Fundamentals
…greet_crew is the name. The rules are the same as for variable names: lowercase letters, words joined with underscores, no spaces, and it can't start with a number. The parentheses () are where inputs…