Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

lower() function not changing value

I wanted to do this system that will check if fruit is in a list, but I need user input to be in lowercase, so it would not duplicate. But when I do try to use lower() function, it does not really work as planned.

fruits = ['banana', 'orange', 'mango', 'lemon']
new_fruit = input("Input the fruit and system will check if it is there, if it is not, it will add it: ")
new_fruit.lower() #lower function.

if new_fruit in fruits:
    print("The fruit has already been added!")
else:
    fruits.append(new_fruit)
    print("Your fruit was not in the list, it was added, here is new list: ", fruits)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You are calling the function, but you’re not saving it’s return.

Try instead

new_fruit = new_fruit.lower()

Or, more concise:

new_fruit = input("Input the fruit and system will check if it is there, if it is not, it will add it: ").lower()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading