Python 为什么我的“for”循环没有完全遍历?
我对python非常陌生,一直致力于密码学。我正在编写一个Caesar密码,但代码快结束时,它停止工作,只加密字符串中的1个字符 为什么会这样? 我怎样才能修好它Python 为什么我的“for”循环没有完全遍历?,python,for-loop,cryptography,Python,For Loop,Cryptography,我对python非常陌生,一直致力于密码学。我正在编写一个Caesar密码,但代码快结束时,它停止工作,只加密字符串中的1个字符 为什么会这样? 我怎样才能修好它 during = [] preBool = True while preBool == True : pre = str(input("Enter your message: ")) if pre.isalpha() == False: print("\nSorry, your input was no
during = []
preBool = True
while preBool == True :
pre = str(input("Enter your message: "))
if pre.isalpha() == False:
print("\nSorry, your input was not recognized.")
print("-------------------------------------------------------")
continue
else:
preBool = False
for char in pre:
during.append(char)
print(during)
while True:
try:
rot = int(input("Enter the rotation value: "))
except ValueError:
print("Sorry, your input was not recognized.")
continue
else:
break
#Here is where I'm having issues. 'Cipher' only prints the first letter.
def encrypt(pre,rot):
result = ""
# transverse the plain text
for i in range(len(pre)):
char = pre[i]
# Encrypt uppercase characters in plain text
if (char.isupper()):
result += chr((ord(char) + rot-65) % 26 + 65)
# Encrypt lowercase characters in plain text
else:
result += chr((ord(char) + rot - 97) % 26 + 97)
return result
print ("Cipher: " + encrypt(pre,rot))
返回结果在for循环内。当代码命中它时,它无条件地退出函数,在过程中中断循环
将其缩进一级,for循环应按预期运行,并且仅在其运行完其自然过程后返回