Question #100462

For each function, describe what it actually does when called with a string argument. If it does not


correctly check for lowercase letters, give an example argument that produces incorrect results, and


describe why the result is incorrect.


# 1


def any_lowercase1(s):


for c in s:


if c.islower():


return True


else:


return False


# 2


def any_lowercase2(s):


for c in s:


if 'c'.islower():


return 'True'


else:


return 'False'


# 3


def any_lowercase3(s):


for c in s:


flag = c.islower()


return flag


# 4


def any_lowercase4(s):


flag = False


for c in s:

flag = flag or c.islower()


return flag


# 5


def any_lowercase5(s):


for c in s:


if not c.islower():


return False


return True

Expert's answer

First. Returnes true only if the first letter in a string is lower.

In: any_lowercase1('Hello')
Out: False

Despite the string has lower symbols in it, function returnes False.


Second. Always returnes true.

In: any_lowercase2('HELLO')
Out: True 

Despite the string has no lower letters al all, function returnes True.


Third. Returnes true only in the last character is lower.

In: any_lowercase3('hELLO')
Out: False 

Despite the string has lower character in it, function returnes False.


Fourth. Correctly checks for lowercase letters in any position.


Fifth. Returnes true only if all symbols in the string are lower.

In: any_lowercase5('hELLO')
Out: False

The string contains lower letter, but function still returnes False, becourse it also contains upper ones.


LATEST TUTORIALS
APPROVED BY CLIENTS