Friday, June 28, 2019

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 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
Capitalize! - Hacker Rank Solution
print ' '.join(word.capitalize() for word in raw_input().split(' '))

11 comments:

  1. I think this won't give all the test cases true as some of the test cases contain multiple spaces between the words and they expect you to return the same number of spaces in your output.

    ReplyDelete
  2. def solve(s):
    o = []
    s = list(map(str,s.split(' ')))
    for i in s:
    o.append(i.capitalize())
    return ' '.join(o)

    ReplyDelete
  3. This will and above code also will work, just we need to use split(' ') instead of
    using default split()

    ReplyDelete
  4. def solve(s):
    if s.isalnum():
    print(s)
    else:
    s1 =s.title()
    print(s1)

    n = input()
    solve(n)

    ReplyDelete
  5. word = list(input().split())
    a = []
    for i in word:
    a.append(i.capitalize())
    print(*a)

    ReplyDelete
  6. def solve(s):
    l=s.split()
    for i in l:
    i=i.capitalize()
    a=" ".join(l)
    return a


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

    s = input()

    result = solve(s)

    fptr.write(result + '\n')

    fptr.close()

    CAN SOMEONE PLEASE TELL ME WHAT IS WRONG IN MY FUNCTION DEFINATION

    ReplyDelete
  7. Thanks for sharing information. it will help to gain knowledge. Especia Associates provide Valuation Services . A valuation report can help you determine and understand your property's overall monetary value. This process is essentially used before putting up a property for sale. if you need Valuation Report call at 9310165114 or visit us Valuation Services.

    ReplyDelete
  8. Thanks For Sharing.
    Looking for a GST registration consultant near you? Hisabkitab can help! They are a professional consultancy firm that offers expert services for GST registration and compliance. Their experienced consultants can guide you through the registration process and ensure that you comply with all necessary regulations. In addition to GST registration, Hisabkitab also provides other GST-related services such as returns filing, audit, and advisory services. Contact Hisabkitab to find a GST registration consultant near you.

    ReplyDelete

Powered by Blogger.