Skip to content

gunjvm/count_reverse_script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Python function that:

  • Accepts a string s as input.
  • Prints the number of words in the provided sentence.
  • Reverts the interior content of every second word in the string

Explanation:

  • Splitting the string into words: The string is split into a list of words.
  • Counting and printing the number of words: The number of words is counted and printed.
  • Reversing the interior content of every second word: The loop iterates over every second word (starting with index 1). If the word has more than two characters, its interior content is reversed.
  • Joining the modified words into a string: The list of words is joined back into a single string and printed.

Example Output:

For the input string

This is a sample test sentence for Python code

the function will output:

Number of words: 9
Modified sentence: This si a elpmas test ecnetnes for nohtyP code

This code now reverses the interior content of every second word in the sentence.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages