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

works fine in Workspace but not locally?

So I finished the masterticket.py and code works fine on TeamTreehouse's Workspace; however, I copied/pasted the same code onto my local computer (sublime) and I'm getting a NameError: name 'blah' is not defined when I try to run it and input a name.

Any ideas why I'm getting this error locally but not in the workspace??

Could you please share the code alongside or provide the course/lecture related to this question.

From the looks of it, _blah _ is something only defined in workspace environment and is not a globally available variable.

lol blah was an arbitrary example...

name = input("Hello! What's your name? ")

oh!!! I thought...

name = input("Hello! What's your name? ")
print(Blah)
C:\Users\username>python c:/Users/username/Desktop/todel.py
Hello! What's your name? Blah
Traceback (most recent call last):
  File "c:/Users/username/Desktop/todel.py", line 3, in <module>
    print(Blah)
NameError: name 'Blah' is not defined

or something similar.

If the code is...

name = input("Hello! What's your name? ")

This should be running fine in any file.

Here is when i tried the above line in a file...

C:\Users\username>python c:/Users/username/Desktop/todel.py
Hello! What's your name? BlahBlah

C:\Users\username>

You'll need to add more details regarding your problem.

here's the code that runs fine in treehouse's workspace but not locally for me..

SERVICE_CHARGE = 2
TICKET_PRICE = 10
tickets_remaining = 100  


# Create the calculate_price function, It takes number of tickets and retunrs buy_tickets * TICKET_PRICE
def calculate_price(number_of_tickets):
  return (number_of_tickets * TICKET_PRICE) + SERVICE_CHARGE


while tickets_remaining >= 1:
  print("there are {} tickets remaining.".format(tickets_remaining))
  name = input("Hello! What's your name? ")
  buy_tickets = input(("Hi {}! How many tickets would you like to buy? ".format(name)))
  # Expect a ValueError to happen and handle it appropriately...remember to test
  try:
    buy_tickets = int(buy_tickets)
    # Raise a ValueError if the request is for more tickets than are available
    if buy_tickets > tickets_remaining:
      raise ValueError("There are only {} tickets remaining.".format(tickets_remaining))
  except ValueError as err:
    # Include the error text in the output
    print("Oh no, we ran into an issue. {}. Please try again.".format(err)) 
  else: 
    total_cost = calculate_price(buy_tickets)
    print("That will be ${}!".format(total_cost))
    response = input("Would you like to proceed? Y or N? ")
    if response == "Y" or response == "y":
      # TODO: Gather Credit Card Info and process it.
      print("SOLD!")
      tickets_remaining -= buy_tickets
    else:
      print("Thanks {} for stopping by!".format(name))
print("Sorry, all the tickets have been Sold Out")

Works fine for me...

Here is my output:

Microsoft Windows [Version 10.0.15063]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\username>python c:/Users/username/Desktop/TODEL.py
there are 100 tickets remaining.
Hello! What's your name? BABA
Hi BABA! How many tickets would you like to buy? 10
That will be $102!
Would you like to proceed? Y or N? y
SOLD!
there are 90 tickets remaining.
Hello! What's your name? BLAHBLAH
Hi BLAHBLAH! How many tickets would you like to buy? 2
That will be $22!
Would you like to proceed? Y or N? N
Thanks BLAHBLAH for stopping by!
there are 90 tickets remaining.
Hello! What's your name? BLAHBLAH2
Hi BLAHBLAH2! How many tickets would you like to buy? 100
Oh no, we ran into an issue. There are only 90 tickets remaining.. Please try again.
there are 90 tickets remaining.
Hello! What's your name? BLAHBLAH3
Hi BLAHBLAH3! How many tickets would you like to buy? 99
Oh no, we ran into an issue. There are only 90 tickets remaining.. Please try again.
there are 90 tickets remaining.
Hello! What's your name? BLAHBLAH4
Hi BLAHBLAH4! How many tickets would you like to buy? 89
That will be $892!
Would you like to proceed? Y or N? Y
SOLD!
there are 1 tickets remaining.
Hello! What's your name? BLAHBLAH5
Hi BLAHBLAH5! How many tickets would you like to buy? 0
That will be $2!
Would you like to proceed? Y or N? N
Thanks BLAHBLAH5 for stopping by!
there are 1 tickets remaining.
Hello! What's your name? BLAHBLAH6
Hi BLAHBLAH6! How many tickets would you like to buy? 1
That will be $12!
Would you like to proceed? Y or N? N
Thanks BLAHBLAH6 for stopping by!
there are 1 tickets remaining.
Hello! What's your name? BLAHBLAH7
Hi BLAHBLAH7! How many tickets would you like to buy? -10
That will be $-98!
Would you like to proceed? Y or N? Y
SOLD!
there are 11 tickets remaining.
Hello! What's your name? BLAHBLAH8
Hi BLAHBLAH8! How many tickets would you like to buy? 11
That will be $112!
Would you like to proceed? Y or N? Y
SOLD!
Sorry, all the tickets have been Sold Out

Although it takes negative number of tickets as input.. but code is executing just fine. I think you'll have to add the error as well.