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

Don Diurba
Don Diurba
104 Points

Python Basics, Challange Task 1 of 1, Correct Errors

I am having trouble with understanding how to do what is required for completing this challenge. I have reviewed the video 3 times

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

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

print("Thanks for playing along!')

2 Answers

So, they want you to correct any errors that might make any of the following statements not work correctly:

print("Hello")
print(name)

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

print("Thanks for playing along!')

First one looks okay. Second - why might this not print out? Because there's no 'name' variable declared. 3rd - looks correct. 4th - what's wrong with this? You can't add an integer and a string. What might fix this? Declaring 5 to be a str type. 5th - The quotes don't match.

Hope that helps!

Tobias Helmrich
Tobias Helmrich
31,602 Points

Hey there Don,

there are a few ways how you can solve this challenge. The goal is to solve the errors in the code. The problems in the code are that...

  • we're printing out a name variable even though we didn't create this variable
  • we want to print the result of the addition of the variable a and 5 but the "a" is in quotes and it also doesn't have a value
  • in the last print function there is one double quotation mark and one single quotation mark

If you fix all of these issues a possible solution would be this:

print("Hello")
name = "Don"
print(name)

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

print("Thanks for playing along!")

I hope that helps! :)