1
juvenile0 = int(input("enter value"))
adult0 = int(input("enter value"))
senile0 = int(input("enter value"))
birth = int(input("enter value"))

#generation 1 formulae
juvenile1 = adult0 * birth
adult1 = juvenile0 * 0.5
senile1 = adult0 + (senile0 * 0.2)
#generation 2 formulae
juvenile2 = adult1 * birth
adult2 = juvenile1 * 0.5
senile2 = adult1 + (senile1 * 0.2)
#generation 3 formulae
juvenile3 = adult2 * birth
adult3 = juvenile2 * 0.5
senile3 = adult2 + (senile2 * 0.2)
#generation 4 formulae
juvenile4 = adult3 * birth
adult4 = juvenile3 * 0.5
senile4 = adult3 + (senile3 * 0.2)
#generation 5 formulae
juvenile5 = adult4 * birth
adult5 = juvenile4 * 0.5
senile5 = adult4 + (senile4 * 0.2)

print("____________________________________________")
print("|generations  |juveniles|  adults | seniles |")
print("|_____________|_________|_________|_________|")
print("|generation 0 |  ""%.2f" % juvenile0,"  | ""%.2f" % adult0,"   | ""%.2f" % senile0,"   |")
print("|_____________|_________|_________|_________|")
print("|generation 1 |  ""%.2f" % juvenile1,"  | ""%.2f" % adult1,"   |      ""%.2f" % senile1,"   |")
print("|_____________|_________|_________|_________|")
print("|generation 2 |  ""%.2f" % juvenile2,"  | ""%.2f" % adult2,"   | ""%.2f" % senile2,"   |")
print("|_____________|_________|_________|_________|")
print("|generation 3 |  ""%.2f" % juvenile3,"  | ""%.2f" % adult3,"   | ""%.2f" % senile3,"   |")
print("|_____________|_________|_________|_________|")
print("|generation 4 |  ""%.2f" % juvenile4,"  | ""%.2f" % adult4,"   | ""%.2f" % senile4,"   |")
print("|_____________|_________|_________|_________|")
print("|generation 5 |  ""%.2f" % juvenile5,"  | ""%.2f" % adult5,"   |  ""%.2f" % senile5,"  |")
print("|_____________|_________|_________|_________|")

I would like to know the most efficient way to create a table in python. The code i have right now works, however when the user enters larger numbers, the table starts to break. Is there a neater way to create a table in python?

A.U
  • 11
  • 4
  • You need to consider the most amount of characters will be in your output if you want to align http://stackoverflow.com/questions/27886954/table-creation-with-csv-data/27887506#27887506 – Padraic Cunningham Apr 26 '16 at 21:30
  • yes, i would like the users input to be multiplied, then displayed, and then that result to be multiplied and displayed e.t.c. – A.U Apr 26 '16 at 21:32
  • Is there a simpler way to create this: – A.U Apr 26 '16 at 21:34

2 Answers2

1

You could use this library: https://pypi.python.org/pypi/tabulate

from tabulate import tabulate

table = [
    ['generations', 'juveniles', 'adults', 'seniles'],
    ['generation 0', '%.2f' % juvenile0, '%.2f' % adult0, '%.2f' % senile0]
]
print(tabulate(table, tablefmt='grid'))
JoseKilo
  • 2,343
  • 1
  • 16
  • 28
0

How about you don't rediscover the wheel and use something that already exists?

You could for example use:

somada141
  • 1,274
  • 2
  • 18
  • 25