Python Forum
Is there another way to solve this code but still using for loop? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Is there another way to solve this code but still using for loop? (/thread-4904.html)



Is there another way to solve this code but still using for loop? - pratriciaexists - Sep-12-2017

def first(s):
""" Determine if a string contains a lowercase or uppercase r
Test data:
input: 'garden'
output: 'r'
Params: s(string)
Returns: (string) lowercase r
"""
c = 'r'
for c in s:
if c == 'r':
return("The string contains a lowercase r")
else:
pass
s= 'garden'
print(first(s))


RE: Is there another way to solve this code but still using for loop? - wavic - Sep-12-2017

Hello!
Looks like a homework.
See str.islower(). c is a string object so it has islower method.