Lesson 2/48 ยท ๐ง The Programmer's Mindset
๐ง The Programmer's MindsetLesson 2/48
Phase 0 ยท The Programmer's Mindset15 min
Instructions for a Robot
Discover why being precise is the core skill of programming
Let's do an experiment. How would you tell a robot to make a cup of tea?
You might say: "Put water in the kettle and boil it."
But the robot asks: How much water? What's a kettle? How do I open the lid? What does "boil" mean? How do I know when it's boiled?
This is exactly what happens when you write code. The computer needs you to answer every single one of those questions, explicitly, in the right order.
You might say: "Put water in the kettle and boil it."
But the robot asks: How much water? What's a kettle? How do I open the lid? What does "boil" mean? How do I know when it's boiled?
This is exactly what happens when you write code. The computer needs you to answer every single one of those questions, explicitly, in the right order.
The Sandwich Test
Try writing instructions to make a peanut butter sandwich for a robot that takes things literally. You'll quickly discover: "spread the peanut butter" requires knowing what "spread" means, which tool to use, how thick, which side of the bread, whether to open the jar first...
Programming is the art of eliminating all ambiguity.
Try writing instructions to make a peanut butter sandwich for a robot that takes things literally. You'll quickly discover: "spread the peanut butter" requires knowing what "spread" means, which tool to use, how thick, which side of the bread, whether to open the jar first...
Programming is the art of eliminating all ambiguity.
Precision = Power
The frustrating part of programming early on is that you must be so precise. But here's the flip side: once you've written those precise instructions, the robot (computer) will follow them perfectly, every single time, no matter how many times you ask.
Write a script to check 1000 log files for errors. The computer will check all 1000, every time, without getting bored or making mistakes.
The frustrating part of programming early on is that you must be so precise. But here's the flip side: once you've written those precise instructions, the robot (computer) will follow them perfectly, every single time, no matter how many times you ask.
Write a script to check 1000 log files for errors. The computer will check all 1000, every time, without getting bored or making mistakes.
๐คQuick Check
Why do computers need such precise instructions?
Practice Exercises
0/2 solvedExercise 1 of 2easy
โฑ 00:00Spot the Ambiguity
These instructions for a robot are ambiguous. Which step would cause the robot to get confused?
1. Go to the kitchen2. Pick up the glass3. Fill it4. Bring it back
Which step is MOST ambiguous?
1. Go to the kitchen2. Pick up the glass3. Fill it4. Bring it back
Which step is MOST ambiguous?
solution.py
1 / 2
Exercise 2 of 2easy
โฑ 00:00Precise Steps
Write precise instructions to add two numbers and print the result.
Your "robot" steps (as comments) should explain: what inputs, what operation, what output.
Then write the actual Python code.
Expected output:
Your "robot" steps (as comments) should explain: what inputs, what operation, what output.
Then write the actual Python code.
Expected output:
The sum of 5 and 3 is 8solution.py
2 / 2
Solve all 2 exercises to unlock completion