Data Science class 009&010
Files
1) what are functions, arguments , command line arguments,
files, read,write,=>
count number of words in a line .
Arguments
def word_count(text# Split the text into a list of words
using whitespace as delimiter
words =
text.split() # Return the length of the
list (number of
words)
return len(words)
# Example usage
text = "This is a sample text string to count the
number of words."
word_count = word_count(text)
print(f"The text contains {word_count} words.")
Comments
Post a Comment