Click here to Skip to main content
14,326,294 members
Rate this:
Please Sign up or sign in to vote.
See more:
# 1

def any_lowercase1(s):

     for c in s:

          if c.islower():

               return True

          else:

               return False


What I have tried:

dont really understand so havent really tried anything
Posted
Updated 5 days ago
Comments
Patrice T 5 days ago
   
And the question is ?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

From the function name I think you need to find if there is any lowercase letter is present in the string. I don't solve home work problems but you are almost there, you made a small mistake.

Your function only checks for the first character as it has return statements in the else condition of the for loop.


# This will return True becuase the first character is lower case
print(any_lowercase1("cAmel"))
# This will return False becuase the first character is upper case
print(any_lowercase1("Camel"))


Remove the else statement and return False outside the loop like this,

def any_lowercase1(s):
     for c in s:
          if c.islower():
               return True
     return False


# This will return True
print(any_lowercase1("cAmel"))
# This will return True
print(any_lowercase1("Camel"))
# This will return False
print(any_lowercase1("CAMEL"))
   
v2
Comments
CPallini 4 days ago
   
5.
Visweswaran N 4 days ago
   
Thank you sir!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100