Last active
January 24, 2016 17:43
-
-
Save miku/360dc9d93d95922e1c6b to your computer and use it in GitHub Desktop.
Cobol in Python. Problem 1, p. 3, Principles of Program Design, 1975. M.A. Jackson.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
""" | |
Problem 1. Multiplication table, Principles of program design (1975). | |
1 | |
2 4 | |
3 6 9 | |
4 8 12 16 | |
5 10 15 20 25 | |
6 12 18 24 30 36 | |
7 14 21 28 35 42 49 | |
8 16 24 32 40 48 56 64 | |
9 18 27 36 45 54 63 72 81 | |
10 20 30 40 50 60 70 80 90 100 | |
""" | |
from __future__ import print_function | |
import sys | |
lineno = 0 | |
colno = 0 | |
num = 0 | |
def display_line(): | |
global num | |
sys.stdout.write('%s ' % num) | |
def pstart(): | |
global lineno, num | |
lineno = 1 | |
num = 1 | |
display_line() | |
print('\n') | |
while True: | |
if lineno == 10: | |
break | |
pline() | |
print('\n') | |
def pline(): | |
global lineno, colno | |
lineno = lineno + 1 | |
colno = 0 | |
while True: | |
if lineno == colno: | |
break | |
pnum() | |
display_line() | |
def pnum(): | |
global lineno, colno, num | |
colno = colno + 1 | |
num = lineno * colno | |
if __name__ == '__main__': | |
pstart() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
""" | |
Problem 1. Multiplication table, Principles of program design (1975). | |
Second version. | |
1 | |
2 4 | |
3 6 9 | |
4 8 12 16 | |
5 10 15 20 25 | |
6 12 18 24 30 36 | |
7 14 21 28 35 42 49 | |
8 16 24 32 40 48 56 64 | |
9 18 27 36 45 54 63 72 81 | |
10 20 30 40 50 60 70 80 90 100 | |
""" | |
from __future__ import print_function | |
import sys | |
lineno = 0 | |
colno = 0 | |
num = 0 | |
def display_line(): | |
global num | |
sys.stdout.write('%s ' % num) | |
def ptable(): | |
global lineno | |
for lineno in range(1, 10 + 1, 1): | |
pline() | |
def pline(): | |
global lineno, colno | |
for colno in range(1, lineno + 1, 1): | |
pnum() | |
display_line() | |
print('\n') | |
def pnum(): | |
global lineno, colno, num | |
num = lineno * colno | |
if __name__ == '__main__': | |
ptable() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment