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
notoriusgru
489 PointsCode from the Handle Exceptions portion of Python Basics doesn't work outside of workstation
I was having problems with the browser-based workstation loading (Firefox, Linux Mint Cinnamon) and decided to try Sublime Text. I installed the REPL in ST and ran the code from the lesson and got a Traceback error. I ran the same code in terminal and got the same error. The code and error are below. Can someone tell me what I'm missing? I'm hoping I'm not learning something that only works in the TeamTreehouse environment, that'd be a bummer.
TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining >= 1:
print("There are {} tickets remaining.".format(tickets_remaining))
name = input("What is your name? ")
num_tickets = input("How many tickets would you like, {} ".format(name))
num_tickets = int(num_tickets)
amount_due = num_tickets * TICKET_PRICE
print("The total due is ${}".format(amount_due))
should_proceed = input("Do you want to proceed? Y/N ")
if should_proceed in [Y, y]:
print("SOLD!")
tickets_remaining -= num_tickets
else:
print("Thank you anyways, {}!".format(name))
print("Sorry, the tickets are all sold out! :(")
There are 100 tickets remaining.
What is your name? Bill
Traceback (most recent call last):
File "masterticket.py", line 8, in <module>
name = input("What is your name? ")
File "<string>", line 1, in <module>
NameError: name 'Bill' is not defined
[MOD: added ```python formatting -cf]
1 Answer
Chris Freeman
Treehouse Moderator 68,468 PointsAn error of the form:
What is your name? Bill
#... NameError: name 'Bill' is not defined
Looks like the input Bill is being treated like a variable name instead of text. This is the standard behavior for Python 2. (See difference between Python 2 input and raw_input). In Python 3 there is only input (which is the same behavior as Python 2 raw_input).
Python 3 input and Python 2 raw_input both interpret input as a string. Python 2 input treats input as code. This has it's obvious drawbacks. The equivalent in Python 3 would be eval(input("Prompt : "))
Post back if you need more help. Good luck!!
notoriusgru
489 Pointsnotoriusgru
489 PointsAhh, so the lesson and workspace utilize python 3 and somehow I've wound up installing and running python 2 on my machine?thank you for your answer!