반응형
def switchcase(string):
switchcaseStr = ""
for index in range(len(string)):
# Condition : lowercase letter, replace lowercase letter to uppercase letter
if (string[index].islower()):
asciiIndex = ord(string[index]) - 32
switchcaseStr += chr(asciiIndex)
# Condition : uppercase letter, replace uppercase letter to lowercase letter
elif (string[index].isupper()):
asciiIndex = ord(string[index]) + 32
switchcaseStr += chr(asciiIndex)
# Condition : non alphabetical letter, leave it the letter
else:
switchcaseStr += string[index]
return switchcaseStr
print (switchcase("Hi Cassie! COLLEGE station weather is REALLY HoT"))
Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux
반응형
'<개인공부> - IT > [Python]' 카테고리의 다른 글
Number of Things Challenge 함수 만들기 (0) | 2018.08.20 |
---|---|
Commafy 함수 만들기 (0) | 2018.08.20 |
Gerund 판단 함수만들기 (0) | 2018.08.20 |
Reverse String 함수 만들기 (0) | 2018.08.20 |
Python 소문자 변경하는 함수만들기 (0) | 2018.08.17 |