Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics All Together Now Handle Exceptions

Why is there a type error for the ">" sign?


tickets_remaining = 100

while tickets_remaining >= 1: user_name = input("Please enter your name: ") print("There are {} tickets remaining.".format(tickets_remaining))

amount_purchased = input("How many tickets would you like {}? ".format(user_name))

try: if amount_purchased > tickets_remaining: raise ValueError("That is not possible, sorry") amount_purchased = int(amount_purchased) except ValueError: print("That is not a valid value, please enter a number") else:
total_cost = TICKET_PRICE * amount_purchased

print("your total for this is £{}".format(total_cost))
proceed = input("Do you want to proceed with this sale, PLease enter yes or no: ")

if proceed == "yes":
  tickets_remaining -= amount_purchased
elif proceed == "no":
  print("Ok, Thank you anyway!")
  print("That is not a valid answer")

print("We are so sorry but we are all out of tickets")

The problem is, I am trying to raise an exception Error but the code stops running after the if statement which says, "amount_purchased > tickets_remaining?

12,964 Points

Hi Faraz Jahangiri! I'd like to help, but your code isn't in proper syntax. While I can correct the syntax in my workspace, I can't be sure that it's set up the same way as yours.

    def proper_syntax():
        print("""You can achieve proper syntax 
                 by typing three back-tics and the name of your coding language.
                 End with three more back-tics.  As seen around this block of code.""")

Hope this helps! :)

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there, Faraz Jahangiri ! The problem here is that you cannot compare a string to an integer in this way. The input that the user gives will be of type string. And tickets_remaining is an integer. To compare them, you will first need to convert the user's input to an int.

On line 9 try this instead:

# convert the user's input to an integer for comparison
amount_purchased = int(input("How many tickets would you like {}? ".format(user_name)))

Hope this helps! :sparkles: