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!")

Nick Evershed
Nick Evershed
6,409 Points

Please can you add your full code

2 Answers

Steven Parker
Steven Parker
204,009 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 :)

Colton Shaw
Colton Shaw
11,591 Points

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
204,009 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.