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 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
231,275 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.
    print("SOLD!")
    # and then decremement the tickets remaining by the number of tickets purchased.
    tickets_remaining = tickets_remaining - int(tickets_wanted)
# otherwise...
else:
    # Thank them by name.
    print("Thank you for looking, {}".format(user_name))
Steven Parker
Steven Parker
231,275 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.