WeixiangYan/CodeTransOcean huggingface dataset:
Task: Product of divisors







Python: def product_of_divisors(n):
    assert(isinstance(n, int) and 0 < n)
    ans = i = j = 1
    while i*i <= n:
        if 0 == n%i:
            ans *= i
            j = n//i
            if j != i:
                ans *= j
        i += 1
    return ans
    
if __name__ == "__main__":
    print([product_of_divisors(n) for n in range(1,51)])



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID.  PRODUCT-OF-DIVISORS.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 DIVISOR-PRODUCTS    PIC 9(9) OCCURS 50 TIMES.
          03 NUM                 PIC 999.
          03 MUL                 PIC 999.
      
       01 OUTPUT-FORMAT.
          03 NUM-OUT             PIC Z(9)9.
          03 LINE-PTR            PIC 99 VALUE 1.
          03 OUT-LINE            PIC X(50) VALUE SPACES.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM INIT VARYING NUM FROM 1 BY 1
               UNTIL NUM IS GREATER THAN 50.
           PERFORM CALCULATE-MULTIPLES VARYING MUL FROM 1 BY 1
               UNTIL MUL IS GREATER THAN 50.
           PERFORM OUTPUT-NUM VARYING NUM FROM 1 BY 1
               UNTIL NUM IS GREATER THAN 50.
           STOP RUN.

       INIT.
           MOVE 1 TO DIVISOR-PRODUCTS(NUM).
       
       CALCULATE-MULTIPLES.
           PERFORM MULTIPLY-NUM VARYING NUM FROM MUL BY MUL
               UNTIL NUM IS GREATER THAN 50.
 
       MULTIPLY-NUM.
           MULTIPLY MUL BY DIVISOR-PRODUCTS(NUM).

       OUTPUT-NUM.
           MOVE DIVISOR-PRODUCTS(NUM) TO NUM-OUT.
           STRING NUM-OUT DELIMITED BY SIZE INTO OUT-LINE
               WITH POINTER LINE-PTR.
           IF LINE-PTR IS EQUAL TO 51,
               DISPLAY OUT-LINE,
               MOVE SPACES TO OUT-LINE,
               MOVE 1 TO LINE-PTR.
Task: Find the last Sunday of each month







Python: import sys
import calendar

year = 2013
if len(sys.argv) > 1:
    try:
        year = int(sys.argv[-1])
    except ValueError:
        pass

for month in range(1, 13):
    last_sunday = max(week[-1] for week in calendar.monthcalendar(year, month))
    print('{}-{}-{:2}'.format(year, calendar.month_abbr[month], last_sunday))



COBOL:        program-id. last-sun.
       data division.
       working-storage section.
       1 wk-date.
        2 yr pic 9999.
        2 mo pic 99 value 1.
        2 da pic 99 value 1.
       1 rd-date redefines wk-date pic 9(8).
       1 binary.
        2 int-date pic 9(8).
        2 dow pic 9(4).
        2 sunday pic 9(4) value 7.
       procedure division.
           display "Enter a calendar year (1601 thru 9999): "
               with no advancing
           accept yr
           if yr >= 1601 and <= 9999
               continue
           else
               display "Invalid year"
               stop run
           end-if
           perform 12 times
               move 1 to da
               add 1 to mo
               if mo > 12              
                   move 12 to mo
                   move 31 to da
               end-if
               compute int-date = function
                   integer-of-date (rd-date)
               if mo =12 and da = 31   
                   continue
               else
                   subtract 1 from int-date
               end-if
               compute rd-date = function
                   date-of-integer (int-date)
               compute dow = function mod
                   ((int-date - 1) 7) + 1
               compute dow = function mod ((dow - sunday) 7)
               subtract dow from da
               display yr "-" mo "-" da
               add 1 to mo
           end-perform
           stop run
           .
       end program last-sun.
Task: Odd and square numbers







Python: import math
szamok=[]
limit = 1000

for i in range(1,int(math.ceil(math.sqrt(limit))),2):
    num = i*i
    if (num < 1000 and num > 99):
        szamok.append(num)

print(szamok)



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ODD-AND-SQUARE.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 N              PIC 999.
          03 SQR            PIC 9999 VALUE 0.
          03 FILLER         REDEFINES SQR.
             05 FILLER      PIC 999.
             05 FILLER      PIC 9.
                88 ODD      VALUE 1, 3, 5, 7, 9.
          03 FMT            PIC ZZ9.
          
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM CHECK VARYING N FROM 10 BY 1
                UNTIL SQR IS NOT LESS THAN 1000.
           STOP RUN.
       
       CHECK.
           MULTIPLY N BY N GIVING SQR.
           IF ODD, MOVE SQR TO FMT, DISPLAY FMT.
Task: Sum of square and cube digits of an integer are primes







Python: 

def isPrime(n):
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False        
    return True

def digSum(n, b):
    s = 0
    while n:
        s += (n % b)
        n = n // b
    return s

if __name__ == '__main__':
    for n in range(11, 99):
        if isPrime(digSum(n**3, 10)) and isPrime(digSum(n**2, 10)):
            print(n, end = "  ")



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. SQUARE-CUBE-DIGITS-PRIME.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 NUMBER-SEARCH-VARS.
          03 CAND             PIC 9(6).
          03 SQUARE           PIC 9(6).
          03 CUBE             PIC 9(6).
          
       01 SUM-DIGITS-VARS.
          03 SUM-NUM          PIC 9(6).
          03 DIGITS           PIC 9 OCCURS 6 TIMES INDEXED BY D
                              REDEFINES SUM-NUM.
          03 SUM              PIC 99.
       
       01 PRIME-TEST-VARS.
          03 DIVISOR          PIC 99.
          03 DIV-TEST         PIC 99V9999.
          03 FILLER           REDEFINES DIV-TEST.
             05 FILLER        PIC 99.
             05 FILLER        PIC 9999.
                88 DIVISIBLE  VALUE ZERO.
          03 PRIME-FLAG       PIC X.
             88 PRIME         VALUE '*'.
       
       01 OUT-FMT             PIC Z9.
       
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM CHECK-NUMBER VARYING CAND FROM 1 BY 1
           UNTIL CAND IS EQUAL TO 100.
           STOP RUN.
       
       CHECK-NUMBER.
           MULTIPLY CAND BY CAND GIVING SQUARE.
           MULTIPLY CAND BY SQUARE GIVING CUBE.
           MOVE SQUARE TO SUM-NUM.
           PERFORM SUM-DIGITS.
           PERFORM PRIME-TEST.
           IF PRIME,
               MOVE CUBE TO SUM-NUM,
               PERFORM SUM-DIGITS,
               PERFORM PRIME-TEST,
               IF PRIME,
                   MOVE CAND TO OUT-FMT,
                   DISPLAY OUT-FMT.
           
       SUM-DIGITS.
           MOVE ZERO TO SUM.
           PERFORM SUM-DIGIT VARYING D FROM 1 BY 1
           UNTIL D IS GREATER THAN 6.
           
       SUM-DIGIT.
           ADD DIGITS(D) TO SUM.
       
       PRIME-TEST.
           MOVE '*' TO PRIME-FLAG.
           PERFORM CHECK-DIVISOR VARYING DIVISOR FROM 2 BY 1
           UNTIL NOT PRIME, OR DIVISOR IS EQUAL TO SUM.
       
       CHECK-DIVISOR.
           DIVIDE SUM BY DIVISOR GIVING DIV-TEST.
           IF DIVISIBLE, MOVE SPACE TO PRIME-FLAG.
Task: Harmonic series







Python: from  fractions import Fraction

def harmonic_series():
    n, h = Fraction(1), Fraction(1)
    while True:
        yield h
        h += 1 / (n + 1)
        n += 1

if __name__ == '__main__':
    from itertools import islice
    for n, d in (h.as_integer_ratio() for h in islice(harmonic_series(), 20)):
        print(n, '/', d)



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. HARMONIC.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARS.
          03 N           PIC 9(5) VALUE ZERO.
          03 HN          PIC 9(2)V9(12) VALUE ZERO.
          03 INT         PIC 99 VALUE ZERO.
       01 OUT-VARS.
          03 POS         PIC Z(4)9.
          03 FILLER      PIC X(3) VALUE SPACES.
          03 H-OUT       PIC Z9.9(12).

       PROCEDURE DIVISION.
       BEGIN.
           DISPLAY "First 20 harmonic numbers:"
           PERFORM SHOW-HARMONIC 20 TIMES.
           DISPLAY SPACES.
           MOVE ZERO TO N, HN.
           DISPLAY "First harmonic number to exceed whole number:"
           PERFORM EXCEED-INT 10 TIMES.
           STOP RUN.

       SHOW-HARMONIC.
           PERFORM NEXT-HARMONIC.
           MOVE HN TO H-OUT.
           DISPLAY H-OUT.

       EXCEED-INT.
           ADD 1 TO INT.
           PERFORM NEXT-HARMONIC UNTIL HN IS GREATER THAN INT.
           MOVE N TO POS.
           MOVE HN TO H-OUT.
           DISPLAY OUT-VARS.

       NEXT-HARMONIC.
           ADD 1 TO N.
           COMPUTE HN = HN + 1 / N.
Task: Comments







Python: 

var x = 0 

var y = 0 


There are also multi-line comments
Everything inside of 
]



discard 



COBOL:       * an asterisk in 7th column comments the line out
Task: Find squares n where n+1 is prime







Python: limit = 1000
print("working...")

def isprime(n):
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            return False
    return True

def issquare(x):
	for n in range(1,x+1):
		if (x == n*n):
			return 1
	return 0

for n in range(limit-1):
	if issquare(n) and isprime(n+1):
		print(n,end=" ")

print()
print("done...")



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. SQUARE-PLUS-1-PRIME.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 N                   PIC 999.
       01 P                   PIC 9999 VALUE ZERO.
       01 PRIMETEST.
          03 DSOR             PIC 9999.
          03 PRIME-FLAG       PIC X.
             88 PRIME         VALUE '*'.
          03 DIVTEST          PIC 9999V999.
          03 FILLER           REDEFINES DIVTEST.
             05 FILLER        PIC 9999.
             05 FILLER        PIC 999.
                88 DIVISIBLE  VALUE ZERO.
           
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM CHECK-N VARYING N FROM 1 BY 1 
                UNTIL P IS GREATER THAN 1000.
           STOP RUN.
       
       CHECK-N.
           MULTIPLY N BY N GIVING P.
           ADD 1 TO P.
           PERFORM CHECK-PRIME.
           SUBTRACT 1 FROM P.
           IF PRIME, DISPLAY P.
           
       CHECK-PRIME.
           IF P IS LESS THAN 2, MOVE SPACE TO PRIME-FLAG,
           ELSE, MOVE '*' TO PRIME-FLAG.
           PERFORM CHECK-DSOR VARYING DSOR FROM 2 BY 1
               UNTIL NOT PRIME OR DSOR IS GREATER THAN N.
       
       CHECK-DSOR.
           DIVIDE P BY DSOR GIVING DIVTEST.
           IF DIVISIBLE, MOVE SPACE TO PRIME-FLAG.
Task: Smallest square that begins with n







Python: 

from itertools import count



def firstSquareWithPrefix(n):
    
    pfx = str(n)
    lng = len(pfx)
    return int(
        next(
            s for s in (
                str(x * x) for x in count(0)
            )
            if pfx == s[0:lng]
        )
    )



def main():
    

    print('\n'.join([
        str(firstSquareWithPrefix(x)) for x in range(1, 50)
    ]))



if __name__ == '__main__':
    main()



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. SMALLEST-SQUARE-BEGINS-WITH-N.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 N            PIC 99.
       01 SQUARE-NO    PIC 999.
       01 SQUARE       PIC 9(5).
       01 OUT-FMT      PIC Z(4)9.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM SMALLEST-SQUARE THRU SQUARE-START-TEST
               VARYING N FROM 1 BY 1 UNTIL N IS EQUAL TO 50.
           STOP RUN.

       SMALLEST-SQUARE.
           MOVE ZERO TO SQUARE-NO.
       SQUARE-LOOP.
           ADD 1 TO SQUARE-NO.
           MULTIPLY SQUARE-NO BY SQUARE-NO GIVING SQUARE.
       SQUARE-START-TEST.
           IF SQUARE IS GREATER THAN N
               DIVIDE 10 INTO SQUARE
               GO TO SQUARE-START-TEST.
           IF SQUARE IS NOT EQUAL TO N
               GO TO SQUARE-LOOP.
           MULTIPLY SQUARE-NO BY SQUARE-NO GIVING OUT-FMT.
           DISPLAY OUT-FMT.
Task: Minimum number of cells after, before, above and below NxN squares







Python: def min_cells_matrix(siz):
    return [[min(row, col, siz - row - 1, siz - col - 1) for col in range(siz)] for row in range(siz)]

def display_matrix(mat):
    siz = len(mat)
    spaces = 2 if siz < 20 else 3 if siz < 200 else 4
    print(f"\nMinimum number of cells after, before, above and below {siz} x {siz} square:")
    for row in range(siz):
        print("".join([f"{n:{spaces}}" for n in mat[row]]))

def test_min_mat():
    for siz in [23, 10, 9, 2, 1]:
        display_matrix(min_cells_matrix(siz))

if __name__ == "__main__":
    test_min_mat()



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. MINIMUM-CELLS-N-BY-N.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 TABLE-SIZE        PIC 99 VALUE 10.
       01 X                 PIC 99.
       01 Y                 PIC 99.
       01 ITEM              PIC 99.
       01 MIN               PIC 99.
       
       01 FMT               PIC ZZ9.
       01 TABLE-LINE        PIC X(72).
       01 LINE-PTR          PIC 99.
       
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM MAKE-LINE VARYING Y FROM 0 BY 1 
               UNTIL Y IS EQUAL TO TABLE-SIZE.
           STOP RUN.
       
       MAKE-LINE.
           MOVE SPACES TO TABLE-LINE.
           MOVE 1 TO LINE-PTR.
           PERFORM ADD-ITEM VARYING X FROM 0 BY 1
               UNTIL X IS EQUAL TO TABLE-SIZE.
           DISPLAY TABLE-LINE.
           
       ADD-ITEM.
           PERFORM FIND-MINIMUM-VALUE.
           MOVE MIN TO FMT.
           STRING FMT DELIMITED BY SIZE INTO TABLE-LINE 
               WITH POINTER LINE-PTR.
       
       FIND-MINIMUM-VALUE.
           MOVE X TO MIN.
           MOVE Y TO ITEM.
           PERFORM CHECK-MINIMUM.
           COMPUTE ITEM = TABLE-SIZE - Y - 1.
           PERFORM CHECK-MINIMUM.
           COMPUTE ITEM = TABLE-SIZE - X - 1.
           PERFORM CHECK-MINIMUM.
       
       CHECK-MINIMUM.
           IF ITEM IS LESS THAN MIN, MOVE ITEM TO MIN.
Task: Strange plus numbers







Python: Python 3.8.5 (default, Sep  3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> from sympy import isprime

>>> [x for x in range(101,500) 
 if isprime(sum(int(c) for c in str(x)[:2])) and
    isprime(sum(int(c) for c in str(x)[1:]))]
[111, 112, 114, 116, 120, 121, 123, 125, 129, 141, 143, 147, 149, 161, 165, 167, 202, 203, 205, 207, 211, 212, 214, 216, 230, 232, 234, 238, 250, 252, 256, 258, 292, 294, 298, 302, 303, 305, 307, 320, 321, 323, 325, 329, 341, 343, 347, 349, 383, 385, 389, 411, 412, 414, 416, 430, 432, 434, 438, 470, 474, 476, 492, 494, 498]
>>>



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. STRANGE-PLUS-NUMBERS.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 CANDIDATE            PIC 999.
          03 DIGITS               REDEFINES CANDIDATE,
                                  PIC 9 OCCURS 3 TIMES.
          03 LEFT-PAIR            PIC 99.
             88 LEFT-PAIR-PRIME   VALUES 2, 3, 5, 7, 11, 13, 17.
          03 RIGHT-PAIR           PIC 99. 
             88 RIGHT-PAIR-PRIME  VALUES 2, 3, 5, 7, 11, 13, 17.
       01 OUT.
          03 ROW                  PIC X(40) VALUE SPACES.
          03 PTR                  PIC 99 VALUE 1.
       
       PROCEDURE DIVISION. 
       BEGIN. 
           PERFORM CHECK-STRANGE-NUMBER
           VARYING CANDIDATE FROM 100 BY 1
           UNTIL CANDIDATE IS GREATER THAN 500.
           DISPLAY ROW.
           STOP RUN.

       CHECK-STRANGE-NUMBER. 
           ADD DIGITS(1), DIGITS(2) GIVING LEFT-PAIR.
           ADD DIGITS(2), DIGITS(3) GIVING RIGHT-PAIR. 
           IF LEFT-PAIR-PRIME AND RIGHT-PAIR-PRIME,
               PERFORM WRITE-STRANGE-NUMBER.

       WRITE-STRANGE-NUMBER.
           STRING CANDIDATE DELIMITED BY SIZE INTO ROW
           WITH POINTER PTR.
           ADD 1 TO PTR.
           IF PTR IS GREATER THAN 40,
               DISPLAY ROW,
               MOVE SPACES TO ROW,
               MOVE 1 TO PTR.
Task: Minimum multiple of m where digital sum equals m







Python: 

from itertools import count, islice



def a131382():
    
    return (
        elemIndex(x)(
            productDigitSums(x)
        ) for x in count(1)
    )



def productDigitSums(n):
    
    return (digitSum(n * x) for x in count(0))




def main():
    

    print(
        table(10)([
            str(x) for x in islice(
                a131382(),
                40
            )
        ])
    )





def chunksOf(n):
    
    def go(xs):
        return (
            xs[i:n + i] for i in range(0, len(xs), n)
        ) if 0 < n else None
    return go



def digitSum(n):
    
    return sum(int(x) for x in list(str(n)))



def elemIndex(x):
    
    def go(xs):
        try:
            return next(
                i for i, v in enumerate(xs) if x == v
            )
        except StopIteration:
            return None
    return go



def table(n):
    
    def go(xs):
        w = len(xs[-1])
        return '\n'.join(
            ' '.join(row) for row in chunksOf(n)([
                s.rjust(w, ' ') for s in xs
            ])
        )
    return go



if __name__ == '__main__':
    main()



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. A131382.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 MAXIMUM      PIC 99 VALUE 40.
          03 N            PIC 999.
          03 M            PIC 9(9).
          03 N-TIMES-M    PIC 9(9).
          03 DIGITS       PIC 9 OCCURS 9 TIMES,
                          REDEFINES N-TIMES-M,
                          INDEXED BY D.
          03 DIGITSUM     PIC 999 VALUE ZERO.
       01 OUTFMT.
          03 FILLER       PIC XX VALUE "A(".
          03 N-OUT        PIC Z9.
          03 FILLER       PIC X(4) VALUE ") = ".
          03 M-OUT        PIC Z(8)9.
       
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM CALC-A131382 VARYING N FROM 1 BY 1
           UNTIL N IS GREATER THAN MAXIMUM.
           STOP RUN.
       
       CALC-A131382.
           PERFORM FIND-LEAST-M VARYING M FROM 1 BY 1
           UNTIL DIGITSUM IS EQUAL TO N.
           SUBTRACT 1 FROM M.
           MOVE N TO N-OUT.
           MOVE M TO M-OUT.
           DISPLAY OUTFMT.
           
       FIND-LEAST-M.
           MOVE ZERO TO DIGITSUM.
           MULTIPLY N BY M GIVING N-TIMES-M.
           PERFORM ADD-DIGIT VARYING D FROM 1 BY 1
           UNTIL D IS GREATER THAN 9.
       
       ADD-DIGIT.
           ADD DIGITS(D) TO DIGITSUM.
Task: Test integerness







Python: >>> def isint(f): 
    return complex(f).imag == 0 and complex(f).real.is_integer()

>>> [isint(f) for f in (1.0, 2, (3.0+0.0j), 4.1, (3+4j), (5.6+0j))]
[True, True, True, False, False, False]

>>> 
...
>>> isint(25.000000)
True
>>> isint(24.999999)
False
>>> isint(25.000100)
False
>>> isint(-2.1e120)
True
>>> isint(-5e-2)
False
>>> isint(float('nan'))
False
>>> isint(float('inf'))
False
>>> isint(5.0+0.0j)
True
>>> isint(5-5j)
False



COBOL: IDENTIFICATION DIVISION.
PROGRAM-ID. INTEGERNESS-PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  INTEGERS-OR-ARE-THEY.
    05 POSSIBLE-INTEGER PIC S9(9)V9(9).
    05 DEFINITE-INTEGER PIC S9(9).
01  COMPLEX-NUMBER.
    05 REAL-PART        PIC S9(9)V9(9).
    05 IMAGINARY-PART   PIC S9(9)V9(9).
PROCEDURE DIVISION.
TEST-PARAGRAPH.
    MOVE ZERO TO IMAGINARY-PART.
    DIVIDE -28 BY 7 GIVING POSSIBLE-INTEGER.
    PERFORM INTEGER-PARAGRAPH.
    DIVIDE 28 BY 18 GIVING POSSIBLE-INTEGER.
    PERFORM INTEGER-PARAGRAPH.
    DIVIDE 3 BY 10000000000 GIVING POSSIBLE-INTEGER.
    PERFORM INTEGER-PARAGRAPH.
TEST-COMPLEX-PARAGRAPH.
    MOVE ZERO TO REAL-PART.
    MOVE 1 TO IMAGINARY-PART.
    MOVE REAL-PART TO POSSIBLE-INTEGER.
    PERFORM INTEGER-PARAGRAPH.
    STOP RUN.
INTEGER-PARAGRAPH.
    IF IMAGINARY-PART IS EQUAL TO ZERO THEN PERFORM REAL-PARAGRAPH,
    ELSE PERFORM COMPLEX-PARAGRAPH.
REAL-PARAGRAPH.
    MOVE POSSIBLE-INTEGER TO DEFINITE-INTEGER.
    IF DEFINITE-INTEGER IS EQUAL TO POSSIBLE-INTEGER
    THEN DISPLAY POSSIBLE-INTEGER ' IS AN INTEGER.',
    ELSE DISPLAY POSSIBLE-INTEGER ' IS NOT AN INTEGER.'.
COMPLEX-PARAGRAPH.
    DISPLAY REAL-PART '+' IMAGINARY-PART 'i IS NOT AN INTEGER.'.
Task: Print debugging statement







Python: import logging, logging.handlers

LOG_FILENAME = "logdemo.log"
FORMAT_STRING = "%(levelname)s:%(asctime)s:%(name)s:%(funcName)s:line-%(lineno)d: %(message)s"
LOGLEVEL = logging.DEBUG


def print_squares(number):
    logger.info("In print_squares")
    for i in range(number):
        print("square of {0} is {1}".format(i , i*i))
        logger.debug(f'square of {i} is {i*i}')

def print_cubes(number):
    logger.info("In print_cubes")
    for j in range(number):
        print("cube of {0} is {1}".format(j, j*j*j))
        logger.debug(f'cube of {j} is {j*j*j}')

if __name__ == "__main__":

    logger = logging.getLogger("logdemo")
    logger.setLevel(LOGLEVEL)
    handler = logging.FileHandler(LOG_FILENAME)
    handler.setFormatter(logging.Formatter(FORMAT_STRING))
    logger.addHandler(handler)

    print_squares(10)
    print_cubes(10)

    logger.info("All done")



COBOL: gcobol
      
      
      
      
       identification division.
       program-id. steptrace.

       data division.
       working-storage section.

       procedure division.
       steptrace-main.

       display "explicit line" upon syserr

    >>Ddisplay "debug line" upon syserr

       display "from " FUNCTION MODULE-ID " in " FUNCTION MODULE-SOURCE
       goback.
       end program steptrace.
Task: Special divisors







Python: 

def reverse(n):
    u = 0
    while n:
        u = 10 * u + n % 10
        n = int(n / 10)
    return u

c = 0
for n in range(1, 200):
    u = reverse(n)
    s = True
    
    for d in range (1, n):
        if n % d == 0:
            b = reverse(d)
            if u % b != 0:
                s = False
    if s:
        c = c + 1
        print(n, end='\t')
                
print("\nEncontrados ", c, "divisores especiales.")



COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. SPECIAL-DIVISORS.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 VARIABLES.
           02 CANDIDATE         PIC 999.
           02 CAND-REV          PIC 999.
           02 REVERSE           PIC 999.
           02 REV-DIGITS        REDEFINES REVERSE PIC 9 OCCURS 3 TIMES.
           02 DIVMAX            PIC 999.
           02 DIVISOR           PIC 999.
           02 DIVRSLT           PIC 999V999.
           02 FILLER            REDEFINES DIVRSLT.
              03 FILLER         PIC 999.
              03 FILLER         PIC 999.
                 88 DIVISIBLE   VALUE 0.
           02 TEMP              PIC 9.
           02 RD                PIC 9 COMP.
           02 STATUS-FLAG       PIC X.
              88 OK             VALUE 'Y'.    
           02 SPECIAL-N         PIC ZZ9.           

        PROCEDURE DIVISION.
        BEGIN.
            PERFORM CHECK-SPECIAL-DIVISOR
                VARYING CANDIDATE FROM 1 BY 1
                UNTIL CANDIDATE IS EQUAL TO 200.
            STOP RUN.
        
        CHECK-SPECIAL-DIVISOR.
            MOVE CANDIDATE TO REVERSE.
            PERFORM REVERSE-NUMBER.
            MOVE REVERSE TO CAND-REV.
            DIVIDE CANDIDATE BY 2 GIVING DIVMAX.
            MOVE 'Y' TO STATUS-FLAG.
            PERFORM TRY-DIVISOR
                VARYING DIVISOR FROM 1 BY 1
                UNTIL DIVISOR IS GREATER THAN DIVMAX.
            IF OK
                MOVE CANDIDATE TO SPECIAL-N
                DISPLAY SPECIAL-N.
        
        TRY-DIVISOR.
            IF OK
                DIVIDE CANDIDATE BY DIVISOR GIVING DIVRSLT
                IF DIVISIBLE
                    MOVE DIVISOR TO REVERSE
                    PERFORM REVERSE-NUMBER
                    DIVIDE CAND-REV BY REVERSE GIVING DIVRSLT
                    IF NOT DIVISIBLE MOVE 'N' TO STATUS-FLAG.
        
        REVERSE-NUMBER.
            SET RD TO 1.
            INSPECT REVERSE TALLYING RD FOR LEADING '0'.
            MOVE REV-DIGITS(RD) TO TEMP.
            MOVE REV-DIGITS(3) TO REV-DIGITS(RD).
            MOVE TEMP TO REV-DIGITS(3).