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)
1. Reverse the string "Programming"
2. Print initials in uppercase
3. Check if a given string is a palindrome
4. Count the number of words in a sentence
5. Replace "is" with "was" in the string