Programming Exercises

  1. Reverse a String

Write a program that asks the user to enter a string and then displays the string in reverse order. For example, if the user enters "hello", the program should display "olleh".

 

  1. Palindrome Checker

Write a program that asks the user to enter a string and checks whether the string is a palindrome. A palindrome is a string that reads the same forwards and backwards, ignoring spaces, punctuation, and capitalization. For example, "A man, a plan, a canal, Panama" is a palindrome.

 

  1. Word Counter

Write a program that asks the user to enter a sentence and then counts the number of words in the sentence. For example, if the user enters "The quick brown fox jumps over the lazy dog", the program should return 9.

 

  1. Character Frequency Counter

Write a program that asks the user to enter a string and then counts the frequency of each character in the string. The program should display each character along with its frequency.

 

  1. Anagram Checker

Write a program that asks the user to enter two strings and checks whether they are anagrams. Anagrams are words or phrases that contain the same characters but in a different order. For example, "listen" and "silent" are anagrams.

 

  1. Title Case Converter

Write a program that asks the user to enter a sentence and then converts the first character of each word to uppercase. For example, if the user enters "the quick brown fox", the program should display "The Quick Brown Fox".

 

  1. Phone Number Formatter

Write a program that asks the user to enter a 10-digit phone number as a single string of digits and formats it as (XXX) XXX-XXXX. For example, if the user enters "1234567890", the program should display "(123) 456-7890".

 

  1. Remove Vowels

Write a program that asks the user to enter a string and then removes all vowels (a, e, i, o, u) from the string. For example, if the user enters "beautiful", the program should display "btfl".

 

  1. Caesar Cipher

Write a program that asks the user to enter a string and an integer shift value, and then encodes the string using a Caesar cipher. A Caesar cipher shifts each character in the string by the given number of positions in the alphabet. For example, with a shift of 3, "a" becomes "d", "b" becomes "e", and so on.

 

  1. Initials Formatter

Write a program that asks the user to enter a string containing multiple names separated by spaces, and then displays the initials of each name. For example, if the user enters "John William Smith Alice Mary Brown", the program should display "J. W. S. A. M. B.".

 

  1. Word Lengths Calculator

Write a program that asks the user to enter a sentence. The program should split the sentence into words and then display the length of each word. For example, if the user enters "Hello world from Python", the program should display:

 

Word lengths:

Hello: 5

world: 5

from: 4

Python: 6

 

  1. Domain Extractor

Write a program that asks the user to enter a series of email addresses separated by spaces. The program should split the input string into individual email addresses and then extract and display the domain of each email address. For example, if the user enters "user1@example.com user2@test.org user3@domain.net", the program should display:

 

Domains:

example.com

test.org

domain.net