Skip to content

Solutions _5240101055_2025.py #218

Description

@Dwumfour-JO

1. Reverse the string "Programming"

# Solution 1
string = "Programming"
reversed_string = string[::-1]  # Using string slicing
print("Reversed String:", reversed_string)

2. Print initials in uppercase

# Solution 2
full_name = input("Enter your full name: ")
initials = ".".join([name[0].upper() for name in full_name.split()]) + "."
print("Initials:", initials)

3. Check if a given string is a palindrome

# Solution 3
string = input("Enter a string to check if it's a palindrome: ")
if string == string[::-1]:  # Compare the string with its reverse
    print(f'"{string}" is a palindrome.')
else:
    print(f'"{string}" is not a palindrome.')

4. Count the number of words in a sentence

# Solution 4
sentence = input("Enter a sentence: ")
word_count = len(sentence.split())  # Using the split() method
print("Number of words in the sentence:", word_count)

5. Replace "is" with "was" in the string

# Solution 5
original_string = "This is a string and it is an example."
modified_string = original_string.replace("is", "was")  # Replace "is" with "was"
print("Modified String:", modified_string)

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