1. Reverse a string
def reverse_string():
text = "Programming"
reversed_text = text[::-1]
print(f"1. Reversed '{text}': {reversed_text}")
2. Get initials from a full name
def get_initials():
full_name = "Suzzane Agyekum"
initials = ".".join([word[0].upper() for word in full_name.split()]) + "."
print(f"2. Initials for '{full_name}': {initials}")
3. Check if a word is a palindrome
def check_palindrome():
word = input("3. Enter a word to check if it's a palindrome: ")
if word.lower() == word.lower()[::-1]:
print(f" '{word}' is a palindrome!")
else:
print(f" '{word}' is NOT a palindrome.")
4. Count words in a sentence
def count_words():
sentence = input("4. Enter a sentence to count words: ")
word_count = len(sentence.split())
print(f" Word count: {word_count}")
5. Replace 'is' with 'was' in a sentence
def replace_is_with_was():
text = "This is a string and it is an example."
modified_text = text.replace("is", "was")
print(f"5. Original: {text}")
print(f" Modified: {modified_text}”)
1. Reverse a string
def reverse_string():
text = "Programming"
reversed_text = text[::-1]
print(f"1. Reversed '{text}': {reversed_text}")
2. Get initials from a full name
def get_initials():
full_name = "Suzzane Agyekum"
initials = ".".join([word[0].upper() for word in full_name.split()]) + "."
print(f"2. Initials for '{full_name}': {initials}")
3. Check if a word is a palindrome
def check_palindrome():
word = input("3. Enter a word to check if it's a palindrome: ")
if word.lower() == word.lower()[::-1]:
print(f" '{word}' is a palindrome!")
else:
print(f" '{word}' is NOT a palindrome.")
4. Count words in a sentence
def count_words():
sentence = input("4. Enter a sentence to count words: ")
word_count = len(sentence.split())
print(f" Word count: {word_count}")
5. Replace 'is' with 'was' in a sentence
def replace_is_with_was():
text = "This is a string and it is an example."
modified_text = text.replace("is", "was")
print(f"5. Original: {text}")
print(f" Modified: {modified_text}”)