'''create three lists called(letters, Encoded, encryptedLettersNum)''' letters=[] Encoded=[] encryptedLettersNum=[] '''Create a String variables called(EncodedMessage) that will contain message after the encryption''' EncodedMessage='' theAlphabetSmall='a' '''create a for loop that add every element in theAlphabetSmall list to the letters list''' for i in range(0,26): letters.append(theAlphabetSmall) theAlphabetSmall=chr(ord(theAlphabetSmall)+1) '''print a question that tell the user to enter the message and save it in the message variable''' message=input ("Enter your message:\n") '''create a for loop that add every character in the message variable to the letters list and add the index+1 to the encryptionLettersNum list''' for i in range(len (message)): index=letters.index(message[i]) encryptedLettersNum.append(index+1) '''create a for loop in for loop that start from pointer +1 and end in the last character in the messag varible''' for i in range(len (message)): for j in range(i+1,len (message)): ''' create a if condation that see if the index i of the encryptedLettersNum is bigger than the index j of the encryptedLettersNum and if it is not bigger subtract them and set the index i of it to the total ''' if encryptedLettersNum[i]>encryptedLettersNum[j]: encryptedLettersNum[i]=encryptedLettersNum[i]-encryptedLettersNum[j] break '''create a for loop that take the index encryptedLettersNum then decreased by 1 then added to Encoded list''' for i in range(len (message)): Encoded.append(letters[encryptedLettersNum[i]-1]) '''create a for loop that set the encodedMassage variable to the sum of it and the index of the encoded list ''' for i in range(len (message)): EncodedMessage= EncodedMessage+Encoded[i]; '''print the message after encoded with the Encoded message''' print("The message after Encoded:\n" + EncodedMessage)
'''create three lists called(letters, Encoded, encryptedLettersNum)'''
letters=[]
Encoded=[]
encryptedLettersNum=[]
'''Create a String variables called(EncodedMessage) that will contain message
after the encryption'''
EncodedMessage=''
theAlphabetSmall='a'
'''create a for loop that add every element in
theAlphabetSmall list to the letters list'''
for i in range(0,26):
letters.append(theAlphabetSmall)
theAlphabetSmall=chr(ord(theAlphabetSmall)+1)
'''print a question that tell the user to enter the message
and save it in the message variable'''
message=input ("Enter your message:\n")
'''create a for loop that add every character in the message variable
to the letters list and add the index+1 to the encryptionLettersNum list'''
for i in range(len (message)):
index=letters.index(message[i])
encryptedLettersNum.append(index+1)
'''create a for loop in for loop that start from pointer +1
and end in the last character in the messag varible'''
for i in range(len (message)):
for j in range(i+1,len (message)):
''' create a if condation that see if the index i of the encryptedLettersNum
is bigger than the index j of the encryptedLettersNum and if it is not bigger
subtract them and set the index i of it to the total '''
if encryptedLettersNum[i]>encryptedLettersNum[j]:
encryptedLettersNum[i]=encryptedLettersNum[i]-encryptedLettersNum[j]
break
'''create a for loop that take the index encryptedLettersNum
then decreased by 1 then added to Encoded list'''
for i in range(len (message)):
Encoded.append(letters[encryptedLettersNum[i]-1])
'''create a for loop that set the encodedMassage variable to the sum of it and
the index of the encoded list '''
for i in range(len (message)):
EncodedMessage= EncodedMessage+Encoded[i];
'''print the message after encoded with the Encoded message'''
print("The message after Encoded:\n" + EncodedMessage)
-----------------------------------------------------------------
in python 3
i want this piece of code more efficiently in one for loop
for i in range(len (message)):
for j in range(i+1,len (message)):
''' create a if condation that see if the index i of the encryptedLettersNum
is bigger than the index j of the encryptedLettersNum and if it is not bigger
subtract them and set the index i of it to the total '''
if encryptedLettersNum[i]>encryptedLettersNum[j]:
encryptedLettersNum[i]=encryptedLettersNum[i]-encryptedLettersNum[j]
break
-----------------------------------
the output must be like:
![Enter your message:
abohamza
The message after Encoded:
aaggalya](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F02244ac6-9573-4210-b8fb-8fa27c6728f4%2F53780561-9bb2-45cb-9c84-b59f3d4c9549%2Fkcwtw9t_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)