+ 5

How do I convert a list elements from uppercase to lowercase or vice versa?

I made a guessing game as shown below. Right now, the first letter of all elements of fruits list are in uppercase. So, we have to provide the input as it is. But, I would like to change this code to accept both upper and lower letters. I know we can do this using for loop and things. Is it possible to do this without them? https://code.sololearn.com/c3C0oq8WF322/?ref=app

11th Feb 2022, 6:08 AM
Python Learner
Python Learner - avatar
5 Answers
+ 13
The fruits in the list all begin with a capital letter. You can ensure the input is capitalized the same way by using a built-in string method named capitalize(). Change: guess = input() To: guess = input().capitalize()
11th Feb 2022, 6:30 AM
Brian
Brian - avatar
+ 7
use .lower() to convert to lower case and .upper() to convert to upper case
12th Feb 2022, 7:00 PM
okonkwo calistus
okonkwo calistus - avatar
+ 5
Brian perfect! Thank you! Actually, I was fighting with lower() method and I could guess that there should be something else. Also, we can use title() method for those wondering. guess = input().title()
11th Feb 2022, 6:40 AM
Python Learner
Python Learner - avatar
+ 1
Thanks! (P.S. Is .upper() and .lower() actual python code?)
4th Jul 2023, 3:38 PM
CodingTranslater638
CodingTranslater638 - avatar
0
FoxCatGirl639 Yes. They are methods built in to the string object. You may learn about these and other string methods here: https://docs.python.org/3/library/stdtypes.html#string-methods
4th Jul 2023, 9:21 PM
Brian
Brian - avatar