我的代码在运行时打印输出.我希望它只打印该特定计数号所需的内容



为什么我的代码在 while 循环中打印输出。 我只想打印计数 # 和该计数 # 的加密文本。

>把list_text2放在你的循环中。

while count < 26:
list_text2 = []
for letter in list_text1:

我假设您每次都出于某种原因附加到list_test2,因此与其将其粘贴到循环之外,以下代码应该只是从它的尾端切出最新的更新,并仅打印该部分:

import string
text_to_encrypt = ('Please enter some text to encrypt: ')
offset = list(range(1,27))
alphabet = list(string.ascii_lowercase)
list_text2 = []
encrypted_text = ''
list_text1 = list(text_to_encrypt.lower())
adjusted_list = 2*alphabet
count = 1
while count < 26:
for letter in list_text1:
if letter not in alphabet:
list_text2 += letter
else:
index = adjusted_list.index(letter)
list_text2 += adjusted_list[index + offset[count]]
list_text2_len = len(list_text2)
slice_start_index = list_text2_len - len(text_to_encrypt)
print(''.join(list_text2[slice_start_index:list_text2_len]))
encrypted_text = ''.join(list_text2)
count += 1

最新更新