In this Capitalize problem, we need to develop a python program that can take two strings as input separated with space. and then we need to ensure that the first letter of both strings is capital or not and if not then we need to print the whole name with the first letter of both strings as a capital letters.

HackerRank Capitalize! solution in Python


Problem solution in Python 2 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
import string

words = raw_input().split(' ')
for i in xrange(len(words)):
    words[i] = string.capitalize(words[i])

print ' '.join(words)


Problem solution in Python 3 programming.


# Complete the solve function below.
def solve(s):
    for x in s[:].split():
        s = s.replace(x, x.capitalize())
    return s


Problem solution in pypy programming.

def capitalize(string):
    os=""
    for idx,x in enumerate(string):
        #print (x,idx,str1[idx-1])
        os+=x.upper() if string[idx-1]==" " or idx == 0 else x
    return "".join(os)


Problem solution in pypy3 programming.

def capitalize(string):
    s=""
    space=True
    for x in string :
        if space and x!=' ':
            s=s+x.upper() 
            space=False
        elif x==' ':
            s=s+x
            space=True
        else :
            s=s+x
                    
    return s