Python Python Basics All Together Now Branch and Loop

Why does using .lower make a difference in output of the function?

pardon me if my question is unclear. This is my first attempt at a question post. While following along in this series, during the portion of coding where you are prompting the user to answer "Do you want to proceed, Y/N?", Greg uses the coding ".lower". assigned to the yes function.

While more or less copying his code on screen, I accidentally put an upper case Y instead of lower case as he did. When I went to test the code, it would not display the result "SOLD!" as expected but would instead move to the "No" prompt that states "Thank you anyway.

I caught it eventually, but don't understand why "Y" or "y", makes a difference in the code, since I assumed ".lower" forces everything to be interpreted as lower case anyway.

Thank you in advance,

1 Answer

Steven Parker
Steven Parker
176,676 Points

You are correct that using the "lower()" method should make the test ignore case. There could be some other issue.

Is it possible that you forgot to put the parentheses after the name "lower"?

If that's not it, show your actual code to facilitate an accurate answer.

I encounter the same problem, it always output to the "else" even if I type "Y or y" please check my code:

TICKET_PRICE = 10

tickets_remaining = 100

print("There are {} tickets remaining.".format(tickets_remaining))

user_name = input("Please enter you're name :")

ticket_prompt = int(input("Hi {}, how many tickets would you like? ".format(user_name)))

ticket_calc = ticket_prompt * TICKET_PRICE

print("The total price of ticket you would like to buy is ${}.".format(ticket_calc))

user_prompt = input("Would you like to proceed? Y/N ")

if user_prompt.lower() == "Y": print("SOLD!") else: print("Thanks, {}.".format(user_name))

Steven Parker
Steven Parker
176,676 Points

John Rey Cadut — in your case, you are converting the input to lower case, but then comparing it with "Y", which is upper case. So it's not possible for it to ever match. Try comparing to "y" instead (or converting to upper case).