DEV Community

loading...

Discussion on: Daily Challenge #190 - capitalizeFirstLast

Collapse
maskedman99 profile image
Rohit Prasad

Python

var = input("Enter the String: ")

def capitalizeFirstLast(x):
        x = x.lower()
        x = list(x)
        x[0] = x[0].upper()
        x[len(x)-1] = x[len(x)-1].upper()

        for i in range(len(x)):
                if x[i] == ' ':
                        x[i-1] = x[i-1].upper()
                        x[i+1] = x[i+1].upper()

        return(''.join(x))

print(capitalizeFirstLast(var))