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

Hi! Seems like an issue with String class in Python. Can someone please help me figure how to fix this error in console?

current_mood = input("How are you today?")
print(current_mood)
yasheshshah@Yasheshs-MacBook-Pro python % python input.py
How are you today?"Great"
Great
yasheshshah@Yasheshs-MacBook-Pro python % python input.py
How are you today?Great
Traceback (most recent call last):
  File "input.py", line 1, in <module>
    current_mood = input("How are you today?")
  File "<string>", line 1, in <module>
NameError: name 'Great' is not defined
yasheshshah@Yasheshs-MacBook-Pro python %

4 Answers

Running python3 sorted the issue.

python3 hello.py

Thanks :)

I can see 2 'Great's one in double quotes and the other not. If you want to call your mood use current_mood then hit enter not the mood, like Great. current_mood is the variable not Great

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,732 Points

You are using 2.7 Python.

If that is the case, switch input() function with a raw_input() function

# works in version 3.x python
current_mood = input("How are you today?")
print(current_mood)
# works in version 2.x python
current_mood = raw_input("How are you today?")
print(current_mood)

best, Jeff