Question #307805

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


Expert's answer

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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS