Challenge
Counter
…works: a dict, and counts.get(level, 0) + 1 to start each new level at 0. That pattern comes up so often that Python has a whole class for it. Swap it in, then use the one thing a plain dict can't do…
Showing 31–40 of 44
Challenge
…works: a dict, and counts.get(level, 0) + 1 to start each new level at 0. That pattern comes up so often that Python has a whole class for it. Swap it in, then use the one thing a plain dict can't do…
Challenge
…keeps one variable up to date instead of creating a new one for each step. Predict how -= and += change a value, follow the fuel through a whole sequence, then track a battery yourself. Predict and…
Example
Tuple unpacking assigns its elements to separate variables simultaneously.
Article Python Fundamentals
…X: 3 Scanning position X: 4 The problem is that's just one line. Mars surface has two dimensions - latitude and longitude. In this case, x_position shows us step by step which square we're scanning…
Example
Tuples are immutable lists. Once created, they cannot be modified.
Challenge
…yet. Read it and decide what it will print on its first line. Write your guess in prediction , at the top, between the quotes. Then run it and compare. Any guess passes this stage: the point is to…
Example
Adding and removing elements from list. Methods append, insert, pop and remove.
Article Python Fundamentals
If you've written even a few lines of Python, you've already used functions. print() is one. So are len() , input() and int() . Somebody wrote them, gave each one a name, and now you can use them…
Challenge
…in a chain of nine elif branches, one per body, and every new destination means another branch. Turn the chain into a table without changing a single character of the output, then use the table for…
Article Mini projects
…3 4 4 5 5 Last single digit in base 6 6 10 Out of digits - new position! 7 11 8 12 9 13 10 14 11 15 Out of digits again in the ones place 12 20 Two groups of six, zero ones See the pattern? It works…