Answer to Question #307805 in Python for jamil

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


1
Expert's answer
2022-03-09T06:38:16-0500
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS