4. Write a Python program to Capitalize the first character of each word in a String [You cannot use the built-in upper() function]
Sample Input:
I love python programming
Sample Output: I Love Python Programming
str = input()
rezstr = ''
up = 0
for i in range(len(str)):
if (str[i] == ' '):
if (ord(str[i+1]) >= 97) & (ord(str[i+1]) <= 122):
up = 1
rezstr = rezstr + str[i]
else:
if up == 1:
rezstr = rezstr + chr(ord(str[i])-32)
up = 0
else:
rezstr = rezstr + str[i]
print(rezstr)
Comments
Leave a comment