Jan-01-2018, 03:44 AM
In the war against Skynet, humans are trying to pass messages to each other without the computers realising what's happening.
To do this, they are using a simple code:
They read the words in reverse order
They only pay attention to the words in the message that start with an uppercase letter
So, something like:
BaSe fOO ThE AttAcK
contains the message:
attack the base
However, the computers have captured you and forced you to write a program so they can understand all the human messages (we won't go into what terrible tortures you've undergone). Your program must work as follows:
code: soMe SuPPLies liKE Ice-cREAm aRe iMPORtant oNly tO THeir cReaTORS. tO DestroY thEm iS pOInTLess.
says: destroy their ice-cream supplies
Notice that, as well as extracting the message, we make every word lowercase so it's easier to read.
This is what I have written so far...
Please help. Thanks
To do this, they are using a simple code:
They read the words in reverse order
They only pay attention to the words in the message that start with an uppercase letter
So, something like:
BaSe fOO ThE AttAcK
contains the message:
attack the base
However, the computers have captured you and forced you to write a program so they can understand all the human messages (we won't go into what terrible tortures you've undergone). Your program must work as follows:
code: soMe SuPPLies liKE Ice-cREAm aRe iMPORtant oNly tO THeir cReaTORS. tO DestroY thEm iS pOInTLess.
says: destroy their ice-cream supplies
Notice that, as well as extracting the message, we make every word lowercase so it's easier to read.
This is what I have written so far...
output=[] b=0 d=0 code=input("code: ") code=code.split() print(code) a=len(code) print(a) while b<a: c=code[b] if c.isupper: output.append(c) b=b+1 elif c.islower: b=b+1 else: b=b+1 print(output)
Output:['BaSe', 'fOO', 'ThE', 'AttAcK']
4
['BaSe', 'fOO', 'ThE', 'AttAcK']
I need the last line to say "BaSe ThE AttAck" eliminating "fOO" and I will be reversing the string in the last step to make sense, but it is not differentiating between a lowercase word and an uppercase word.Please help. Thanks