简体   繁体   中英

Code Not fulfilling all the Sample Inputs' result on HackerRank

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)

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 . ie print or return statements etc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM