Python13 期字符串大考核!!!

本贴最后更新于 1361 天前,其中的信息可能已经时移世异

请用自己目前所学实现字符串大写转小写,小写变大写,并且将字符串变为镜像字符串。例如:’A’变为’Z’,’b’变为’y
示范字符串:
”sdSdsfdAdsdsdfsfdsdASDSDFDSFa”字符串大写变小写 小写变大写,然后最后变为镜像字符串。

Python13期 前来报道!!!

107 回帖
请输入回帖内容 ...
  • xiaochen_python13

    image.png

  • 其他回帖
  • xmm

    #请用自己目前所学实现字符串大写转小写,小写变大写,并且将字符串变为镜像字符串。例如:’A’变为’Z’,’b’变为’y

    示范字符串: ”sdSdsfdAdsdsdfsfdsdASDSDFDSFa”字符串大写变小写,小写变大写,然后最后变为镜像字符串。

    str_1="sdSdsfdAdsdsdfsfdsdASDSDFDSFa"
    #大小写互换
    str_2=str_1.swapcase()
    print(str_2)
    #变成镜像字符串
    str=''
    for i in range(len(str_2)):
    if str_2[i].isupper():
    str+= chr(155-ord(str_2[i]))
    if str_2[i].islower():
    str+= chr(219-ord(str_2[i]))
    print(str)

  • liyanhe

    w='sdSdsfdAdsdsdfsfdsdASDSDFDSFa'
    w1=w.swapcase()
    print('大小写转换后的字符串:',w1)
    new_w=''
    for i in w:
    if i.islower():
    i = chr(219-ord(i))
    new_w +=i
    elif i.isupper():
    i = chr(155 - ord(i))
    new_w +=i
    print('镜像字符串是:',new_w)

  • qizai

    #定义一个字符串a
    a="sdSdsfdAdsdsdfsfdsdASDSDFDSFa"
    #字符串a大写
    a_up=a.upper()
    #字符串a小写
    a_low=a.lower()
    #字符串中的A替换为Z
    a_z=a.replace("A","Z")
    #字符串中没有b,本行结果不变
    a_zy=a_z.replace("b","y")
    #格式化输出结果
    print("""
    ----字符串作业---
    {0}大写结果{1}
    {0}小写结果{2}
    {0}镜像字符串’A’变为’Z’,’b’变为’y’ 结果{3}
    """.format(a,a_up,a_low,a_zy))

  • 查看更多回帖