How do I manage sentence lengths in a Python assignment?

0
6
Asked By CuriousCoder42 On

Hey everyone! I'm new here and I've been given a Python assignment that involves writing a function with three inputs: a list of sentences, an integer, and a filler word. The task is to check the length of each sentence—if a sentence exceeds the given integer, I need to trim it down, and if it's too short, I should append the filler word. My main issue is that I can split the list, but I'm having trouble splitting each sentence to count their lengths. Any help would be appreciated!

3 Answers

Answered By TechieTommy On

If you keep running into errors while trying to split your sentences, double-check your syntax. If the sentences are in a list, you’ll need to access each string correctly. If you're stuck, feel free to share a snippet of your code!

Answered By CodeGuru88 On

Have you considered that you might not need to actually split the sentences just to count their lengths? The `len()` function will give you the length of the string without needing to split it. This way, you can check if it's too long or too short, and then proceed from there!

Answered By HelpfulHarry On

It sounds like you're on the right track! Remember, a sentence is just a string, so you can use string slicing to manage its length. You might want to look up how to slice strings in Python—it allows you to easily cut down sentences. Also, to count the length, you can use the `len()` function directly on each sentence.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.