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

Moe Myint Kyal Sin
PLUS
Moe Myint Kyal Sin
Courses Plus Student 553 Points

How can I correct errors?

https://teamtreehouse.com/library/python-basics/python-for-beginners/correct-errors How can I correct errors of the question?

errors.py
print("Hello")
print(name)
NameError

print("Let's do some math!")

print(5 + "a")

print("Thanks for playing along!')

1 Answer

Ari Misha
Ari Misha
19,323 Points

Hiya Moe!! I'd only mention the lines of codes that needs to be rectified so yeah here we go:

print(name)
  • This line of code will throw an error 'coz the variable "name" is not defined. Python tryna find this variable and it couldnt so it threw an Error. To prevent this bug, all you have to do define the "name" variable and assign anything to this variable.
print(5 + "a")
  • In Python, this line of code will throw a "TypeError". Why? Its coz ya cant add an integer to a string. So yeah to prevent this bug , just convert "5" to a string.
print("Thanks for playing along!')
  • this line of code will throw a SyntaxError coz you've to be consistent with quotes. If you've opened a string with a single quotes , then end it with a single quote as well. And same goes for double quotes. I'd recommend ya to stick with double-quotes in python.

Consider these suggestions and your code will pass with flying colors. (:

Michael Hulet
Michael Hulet
47,912 Points

I'm marking this answer as best because the other one was a straight copy/paste, and this is the only remaining answer to the question. If someone else posts an answer and the OP decides that the new answer is better, they can feel free to change it