Skip to content

5240101391 #724

Description

@Owusu25

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}”)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions