Question: PYTHON PROGRAMMING Hint: Think of how slicing and reversing of strings can help with this problem You want to send a note to your friend

PYTHON PROGRAMMING

Hint: Think of how slicing and reversing of strings can help with this problem

You want to send a note to your friend in class, and because you want to be respectful in class, you dont want to whip out your phone and send a text or an email (or any other digital communication). Instead, you choose to go old school and write it out on a piece of paper and pass it along to your friend. The problem is, you dont want anyone else to read the note as they pass it along. Luckily, your friend and you have come up with an encryption system so that nobody else can understand your message. Heres how it works: you write out your message backwards (so, Hello, 5 world becomes dlrow ,olleH). But you dont stop there, because thats too easy to crack - anyone can figure that out! Now that youve written in backwards, Then you start on either side of the string and bring the characters together. So the first and the last characters become the first and the second character in the encrypted string, and the second and the second last characters become the third and the fourth characters in the string, and so on. Thus, Hello, world ultimately becomes dHlerlolwo , (notice how all punctuation, special characters, spaces, etc are all treated the same) and 0123456789 becomes 9081726354. Write a function called encrypt, that has one parameter s where s is a string and encrypt returns a string which is the encrypted version of s.

>>> TESTING CODE:

>>> encrypt("Hello, world")

dHlerlolwo ,

>>>> encrypt("1234")

4132

>>> encrypt("12345")

51423

>>> encrypt("1")

1

>>> encrypt("123")

312

>>> encrypt("12")

21

>>> encrypt("Secret Message")

eSgeacsrseetM

>>> encrypt(",4r")

"r,4"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!