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 trialAsuka A.
379 Points"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!")
2 Answers
Steven Parker
231,269 PointsTry limiting the test to just the first character of the string:
if should_proceed[0].lower() == "y":
Asuka A.
379 PointsThank you! That seemed to fix that error. I will have to look into that more :)
Colton Shaw
12,634 PointsI 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
231,269 PointsBe 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.
Nick Evershed
6,429 PointsNick Evershed
6,429 PointsPlease can you add your full code