Challenge 5-1: Debugging

Challenge 5-1: Debugging

Errors

Now we’re going to talk about something that’s really important in programming - errors and error messages. You've almost certainly come across some Python errors through this course and in your own programs, but we'll break them down in more detail here.

Error messages are so useful. They're nothing to be afraid of - they’re a good thing, because they tell us what went wrong. Without error messages, it’s hard to fix something that’s broken.

Try entering some of these expressions and see what answers Python gives you.

The first expression multiplies the string "friend" and prints it 5 times.

>>> "friend" * 5

'friendfriendfriendfriendfriend'

What is this next expression supposed to do? Should it combine the word "friend" and the number 5? What happens instead?

>>> "friend" + 5

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

TypeError: Can't convert 'int' object to str implicitly

What do you think str and int mean here?

Does the error message tell you what’s wrong?