0
試圖編寫一個python代碼來加密字符串。Python列表中的IndexError
對字符串進行加密並且輸出是一個加密字符串。
print "Enter the string "
a=raw_input()
b=len(a)+1
i=0
e=''
while i<b:
c=''
if i % 3 == 0:
c+=a[i]
e+=chr(ord(c)+5)
del c
elif i%3==1:
c+=a[i]
e+=chr(ord(c)+2)
del c
elif i%3==2:
c+=a[i]
e+=chr(ord(c)+6)
del c
i=i+1
print e
但是,當運行此腳本時,出現錯誤。
c+=a[i]
IndexError: string index out of range
這是一個提示:給你的標識符*有意義的*名稱。即使有了這個簡短的程序,它也不應該跟隨正在發生的事情以及每個事物所代表的事情。請閱讀[Python風格指南](https://www.python.org/dev/peps/pep-0008/)以獲取更多關於改進編碼風格的提示。 – MattDMo