+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

加密返回与输入的原始字符串相同的字符串

发布于2020-11-28 09:06     阅读(493)     评论(0)     点赞(5)     收藏(4)


0

1

2

3

4

5

6

7

8

9

该程序将加密一条消息。它将使用带有偶数编号索引的所有值并将其放入列表中,并将赔率保留在第一个列表中。最后,它将为您提供后置置换加密消息。示例:ababab变为aaabbb

上面是程序应该做的,但是当我实际运行程序时,给出的是完全相同的字符串而不是加密版本。

crypt = [] # list to store original answers
original = raw_input("Enter your string: ") # prompts user for their desired string
crypt.append(original) # stores user answers in list crypt
crypt2 = [] # all the items with an even index from list crypt
x = 0

for a in crypt:
   if x % 2 == 1: # checks for oddness in the index value
      crypt2.append(a) # adds value associated with index to list crypt2
      crypt.remove(a) # removes value associated with index from list crypt
   x += 1

print crypt + crypt2

我的程序的逻辑部分有问题吗?


解决方案


进行循环时:

for a in crypt

您运行的crypt列表中的对象只有1个元素,它是用户编写的字符串。将程序更改为此:

original = raw_input("Enter your string: ") # prompts user for their desired
crypt = [] # list to store original answers
crypt2 = [] # all the items with an even index from list crypt
x = 0
print original
for a in original:
    if x % 2 == 1: # checks for oddness in the index 
        crypt2.append(a) # adds value associated with index to list crypt2
    else:
        crypt.append(a)
    x += 1
print crypt + crypt2

0

1

2

3

4



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接: https://www.pythonheidong.com/blog/article/634474/21a2e80daa197467b8a5/

来源: python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

5 0
收藏该文
已收藏

评论内容:(最多支持255个字符)