181k views
4 votes
This assignment is based on Exercise 8.4 from your textbook. Each of the following Python functions is supposed to check whether its argument has any lowercase letters.

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.

def any_lowercase4(s):
flag = False
for c in s:
flag = flag or c.islower()
return flag
print(any_lowercase4(s))

User Zorf
by
6.1k points

1 Answer

4 votes

Answer:

The answer is "True".

Step-by-step explanation:

Following are the correct code to this question, at which it will give "true" output:

def any_lowercase4(s): #defining method any_lowercase4

flag = False #defining flag variable and assign boolean value

for c in s: #define loop that collect s variable value

flag = flag or c.islower() # using flag variable that checks passes value in lower case

return flag #return flag value

s="Row Data" #assign string value in s variable

print(any_lowercase4(s)) #call method and prints its return value

Output:

True

Program explanation:

  • In this code a method "any_lowercase4" is defined, that accepts a variable s in its parameter, inside the method "flag" variable is used, that assign a value, that is false.
  • In the next line, for loop is declared, inside the loop flag variable check parameter value into the lower case with or operator, and returns flag value.
  • In the last line, inside the print method, the method "any_lowercase4" is called that accepts a string value.
User Celt
by
6.3k points