We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#!/bin/python3importmathimportosimportrandomimportreimportsys# Complete the solve function below.defsolve(s):updt_s=""s=s.capitalize()foriinrange(len(s)):ifs[i-1]==" "ands[i].isalpha():updt_s+=s[i].upper()else:updt_s+=s[i]returnupdt_sif__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')s=input()result=solve(s)fptr.write(result+'\n')fptr.close()
way 2 is list comprehension:
#!/bin/python3importmathimportosimportrandomimportreimportsys# Complete the solve function below.defsolve(s):result=list(s)result[0]=result[0].upper()foriinrange(1,len(result)):ifresult[i-1]==' 'andresult[i].isalpha():result[i]=result[i].upper()return''.join(result)if__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')s=input()result=solve(s)fptr.write(result+'\n')fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Capitalize!
You are viewing a single comment's thread. Return to all comments →
Hi guies, you can go two ways:
way 1 is +=:
way 2 is list comprehension: