不使用内置函数,将从键盘输入的字符串中的所有小写字母替换成大写字母。

不使用内置函数,将从键盘输入的字符串中的所有小写字母替换成大写字母。

string = input("请输入字符串:")
converted_string = ""
for char in string:
    # 判断是否是小写字母
    if ord("a") <= ord(char) <= ord("z"):
        # ASCII 码中相应的大写字母的编码值为小写字母的编码值减去固定的距离
        converted_char = chr(ord(char) - ord("a") + ord("A"))
    else:
        converted_char = char
    converted_string += converted_char
print("转换后的字符串:", converted_string)