Section 1.11 Let’s Make Mistakes!
When students get their first syntax error in Python, some of them freak out a little bit. All of a sudden there’s some mysterious message with lots of technical terms they don’t understand, and yes, it is a bit scary.
Let’s put that experience under your control. We’re going to ask you to purposely make mistakes so you can see what happens when Python doesn’t like your program’s syntax. You’ll see the messages that common syntax errors produce. Then, when you see an error message in one of your programs, your reaction will be “Oh, yeah, I remember seeing that when I was playing around making mistakes” instead of “OMG!! What will I do? All is lost! *PANIC*”.
A few pages ago, we asked you to write a program that displays two lines of output. Here’s the solution. (Run it to see what it does.)
Try making the following changes to the program, one at a time, and see what the results are. Some of these changes will cause errors, and some of them won’t. After each error, put the program back the way it was originally so you’re starting with a working program.
- Misspell one of the occurrences of
print
asprimt
. - Misspell
Python
asPiethawn
in the second line. - Leave off one or both of the parentheses on one of the lines.
- Put some extra spaces before or after one of the parentheses.
- Put some extra spaces after the opening double quotes.
- Write
Print
instead ofprint
. - Write
Program
instead ofprogram
in the first line. - Leave off one or both of the double quotes on one of the lines.
- Make an English grammar error; change the second line to
print("I writed it in Python.")
- Be creative—think of other fun new mistakes to make and see what happens.