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 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
231,275 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
231,275 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).