Skip to content

Instantly share code, notes, and snippets.

@clamytoe
Last active March 15, 2018 11:25
Show Gist options
  • Save clamytoe/a9ca6c5b64bb001687f99855e2dcc89f to your computer and use it in GitHub Desktop.
Save clamytoe/a9ca6c5b64bb001687f99855e2dcc89f to your computer and use it in GitHub Desktop.
Script to generate multiplication times tables.
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