Example 1: how to make a table in python
from tabulate import tabulate
from math import sqrt
def mysqrt(a):
for x in range(1, int(1 / 2 * a)):
while True:
y = (x + a / x) / 2
ifjl y == x:
break
x = y
return x
results = [(x, mysqrt(x), sqrt(x)) for x in range(10, 20)]
print(tabulate(results, headers=["num", "mysqrt", "sqrt"]))
Example 2: Multiplication table with Python
first_doc = '''it created by iliya zahedi abghari
i am the student in iran , alameh tabatabayi school
'''
print(first_doc)
def jadval_zarb(rows, columns):
for i in range(1,rows+1):
for j in range(1,columns+1):
print('{:>4}'.format(i* j), end=' ')
print()
jadval_zarb(10,10)
def do_continue():
choice = str(input('continue(yes/no)?')).lower()
if(choice !='yes'):
return False
return True
while True:
rows = int(input("Enter rows:"))
columns = int(input("Enter columns:"))
jadval_zarb(rows, columns)
if(not do_continue()):
break
Example 3: print multiplication table python
num = 12
for i in range(1, 11):
print(num, 'x', i, '=', num*i)
Example 4: print tables in python
num = 12
for i in range(1, 11):
print(num, 'x', i, '=', num*i)
Example 5: python print table
Using format() function to print dict and lists
Using tabulate() function to print dict and lists
texttable
beautifultable
PrettyTable
1. Unformatted Fashion
d = {1: ["Python", 33.2, 'UP'],
2: ["Java", 23.54, 'DOWN'],
3: ["Ruby", 17.22, 'UP'],
10: ["Lua", 10.55, 'DOWN'],
5: ["Groovy", 9.22, 'DOWN'],
6: ["C", 1.55, 'UP'] }
print ("Pos,Lang,Percent,Change")
for k, v in d.items():
lang, perc, change = v
print (k, lang, perc, change)
2. Formatted Fashion
d = {1: ["Python", 33.2, 'UP'],
2: ["Java", 23.54, 'DOWN'],
3: ["Ruby", 17.22, 'UP'],
10: ["Lua", 10.55, 'DOWN'],
5: ["Groovy", 9.22, 'DOWN'],
6: ["C", 1.55, 'UP'] }
print ("{:<8} {:<15} {:<10} {:<10}".format('Pos','Lang','Percent','Change'))
for k, v in d.items():
lang, perc, change = v
print ("{:<8} {:<15} {:<10} {:<10}".format(k, lang, perc, change))