Capitalize! HackerRank Python Solutions

Capitalize - Python HackerRank Solution

Hello Friends, How are you? Today I am going to solve the HackerRank Capitalize Problem in Python with a very easy explanation. In this article, you will get one or more approaches to solving this problem. So let's start-

{tocify} $title={Table of Contents}

Default Arguments Python HackerRank Solution

HackerRank Python Capitalize Solution - Problem Statement

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 0

chris alan {codeBox}

Sample Output 0

Chris Alan {codeBox}

Python Capitalize - Hacker Rank Solution

Approach I: Capitalize HackerRank Python Solution

# ========================
#       Information
# ========================

# Name: Capitalize in Python HackerRank
# Direct Link: https://www.hackerrank.com/challenges/capitalize/problem
# Difficulty: Easy
# Max Score: 20
# Language: Python 3

# ========================
#         Solution Start
# ========================

#Capitalize in Python - Hacker Rank Solution
   
#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the solve function below.

def solve(s):
    for x in s[:].split():
        s = s.replace(x, x.capitalize())
    return s

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    s = input()

    result = solve(s)

    fptr.write(result + '\n')

    fptr.close()
   
#Capitalize in Python - Hacker Rank Solution END
# MyEduWaves


Disclaimer: The above Problem ( Python Capitalize ) is generated by Hackerrank but the Solution is Provided by MyEduWaves. This tutorial is only for Educational and Learning purposes. Authority if any queries regarding this post or website fill out the contact form.

I hope you have understood the solution to this HackerRank Problem. All these three solutions will pass all the test cases. Now visit Python Capitalize Hackerrank Problem and try to solve it again.

All the Best!

Post a Comment

Previous Post Next Post