Click here to Skip to main content
15,905,963 members
Please Sign up or sign in to vote.
1.00/5 (1 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 9-Oct-19 15:13pm
Comments
Patrice T 9-Oct-19 20:40pm    
And the question is ?

1 solution

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.


Python
# 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,

Python
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"))
 
Share this answer
 
v2
Comments
CPallini 10-Oct-19 4:27am    
5.
Visweswaran N 10-Oct-19 4:28am    
Thank you sir!

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900