Errors and debugging
I’ll start this section by giving you some advice: Sometimes the best solution to a bug is hard to find. Take a break if you can’t find it. All it takes sometimes is some space away from your code. You can sometimes solve in 5 minutes something you’d been staring at for hours if you simply walk away. It won’t always work, but it is very helpful.
Now let’s take a look at some buggy code.
ch5_buggyCode1.py
import random for i in range(0, 10): n = random.randint(0, 5) print(in)
Let’s try to execute this program. I’m getting a SyntaxError! It only highlights my i. Why is that invalid syntax? I just want to get the product of i and n. But here’s the problem, in Python programming, putting letters together does not imply multiplication. That’s something some mathematicians do. And since I was a mathematics teacher for more than 10 years before shifting...