Codeforces: 131A – cAPS lOCK


This is from http://www.codeforces.com/problemset/problem/131/A

131A Codeforces: 131A - cAPS lOCK beginner codeforces implementation non-technical python string

The python does not allow altering string, because it seems the string is immutable. For example, if you try the following.

s = "1234"
s[0] = "a"

It will complain: TypeError: ‘str’ object does not support item assignment

The python solution is presented below:

s = raw_input("")

def chk(s, idx):
    for i in range(idx, len(s)):
        if (s[i].islower()):
            return 0
    return 1

if chk(s, 0):
    ns = s.lower()
elif chk(s, 1):
    ns = s[0].upper() + s[1:].lower()
else:
    ns = s

print ns

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
173 words
Last Post: Codeforces: B. Jumping Jack
Next Post: First Experience in Online Contest

The Permanent URL is: Codeforces: 131A – cAPS lOCK

Leave a Reply