Skip to Content
PythonHandling StringsPractice Problems

String Practice Lab

Apply your knowledge with these hands-on challenges. Each problem includes a detailed explanation of the solution.

Challenge 1: Palindrome Checker

A palindrome is a word or phrase that reads the same forwards and backwards, ignoring case, punctuation, and spaces.

PygroundTry It Out

Write a function that checks if a given phrase is a palindrome. Test it with 'Was it a car or a cat I saw'.

Expected Output:

Is 'Was it a car or a cat I saw' a palindrome? True
Is 'Hello World' a palindrome? False

Output:

Challenge 2: URL Slug Generator

Create a “slug” from a blog post title. A slug is a URL-friendly version of a string, typically all lowercase, with spaces replaced by hyphens.

PygroundTry It Out

Convert the title 'My Awesome Guide to Python 3.9!' into a URL slug.

Expected Output:

Original: 'My Awesome Guide to Python 3.9!'
Slug: 'my-awesome-guide-to-python-39'

Output:

Challenge 3: Summarize Text

Write a function that truncates a text to a certain length and adds ”…” if it was cut short, without cutting words in half.

PygroundTry It Out

Summarize a long sentence to a maximum length of 50 characters.

Expected Output:

Python is an interpreted, high-level and...
This is short.

Output:

Challenge 4: Word Frequency Counter

Given a block of text, count the frequency of each word. The function should be case-insensitive and ignore punctuation.

PygroundTry It Out

Count word frequencies in the text: 'Code, code, and more code! Python is fun. Is it?'

Expected Output:

{'code': 3, 'and': 1, 'more': 1, 'python': 1, 'is': 2, 'fun': 1, 'it': 1}

Output:

Challenge 5: Format a Table of Data

Given a list of tuples representing products (name, price, quantity), format them into a neatly aligned table using f-strings.

PygroundTry It Out

Format a list of products into a clean, aligned table.

Expected Output:

Product                   Price   Quantity
------------------------------------------
Laptop                  1200.50         15
Mouse                     25.00        120
Keyboard                  75.99         50

Output:

Last updated on