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.
import math
import os
import random
import re
import sys
Complete the solve function below.
def solve(s):
new_word = []
last_char = ''
for index, char in enumerate(s):
if index == 0:
new_word.append(char.capitalize())
last_char = char
continue
if last_char == ' ' and char == ' ': # Last char is space and new char is space
new_word.append(char)
elif last_char.isalnum(): # Last char is alpha, dont capitalize
new_word.append(char)
elif last_char == ' ' and char.isalnum():
new_word.append(char.capitalize())
last_char = char
return ''.join(new_word)
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 →
To preserve black spaces in totaly, i did it.
!/bin/python3
import math import os import random import re import sys
Complete the solve function below.
def solve(s):
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')