2016-11-02 39 views
-1

我試圖使ASCII到字符串轉換器(不知道這是否是正確的術語)使用chr()但是當我輸入類似於68(大寫字母D)的東西時,沒有任何反應。我試圖用這種想法來完成它:我怎樣才能使一個ASCII字符串轉換器在Python中使用:''.join(chr(i)爲我在templist中)

>>> L = [104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100] 
>>> ''.join(chr(i) for i in L) 
'hello, world' 

我希望它與用戶自定義輸入的程序運行,所以我想出了這個:

templist = [] 
number = int(input("Please enter an ASCII number here: ")) 
templist.append(number) 
''.join(chr(i) for i in templist) 

正如我上面可是說,當我輸入一個值時,沒有任何反應。

任何幫助,非常感謝。

編輯:我已經嘗試打印templist,但它只是讓我回到我想要轉換爲字符(68)的數字。

+0

https://docs.python.org/3 /library/functions.html#print – davidism

+1

沒有代碼會導致數字出現在輸出中。按照davidism的建議,參見print()函數。 – lit

+0

在第一種情況下,您正在使用REPL。第二,你正在運行自定義腳本。在REPL中,最後一個隱含值將被隱式打印。在腳本中,您需要明確地打印它。 –

回答

0

我需要把 ''。加入(CHR(i)對於我在templist)在打印語句,這樣的代碼看起來像這樣

templist = [] 
number = int(input("Please enter an ASCII number here: ")) 
templist.append(number) 
print(''.join(chr(i) for i in templist)) 
相關問題