Reputation: 3
def last_early(check_str):
x = check_str.count(check_str[-1])
if( x > 1):
valid = True
else:
valid = False
return valid
my_str = input("enter str: ")
my_str = my_str.lower()
valid = last_early(my_str)
print(valid)
the question is: "The function accepts as a string parameter. The function returns "true" if the character that appears last in the string also appears earlier. Otherwise, false will be printed"
Upvotes: 0
Views: 76
Reputation: 33107
when
check_str
is empty string i.e.''
, you would getIndexError
. Maybe you are failing this edge test-case.
To see if this is the problem, try adding a guard clause for the empty string:
def last_early(check_str):
if not check_str:
return False
...
Upvotes: 1