选择结构程序设计-字母大小写转换

编写一个程序,其功能为实现字符串中字母的大小写转换。要求:字符串中的大写字母转换为小写字母;小写字母转换为大写字母,其他字符不变。并输出转换后的字符串。
【输入提示】"Input a string:"
【输出】转换后的字符串


s  = input("Input a string:")
sNew = ""
for c in s:
    if c.islower():
        temp = c.upper()
    elif c.isupper():
        temp = c.lower()
    else:
        temp = c
    sNew += temp
print(sNew)

结果:

img

如果觉得答案对你有帮助,请点击下采纳,谢谢~

s=input("Input a string:")
for i in s:
     if i>='A' and i<='Z':
          i=chr(ord(i)+32)
     elif i>='a' and i<='z':
          i=chr(ord(i)-32)
     print(i,end='')