我在Python中使用了这个凯撒的密码代码来快速加密一些消息,并将其展示给我的同学。如何在Python中循环代码?
我已经完成这一切,除了东西...
我想打一个“你要加密的另一个消息?”选项,但我无法循环代码。
如何循环整个代码?我正在使用Python 3.5.1。
这里是我的代码:
print('QuantumShadow\'s Caesar Cipher')
message = input('Write your message here: ')
print('The encryption key is: ')
key = int(input())
print('Do you want to encrypt or decrypt?')
mode = input()
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
translated = ''
message = message.upper()
for symbol in message:
if symbol in LETTERS:
num = LETTERS.find(symbol)
if mode == 'encrypt':
num = num + key
elif mode == 'decrypt':
num = num - key
if num >= len(LETTERS):
num = num - len(LETTERS)
elif num < 0:
num = num + len(LETTERS)
translated = translated + LETTERS[num]
else:
translated = translated + symbol
print(translated)
print('Do you want to encrypt\\decrypt another message?')
print('Here is where I want to make the loop')
print('Coded with Python by QuantumShadow.')
把代码放在问题中,而不是链接中。要使其成为代码块,请突出显示它并按下Ctrl-k。 – zondo