0

String ends with?

Complete the solution so that it returns true if the first argument(string) passed in ends with the 2nd argument (also a string). Examples: solution('abc', 'bc') # returns true solution('abc', 'd') # returns false Please help I don't really know what's the problem and how to improve my code. If possible help! Here is my code: def solution(string, ending): count = len(string) if string[count] in ending: return True else: return False

28th May 2021, 5:25 PM
Ailana
Ailana - avatar
10 Réponses
+ 2
Okay how about return string.endswith(ending)
28th May 2021, 6:07 PM
Oma Falk
Oma Falk - avatar
28th May 2021, 9:43 PM
McInventor29
McInventor29 - avatar
0
Let's debug Count =3 String[3]=crashhhhhh index error Please explain in own words how u want to solve it Then we do it step by step
28th May 2021, 5:38 PM
Oma Falk
Oma Falk - avatar
0
on line 3 I want to be able to count the end of the string and see if it is in the ending
28th May 2021, 6:02 PM
Ailana
Ailana - avatar
0
My solution before was : def solution(string, ending): if ending in string: return True else: return False
28th May 2021, 6:02 PM
Ailana
Ailana - avatar
0
How can one count the end of a string?
28th May 2021, 6:03 PM
Oma Falk
Oma Falk - avatar
0
so you see. if we count the length of the string its index is the last letter!
28th May 2021, 6:06 PM
Ailana
Ailana - avatar
0
Example I dont really understand
28th May 2021, 6:08 PM
Ailana
Ailana - avatar
0
Same as Frogged example: "sololearn" str.endswith("rn") :true str.endswith('n') :true str.endswith('arn',0:start,8:end) :true
29th May 2021, 1:53 PM
Isabella
Isabella - avatar