Length of Last Word

Advanced

Length of Last Word Challenge

Hello young coder! Today, we're on a quest to find the length of the last word in a sentence. Imagine you have a magic stick that can tell you how many letters there are in the last word of any given sentence. Let's build that magic stick using the power of Python!

For this challenge, you need to write a function called length_of_last_word that takes one argument:

  • sentence: a string that represents a sentence made up of words separated by spaces.

Your goal is to return the length of the last word in the sentence. Words in the sentence will be separated by spaces, and you can assume the string contains only alphabetic characters and spaces.

Examples:

length_of_last_word("The sun rises") # Output: 5 length_of_last_word("Hello world") # Output: 5 length_of_last_word("Python programming") # Output: 11 length_of_last_word("Keep going") # Output: 5

Tips:

  • Consider using Python's string methods to help you out.
  • Make sure you handle cases where there might be multiple spaces before or after words.
  • You can assume the input will always have at least one word.

Have fun coding and let the magic begin!

Geek
Inputs

Arg 1:

"The sun rises"
Expected Output
5
Actual Output
Length of Last Word [advanced] | Coding for Kids