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

John Morris
John Morris
4,752 Points

Variable

I think I am describing the variables right, but for some reason it is not working.

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

3 Answers

You have to initialize the variable before you can use it; put the lines with the equals signs before the corresponding print lines. This is what you have:

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

This what it needs to look like:

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

but your output will look something like this:

jeff

Let's do some math!

521

Edited*

I believe your last print line will throw an error, fyi.

If you need help fixing it let me know.

You're welcome :)