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 Branch and Loop

"SOLD!" isn't running if the 'yes' input is something other than 'y'. YES isn't prompting "Sold!", yup isn't either.

If they want to proceed

if should_proceed.lower() == "y": # Print out to the screen "SOLD!" to confirm purchase # TODO: Gather credit card information and process it. print("SOLD!")

Please can you add your full code

2 Answers

Steven Parker
Steven Parker
210,425 Points

Try limiting the test to just the first character of the string:

if should_proceed[0].lower() == "y":

Thank you! That seemed to fix that error. I will have to look into that more :)

I ran this as the below assuming the user would input something like "Yes", "yes", "y", "Y" similar to the possibilities on a Linux command line.

if "y" in proceed.lower():
    # print out to the screen "SOLD!" to confirm purchase.
    # and then decremement the tickets remaining by the number of tickets purchased.
    tickets_remaining = tickets_remaining - int(tickets_wanted)
# otherwise...
    # Thank them by name.
    print("Thank you for looking, {}".format(user_name))
Steven Parker
Steven Parker
210,425 Points

Be aware that "in" will look at every letter, not just the first. So an answer like "nay" or "no way" would be misinterpreted as an affirmative by this code.

My original suggestion would recognize all of the affirmative examples you gave, plus "yep", "You bet!", etc.