首页> 学术问答> Python的期末作业不会写,急需老师帮助!
我目前在美国上学,我们马上期末了,最后一个作业有一道题是:编写一个Python程序来计算给定字符串中大写字符的ASCII值之和。比如说,输入:PytHon PRocESS,输出:373;输入:Java Script,输出:157。这个作业题老师能帮忙解决一下吗?我还有很多问题,希望老师能辅导!
最佳答案
课程顾问-小管家
2023-04-27 05:16:53
同学目前可能对Python掌握得还不够熟练,临近期末,时间比较紧张,如果同学还有很多问题需要老师解答的话,可以联系我们的美国课程辅导老师。老师会针对同学的实际学习情况,从基础内容开始讲起,帮助同学巩固所学知识,并加深对Python的理解。针对同学提出的问题,具体解决过程如下:
一、代码:
def test(strs):
return sum(map(ord,filter(str.isupper,strs)))
strs = "PytHon ExerciSEs"
print("Original strings:")
print(strs)
print("Sum of the ASCII values of the upper-case characters in the said string:")
print(test(strs))
strs = "JavaScript"
print("\nOriginal strings:")
print(strs)
print("Sum of the ASCII values of the upper-case characters in the said string:")
print(test(strs))
二、逻辑:
三、输出:
Original strings:
PytHon ExerciSEs
Sum of the ASCII values of the upper-case characters in the said string:
373
任何有关Python的问题,只要同学提出,老师基本都能解决,包括Python编程的所有主题,例如:控制语句、字符串、列表、元组、异常、日期和时间、文件I/O、程序等。相信通过老师的辅导,同学能更好地理解Python编程。
相关问答