Python Practice Lab
easyUnit 3 · Strings

P8. Word Operations

Strings

Read a sentence and print the number of words, the sentence with each word reversed (words stay in the same order), the sentence in title case (str.title()), and the longest word (the first one if there is a tie).

Input Format

  • Line 1: a sentence of words separated by single spaces

Output Format

  • Line 1: Words: <n>
  • Line 2: Reversed words: <sentence>
  • Line 3: Title case: <sentence>
  • Line 4: Longest word: <word>

Constraints

  • 1 ≤ number of words ≤ 50
  • Words contain only letters

Sample Test Cases

Sample 1
Input
python is fun
Output
Words: 3
Reversed words: nohtyp si nuf
Title case: Python Is Fun
Longest word: python
Sample 2
Input
Hello
Output
Words: 1
Reversed words: olleH
Title case: Hello
Longest word: Hello

Submitting checks 2 sample cases and 3 hidden test cases.

Hints

Saved
Custom 1

This is your own input, so Run will show what your program prints but can't say whether it's correct.