Computer Science, asked by aaaa6822, 1 year ago

write a python program to capitalize the frst and last letter of each word in a string

Answers

Answered by rakeshchennupati143
13

Program:  

st = input("Enter a sentence or string : ")  

for word in st.split():  

   print(word[0].upper()+word[1:-1]+word[-1].upper(), sep=' ', end=' ')  

Output:  

Enter a string : brainliest answer ever  

BrainliesT AnsweR EveR  

Explanation:  

  • in the slicing part of the string string_1[0] is the first letter and string_1[1:-1] is string from 2nd letter to (last_letter -1) and string_1[-1] is the last letter of the string  
  • and i used upper() method to only string_1[0] which is first letter and to string_1[-1] which is last letter  
  • while printing the string_1[0] and string_[-1] which are first and last letter of string will be converted into upper case and the remaining string will be added in between them and printed  
  • in loop i took word by word from the string by splitting the string with space using split() method
  • so i capitalized first and last letters of each word and printed there only so in loop the letters get capitalized and printed
  • in print statement spe='' is the separator which separates the printed word by the value given
  • end='' is the the end value, which value should be the string ended with so i gave nothing

-----Hope this helps, mark brainliest if you like my answer  

Answered by siddharthgager30
0

Answer:

str= input("Enter the string: ")

str= str.title()

word= str.split()

r= ' '

for i in word:

r = r+i[ :-1] + i[ -1].upper() + ' '

print("the modified string: ",r[ :-1])

Similar questions