Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python2.7
- # Multiplication table. http://redd.it/2agwnq
- # by tacogratis, adapted from wukaem
- def show_mtable(cols, rows=None):
- """
- Function printing multiplication table.
- rows, cols - ints, dimensions of table. If rows not provided: rows = cols.
- """
- if not rows:
- rows = cols
- # Calculate column width (minimum 2 chars spacing)
- width = len(str(rows * cols)) + 2
- # First row: header
- for num in range(1, cols+1):
- print '\t', num, ' ',
- print '\n' + '-' * ((cols) * 8 )
- # Rest of rows
- for row in range(1, rows+1):
- print row, ' | \t',
- for col in range(1, cols+1):
- print row*col, '\t',
- print
- def main():
- end = input('Up to what number: ')
- endnum = int(end)
- if endnum > 14:
- print 'That number is too high!'
- else:
- show_mtable(endnum)
- if __name__ == "__main__": main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement