d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Python Question
Add Reply New Topic New Poll
Member
Posts: 19,197
Joined: Nov 13 2008
Gold: 4,787.14
Sep 26 2012 11:13pm
So I am given this problem:



Add an option to the menu, and decode the following series of messages.

Given:
secret_message=\
"DIIRe_teaa_utmnnh_ei_vetiedesns__g_P"+\
"se2ata_ninbglceele_a_!a!w_bRoIoer_uu"+\
"katnim_in_2tgt0e_h%_le_Pi_caknoneiog"+\
"_gleahea_tr!m!IRo_tel__ueInn,_ei_aet"+\
"Amden_s_dB_P_a2adt_nimbggaeesn_a_!a!"+\
"mIbRy_oe_auugmtnr__iav2tve0een%__g_P"+\
"aecataon_nogecleaeeac!r!h_IR_Iter__u"+\
"eannmmeio_etvtdeehs_:e_P__2aGn_neibg"+\
"ogeerh_agta!e!bR__oeH_uueItnr__iba2t"+\
"em0er_%_tB_P,aca_ton1mog6ale3nea3!r!"


Algorithm:
 A counter will be set to 0
 Create a pair of nested loops.
 The outer loop shall be of a range of 0 to 4.
 The inner loop will be a range of 1 to 5.
 Inside the inner loop, the counter will be incremented.
 Inside the inner loop, print the counter, the value of the outer loop, the value of the inner loop, and the value of
“secret” altered by changing the beginning of the string with the outer loop, and setting the interval of the string using the inner loop.

print count, outer, inner, secret[outer, inner]

Once this is done, a noticeable pattern will appear in the strings.

Now, using your own knowledge and the translated data, write if statements and use string properties and functions to
display the four messages cleanly. This includes replacing all underscores with single spaces. Points are awarded for
following the algorithm, solving the last step, and the corrected output.

Find:
Add this as option to your Menu.
Print out the four hidden messages.



ignore the menu part, but the actually decoding im not sure howto to go about it, it gives some instructions but its a bit vague =/

can anyone help me with this?
Member
Posts: 29,131
Joined: Sep 16 2007
Gold: 400.01
Sep 27 2012 03:09am
so you can enjoy the wait B)
Member
Posts: 13,630
Joined: Dec 4 2009
Gold: 0.00
Sep 27 2012 06:15pm
It's pretty straightforward, actually.

Code
counter = 0
for outer in range(4):
   # do outer stuff
   for inner in range(5):
       # do inner stuff
Member
Posts: 13,630
Joined: Dec 4 2009
Gold: 0.00
Sep 27 2012 07:47pm
Quote (Shamx @ Sep 27 2012 06:44pm)
thnx for the post but the parts im confused about are these:

 Inside the inner loop, the counter will be incremented.
 Inside the inner loop, print the counter, the value of the outer loop, the value of the inner loop, and the value of
“secret” altered by changing the beginning of the string with the outer loop, and setting the interval of the string using the inner loop.

I'm assuming im incrementing the counter by 1 so thats not the issue, the issue is the printing part.


Please keep this discussion in this thread; there is no reason to move it to my inbox.

What do you not understand about the printing? You print the counter, the outer loop's value in the range, then the an interval of the string with those numbers.
Member
Posts: 19,197
Joined: Nov 13 2008
Gold: 4,787.14
Sep 27 2012 07:52pm
Quote (BreakPoint @ Sep 27 2012 07:47pm)
Please keep this discussion in this thread; there is no reason to move it to my inbox.

What do you not understand about the printing? You print the counter, the outer loop's value in the range, then the an interval of the string with those numbers.


sorry about that, im confused where it says

"the value of “secret” altered by changing the beginning of the string with the outer loop, and setting the interval of the string using the inner loop."

secret is obviously the secret message but not sure what it means change the beginning with the outer loop and the inner loop part.
Member
Posts: 13,630
Joined: Dec 4 2009
Gold: 0.00
Sep 27 2012 07:55pm
Quote (Shamx @ Sep 27 2012 06:52pm)
sorry about that, im confused where it says

"the value of “secret” altered by changing the beginning of the string with the outer loop, and setting the interval of the string using the inner loop."

secret is obviously the secret message but not sure what it means change the beginning with the outer loop and the inner loop part.


Look into Python iterators. Itertools is a good way to do this:

http://docs.python.org/library/itertools.html
Member
Posts: 19,197
Joined: Nov 13 2008
Gold: 4,787.14
Sep 27 2012 09:18pm
Quote (BreakPoint @ Sep 27 2012 07:55pm)
Look into Python iterators. Itertools is a good way to do this:

http://docs.python.org/library/itertools.html


ty man I figured it out!!!!

if anyone is curious the output this this :p :

Code
Death is still working like a mole, And digs my grave at each remove: George Herbert, 1633
I am vengeance!   I am the night!    I am Batman!  I am vengeance!   I am the night!    I am Batman!  
It needs 2 be about 20% cooler.  It needs 2 be about 20% cooler.  It needs 2 be about 20% cooler
Reunite Pangea!  Reunite Pangea!  Reunite Pangea!  Reunite Pangea!  Reunite Pangea!  Reunite Pangea!


This post was edited by Shamx on Sep 27 2012 09:18pm
Member
Posts: 13,630
Joined: Dec 4 2009
Gold: 0.00
Sep 27 2012 11:04pm
Quote (Shamx @ Sep 27 2012 08:18pm)
ty man I figured it out!!!!

if anyone is curious the output this this :p  :

Code
Death is still working like a mole, And digs my grave at each remove: George Herbert, 1633
I am vengeance!   I am the night!    I am Batman!  I am vengeance!   I am the night!    I am Batman!  
It needs 2 be about 20% cooler.  It needs 2 be about 20% cooler.  It needs 2 be about 20% cooler
Reunite Pangea!  Reunite Pangea!  Reunite Pangea!  Reunite Pangea!  Reunite Pangea!  Reunite Pangea!


Good job. Mind sharing your code?
Member
Posts: 19,197
Joined: Nov 13 2008
Gold: 4,787.14
Sep 28 2012 12:45am
Quote (BreakPoint @ Sep 27 2012 11:04pm)
Good job. Mind sharing your code?


Sure


Code
secret_message="DIIRe_teaa_utmnnh_ei_vetiedesns__g_Pse2ata_ninbglceele_a_!a!w_bRoIoer_uukatnim_in_2tgt0e_h%_le_Pi_caknoneiog_gleahea_tr!m!IRo_tel__ueInn,_ei_aetAmden_s_dB_P_a2adt_nimbggaeesn_a_!a!mIbRy_oe_auugmtnr__iav2tve0een%__g_Paecataon_nogecleaeeac!r!h_IR_Iter__ueannmmeio_etvtdeehs_:e_P__2aGn_neibgogeerh_agta!e!bR__oeH_uueItnr__iba2tem0er_%_tB_P,aca_ton1mog6ale3nea3!r!"
       
       counter = 0
       for outer in range(0,4):  #Outer loop range as per instruction
           for inner in range(1,5): # inner loop range as per instruction
               counter=counter+1
               print(counter, outer, inner, secret_message[outer:: inner])
       
       print()
       print()
       print()
       print()
             
       counter = 0
       for outer in range(0,4): # Outer loop range as per instruction
           for inner in range(1,5): # inner loop range as per instruction
               counter=counter+1
               if (inner==4): #When inner is 4, thats when the decoded message appears, and when it does correction is done.
                   x=secret_message[outer:: inner]
                   x=x.replace("coolerIt", "cooler.  It")
                   x=x.replace("_", " ")
                   x=x.replace("!", "!  ")
                   print(x)
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll