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 Cleaner Code Through Refactoring

walter fernandez
walter fernandez
4,992 Points

in my last if statement. It does not matter if I input yes or not. my code always output "SOLD OUT". I don't know why.

tickets_remaining = 100
#create the calculate function, it take the number tickets and return
# return TICKET_PRICE * num_tickets
def calculate_price(number_of_tickets):

    return TICKET_PRICE * number_of_tickets + SERVICE_CHARGE

while tickets_remaining >= 1 :
    print("there are {} tickets".format(tickets_remaining))
    name = input("what is you name? ")
    num_tickets = input ("how many tickets would you like {}? ".format(name))
    #Expect a ValueError to happen and handle it appropiatly...remember to test it out!
       num_tickets = int(num_tickets)
                    #Raise a ValueError if the request is for more tickets than there are available.
       if num_tickets > tickets_remaining :
                    raise ValueError("Sorry, There are only {} tickets remaining".format(tickets_remaining))
    except ValueError as err:
            #Include the error text in the output.
          print("Oh no!, you don't know what an integer is. {} please try again".format(err))
        amount_due = calculate_price(num_tickets)
        print("the total due is {}".format(amount_due))
        should_proceed  = input("do you want to proceed? Y/N ")
        if should_proceed == "yes" or "Yes" or "YES":
           print("SOLD OUT")
           tickets_remaining -= num_tickets
           print("thanks, {}, have a nice day".format(name))
print("the tickets are SOLD OUT")

MOD: I just updated your question to put your code in Markdown format so it's much easier for everyone to read, and to help you out! See the Markdown Cheatsheet that is linked just below the textbox when you're typing a question, to format code. Don't worry, it's easy! :-)

Steven Parker
Steven Parker
210,487 Points

Thanks, "mystery mod". :wink: And for those unfamiliar with Markdown, there's also a video on code formatting.

1 Answer

Steven Parker
Steven Parker
210,487 Points

You need to use complete expressions on both sides of any logic operation (like "or"). A non-empty string by itself will be evaluated as "truthy".

But a more compact test for multiple versions of the same word can be done using case conversion:

        if should_proceed.lower() == "yes":  # will also match "Yes", "YES", etc.