Read:
Chapters 7 and 8 of the textbook (Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press. https://greenteapress.com/thinkpython2/thinkpython2.pdf)
Watch:
Fun with Strings (Khan Academy. (2011, June 30). Fun with strings. [Video]. YouTube. https://youtu.be/iZAtkS0F-Zo)
For Loops in Python (Khan Academy. (2011, June 30). For loops in Python. [Video]. YouTube. https://youtu.be/9LgyKiq_hU0)
While Loops in Python (Khan Academy. (2011, June 30). While loops in Python. [Video]. YouTube. https://youtu.be/D0Nb2Fs3Q8c)
For DISCUSSION POST:
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()
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
The code and its output must be explained technically whenever asked. The explanation can be provided before or after the code, or in the form of code comments within the code. For any descriptive type question, Your answer must be at least 150 words.
End your discussion post with one question related to programming fundamentals learned in this unit from which your colleagues can formulate a response or generate further discussion.
Last Completed Projects
topic title | academic level | Writer | delivered |
---|