Jul-21-2017, 10:36 AM
Hi!
I'm doing the Intro to Computer Science course on Udacity and I'm trying to:
#Define a procedure, find_last, that takes as input
# two strings, a search string and a target string,
# and returns the last position in the search string
# where the target string appears, or -1 if there
# are no occurrences.
#
# Example: find_last('aaaa', 'a') returns 3
# Make sure your procedure has a return statement.
This is my attempt, but it won't work. Can anyone explain what I did wrong?
I'm doing the Intro to Computer Science course on Udacity and I'm trying to:
#Define a procedure, find_last, that takes as input
# two strings, a search string and a target string,
# and returns the last position in the search string
# where the target string appears, or -1 if there
# are no occurrences.
#
# Example: find_last('aaaa', 'a') returns 3
# Make sure your procedure has a return statement.
This is my attempt, but it won't work. Can anyone explain what I did wrong?
def find_last(text,s): x = -1 b = text[x] while b != s: x = x-1 return x