TQC+ 程式語言 Python 3 _ 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
程式碼:
str1, total = input(), 0

for i in range( len( str1 ) ):
    print("ASCII code for '{}' is {}".format( str1[i], ord( str1[i] ) ) )
    total += ord( str1[i] )

print( total )

沒有留言:

張貼留言