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 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?


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))
        print("Please enter a valid answer. Your order has not gone through") ```