Capitalize! Hacker Rank Solution – Queslers

Problem: Capitalize! Hacker Rank Solution

You are asked to ensure that the first and last names of people begin with a capital letter in their passports. For example, alison heck should be capitalized correctly as Alison Heck.

alison heck  – Alison Heck

Given a full name, your task is to capitalize the name appropriately.

Input Format

A single line of input containing the full name, S.

Constraints

  • 0 < len(S) < 1000
  • The string consists of alphanumeric characters and spaces.

Note: in a word only the first character is capitalized. Example 12abc when capitalized remains 12abc.

Output Format

Print the capitalized string, S.

Sample Input

chris alan

Sample Output

Chris Alan

Capitalize! Hacker Rank Solution in Python 2

# 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)

Capitalize! Hacker Rank Solution in Python 3

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

Capitalize! Hacker Rank Solution in pypy

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)

Capitalize! Hacker Rank Solution in pypy3

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 
Capitalize! Hacker Rank Solution Review:

In our experience, we suggest you solve this Capitalize! Hacker Rank Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

Capitalize! Problem is available on Hacker Rank for Free, if you are stuck anywhere between compilation, just visit Queslers to get all Hacker Rank Solution

Conclusion:

I hope this Capitalize! Hacker Rank Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Hacker Rank Problem & Solutions >>

String Formatting Hacker Rank Solution

Merge the Tools! Hacker Rank Solution

Text Alignment Hacker Rank Solution

The Minion Game Hacker Rank Solution

itertools.product() Hacker Rank Solution

Leave a Reply

Your email address will not be published.