+ 1
Can someone please help me fix the error in this code?
I'm trying to create a program to calculate the length of the last word. https://code.sololearn.com/cA7A9A720A1A/?ref=app
6 Answers
+ 5
Just a couple minor changes. I moved input into the main code. The removed the extra declarations in your object. Done.
class Solution:
def lengthOfLastWord(self, s: str) -> int:
lists = s.split()
str=lists[-1]
print(len(str))
r=Solution()
r.lengthOfLastWord(input())
+ 5
You could always just use
print(len(input().split()[-1]))
đ
+ 3
Thanks alot
+ 2
Calvin Thomas thanks alot
+ 1
Thanks alot
+ 1
Maxwell D. Dorliea Here's another solution:
a = input()
print(len(a) - a.rindex(" "))
# Hope this helps