#optable.py # Operation table. Mult, div, add, sub, mod. def print_table (size, op): print(" ", op, end="") for i in range(size+1): # header row (column headings) print("%4d"%(i), end="") #setw 4 print() print(" |", end="") print("----"*(size+1)) #row of dashes for row in range(size+1): #each row print("%3d|"%(row), end="") #row number| for col in range(size+1): #each column of row if op == '+': res = row+col elif op == '-': res = row-col elif op == '*': res = row*col elif op == '/': if col != 0: res = row//col #integer divide else: res = '-' elif op == '%': if col != 0: res = row%col else: res = '-' if res != '-': print("%4d"%(res), end="") else: print(" -", end="") print() ans = 'y' while ans == 'y': uprange = int(input("Enter upper range of table: ")) op = input("Enter operation character (* / + - %): ") print_table(uprange,op) ans = input("Another? (y or n): ") """ Make table of math operation Enter upper range of table: 10 Enter operation character (* / + - %): * * 1 2 3 4 5 6 7 8 9 10 |---------------------------------------- 1| 1 2 3 4 5 6 7 8 9 10 2| 2 4 6 8 10 12 14 16 18 20 3| 3 6 9 12 15 18 21 24 27 30 4| 4 8 12 16 20 24 28 32 36 40 5| 5 10 15 20 25 30 35 40 45 50 6| 6 12 18 24 30 36 42 48 54 60 7| 7 14 21 28 35 42 49 56 63 70 8| 8 16 24 32 40 48 56 64 72 80 9| 9 18 27 36 45 54 63 72 81 90 10| 10 20 30 40 50 60 70 80 90 100 Another? (y or n): y Enter upper range of table: 12 Enter operation character (* / + - %): % % 1 2 3 4 5 6 7 8 9 10 11 12 |------------------------------------------------ 1| 0 1 1 1 1 1 1 1 1 1 1 1 2| 0 0 2 2 2 2 2 2 2 2 2 2 3| 0 1 0 3 3 3 3 3 3 3 3 3 4| 0 0 1 0 4 4 4 4 4 4 4 4 5| 0 1 2 1 0 5 5 5 5 5 5 5 6| 0 0 0 2 1 0 6 6 6 6 6 6 7| 0 1 1 3 2 1 0 7 7 7 7 7 8| 0 0 2 0 3 2 1 0 8 8 8 8 9| 0 1 0 1 4 3 2 1 0 9 9 9 10| 0 0 1 2 0 4 3 2 1 0 10 10 11| 0 1 2 3 1 5 4 3 2 1 0 11 12| 0 0 0 0 2 0 5 4 3 2 1 0 Another? (y or n): y """