Python program to capitalize the first and last letter of each word of a string
Login/Signup to comment
11 comments on “Python program to capitalize the first and last letter of each word of a string”
×


30+ Companies are Hiring
Get Hiring Updates right in your inbox from PrepInsta
inp=input(“Enter the string:”)
firstletter=(inp[0])
between=(inp[1:-1])
cap=firstletter.capitalize()
lastletter=(inp[-1])
cp=lastletter.capitalize()
print(cap+between+cp)
char=’prepinsta’
res=char[0:1].upper()+char[1:2].lower()+char[2:3].lower()+char[3:4].lower()+char[4:5].lower()+char[5:6].lower()+char[6:7].lower()+char[7:8].lower()+char[8:9].upper()
print(res)
s=’prepinsta’
print(s.capitalize())
st=’prep insta’
ar=list(st.split(‘ ‘))
for i in range(len(ar )):
ar[i]= ar[i].replace(ar[i][0],ar[i][0].upper())
ar[i]=ar[i].replace(ar[i][-1],ar[i][-1].upper())
print(‘ ‘.join(ar))
s = input(‘enter a value:’)
t = s.split()
new = []
for word in t:
if len(word)>=2:
new_word = word[0].upper()+word[1:-1]+word[-1].upper()
else:
new_word = word.upper()
new.append(new_word)
out = ‘ ‘.join(new)
print(out)
print([i[0:1].upper() + i[1:len(i)-1] + i[-1].upper() for i in input(“-> “).split()])
my_string = input(“>”)
b = my_string[0].upper() + my_string[1:-1] + my_string[-1].upper()
print(b)
s=input()
result=”
for i in s.split():
result =result + i[0].upper()+ i[1:-1] + i[-1].upper() +” ”
print(result)
a=input().split()
for i in a:
print(i[0].upper()+i[1:len(i)-1]+i[len(i)-1].upper(),end=” “)
a=input()
print(a[0].upper()+a[1:len(a)-1]+a[len(a)-1].upper())
s=input()
n=len(s)
print(s[0].upper()+s[1:n-1]+s[-1].upper())