From 2e8a4cbb88d830cf939311f46ecfa9bc485452ef Mon Sep 17 00:00:00 2001 From: Pete Bell Date: Wed, 18 Dec 2024 18:52:44 +0000 Subject: [PATCH] reordered code to match project --- en/code/secret-messages-complete/main.py | 26 +++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/en/code/secret-messages-complete/main.py b/en/code/secret-messages-complete/main.py index 9b8f5630..8a223ef0 100644 --- a/en/code/secret-messages-complete/main.py +++ b/en/code/secret-messages-complete/main.py @@ -1,20 +1,18 @@ #!/bin/python3 alphabet = 'abcdefghijklmnopqrstuvwxyz' -newMessage = '' - -message = input('Please enter a message: ') - -key = input('Enter a key (1-26): ') +key = input('Please enter the key: ') key = int(key) +new_message = '' -for character in message: - if character in alphabet: - position = alphabet.find(character) - newPosition = (position + key) % 26 - newCharacter = alphabet[newPosition] - newMessage += newCharacter - else: - newMessage += character +message = input('Please enter a message: ') -print('Your new message is: ', newMessage) \ No newline at end of file +for character in message: + if character in alphabet: + position = alphabet.find(character) + new_position = (position + key) % 26 + new_character = alphabet[new_position] + new_message += new_character + else: + new_message += character +print(new_message)