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! While you're at it, check out some resources Treehouse students have shared here.

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

Syntax Error on Error corrections

print("Hello") print(name) def name = "treehouse" print("Let's do some math!") print(5 + "a") def a = 7 print("Thanks for playing along!")

Code Above is what I am attempting to submit. Have rewatched all modules twice.

errors.py
print("Hello")
print(name)
def name = "treehouse"
print("Let's do some math!")
print(5 + "a")
def a = 7
print("Thanks for playing along!")

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I can see that you've really tried here so let me give you some hints. We use the def keyword to define a method/function. But that is not required for this challenge.

So let me show you how I would tackle it. First, I would start the challenge fresh and just hit "Check work". That will give the first error. Let's take a look:

Bummer! SyntaxError: EOL while scanning string literal

This part, you figured out so kudos! :thumbsup: The final line doesn't having matching types of quotation marks so the string literal is unterminated in the original code, but you fixed that!

Then we run "Check Work" again, and we get:

Bummer! NameError: name 'name' is not defined

This is where you got stuck. The original code is print(name), but name isn't defined. Now, there are two solutions to this. You could either make name into a string literal by placing quotes around it or you could define it. But you need to define it before you try and use it.

So we could do:

#this
print("name")

#or something like
name = "treehouse"
print(name)

Once we fix that, we run "Check work" again, and we get:

TypeError: unsupported operand type(s) for +: 'int' and 'str'

Here, you will notice that we are trying to add an integer with a string. This operation is not valid in Python. They either both need to be a string or both need to be an integer. How you do that is completely up to you, and I feel confident that you can get the rest from here, but let me know if you're still stuck! :sparkles:

Thank you Jennifer for the clarification and swift response. I look forward to working more with the Treehouse community.

print("Hello")
print("name")

print("Let's do some math!")
print(str(5) + "a")

print("Thanks for playing along!")

You have placed def in your code, def is for declaring functions and not for declaring variables, also you have declared the variables after they have been called, they needed to be declared before they can be used

name = "treehouse"
print(name)