Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Python for Beginners Correct errors

Dolapo Sekoni
Dolapo Sekoni
Courses Plus Student 1,431 Points

help detect the errors

i tried to correct the errors in the challenge but keep getting bummers my corrections are in line 3,5,7,9.

kindly assist . am new to coding

print("Let's do some math!")
print(5 + "a")
print("Thanks for playing along!')

2 Answers

Alex Koumparos
Alex Koumparos
Python Development Techdegree Student 36,886 Points

Hi Dolapo,

What the challenge wants you to do here is to fix the errors in the existing lines of code. You shouldn't be adding any more outputs. For example, you've added a line that prints "Thanks_for_playing_along".

So the first thing to do is to remove the lines of your code that add behaviour to the program, since the challenge isn't asking for that.

Next, we need to fix the errors in the code:

The first error message we get is 'SyntaxError: EOL while scanning string literal'. The interpreter is telling you that it got to the end of the line before seeing a closing quote that it expected (since that is what would end the string literal). So the way to address this is to take a look at all the strings and see if any of them are missing closing quotes. If there are no strings missing closing quotes then maybe there is a mismatch between the opening and closing quotes (e.g., the string starts with a single quote and ends with a double quote).

The next error is "NameError: name 'name' is not defined". Take a look and see if there are any references to a name variable that hasn't been assigned. There are a couple of possible fixes to a variable reference with no assignment. You could either assign some value to that variable in a line prior to where it is used, or just turn 'name' into a string literal. I think either would pass the challenge, but it's pretty clear from the challenge text "You might need to fix some quote marks or make a new variable or two" which option is the challenge's preference.

Once that is fixed, you'll get the error: "TypeError: unsupported operand type(s) for +: 'int' and 'str'" This is telling you that you are trying to combine an int and a str with the + operator. Since the + operator will only work with two operands of the same type, we need to change the type of one of those values. There's a bunch of things you can choose to do here. You could replace the int with a string literal (so you're concatenating two strings), or you could turn the string into a variable (remembering to assign an int value to it in a previous line), you could use the str() function to turn the int into a string, you could replace the string literal with an int literal. It's up to you.

Hope that clears it up.



Dolapo Sekoni
Dolapo Sekoni
Courses Plus Student 1,431 Points

thanks Alex, i did that and passed the challenge,

God bless you