You are on page 1of 40

1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

CS 1101 Programming Fundamentals - AY2022-T2


Dashboard / My courses /
CS 1101 - AY2022-T2 / 9 December - 15 December /
Discussion Forum Unit 5 /
Discussion Unit 5

 Search forums

Discussion Forum Unit 5


Discussion Unit 5

Settings

Display replies in nested form

The cut-off date for posting to this forum is reached so you can no longer post to it.

Discussion Unit 5
by Leonidas Papoulakis (Instructor) - Wednesday, 10 November 2021, 7:10 AM

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.

#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()

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 1/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

     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

141 words

Permalink

Re: Discussion Unit 5


by Yahya Al Hussain - Thursday, 9 December 2021, 4:09 PM

#4  is the only one that checks for ANY lowercase letters

# 1

def any_lowercase1(s):

for c in s:

if c.islower():     #Function islower() from <ctype.h> Functions takes a single argument then turns it to an int type value, 0=not
lowercase and anything >0 is lowercase

return True        

else:

return False           #the code doesn't work correctly

                             #here the function only takes the first letter

input   >>>any_lowercase1('myCar')      

output >>>True
input   >>>any_lowercase1('Car')

output >>>False

# 2

def any_lowercase2(s):

for c in s:

if 'c'.islower():        #the code here is only checking for 'c' the string and not c the variable

return 'True'          #the code doesn't work correctly



else:

return 'False'

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 2/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

input   >>>any_lowercase2('myCar')  #the arguments are irrelevant

output >>>'True'
input   >>>any_lowercase2('Car')

output >>>'True'

# 3

def any_lowercase3(s):

for c in s:

flag = c.islower()          #the code doesn't work correctly

return flag                     #returns every letter on its own and checks if there are any lowercase but only checks the first "flag"

input   >>>any_lowercase3('myCar')     

output >>>True
input   >>>any_lowercase3('Car')

output >>>False

# 4

def any_lowercase4(s):

flag = False

for c in s:                            

flag = flag or c.islower()     #returns every letter on its own and checks if there are any lowercase

                                             #checks "flag" or c.islower()             

                                            #the code works correctly


return flag

input   >>>any_lowercase4('myCar')  

output >>>True
input   >>>any_lowercase4('CAR')

output >>>False

# 5

def any_lowercase5(s):

for c in s:

if not c.islower():     #instead of searching for a lowercase the code checks if there are any upper case, if true then it returns
false
return False             #the code doesn't work correctly

return True

input   >>>any_lowercase5('myCar')

output >>>False
input   >>>any_lowercase5('Car')

output >>>False

271 words
Tags:
Discussion forum unit 5

Permalink Show parent

Re: Discussion Unit 5


https://my.uopeople.edu/mod/forum/discuss.php?d=640883 3/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

by Ahmet Yilmazlar - Sunday, 12 December 2021, 10:23 AM

Great explanation
2 words

Permalink Show parent

Re: Discussion Unit 5


by Samrawi Berhe - Monday, 13 December 2021, 6:14 AM

Dear, Yahya, the inline comments are good and informative. But I think it would have been better to give explanations for
what was wrong and how to solve them. Otherwise, your work fails to answer the questions partially.
38 words

Permalink Show parent

Re: Discussion Unit 5


by Yahya Al Hussain - Monday, 13 December 2021, 11:20 AM

Dear Samrawi,

You can find there is no actual mention of solving the errors, furthermore below you can find the explanations for why
the result is incorrect.

"give an example argument that produces incorrect results, and describe why the result is incorrect."

1* #here the function only takes the first letter

2*#the code here is only checking for 'c' the string and not c the variable

3*#returns every letter on its own and checks if there are any lowercase but only checks the first "flag"

5*#instead of searching for a lowercase the code checks if there are any upper case, if true then it returns false
106 words

Permalink Show parent

Re: Discussion Unit 5


by Wilmer Portillo - Tuesday, 14 December 2021, 2:13 PM

Hi Yahya, Great work. Your comments are on point and are useful in understanding the development of your function.
Keep it up!
22 words

Permalink Show parent

Re: Discussion Unit 5


by Simon Njoroge - Tuesday, 14 December 2021, 2:45 PM

I clearly understand your explanation on various functions as you put it. Thank you for your positive input in the
discussion. It has gone a long way to make it clear for me.
33 words

Permalink Show parent

Re: Discussion Unit 5


https://my.uopeople.edu/mod/forum/discuss.php?d=640883 4/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

by Fouad Tarabay - Tuesday, 14 December 2021, 3:36 PM

Hello Yahya,

You did great explanation using comments in python at the statements that work or doesn't work, which makes it more
clear to point at which statement gives a sementic error by giving an explanation on what that statement does.
41 words

Permalink Show parent

Re: Discussion Unit 5


by Stephen Chuks - Wednesday, 15 December 2021, 8:02 PM

Nice one Yahya. Your post helped me understand the question better.
11 words

Permalink Show parent

Re: Discussion Unit 5


by Crystal Noralez - Wednesday, 15 December 2021, 8:55 PM

A good well done. Keep it up


7 words

Permalink Show parent

Re: Discussion Unit 5


by Peter Odetola - Wednesday, 15 December 2021, 11:00 PM

Thanks Yahya for the effort you put into this work, plus the clearly spelt out comments all through.
18 words

Permalink Show parent

Re: Discussion Unit 5


by Fouad Tarabay - Friday, 10 December 2021, 6:18 AM

# 1

def any_lowercase1(s):

for c in s:

if c.islower():

return True

else:

return False

when the interpreter executes the return statement it gets out of the function without completint the rest of the code here the
function returns true if and only if the lower case is the first character of the given string.

example of the argument that produces incorrect result is : "Hello" which returns False when the string contains lowercase
letters.


# 2

def any_lowercase2(s):

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 5/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

for c in s:

if 'c'.islower():

return 'True'

else:

return 'False'

Here the function is checking the character 'c' if it is in lower case so, it always give us true no matter what the argument is.

example of the argument that produces incorrect result is : "HELLO" when the string is all uppercase letters.

# 3

def any_lowercase3(s):

for c in s:

flag = c.islower()

return flag

In this function the value that is stored in the flag is the execution of the last character in the string given with the islower
function so, the result depends on the last character only.

example of the argument that produces incorrect result is : "hellO" which it must returns true but it returns false.

# 4

def any_lowercase4(s):

flag = False

for c in s:

flag = flag or c.islower()

return flag

The "or" operation returns true if one of the conditions is true so, here in the function when the variable c is equals to one
lower case the flag will be true hence in all the iterations the flag will remain true.

This is a correct function.

# 5

def any_lowercase5(s):

for c in s:

if not c.islower():

return False

return True

This function reurns False when c becomes equal to a first non lowercase letter and returns true if and only if all the letters in
the string are in lowercase.

example of the argument that produces incorrect result is : "heLlo", here it will return false which is not a correct result.
334 words

Permalink Show parent

Re: Discussion Unit 5


by Yahya Al Hussain - Friday, 10 December 2021, 2:45 PM

Great explanation and structure, I don't have any other points, thanks for your post it helped explain things more clearly!! 

20 words

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 6/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

Permalink Show parent

Re: Discussion Unit 5


by Samrawi Berhe - Sunday, 12 December 2021, 10:14 AM

dear Fouad, It is a nice explanation overall. You have explained the reason why and why not in all cases and that is great
work. But I think that you forget to tell us how to fix for the wrong one.
41 words

Permalink Show parent

Re: Discussion Unit 5


by Ahmet Yilmazlar - Sunday, 12 December 2021, 10:22 AM

Great explanation
2 words

Permalink Show parent

Re: Discussion Unit 5


by Stephen Chuks - Wednesday, 15 December 2021, 8:05 PM

A very insightful one from you. Your post also made me see the points I missed.
16 words

Permalink Show parent

Re: Discussion Unit 5


by Crystal Noralez - Wednesday, 15 December 2021, 8:58 PM

Very well explained and organized. Easy to understand.


8 words

Permalink Show parent

Re: Discussion Unit 5


by Ahmet Yilmazlar - Saturday, 11 December 2021, 9:56 AM

# 1

def any_lowercase1(s):

for c in s:

if c.islower():

return True

else:

return False

# This will return false

print (any_lowercase1( ''MaXim'' ))

# This will return true


print (any_lowercase1( ''maxiM'' ))

# This will return false

print (any_lowercase1( ''MAXim'' ))

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 7/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

output:

false

true

false

[ Program finished ]

The first function will produce an exception and that is because the aim ofthis function is to check for any lowercase strings
and return a True value.

Now the reason is because when an if...else conditional l'd used, it ends the execution of the program immediately it comes
across a true value.

( To crorrect this, the else branch should be intented outside the if condition ( i.e. at the same level with the for loop).

# 2

def any_lowercase2(s):

for c in s:

if 'c'.islower():

return 'True'

else:

return 'False'

# This will return true

print (any_lowercase2( ''MaXim'' ))

# This will return true

print (any_lowercase2( ''maxiM'' ))

# This will return true

print (any_lowercase2( ''' ))

output

true

true

true

[ Program finished ]

This second function checks only the string c is lower, which always returns true.

# 3

def any_lowercase3(s):

for c in s:

flag = c.islower()

return flag

# This will return false

print (any_lowercase3( ''MaXiM'' ))

# This will return false

print (any_lowercase3( ''maxiM'' ))


# This will return true

print (any_lowercase3( ''MAXim' ))

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 8/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

output

false

false

true

[ Program finished ]

in this third function, the result only depends on the last letter of given string as it is shown in the output

# 4

def any_lowercase4(s):

flag = False

for c in s:

flag = flag or c.islower()

return flag

# This will return true

print (any_lowercase4( ''mAxiM'' ))

# This will return true

print (any_lowercase4( ''maxiM'' ))

# This will return false

print (any_lowercase4( ''MAXİM' ))

output

true

true

false

[ Program finished ]

this fourth function finally returned an expected value

# 5

def any_lowercase5(s):

for c in s:

if not c.islower():

return False

return True

# This will return true

print (any_lowercase5( ''maxim'' ))

# This will return true

print (any_lowercase5( ''maxiM'' ))

# This will return false

print (any_lowercase5( ''MAXİM' ))

output

true

false

false


[ Program finished ]

the last function is a bit tricky. ın stead of looking out for lowercase letters, python interpreter will be looking for uppercase

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 9/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

letters because of the 'not' keyword which has reversed it.

references

Downey, A. (2015). think python, how to think lika a computer scientist.


416 words

Permalink Show parent

Re: Discussion Unit 5


by Samrawi Berhe - Sunday, 12 December 2021, 10:22 AM

dear Ahmet, It is a nice explanation generally. You have explained why the cases are right, the right ones, and why are
wrong. So, this is great work. But I think that you forget to tell us how to fix the wrong ones.
43 words

Permalink Show parent

Re: Discussion Unit 5


by Luke Henderson - Monday, 13 December 2021, 5:39 AM

Great job testing the functions and altering them to find the issues. I got most of the answers similar to you but I missed
out that the 3rd function only cares about the last letter. Great find.

Make sure that your APA citation is correct as it is spelled incorrectly, and a few other spelling mistakes in your post a
good check through in the spellchecker will help this. Otherwise great work.
72 words

Permalink Show parent

Re: Discussion Unit 5


by Yahya Al Hussain - Monday, 13 December 2021, 11:25 AM

great attempt and simple explanations, the answers along with the reasons of why the error happened satisfies the
question.
19 words

Permalink Show parent

Re: Discussion Unit 5


by Simon Njoroge - Tuesday, 14 December 2021, 2:47 PM

You have put a great effort to put all things very clear about the functions. It clears many aspects of the functions and
make me understand more . I like your explanation.
32 words

Permalink Show parent

Re: Discussion Unit 5


by Fouad Tarabay - Tuesday, 14 December 2021, 4:31 PM

Hello Ahmet, You did great explanation to the correct and incorrect codes by using different test cases and giving the
output for each one! Thank you and well done.
29 words

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 10/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

Permalink Show parent

Re: Discussion Unit 5


by Crystal Noralez - Wednesday, 15 December 2021, 8:58 PM

A very understandable and structure work. Keep up the great job.


11 words

Permalink Show parent

Re: Discussion Unit 5


by Samrawi Berhe - Saturday, 11 December 2021, 5:31 PM

Discussion Forum Unit

Questions

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.

Answer

Question #1

The script will be as follows

def any_lowercase1(s):

for c in s:

if c.islower():

return True

else:

return False

print(any_lowercase1("GOogle")) # This will return True

print(any_lowercase1("googLE")) # This will return True

print(any_lowercase1("GOOgle")) # This will return True

print(any_lowercase1("gOOgle")) # This will return True

The output of the above code is as follow

False

True

False

True

Process finished with exit code 0



Description

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 11/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

Because the purpose of the first function is to check for any lowercase strings and return a True value. Otherwise, it will print
False. However, as you can see in the code above, the function call's four arguments have all lowercase strings, so the output
should have been all True. But the output is different from what was intended to do. The reason for this is that when I used an
if...else conditional, it terminated the program execution as soon as it encountered a True value. A For loop statement, on the
other hand, normally loops through the argument, verifying each value in the string one by one. A For loop will repeat a
procedure six times in a string of six characters, each time taking a character from the string. The if...else conditional in the
above case, on the other hand, gets a True result in either of the return values and terminates the program. This is due to the
wrong indentation on the else part.

Therefore, to fix this, the else branch should be indented outside the if condition (i.e., at the same level as the For Loop). The
code after fixing the problem is as below.

def
any_lowercase1(s):

   for c in s:

       if c.islower():

           return True

   else:

       return False

print(any_lowercase1("GOogle")) # This will return True

print(any_lowercase1("googLE")) # This will return True

print(any_lowercase1("GOOgle")) # This will return True

print(any_lowercase1("gOOgle")) # This will return True

So, after fixing the problem the output looks as follows.

True

True

True

True

Process finished with exit code 0

Question #2

The script will be as follows

def any_lowercase2(s):

         for c in s:

             if 'c'.islower():

                    return 'True'

      else:

            return 'False'

print(any_lowercase2("GOogle")) # This will return True



print(any_lowercase2("googLE")) # This will return True

print(any_lowercase2("GOOgle")) # This will return True

print(any_lowercase2("gOOgle")) # This will return True

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 12/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

The output of the above code is as below.

True

True

True

True

Process finished with exit code 0

Only the string 'c' is checked in this second function, which always returns the string value “True” This is because the string “c”
is lower case and is always true. We should note that the function is very identical to the first, but with a different setting which
is the if conditional has been given a string to work with while the first function is working on Boolean value and the variable c
is not used in the second one. If you are confused about which way the return statement is working you can print the type of
the return statement's value. So, the function call's argument just allows it to run where it searches for a lower case, and the
condition meets for the lower-case string “c” which finds it always true. To fix this, I can use the variable instead of string 'c' in
the For-loop statement, and then place the else branch of the if...else conditional outside the if condition. In addition to this,
the return statement should return Boolean value instead of string value “True/Fales”. Let’s see printing the data type of the
return statement

<class 'str'>

False

<class 'str'>

False

<class 'str'>

False

<class 'str'>

False

Process finished with exit code 0

After fixing the problem, the script will look as follows.

def
any_lowercase2(s):

   for c in s:

       if c.islower():

           print(type(c.islower()))

           return True

   else:

       print(type(c.islower()))

       return False


print(any_lowercase2("GOogle")) # This will return True

print(any_lowercase2("googLE")) # This will return True

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 13/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5
print(any_lowercase2("GOOgle")) # This will return True

print(any_lowercase2("gOOgle")) # This will return True

print(any_lowercase2("GOOGLE")) # This will return False

And the output is as follows.

<class 'bool'>

True

<class 'bool'>

True

<class 'bool'>

True

<class 'bool'>

True

<class 'bool'>

False

Process finished with exit code 0

Question #3

The script looks like below

def any_lowercase3(s):

      for c in s:

            flag = c.islower()

     return flag

print(any_lowercase3("GOogle")) # This will return True

print(any_lowercase3("googLE")) # This will return True

print(any_lowercase3("GOOgle")) # This will return True

print(any_lowercase3("gOOgle")) # This will return True

print(any_lowercase3("GOOGLE")) # This will return False

And the output is as follows

True

False

True

True

False

Process finished with exit code 0



In this third function, the result only depends on the last letter of the given string as it is shown in the output. This is because
there is variable 'flag' (inner variable) is declared inside the scope of the for loop and its scope doesn't extend to the parent

scope of the function. Since the return statement is returning the value of the local variable, it checks for lower string one by

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 14/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

one takes the last value then assigns it to the ‘flag’ variable and prints its truth's value of the variable flag. So, to fix this
problem we should avoid using a local variable that is out of the scope of the for-loop. So, after fixing the problem. the script
after fixing looks as below.

def any_lowercase3(s):

      for c in s:

           if c.islower():

              return True

     return False

print(any_lowercase3("GOogle")) # This will return True

print(any_lowercase3("googLE")) # This will return True

print(any_lowercase3("GOOgle")) # This will return True

print(any_lowercase3("gOOgle")) # This will return True

print(any_lowercase3("GOOGLE")) # This will return False

And the output is as follows:-

True

True

True

True

False

Process finished with exit code 0

Question #4

The script looks like below

def any_lowercase4(s):

      flag = False

      for c in s:

            flag = flag or c.islower()

      return flag

print(any_lowercase4("GOogle")) # This will return True

print(any_lowercase4("googLE")) # This will return True

print(any_lowercase4("GOOgle")) # This will return True

print(any_lowercase4("gOOgle")) # This will return True

print(any_lowercase4("GOOGLE")) # This will return False

The output is

True

True

True

True

False


Process finished with exit code 0

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 15/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

From the above, we can see that the output is as expected but why? Here, initially, the flag variable is always False, and the for-
loop search through the given value and goes to the next statement. The flag variable is then assigned the flag variable and
the logical operator or is connecting with the searched value. I know that the logical operator or evaluates to False if only both
the left and the right operands are False. So, this is what is happening here.

Question #5

The script looks like below

def any_lowercase5(s):

     for c in s:

           if not c.islower():

                    return False

     return True

print(any_lowercase5("GOogle")) # This will return True

print(any_lowercase5("googLE")) # This will return True

print(any_lowercase5("GOOgle")) # This will return True

print(any_lowercase5("gOOgle")) # This will return True

print(any_lowercase5("GOOGLE")) # This will return False

The output of the above code is as follows

False

False

False

False

False

Process finished with exit code 0

From the above code, we can see that all the outputs are evaluated as false since it is checking for none lower case and when
one string meets the condition it evaluates to False and returns the result. Here the conditional statement is wrongly used. So,
we just remove the ‘not’ operator and the return statement should return True to fix the problem

Downey, A. (2015). Think Python: How to Think Like a Computer Scientist (2nd ed., Version 2.4.0). Needham: Green Tea Press.

1417 words
Tags:
Discussion forum unit 5
is_lower_case.py

Re: Discussion Unit 5


by Ahmet Yilmazlar - Sunday, 12 December 2021, 10:23 AM

Great explanation
2 words

Permalink Show parent


Re: Discussion Unit 5
by Luke Henderson - Monday, 13 December 2021, 5:34 AM

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 16/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

Great to see such an in depth post and your solutions to fixing the issues. I especially liked that you modified the functions
to analyse what issues or solutions might come up. I did the same myself and often take the approach of try to break it or
fix it and either way you will learn more about it.
59 words

Permalink Sho parent

Re: Discussion Unit 5


by Samrawi Berhe - Monday, 13 December 2021, 6:08 AM

Thank you, Luke, for your comments.


6 words

Permalink Show parent

Re: Discussion Unit 5


by Fouad Tarabay - Tuesday, 14 December 2021, 3:48 PM

Hello Samrawi,

You did an excellent detailed explanation for each part of code, the most part that drawed my attention is that you did
different tests with different upper and lower case characters which covers the test cases that makes sure about which
code is correct and which one is not, because what we have is a semantic error that cannot be detected by the interpreter.
66 words

Permalink Show parent

Re: Discussion Unit 5


by Janelle Bianca Cadawas Marcos - Wednesday, 15 December 2021, 10:10 AM

Great job Samrawi!

This shows that you really worked on this, your in-depth explanations were really nice to read. It wasn't asked for us to fix
the code but you did it anyways. Going above and beyond. Good work, keep it up!
42 words

Permalink Show parent

Re: Discussion Unit 5


by Juan Duran Solorzano - Wednesday, 15 December 2021, 10:14 AM

Hello Samrawi,

Excellent discussion post, very well explained with many different examples easy to follow.

Regards

Juan Carlos
18 words

Permalink Show parent

Re: Discussion Unit 5


by Peter Odetola - Wednesday, 15 December 2021, 11:04 PM 

Thanks Samrawi for the detail description of the coding work flow. Am able to learn lots more about the topic via that.
22 words

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 17/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

Permalink Show parent

Re: Discussion Unit 5


by Wilmer Portillo - Sunday, 12 December 2021, 9:45 PM

Discussion Assignment Unit 4:

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.

#1

The Output is False, which is not true because there are multiple lowercase letters (ippo). In this case it is incorrect because it
only looked at the first letter which was the only uppercase letter and gave us a false output without checking the rest.

#2

The output is True, which is not so because argument has no lowercase letters. Expected output False. It checked if string ‘c’ is
lowercase or not; and returned string ‘True’, returns ‘true’ every time, given argument does not matter.

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 18/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

#3

The output is False, which is not so because the argument has four lowercase letter ‘hipp’. It was asked to check if each letter in
string is lowercased or not and assign the outcome in this case the Boolean value to the variable ‘flag’, new value should be
assigned to ‘flag’ with every checked letter and then returns Boolean value of calling islower() method only on the last letter of
the given string.
#4

When the first call was made in line 7, it gave the output ‘True’ as expected. We had asked to return True whether _any_ letter
is lowercase otherwise False. The argument did have a lowercase letter.
When the second call was made in line 8, it gave the output ‘False’ as expected. The argument had no lowercase letters.
#5

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 19/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

In this case the output was ‘False’, which is incorrect as all letter except for ‘P’ are lowercase. The answer expected was ‘True’.

References:

Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press. This book is licensed under Creative
Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0).

Re: Discussion Unit 5


by Luke Henderson - Monday, 13 December 2021, 5:28 AM

Nice use of screenshots and good explanations for most of the issues with the functions and the output from them for
function 5 you didn't explain what was the use of the "not" keyword however your explanation for function 3 gave me
some new insight. Great Job
47 words

Permalink Show parent

Re: Discussion Unit 5


by Yahya Al Hussain - Monday, 13 December 2021, 11:30 AM

Great work and i appreciate the use of screen shots, everything was explained except for #5, otherwise great answer.
19 words

Permalink Show parent

Re: Discussion Unit 5


by Siphumelelise Ntshwenyese - Wednesday, 15 December 2021, 4:56 AM

Great explanation, the use of screenshots was amazing, you also referenced your work, amazing, well done.
16 words

Permalink Show parent


Re: Discussion Unit 5
by Janelle Bianca Cadawas Marcos - Wednesday, 15 December 2021, 10:12 AM

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 20/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

Hey Wilmer,

Good work! I did the same as you, just using short sentences to fulfill what was asked of us. Keep it up!
24 words

Permalink Show parent

Re: Discussion Unit 5


by Stephen Chuks - Wednesday, 15 December 2021, 8:08 PM

Insightful one from you here. You answered all the questions and your examples are easy to understand.
17 words

Permalink Show parent

Re: Discussion Unit 5


by Peter Odetola - Wednesday, 15 December 2021, 11:07 PM

Hello Wilmer, I love the screenshot presentation of your coding as well as the brief explanation of what they meant. It is
concise and clear to me. Thanks
28 words

Permalink Show parent

Re: Discussion Unit 5


by Luke Henderson - Monday, 13 December 2021, 4:32 AM

# 1

def any_lowercase1(s):

   for c in s:

        if c.islower():

             return True

        else:

             return False

Input:

any_lowercase1("jimmyBeam")

any_lowercase1("LOUD")

Output:

True

False

C could be understood to be character in S (sentence). The for loop iterates through every letter

of a string and returns True if the string contains lower case letters and False if otherwise.

the data type is not specified in the function so this creates many errors.

All of the functions only work if a string is used as the argument wether it's a word or sentence input. Interestingly if I input “2”
it results in a false.

# 2

def any_lowercase2(s):


   for c in s:

        if 'c'.islower():

             return 'True'

        else:

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 21/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

             return 'False'

Input:

any_lowercase2("bingo")

any_lowercase2("binNGO")\

any_lowercase2("Ice")

Output:

'True'

'True'

'True'

This function is unable to check the input that you give it. It simply checks if the letter
c in quotation marks is lowercase or not. Instead of returning a boolean it simply returns a string that says 'True',

it will never return 'False' unless you change the lower case 'c' to a capital 'C'

# 3

def any_lowercase3(s):

   for c in s:

        flag = c.islower()

   return flag

Input:

any_lowercase3("T")

any_lowercase3("TOTALLY")

any_lowercase3("Toasty")

Output:

False

False

True

This function uses the flag keyword which is basically the same as boolean. It will check the input as long as it

is a string and will return true even if there is only one lowercase character in the whole string. To make it return

a False, the user must input a string all in capitals.

# 4

def any_lowercase4(s):

   flag = False

   for c in s:

        flag = flag or c.islower()

   return flag

Input:

any_lowercase4("China")

any_lowercase4("C")

Output:

True

False

This function has the exact same outcome as the last. As long as a string is entered, if it has lowercase characters it will return
True and if all the characters are upper case it will return False. The only difference with this function is initially setting flag to

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 22/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

false, but once the for loop is entered it changes flags assignment with an 'or' statement c.islower() overrides flags initial
assignment as False.

# 5

def any_lowercase5(s):

   for c in s:

        if not c.islower():

             return False

   return True

Input:

any_lowercase5('s')

any_lowercase5('S')

any_lowercase5('slinkY')

any_lowercase5('stinky')

Output:

True

False

False

True

The condition in this function checks if the content of the string input is not lowercase. The function will return false if there
are any upper case characters. If the condition is not met it will always return True.
415 words

Permalink Show parent

Re: Discussion Unit 5


by Samrawi Berhe - Monday, 13 December 2021, 6:21 AM

Dear, Luke, very nice explanation and analysis. From your explanation, I have learned the variable 'flag' used there, is a
keyword. I thought it is only variable. Thank you!
29 words

Permalink Show parent

Re: Discussion Unit 5


by Wilmer Portillo - Tuesday, 14 December 2021, 2:16 PM

Hi luke, great work on the detailed explanations you provided. It definitely make your work more digestible. I did grab a
couple useful tools from you work.
27 words

Permalink Show parent

Re: Discussion Unit 5


by Simon Njoroge - Tuesday, 14 December 2021, 2:49 PM

You have clearly shown the output of the functions. I like the explanation that makes it quite clear for me to understand.
Thanks a lot. 
25 words

Permalink Show parent

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 23/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

Re: Discussion Unit 5


by Siphumelelise Ntshwenyese - Wednesday, 15 December 2021, 4:54 AM

Great work Luke, you have taught me a few things, I like everything about this post, well done.
18 words

Permalink Show parent

Re: Discussion Unit 5


by Simon Njoroge - Monday, 13 December 2021, 1:59 PM

# 1

def any_lowercase1(s):

for c in s:

if c.islower():

return True

else:

return False

1. The function is meant to check if the first letter of the string is a capital letter. This function is not working as it is. There is
need to define s in the function.

# 2

def any_lowercase2(s):

for c in s:

if 'c'.islower():

return 'True'

else:

return 'False'

2. This function checks if the string is made of lower case letters. It is having a syntax error at the moment.

# 3

def any_lowercase3(s):

for c in s:

flag = c.islower()

return flag

3. The function is checking each letter in the string to confirm if it is lower case and returns True or False.

# 4

def any_lowercase4(s):

flag = False

for c in s:

flag = flag or c.islower()

return flag

4. The function checks if there is a lower case letter in the string. It is works ok and does not generate any error.

# 5

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 24/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

def any_lowercase5(s):

for c in s:

if not c.islower():

return False

return True

5. The function checks if there is no use of lower case letter in a string. Its output is either True or false. In this case the function
is not working fine.
211 words

Permalink Show parent

Re: Discussion Unit 5


by Wilmer Portillo - Tuesday, 14 December 2021, 2:25 PM

Hi Simon, thank you very much for you valuable discussion. My only concern is I am not seeing the output. I know they
would surely work but was hoping to see the output. Thank you
35 words

Permalink Show parent

Re: Discussion Unit 5


by Siphumelelise Ntshwenyese - Wednesday, 15 December 2021, 4:53 AM

Great explanation Simon, it would have been nice if you included the output.
13 words

Permalink Show parent

Re: Discussion Unit 5


by Siphumelelise Ntshwenyese - Wednesday, 15 December 2021, 4:29 AM

Here are my observations for the following 5 functions

This function loops through all the words c and if all of them are lower case, it returns true

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 25/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

This function loops through all the characters 'c' if it any character is lowercase it returns true

This function loops through all the words c, checks if the word is a lower case word using the slower() method. assigns this to a
variable flag

This function loops through all the words c, checks if the word is a lower case word using the slower() method. assigns this to a
variable flag, it will return false since the flag is always false

This checks all the words, if the word is not a lower case word it returns false, else it will return true

Let's define a string with a mixture of upper and lowercase letters and print the results of the functions:

We get the following results: 


https://my.uopeople.edu/mod/forum/discuss.php?d=640883 26/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

155 words

Permalink Show parent

Re: Discussion Unit 5


by Juan Duran Solorzano - Wednesday, 15 December 2021, 10:11 AM

Hello Siphumelelise,

Great job. You could have added more comments explaining more in-depth the process of the functions. Just remember
when the function returns any value the for loop will stop, so in most of the cases, the for loop will iterate with the first
letters or the last ones depending on the case. To check the process of the function you can add print functions to check
the flow of the data.

In which part of a website or a program do you think we could use the islower() method?

Keep it up

Juan Carlos
96 words

Permalink Show parent

Re: Discussion Unit 5


by Janelle Bianca Cadawas Marcos - Wednesday, 15 December 2021, 10:19 AM

Hey Siphumelelise,

You are completely off-topic on what was asked of us unfortunately, no offense. Try reading a few of what our other peers
have done. Each function was supposed to check if there were any lowercase letters in the given string. It was not asking
for our observations. All of the functions were incorrect doing this except number 4. You might want to read the book and
do some research on this so you can catch up to where we are now, it'll be harder to catch up if you wait on this. Your
observations weren't accurate too. Reading through the other posts will help a lot. Good luck!

110 words

Permalink Show parent

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 27/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

Re: Discussion Unit 5


by Hamidou Diallo - Wednesday, 15 December 2021, 2:35 PM

Hi, the way you explain your Observations is just great even I don't think you are right on all the exercise. Congratulations
for the efforts. Keep up the good work.
30 words

Permalink Show parent

Re: Discussion Unit 5


by Juan Duran Solorzano - Wednesday, 15 December 2021, 9:12 AM

Exercise 1:

In this case, the function has a for loop where is meant to go through each character in the string given as a parameter. Then
there is a conditional checking if the character is lowercase, or not. In both cases will return a boolean value where will make
the loop stop.

Function:

Output:

False

The output is correct but the loop only will run once, as we have the return key inside the conditional breaking the loop, in
both cases True or False.

Exercise 2:

The function takes an argument then the for loop will go through each character of the string, the conditional only will check if
the letter 'c' is lowercase, and return 'True' if it is. After returning a value the for loop will stop.

Function:

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 28/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

Output:

True

The syntax of the function is correct, the only problems are whit the return key, the for loop will stop no matter what. Also the
conditional only will check the string 'c', it will never change the value.

Exercise 3

The function will take an argument, then a for loop will run through each character of the string, and the boolean value will be
stored in the flag variable. The function will return the last interaction done of the string.

Function:

# 3

def any_lowercase3(s): # this is the third version of any_lowercase


for c in s: # this for loop will go through each character in the string
flag = c.islower() # the flag is a boolean value, it will be True if the character is lowercase, and False if it is not
return flag
# this will return the value of flag when the for loop finishes running, and will take the value of flag from the last iteration of
the loop

print(any_lowercase3('AbCdEf'))

Output:

True

The function will return the result of the last iteration.

Exercise 4:

The function will take one argument, then the variable flag is defined with a False value. A for loop will run through each
character of the string and inside the loop the flag variable will store the value if the iteration is True otherwise will be False.
When the function finishes, the function will return a boolean value of the last iteration.

Function:


Output:

True

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 29/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

Exercise 5

The function will take one argument, and will run a for loop through each character of the string, the conditional will check if
the character is not lowercase if this condition is met the function will return false and the loop will stop. 

Function:

Output:

False

425 words

Permalink Show parent

Re: Discussion Unit 5


by Hamidou Diallo - Wednesday, 15 December 2021, 2:30 PM

Hi Juan you have done great efforts to explain thes cases. I agree with you on the second exercise but I'm affraid that our
answers didn't matche on the rest. Keep moving forward
33 words

Permalink Show parent

Re: Discussion Unit 5


by Juan Duran Solorzano - Wednesday, 15 December 2021, 7:07 PM

Hi Hamidou, may I ask which answer didn't match yours? Please help me to improve by providing more detail on the
answers that are not correct.

Regards

Juan
28 words

Permalink Show parent

Re: Discussion Unit 5 


by Janelle Bianca Cadawas Marcos - Wednesday, 15 December 2021, 9:41 AM

1)

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 30/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

def
any_lowercase1(s):

for c in s:

if
c.islower():

return True

else:

return False

This function
terminates after checking the first letter of the string.

Example:

any_lowercase1(‘Hello’)

False

This is incorrect
because it only checks the first letter of the argument because of
the return statement on both if and else.

2)

def
any_lowercase2(s):

for c in s:

if
'c'.islower():

return 'True'

else:

return 'False'

This function checks


if ‘c’ is lowercase and then terminates. (Hint: it always is.)

Example:

any_lowercase2(‘GREETINGS’)

‘True’

This is incorrect
because it incorrectly only checks ‘c’ and not the actual letters
of the argument.

3)

def
any_lowercase3(s):

for c in s:

flag =
c.islower()

return flag

This function
reassigns “flag” to True or False depending on if the letter it
is on is lowercase or uppercase, then terminates at
the last letter
reassigning flag to either True or False depending on that last
letter and returning flag.

Example:

any_lowercase3(‘holA’)

False

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 31/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

This is incorrect
because it returns True or False based on the last letter of the
argument and not the entire argument.

4)

def
any_lowercase4(s):

flag = False

for c in s:

flag =
flag or c.islower()

return flag

#OR returns False


when both are False, else returns True

This function checks


each letter of the argument and keeps flag = False until it hits a
lowercase letter. Flag stays True if it hits a
lowercase as it runs
but it remains False if there are no lowercase at all.

This correctly
checks if the argument has any lowercase letters.

5)

def
any_lowercase5(s):

for c in s:

if not
c.islower():

return False

return True

This function
terminates and returns False if it hits an uppercase letter, if no
uppercase letter is passed then it returns True.

Example:

any_lowercase5(‘aloHA’)

False

This is incorrect
because there are lowercase letters in the argument so it should
return True, however they are ignored since
there are uppercase
letters in the argument and triggers the return False.

Reference:

Downey, A. (2015).
Think Python: How to think like a computer scientist. Green Tea
Press. This book is licensed under Creative
Commons
Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0).

356 words

Permalink Show parent

Re: Discussion Unit 5


by Juan Duran Solorzano - Wednesday, 15 December 2021, 9:56 AM

Hi Janelle,

Great job, explaining what does it happen in each case. I think It could have been easier to read and follow adding

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 32/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

comments in the code, you could have explained the code line by line using the comments for easier understanding.

Where do you think we could use this method in a real program?

Kind regards

Juan Carlos
60 words

Permalink Show parent

Re: Discussion Unit 5


by Janelle Bianca Cadawas Marcos - Wednesday, 15 December 2021, 10:22 AM

Hey Juan,

That's true, I'll keep that in mind next time. I keep forgetting to add comments because I think it's mostly self-
explanatory. But yeah it would make it a lot easier to read that way since I did have to think a little on them.

I can't think of a real program we can use this lowercase check on from the top of my head, but I'm sure it's very useful
somewhere.

Thanks,

Janelle
75 words

Permalink Show parent

Re: Discussion Unit 5


by Hamidou Diallo - Wednesday, 15 December 2021, 2:25 PM

Hi Janell I'm not sure if we have the same understanding of the instructions but the flow of your description is valuable.
However you've done necessary efforts to try your best. I hope you will move forward.
37 words

Permalink Show parent

Re: Discussion Unit 5


by Hamidou Diallo - Wednesday, 15 December 2021, 11:19 AM

# 1

def any_lowercase1(s):

   for c in s:

        if c.islower():

             return True

        else:

             return False

This function intends to check for lowercase but won't run and outputs an error.

An example that produce incorrect result: (40).

It is incorrect because '40' is not a string.


# 2

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 33/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

def any_lowercase2(s):

   for c in s:

        if 'c'.islower():

             return 'True'

        else:

             return 'False'

The second function is as the first function but it won't run too because there is an error in the if statement. An example of
argument which produce incorect result is : (age4).

(age4) argument is not a string so it's incorrect.

# 3

def any_lowercase3(s):

for c in s:

flag = c.islower()

return flag

This function also checks for lowercase and it will run when it's called with a string argument as the condition and the for loop
are correct.

# 4

def any_lowercase4(s):

flag = False

for c in s:

flag = flag or c.islower()

return flag

The 4th function won't run because of a wrong for loop condition. An example of argument which output incorrect is (11). The
mistake is that (11) is not a string.

# 5

def any_lowercase5(s):

for c in s:

if not c.islower():

return False

return True

This function is supposed to to check if the argument has any lowercase and the "not" operator provide a negation it means
there is no lowercase and this is true instead of false.
237 words

Permalink Show parent

Re: Discussion Unit 5


by Crystal Noralez - Wednesday, 15 December 2021, 5:13 PM

Discussion Assignment

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.


# 1

def any_lowercase1(s):

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 34/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

for c in s:

if c.islower():

return True

else:

return False

print(any_lowercase1("Best"))

(False)

In this function any_lowercase1(s) is incorrect because it test for lowercase only for the

First letter of the string and then returns True or False.

# 2

def any_lowercase2(s):

for c in s:

if 'c'.islower():

return 'True'

else:

return 'False'

print(any_lowercase2("SEVEN"))

(True)

In cases any_lowercase2(s) is incorrect because it returns True. It checks whether or not

'c' is lowercase and this function doesn't check any letter from the given string. It is telling

us that there are lowercase letters in the string when there are not.

# 3

def any_lowercase3(s):

for c in s:

flag = c.islower()

return flag

print(any_lowercase3("besT"))

False

When it gets to the final letter "T" 'flag' gets set to False which tells us that there were no lowercase letters in the string, which
is not true.

# 4

def any_lowercase4(s):

flag = False

for c in s:

flag = flag or c.islower()

return flag

print(any_lowercase4("bEST"))

True

In this case any_lowercase4 is working fine.

# 5

def any_lowercase5(s):

for c in s:

if not c.islower():

return False

return True

print(any_lowercase5("besT"))

False

In this case any_lowercase5(s) is incorrect because it checks whether all letters in the string

are lowercase
275 words

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 35/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

Permalink Show parent

Re: Discussion Unit 5


by Stephen Chuks - Wednesday, 15 December 2021, 7:43 PM

def any_lowercase1(s):

for c in s:

if c.islower():

return True

else:

return False

any_lowercase1('Check')

#This returned no result.

def any_lowercase2(s):

for c in s:

if 'c'.islower():

return 'True'

else:

return 'False'

any_lowercase2('check')

#This also returned no result.

def any_lowercase3(s):

for c in s:

flag = c.islower()

return flag

any_lowercase3('check')

#This also returned no result.

def any_lowercase4(s):

flag = False

for c in s:

flag = flag or c.islower()

return flag

any_lowercase4('check')

#This also returned no result.

def any_lowercase5(s):

for c in s:

if not c.islower():

return False

return True

any_lowercase5('check')

#This also returned no result.



95 words

Permalink Show parent

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 36/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

Re: Discussion Unit 5


by Peter Odetola - Wednesday, 15 December 2021, 10:23 PM

CS1101 DISCUSSION FORUM UNIT 5

This assignment is bas

ed 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.

#1 Answer

>>> def any_lowercase1(s):

... for c in s:

... if 'c'.islower():

... return 'True'

... else:

... return 'False'

...

...
>>> print(any_lowercase1("Timy"))

False

>>> print(any_lowercase1("tIMY"))

True

>>> In this first example, the iteration terminated after the first run because it reached a return statement. Otherwise, the
function would have noticed that there were subsequent characters after the first one in the argument that were in lowercase.

Reason for the above: when an if-else conditional is used, it ends the execution of the program immediately it comes across a
True value. On the other hand, a for-loop statement usually runs through the argument, checking each value in the string at a
time. Therefore, in a string of four characters as shown in the first example above, a for-loop will repeat a process four times
taking a character from the string each time. In the example above, the if-else conditional gets a True value in either of the
return values and ends the program.

To correct this, the else branch should be indented outside the if condition (that is, at the same level with the for-loop)

#2 Answer

>>> def any_lowercase2(s):

... for c in s:

... if 'c'.islower():

... return 'True'

... else:

... return 'False'

...

...
>>> print(any_lowercase2("TIMY"))

True

>>> print(any_lowercase2("timy"))

True

>>> This function is supposed to check if there is any lowercase character in the string passed as argument to the ‘s’
parameter by iterating through all the characters in the string. However, what it really does is to check if ‘c’ in line 3 is of a
lowercase or not. Therefore, for every string that is passed as argument, this function will always return True because ‘c’ is
already hardcoded as the argument to be checked whether it is lowercase or not. In other words, the function fails to check

any argument passed because it will always be checking for ‘c’, thereby ignoring any argument passed initially. Irrespective of
the argument passed, the function continues to return True.

To correct this error, the variable in the for-loop statement should be use in place of ‘c’ and then lace the else branch of the if-
else conditional outside the if condition.

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 37/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

#3 Answer

>>> def any_lowercase3(s):

... for c in s:

... flag = c.islower()

... return flag

...

>>> print(any_lowercase3("TIMY"))

False

>>> print(any_lowercase3("timy"))

True

>>> print(any_lowercase3("TImy"))

True

>>> This function is supposed to check if there is any lowercase character in the string passed as argument to the ‘s’
parameter by iterating through all the characters in the string. The function works work well.

#4 Answer

>>> def any_lowercase4(s):

... flag = False

... for c in s:

... flag = flag or c.islower()

... return flag

...

>>> print(any_lowercase4("TimY"))

True

>>> print(any_lowercase4("tImY"))

True

>>> print(any_lowercase4("TimY"))

False

>>> This code is also meant to check for lowercase characters in any argument passed into it. This function also works well.

#5 Answer

>>> def any_lowercase5(s):

... for c in s:

... if not c.islower()

... return False

... return True


>>> print(any_lowercase4("Timy"))

False

>>> print(any_lowercase4("timy"))

True

>>> This function also checks to confirm if there is any lowercase in any string argument passed into it. However, because of
the if not conditional statement inside the for-loop code block in line 3, what this code really does is return False if there is any
character in the argument that is not lowercase. In other words, if there is an uppercase in the argument, even if every other
characters in the argument are in lowercase, the function will return a False.

The python interpreter will be looking for uppercase letters because of the ‘not’ keyword which has reversed it. When it
eventually finds it, it returns a False value because it has been instructed to return a False value if any uppercase letters are
found in the argument of the function.

References

Downey, A. (2015). Think Python, How to think like a computer scientist. This book is licensed under Creative Commons 
Attribution-Noncommercial 3.0 unported (CC BY-NC 3.0).

WikiPedia (2019). Precondition. Retrieved: https://en.m.wikipedia.org/wiki/precondition.


746 words

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 38/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5

Permalink Show parent

UoPeople Clock (GMT-5)

All activities close on Wednesdays at 11:55 PM, except for Learning Journals/Portfolios which close on Thursdays at 11:55 PM always
following the clock at the top of the page.

Due dates/times displayed in activities will vary with your chosen time zone, however you are still bound to the 11:55 PM GMT-5
deadline.

◄ Learning Guide Unit 5

Jump to...

Programming Assign. Unit 5 ►

Disclaimer Regarding Use of Course Material  - Terms of Use


University of the People is a 501(c)(3) not for profit organization. Contributions are tax deductible to the extent permitted by law.
Copyright © University of the People 2021. All rights reserved.

You are logged in as Stephen Chuks (Log out)


Reset user tour on this page
 www.uopeople.edu










Resources
UoPeople Library
Orientation Videos
LRC
Syllabus Repository
Honors Lists
Links
About Us
Policies
University Catalog

Support
Student Portal
Faculty
Faculty Portal
CTEL Learning Community
Office 365
Tipalti
Contact us
English (‎en)‎ 
English (‎en)‎
‫ العربية‬‎(ar)‎
Data retention summary
Get the mobile app
https://my.uopeople.edu/mod/forum/discuss.php?d=640883 39/40
1/5/22, 1:48 AM CS 1101 - AY2022-T2: Discussion Unit 5
Get the mobile app

https://my.uopeople.edu/mod/forum/discuss.php?d=640883 40/40

You might also like