试图编写python代码来加密字符串。
加密字符串,输出为加密字符串。
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 发布于 2016-05-12 16:26:54
问题是,当i与len(a)相等时,您的a[i]将生成IndexError。
除了这个之外,还有很多其他的改进,比如您总是在执行c+=a[i],而不管条件如何,还有更多您应该自己尝试解决的问题。
https://stackoverflow.com/questions/37192397
复制相似问题