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
10 ответов
+ 2
Okay how about
return string.endswith(ending)
+ 1
How about this?
https://code.sololearn.com/ciDtlMnCyJvt/?ref=app
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
0
on line 3 I want to be able to count the end of the string and see if it is in the ending
0
My solution before was :
def solution(string, ending):
if ending in string:
return True
else:
return False
0
How can one count the end of a string?
0
so you see. if we count the length of the string its index is the last letter!
0
Example I dont really understand
0
Same as Frogged
example:
"sololearn"
str.endswith("rn") :true
str.endswith('n') :true
str.endswith('arn',0:start,8:end) :true