华为2019春招留学生笔试第一题python

题目:将输入中的英文字符,大写改成小写,小写改成大写

思路一:

while True:
    try:
        s = input()
        low = 'abcdefghijklmnopqrstuvwxyz'
        up = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
        ns = ''
        for c in s:
            if c in low:
                ns += c.upper()
            elif c in up:
                ns += c.lower()
            else:
                ns += c
        print(ns)
    except:
        break

思路二:
用python内置函数

while True:
    try:
        s = input()
        print(s.swapcase())
    except:
        break

猜你喜欢

转载自blog.csdn.net/weixin_43236007/article/details/88679448