Computer Science
Write a Python program to capitalize first and last letters of each word of a given string.
Python
Python String Manipulation
2 Likes
Answer
input_string = input("Enter the string: ")
words = input_string.split()
result = []
for word in words:
if len(word) > 1:
modified_word = word[0].upper() + word[1:-1] + word[-1].upper()
else:
modified_word = word.upper()
result.append(modified_word)
capitalized_string = ' '.join(result)
print(capitalized_string)
Output
Enter the string: the quick brown fox jumps over the lazy dog
ThE QuicK BrowN FoX JumpS OveR ThE LazY DoG
Answered By
1 Like
Related Questions
Write a program to store student names and their percentage in a dictionary and delete a particular student name from the dictionary. Also display the dictionary after deletion.
Write a Python program to input names of 'n' customers and their details like items bought, cost and phone number, etc., store them in a dictionary and display all the details in a tabular form.
Write a Python program to remove duplicate characters of a given string.
Write a Python program to compute sum of digits of a given number.