Last active
March 15, 2018 11:25
-
-
Save clamytoe/a9ca6c5b64bb001687f99855e2dcc89f to your computer and use it in GitHub Desktop.
Script to generate multiplication times tables.
This file contains hidden or 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
| def gen_table(nums, stop=12): | |
| for num in nums: | |
| print(gen_title(num)) | |
| for x in range(1, stop+1): | |
| result = pad(num * x, 3) | |
| print(f' {pad(num)} x {pad(x)} = {result}') | |
| print('') | |
| def gen_title(num): | |
| title = f' times table: {pad(num)} ' | |
| border = '#' * len(title) | |
| return title.upper() + f'\n{border}' | |
| def pad(num, zeros=2): | |
| snum = str(num).zfill(zeros) | |
| return snum | |
| if __name__ == '__main__': | |
| gen_table(range(1, 13)) | |
| gen_table([14]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment