Python题目:输入一个字母,变成此字母后面的第三个字母,如果此字母是x,y,z或X,Y,Z,则转换成对应的a,b,c或A,B,C,输出变换后的字母。怎么写
时间: 2023-06-05 17:07:55 浏览: 669
python 输入3个数a,b,c,按大小顺序输出(示例)
请看下面的Python代码实现:
```
letter = input("请输入一个字母:")
# 判断是否为小写字母x,y,z
if letter == "x":
new_letter = "a"
elif letter == "y":
new_letter = "b"
elif letter == "z":
new_letter = "c"
# 判断是否为大写字母X,Y,Z
elif letter == "X":
new_letter = "A"
elif letter == "Y":
new_letter = "B"
elif letter == "Z":
new_letter = "C"
else:
# 将字母转成ASCII码值 + 3,再转回字母
new_letter = chr(ord(letter) + 3)
print("变换后的字母是:" + new_letter)
```
阅读全文