HackerRankInterview QuestionsPythonPython InterviewRandom

HackerRank Capitalize! problem solution in Python | python problem 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 capitalised correctly as 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, .

Constraints

  • 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, .

Sample Input

chris alan

Sample Output

Chris Alan

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


Leave a Reply

10 Best Artificial Intelligence Software|artificial intelligence tools 5 nft games to earn money | Best NFT games for earn crypto Earn Money From Minting NFTs| How to mint NFT for free Top 10 Things You Need To Know About Python List | python lists functions 10 Popular PHP frameworks for web developers| best php frameworks 12 Tips On How To Become a Python Developer | python For beginner 12 Best Nodejs Frameworks for App Development in 2022 how to create google web stories, Steps to create web stories Top 10 Features in Angular 13 Every Developer Should Know | Angular 13 Features 10 Best Angular UI Libraries | angular ui components | angular Project 10 Best Web Development Frameworks in 2022 Frontend & Backend 18 Best Open-Source and Free Database Software | best database software for beginners Top 10+ Best Java IDEs & Online Java Compilers | best java ide for beginners top 10 besic to andvance java books |java books for beginer Top 5 Themes For Blogger, professional blogger theme download BEST Python Courses Online,Top 10 Courses to Learn Python in 2022 Top 13 python libraries for data science