我目前在美國上學,我們馬上期末了,最后一個作業(yè)有一道題是:編寫一個Python程序來計算給定字符串中大寫字符的ASCII值之和。比如說,輸入:PytHon PRocESS,輸出:373;輸入:Java Script,輸出:157。這個作業(yè)題老師能幫忙解決一下嗎?我還有很多問題,希望老師能輔導!
同學目前可能對Python掌握得還不夠熟練,臨近期末,時間比較緊張,如果同學還有很多問題需要老師解答的話,可以聯(lián)系我們的美國課程輔導老師。老師會針對同學的實際學習情況,從基礎內(nèi)容開始講起,幫助同學鞏固所學知識,并加深對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編程。