我是 Python 新手,目前正在閱讀 Python 的動手密碼學,當我閱讀書中的 caesar5.py 腳本時,我想到了一個問題,我將不勝感激任何能幫助我解決問題的人。代碼說:
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
str_in = raw_input("Enter ciphertext: ")
for shift in range(26):
n = len(str_in)
str_out = ""
for i in range(n):
c = str_in[i]
loc = alpha.find(c)
newloc = (loc shift)%26
str_out = alpha[newloc]
print shift, str_out
它將結果列印在 26 行中,我想知道如何將結果列印在一個串列中?而不是像列印一樣
0 KHOOR
1 LIPPS
.
.
.
25 JGNNQ
它只是列印出來[KHOOR, LIPPS,...,JGNNQ],像這樣。
uj5u.com熱心網友回復:
所以基本上你想要做的是在 python 中創建一個陣列。有關于此的教程:https : //www.w3schools.com/python/python_arrays.asp。
我會嘗試快速寫出代碼:
array = []
array.append(str_out)
然后在 for 回圈結束時:
print(array)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/312276.html
標籤:Python python-2.7 凯撒密码
下一篇:如何找出字母表和字母表轉換頻率?
