TQC+ 程式語言Python 802 字元對應
題目說明:
請撰寫一程式,要求使用者輸入一字串,顯示該字串每個字元的對應ASCII碼及其總和。
範例輸入
Kingdom
範例輸出
ASCII code for 'K' is 75
ASCII code for 'i' is 105
ASCII code for 'n' is 110
ASCII code for 'g' is 103
ASCII code for 'd' is 100
ASCII code for 'o' is 111
ASCII code for 'm' is 109
713
程式碼:
Str = input()
Sum = 0
for i in range(len(Str)):
print("ASCII code for '%s' is %d" %(Str[i], ord(Str[i])))
Sum += ord(Str[i])
print(Sum)