Home > Mobile >  Code Not fulfilling all the Sample Inputs' result on HackerRank
Code Not fulfilling all the Sample Inputs' result on HackerRank

Time:10-20

Question on HackerRank- 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.(What they actually want is to capitalize the first letter of every individual string)

 def solve(s):
        0<len(s)<1000
        abc=[]
        for p in s.split():
            abc.append(p.capitalize())
            x=" ".join(abc)
        return x
    

I am getting correct answers on putting my own custom inputs but HackerRank says otherwise.(4/6 Sample Inputs are unsatisfied)

CodePudding user response:

arr = ['muhammad Atif', 'alison heck','dr dexter Morgan']
def capitalizeName(word):
    words = word.split(' ')
    for i in range(0,len(words)):
        words[i] = words[i].capitalize()
    
    return ' '.join(words)
    
for word in arr:
    print(capitalizeName(word))

Hopefully, This simple function will solve your problem. Further, modify it according to the hackerrank criteria . i-e print or return statements etc

  • Related