Python Forum
Impossible Function Task?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Impossible Function Task?
#1
I have recently taught myself to use functions, and tried to do the impossible, this task:

Shhh. They are listening! We need a plan…
I know, let us use a cipher to hide our conversations. That way they will not understand what we say.
The cipher works like this. You take a sentence and split it into two lists. One has the even words, the other the odd words. All punctuation is ignored.
So for example

"Hello world! I am pleased to meet you!"
odd = [“Hello”, “I” ,”pleased” ,”meet”]
even = [“world”, “am”, “to”, “you”]
You then combine the two lists using these rules –
  • Take the last word of each list.
    Take the last letter of each word and place them next to each other. One from each word (starting with odd)
    Repeat until one word is out of letters.
    Place a “!” symbol if it belonged to the odd word or a “#” if it belonged to the even and then copy the rest of the letters.
    Place a space in the output
    Repeat until one list is empty
    Finally copy the last word (if any) over to the output.
So the result of these rules would be –

"Hello world! I am pleased to meet you!"
odd = [“Hello”, “I” ,”pleased” ,”meet”]
even = [“world”, “am”, “to”, “you”]
output = “tueoey!m doet!saelp im#a odlllreohw”
You are to write two functions. One which will encrypt a sentence and one which will decrypt one. This is a hard problem! Make sure you can decipher the text before you begin the code.

So far, I have done this much:
def encrypt(inp):
    for x in string.punctuation:
        inp=inp.replace(x,"")
    inp=inp.split()
    odd=[]
    even=[]
    for x in range(0,len(inp)):
        if x % 2 == 0:
            odd.append(inp[x])
        elif x % 2 != 0:
            even.append(inp[x])
    
    return odd,even

import string

#sentence=input("What is your sentence?")
sentence="Hello world! I am pleased to meet you!" 
print(encrypt(sentence))
Any tips on how I should go about doing the next step, thanks!

Feel free to try yourselves.
Reply


Messages In This Thread
Impossible Function Task? - by ShadowWarrior17 - Jan-02-2018, 10:36 PM
RE: Impossible Function Task? - by nilamo - Jan-02-2018, 11:03 PM
RE: Impossible Function Task? - by squenson - Jan-02-2018, 11:43 PM
RE: Impossible Function Task? - by squenson - Jan-03-2018, 09:23 AM
RE: Impossible Function Task? - by buran - Jan-03-2018, 09:38 AM
RE: Impossible Function Task? - by squenson - Jan-03-2018, 12:04 PM
RE: Impossible Function Task? - by buran - Jan-03-2018, 12:48 PM
RE: Impossible Function Task? - by squenson - Jan-03-2018, 07:16 PM
RE: Impossible Function Task? - by ShadowWarrior17 - Jan-03-2018, 09:31 PM
RE: Impossible Function Task? - by squenson - Jan-03-2018, 10:48 PM
RE: Impossible Function Task? - by jajjaja - Jan-06-2018, 06:52 PM
RE: Impossible Function Task? - by squenson - Jan-06-2018, 07:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Mission Impossible : New to Python and 3 days to do theses exercises Kangaaxx 6 3,797 Aug-16-2018, 05:58 PM
Last Post: Kangaaxx

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020