Capitalize!

  • + 0 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):

    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()