python假定字符串的upper()方法不存在,编写一个函数对传入的字符串返回一个所有字母全大写的字符串。


【问题描述】

假定字符串的upper()方法不存在,编写一个函数对传入的字符串返回一个所有字母全大写的字符串。

请编写一个函数upper(),类似于如下形式:

def upper(s):

    <函数体>

    return <全大写的字符串>

【输入形式】

【输出形式】
【样例输入】

Hello, 123, World!
【样例输出】

HELLO, 123, WORLD!

【样例说明】

对于输入的字符串中的英文字母全部大写
【评分标准】

 
def upper(s):
result = ''
for ch in s:
if 'a'<=ch<='z':
ascii_big = ord(ch)-32
result+=chr(ascii_big)
else:
result+=ch
return result
def main():
s = input()
print(upper(s))
main()

相关