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

So a user can currently put anything in the confirm purchase except N or n. How to change?

Currently when confirming as long as the user does not put N/n in as input, the program confirms the order.

How would I and where would I add code that says it needs to be Y/y/YES/yes. or even something like if not Yes or no related it makes the user try again?

2 Answers

I'm not seeing the same thing you are. In the video's workspace the confirmation checks for "y" or "Y" (by converting the variable storing the input to lowercase) on line 23:

if should_proceed.lower() == "y":

If you also wanted to include various combinations of case for "yes" you could add

if should_proceed.lower() == "y" or should_proceed.lower() == "yes":

Can you provide a link/time for the video showing the code checking for N/n?

Hi,

I am a beginner to python so I don't know if this the ideal solution... but I tried this using "else if" (elif) to see if could get this to work:

 if confirmation.lower() == "yes":
        tickets_remaining -= number_of_tickets
        print("Thanks, {}! Your tickets are confirmed! There are now {} tickets remaining".format(customer_name, tickets_remaining))
    elif confirmation.lower() == "no":
        print("No problem, {}. No purchase has been made".format(customer_name))
    else:
        print("Please enter a valid answer. Your order has not gone through") ```