Indirect Recursion in Python

What is the output of this code snippet? Recursion is a powerful tool in your coding toolbox. Understanding it is a key skill on your path to mastery. Stephen Hawking used a concise explanation: “to understand recursion, one must first understand recursion.” This puzzle uses indirect recursion where a function f calls a function g … Read more

String Formatting: Keep It Simple, Stupid!

What is the output of this code snippet? The string format function is a useful feature that is new in Python 3. Use it to programmatically insert variable values into the string. Without the format function, you must break the string into a series of smaller substrings and concatenate them. For example, the last line … Read more

Python List Indexing

πŸ›‘ Note: Python has zero-based indexing, i.e., the index of the first element is 0, and the index of the i-th element is (i-1). Not considering zero-based indexing but assuming the i-th element has index i is a common source of bugs! Here’s an example that demonstrates how list indexing works in Python: πŸƒ Training … Read more

Set, Lambda, and Filter in Python

Social Media

What is the output of this code snippet? You will use or have already used the operations introduced in this puzzle. They are elementary pieces of knowledge for any Python programmer. First, we have the two dictionaries mapping an account name to the number of followers. For example, Cristiano Ronaldo (key: “@cristiano”) has 120 million … Read more

Parameter Passing in Python: Call By Object

What is the output of this code snippet? This puzzle demonstrates that parameters are called by object in Python. What does that mean? We look into two functions depreciation1 and depreciation2. The functions take an asset value or a list of asset values as inputs. They depreciate this value by multiplying it with the depreciation … Read more

String Indexing in Python (2-Min Tutorial)

What is the output of this code snippet? This puzzle introduces a powerful tool for your Python toolbox. Make sure, you feel comfortable using it because many advanced puzzles depend on it. The name of the tool is indexing. In Python, you can access every character in the string by using an integer value which … Read more

Python Division: A Short Guide

Python Division

What is the output of this code snippet? The majority of people solve this puzzle correctly. Even so, the first goal of this puzzle is to introduce the concept of variables. Python evaluates the result of the expression on the right side of the equation and stores it in the variable x. After defining the … Read more