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 trialTyler Wasser
279 PointsNesting dot notation
Is there a way to make the variable understanding only produce a lowercase answer using the .lower() method while also utilizing the .format() method to input the name in the string? I want it to not continue the loop if I were to type "Yes" in the prompt.
2 Answers
Steven Parker
231,269 PointsYou're right, you just need to use the "lower" method to make the test work with any case input:
while understanding.lower() != 'yes':
justlevy
6,325 PointsI have a question about making user input lower case all the time...
My code below has 2 .lower() methods.
Is this considered 'clean' or is there a way to do this only once?
Thanks in advance!
name = input("What's your name? ")
answer = "no"
while answer.lower() == "no":
print("{}, do you understand Python while loops? ".format(name))
answer = input("Enter yes/no ")
if answer.lower() == "no":
print("Python while loops are great for repeating blocks of code that appear infinitely. Remember, DRY!")
print("Congratulations, {}, you understand!".format(name))
Tyler Wasser
279 PointsTyler Wasser
279 PointsOkay awesome! Thank you. Is it possible to do an input("string".format().lower) or something along those lines to do multiple methods on the same string?
Steven Parker
231,269 PointsSteven Parker
231,269 PointsSure, you could also code this as:
understanding = input("Hey, {}. Do you understand while loops? ".format(name)).lower()
The potential disadvantage is that you no longer have the verbatim answer for outputting if needed.