我正在寫一個程序在python 3將輸入字符串轉換爲整數。代碼只有一個問題。只要有空間,它就會打印-64。我試過編輯一個代碼,但是它打印了64個空格。有什麼建議?打印字符串作爲整數在python 3
n = input("please enter the text:").lower()
print(n)
a = []
for i in n:
a.append(ord(i)-96)
if (ord(i)-96) == -64:
a.append(" ")
print(a)
感謝
Input: "BatMan is Awesome"
Output: [2, 1, 20, 13, 1, 14, -64, ' ', 9, 19, -64, ' ', 1, 23, 5, 19, 15, 13, 5]
您能提供一些樣本輸入和您的預期輸出嗎? – CoryKramer
@Cyber:完成,添加了一個輸入和輸出 – pythonnewbie
@Cyber *一個代碼,但它打印64與空間* – ZdaR