3 月 132021
 
"""
反向密码
"""

# 待加密消息字符串赋值变量
message = 'Three can keep a secret, if two of them are dead.'
# 空字符串赋值变量用以存储反转后的加密信息
translated = ''

# 计算待加密消息字符串长度减1并赋值变量i作为字符串最后一个字符的索引值
i = len(message) - 1
# 定义while循环,直到i小于0(False)时终止
while i >= 0:
    # 当前变量值拼接待加密消息字符串索引字符并赋值给变量
    translated = translated + message[i]
    # 打印每一次循环
    print('i is ', i, ', message i is ', message[i], ', translated is ', translated)
    # 执行i减1并将值重新赋值给变量i
    i = i - 1

# 结束循环后打印反转后的加密信息
print(translated)

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)