DEV Community

Cover image for Hello World meets the Feynman Technique
William Baptist
William Baptist

Posted on • Edited on

Hello World meets the Feynman Technique

Imagine taking a simple one-liner in Python and turning it into a more complex program that you have to explain to a toddler. Sound like a challenge? Well, it certainly was for me.

To guide me through the process, I decided to use the powerful and effective Feynman Technique, which follows the following four steps:

Step 1: Choose a Concept

The first step of the Feynman Technique is to choose a concept that you want to understand. In my case, I wanted to understand the basics of Python programming and how to create a “Hello World” program that was more complex than the usual one-liner.

I went back to basics with Python and experimented with the different code snippets below:

# How must people would (and should) print Hello, World!
print("Hello, World!")

# Using variables in a Hello, World!
message = "Hello, World!"
print(message)

# Adding user input to a "Hello World" program
name = input("What is your name? ")
print("Hello " + name)

# Adding a loop to the Hello, World! program
for i in range(5):
    print("Hello, World!)
Enter fullscreen mode Exit fullscreen mode

Step 2: Teach it to a Toddler

The second step of the Feynman Technique, of course, is to teach the concept to a toddler. If I can explain it in simple terms that a child can understand, then it helps two people. So, luckily for me (and him), it was my grandfather’s birthday recently, so I decided to explain the basics of Python programming to my little cousin, who is six years old. I started by showing him some simple Python code and explaining what each line did.

Photo by [Lauren McConachie](https://unsplash.com/@coldwisper?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)

I used analogies and examples to help him understand, and I tried to make it fun by turning it into a game. I explained conditional statements by comparing them with a traffic light. When the light is green, you can go, but when it is red, you have to stop. Similarly, in a program, if a certain condition is met, you can execute a set of instructions, but if it is not met, you can execute a different set of instructions. By the end of our lesson, he was able to create his own “Hello World” program and, to my surprise, was excited to learn more.

Step 3: Identify Gaps and Fill Them

The third step of the Feynman Technique is to identify any gaps in your understanding and fill them in. After teaching my little cousin about Python, I realised that there were still some areas that were hard to teach to people who weren’t already proficient in coding. My cousin had trouble understanding why we needed to use variables and how they were different from one another. To overcome this challenge, I used another simple analogy to explain the concept. I told him that variables were like containers that we use to store different types of things, such as toys or clothes. Just like we use different containers for different things, we use different variables to store different types of data, such as numbers or words.

Photo by [Annie Spratt](https://unsplash.com/@anniespratt?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)

I found that explaining the concept of object-oriented programming to someone without any prior knowledge of coding can be a bit challenging. However, through further research and practice, I was able to strengthen my understanding and break down the topic in a more approachable way. By the end of this step, I felt confident in my ability to explain the more complex “Hello, World!” program.

Step 4: Simplify and Use Analogies

The fourth and final step of the Feynman Technique is to simplify the concept and use analogies to help explain it.

Here’s what my “complex” Hello World program looks like:

import random

def get_greeting():
    greetings = ["Hello", "Hi", "Hey", "Greetings"]
    return random.choice(greetings)

def get_name():
    name = input("What's your name? ")
    return name

def greet():
    greeting = get_greeting()
    name = get_name()
    print(f"{greeting} {name}, welcome to my program!")

if __name__ == "__main__":
    greet()
Enter fullscreen mode Exit fullscreen mode

Terminal output

Let’s say my grandpa’s birthday had a surprise party. We want to greet him with a random greeting from a list of possible greetings and also ask him for his name so we can address him properly.

Photo by [RDNE Stock project](https://www.pexels.com/photo/an-elderly-man-wearing-sunglasses-and-a-party-hat-7867915/)

import random
Enter fullscreen mode Exit fullscreen mode

We need to import the random module from Python to randomly choose a greeting from the list of greetings that we have prepared.

def get_greeting():
    greetings = ["Hello", "Hi", "Hey", "Greetings"]
    return random.choice(greetings)
Enter fullscreen mode Exit fullscreen mode

We need to define a function called get_greeting() that will randomly choose a greeting from a list of possible greetings. In the party analogy, this is like having a box of greeting cards with different messages. Someone will randomly pick one card and read the message to our grandad.

def get_name():
    name = input("What's your name? ")
    return name
Enter fullscreen mode Exit fullscreen mode

We also need to define a function called get_name() that will ask my grandpa for his name. In our party analogy, this is like having a guestbook where I ask my grandpa to write down his name. The input() function in Python will allow me to get his name as input from the keyboard.

def greet():
    greeting = get_greeting()
    name = get_name()
    print(f"{greeting} {name}, welcome to my program!")
Enter fullscreen mode Exit fullscreen mode

Finally, we define the main function greet() that will put everything together. In our party analogy, this is like having a host who will read the greeting card to my grandad and address him properly by his name. The print() function in Python will allow the display of a greeting and the grandad's name on the screen.

if __name__ == "__main__":
    greet()
Enter fullscreen mode Exit fullscreen mode

This line of code is a bit technical, but it’s important to include. It basically checks if the code is being run as the main program or if it is being imported as a module. In this party analogy, this is like having my mother at the entrance of the party who will only allow guests who were invited by us to enter. If the code is run as the main program (which is what we want), then it will call the greet() function and start the party by displaying the greeting to my grandad.

Through the four steps of choosing a concept, teaching it to a toddler, identifying gaps, and simplifying with analogies, I was able to turn a simple “Hello World” program into a more complex program. The Feynman Technique can be used in any subject, and I would highly recommend it to anyone looking to improve their understanding of a topic.

Top comments (0)