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

I wrote a loop that prints only the items in the list that begin with capital letter but islower() method doesnt return True if the item is lower case

friends = ["Mohamed", "Shady", "ahmed", "eman", "Sherif"]
ignoredNames = []
i = 0

while i < len(friends):
    if friends[i].islower != True:
        print(friends[i])   
    else:
        ignoredNames.append(friends[i])
    i += 1

print(f"The Number Of The Ignored Names Is {len(ignoredNames)}")

>Solution :

You need to call the method as .islower() rather than .islower. The former calls the method and actually returns the boolean value you want in the check.

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

For instance:

friends = ["Mohamed", "Shady", "ahmed", "eman", "Sherif"]
i=0
ignoredNames=[]
while i < len(friends):
    if friends[i].islower() != True:
        print(friends[i])   
    else:
        ignoredNames.append(friends[i])
    i += 1


print(ignoredNames)

Output:

Mohamed
Shady
Sherif
['ahmed', 'eman']
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