Answer to Question #277740 in Python for solokin

Question #277740

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


1
Expert's answer
2021-12-09T08:50:23-0500
# 1

def any_lowercase1(s):
    for c in s:                            # Checking the first character and
        if c.islower():                    # immediately displaying the True if
            return True                    # lower and False if upper
        else:
            return False

# Returns true only if the first letter in a string is lower.

# 2

def any_lowercase2(s):
    for c in s:
        if 'c'.islower():                  # Always checking string 'c',
            return 'True'                  # so always True
        else:
            return 'False'

# Always returns true.

# 3

def any_lowercase3(s):
    for c in s:                            # Draws output at the last character
        flag = c.islower()
    return flag

# Returns true only in the last character is lower.

# 4

def any_lowercase4(s):
    flag = False
    for c in s:                            # Changes and leaves the flag on the
        flag = flag or c.islower()         # True in case you have met at least
    return flag                            # once lowercase

# Correctly checks for lowercase letters in any position.

# 5

def any_lowercase5(s):
    for c in s:
        if not c.islower():                # Will return False if it finds at 
            return False                   # least one uppercase 
    return True

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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS