Phase 5 - Category 3: Word Operations
Master word-level string operations.
10 programs · open one, then the next
Start with Print First Word- 01Print First WordBeginnerPrint the first whitespace-separated word safely with Python. Students use split before indexing and handle blank or space-only responses without an IndexError.Open example →py# Take string input s = input("Enter a string: ") # Get first word
- 02Print Last WordBeginnerPrint the last whitespace-separated word with Python. Students combine split, an empty-input guard, and negative indexing while retaining attached punctuation.Open example →py# Take string input s = input("Enter a string: ") # Get last word
- 03Reverse Order of WordsIntermediateReverse token order with Python split, list slicing, and join. Students follow the three-stage word pipeline and see how extra whitespace becomes single spaces.Open example →py# Take string input s = input("Enter a string: ") # Reverse words
- 04Find Longest WordIntermediateChoose the longest whitespace-separated word with max and key=len. Students compare word lengths rather than alphabetic values and handle a tie or empty input.Open example →py# Take string input s = input("Enter a string: ") # Find longest word
- 05Find Shortest WordIntermediateFind the shortest token with Python min and key=len. Students guard empty input, compare lengths, and predict first-occurrence behavior when several words tie.Open example →py# Take string input s = input("Enter a string: ") # Find shortest word
- 06Capitalize First Letter of Each WordIntermediateApply title casing to entered text. Students inspect uppercased starts, lowercased remaining letters, and why title is not simply a first-letter-only operation.Open example →py# Take string input s = input("Enter a string: ") # Capitalize first letter of each word
- 07Swap First and Last WordIntermediateSwap the first and last words in Python while retaining middle-word order. Students split text, require two tokens, and rebuild the result with single spaces.Open example →py# Take string input s = input("Enter a string: ") # Swap first and last word
- 08Count Words Starting with VowelIntermediateCount words beginning with English vowels using Python. Students split whitespace and test the first character, including uppercase and punctuation cases.Open example →py# Take string input s = input("Enter a string: ") # Count words starting with vowel
- 09Remove Duplicate WordsIntermediateRemove duplicate words while preserving first appearances with Python. Students combine a seen set and output list and understand case-sensitive token equality.Open example →py# Take string input s = input("Enter a string: ") # Remove duplicate words
- 10Sort Words AlphabeticallyIntermediateSort whitespace-separated words using Python's default string ordering. Students compare a sorted copy with the token order and recognize case-sensitive results.Open example →py# Take string input s = input("Enter a string: ") # Sort words