import sys msg="qingQIAO_HighSchool" def my_function(???): for i in msg: if 97 <= ??? <= 122: # 对小写字母数值判断 upper_num = ??? - 32 # 转换得到大写字母数值 print(chr(upper_num),end="") # 通过数值返回大写字母并打印 elif ??? : # 对大写字母数值判断,转换成小写字母 ??? ??? else: print(i,end="") # 其他字符不变直接打印 print("转换后的字符串为:",end="") my_function(???)
时间: 2024-01-23 18:01:52 浏览: 64
这段代码中需要填写的内容是函数的参数和函数内部的语句。
根据代码中的提示,函数的参数应该是一个字符串,表示待转换的字符串。因此,函数定义应该为:
```
def my_function(s):
```
在函数内部,需要遍历字符串中的每个字符,判断其是否为小写字母或大写字母。如果是小写字母,就转换成大写字母并打印出来;如果是大写字母,就转换成小写字母并打印出来;如果是其他字符,就直接打印出来。根据这个要求,可以将函数内部的语句填写如下:
```
def my_function(s):
for i in s:
if 97 <= ord(i) <= 122: # 对小写字母数值判断
upper_num = ord(i) - 32 # 转换得到大写字母数值
print(chr(upper_num), end="")
elif 65 <= ord(i) <= 90: # 对大写字母数值判断,转换成小写字母
lower_num = ord(i) + 32
print(chr(lower_num), end="")
else:
print(i, end="")
print("转换后的字符串为:", end="")
```
最终的代码如下:
```
import sys
msg = "qingQIAO_HighSchool"
def my_function(s):
for i in s:
if 97 <= ord(i) <= 122: # 对小写字母数值判断
upper_num = ord(i) - 32 # 转换得到大写字母数值
print(chr(upper_num), end="")
elif 65 <= ord(i) <= 90: # 对大写字母数值判断,转换成小写字母
lower_num = ord(i) + 32
print(chr(lower_num), end="")
else:
print(i, end="")
print("转换后的字符串为:", end="")
my_function(msg)
```
阅读全文