How to code my psuedocode in Python?

hundreds of years ago I was a programmer. now i’m a dunce. would like to come to grips with python.

I have this bit of psuedocode or this algorithm that I can’t express in Python. That’s a good indication of where I’m at. Can you help?

It is meant to look at a ordered in increasing value list of numbers (which are byte location offset numbers) and if any two adjoining numbers are within 100 of each other print them out consecutively: i.e. no space between. But when we find two that are more than 100 apart then print out a blank row.

so we are supposed to finish up with ‘chunks’ of numbers that are all within 100 of each other.

I think of it like this:

get number1
get number 2

loop 1
if n2 -n1 < 100 write n1,n2
n1 = n2
else
goto loop 1
loop 2
get n3
if n3 - n2 < 100 write n3
n1 = n3)
goto loop 2
else
write blank line
goto loop 1

sorry about the goto’s. you know what i mean i guess. i can’t implement it so’s it works.

don’t know enough python as yet. very early days. started yesterday actually, getting kinda serious about it. :slight_smile:

Wow! Did you ever collaborate with Ada Lovelace? :slight_smile:

You should be able to translate your code step by step into Python, but I would recommend that, instead of thinking about “goto”, you think in terms of loops. Loop 2 is entirely nested inside loop 1, but you need to (conditionally) cut short prior to it, which can be done with the continue statement (which will skip to the next run of the current loop).

Naming your variables more usefully may make it easier to get an idea of what you’re working on.

Does “get” here mean accepting something from the user (eg typed at the keyboard)? If so, the input function is what you want. You can write things out with print, and your loops will be while loops. Unsurprisingly, if and else are themselves. I think that should be enough to get you started.