Python Forum
Is there another way to solve this code but still using for loop?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there another way to solve this code but still using for loop?
#1
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))
Reply
#2
Hello!
Looks like a homework.
See str.islower(). c is a string object so it has islower method.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020