{Spam?} [Tutor] Help with appropriate looping and logic

Bob Gailer bgailer at alum.rpi.edu
Fri Feb 6 21:38:23 EST 2004


At 09:49 AM 2/6/2004, Vicki Stanfield wrote:

>I have some code that I have written which should rightly be one section
>of code, but which I have had to code in three separate sections to get it
>to work right. I am hoping that someone on this list can help me get it
>right. I have written some pseudo-code to post here. The problem is that
>there are a few loops and several if/elif statements. For some reason I
>have not been able to work it out in Python.

I for one don't see what your problem is, and don't fully understand the 
pseudocode.

So let's try this: first change IF to if.

What does [AA] mean, Do you want to send left bracket, A, A, right bracket? 
If so you need a send function to do with an input string whatever send 
does. (What does it do?) Ditto receive.

Repeat whole sequence 12 times. What sequence? All code above that line? 
All code?

Codes in <> look like ASCII control codes, which are usually rendered in 
Python '\xnn' where nn is the hex value of the control code (<TAB> becomes 
'\x09'). If you want to use the <> syntax I'd create a dictionary to 
convert these codes to the hex equivalent.

You use for loops to do things multiple times, or a string multipler e.g. 
('[BB][BB]'*4) will expand to '[BB][BB][BB][BB][BB][BB][BB][BB]'

>Here is the pseudo-code:
>
>send <STX>
>IF 1: send [AA][AA]
>IF 2: send [AB][AB]
>IF 3: send [AC][AC]
>send <TAB>
>IF 1 or 2: send [BB][BB] 16 times
>IF 3: send [BB][BB] once
>send <TAB>
>IF 1: send [CA][CA]
>IF 2: send [CB][CB]
>IF 3: send [CC][CC]
>IF 1 or 2: send <ETX>
>         receive <ACK>
>IF 3: SEND <EOT>
>         receive <ACK>
>IF 1: Repeat whole sequence 12 times
>IF 2: send <STX>
>         send [DA][DA]
>         send <TAB>
>         send [BB][BB] 4 more times
>         send <TAB>
>         send [EA][EA]
>         send <EOT>
>         receive <ACK>
>         receive <ACK>
>IF 3: receive <ACK>
>IF 1: send <STX>
>         send [FA][FA]
>         send <TAB>
>         send [BB][BB] 8 more times
>         send <TAB>
>         send [FB]
>         send <EOT>
>         receive <ACK>
>         receive <ACK>
>
>I would appreciate someone helping me map this out as one unit of code.

What does "one unit/section of code" mean? Where do you see 3 units/sections?

Will you take a stab at coding this in Python and let us see the results?

The IF statements suggest that you are testing some variable. Should read 
if a == 3: etc.

Does any of this help? Obviously we need more information.

Bob Gailer
bgailer at alum.rpi.edu
303 442 2625 home
720 938 2625 cell 
-------------- next part --------------

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.577 / Virus Database: 366 - Release Date: 2/3/2004


More information about the Tutor mailing list