Created
June 20, 2019 13:28
-
-
Save tvdsluijs/f889577933aa6af674706aa25dca228e to your computer and use it in GitHub Desktop.
Small python script to show exponential growth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import locale | |
import math | |
import tableprint as tp | |
locale.setlocale(locale.LC_ALL, "") | |
class Expo_Growth: | |
def __init__(self, start=0, stop=10, words=True): | |
self.millnames = ['', '', ' Million', ' Billion', ' Trillion', ' Quadrillion', ' Quintillion', | |
' Sextillion', ' Septillion', ' Octillion', ' Nonillion', ' Decillion', ' Undecillion', | |
' Duodecillion', ' Tredecillion', ' Quatttuor-decillion', ' Quindecillion', ' Sexdecillion', | |
' Septen-decillion', ' Octodecillion', ' Novemdecillion', ' Vigintillion', | |
' Unvigintillion', 'Duovigintillion', ' Tresvigintillion', ' Quattuorvigintillion', | |
' Quinquavigintillion', ' Sesvigintillion', ' Septemvigintillion', ' Octovigintillion', | |
' Novemvigintillion', ' Trigintillion', ' Untrigintillion', ' Duotrigintillion', | |
' Trestrigintillion', ' Quattuortrigintillion', ' Quinquatrigintillion', | |
' Sestrigintillion', ' Septentrigintillion', ' Octotrigintillion', ' Noventrigintillion', | |
' Quadragintillion', ' Quinquagintillion', ' Sexagintillion', ' Septuagintillion', | |
' Octogintillion', ' Nonagintillion', ' Centillion', ' Uncentillion', ' Decicentillion', | |
' Undecicentillion', ' Viginticentillion', ' Unviginticentillion', ' Trigintacentillion', | |
' Quadragintacentillion', ' Quinquagintacentillion', ' Sexagintacentillion', | |
' Septuagintacentillion', ' Octogintacentillion', ' Nonagintacentillion', ' Ducentillion', | |
' Trecentillion', ' Quadringentillion', ' Quingentillion', ' Sescentillion', | |
' Septingentillion', ' Octingentillion', ' Nongentillion', ' Millinillion'] | |
self.expo = 0 | |
self.start = start | |
self.stop = stop | |
self.llist = [] | |
self.words = words | |
self.create_growth() | |
self.create_table() | |
def create_table(self): | |
tp.banner("Normal vs Exponential growth, just {} steps".format(self.stop), 105) | |
headers = ['Normal', ' Exponential'] | |
tp.table(self.llist, headers, '5g', [10, 45], 'round') | |
def millify(self, n): | |
n = float(n) | |
millidx = max(0,min(len(self.millnames)-1, | |
int(math.floor(0 if n == 0 else math.log10(abs(n))/3)))) | |
zeros = millidx*3 | |
if zeros > 0: | |
return '{:.0f}{} Kilometers ({} Zero\'s)'.format(n / 10**(3 * millidx), self.millnames[millidx], millidx*3) | |
else: | |
return '{:.0f}{} Kilometers'.format(n / 10 ** (3 * millidx), self.millnames[millidx]) | |
def create_growth(self): | |
for i in range(self.start, self.stop+1): | |
nor = "{} meter".format(i) | |
if i == 1: | |
self.expo = 1 | |
elif i == 2: | |
self.expo = 2 | |
else: | |
self.expo = self.expo * self.expo | |
if self.expo >= 1000: | |
km = round(self.expo / 1000) | |
if self.words: | |
expo_print = "{}".format(self.millify(km)) | |
else: | |
expo_print = "{:,} kilometers".format(km) | |
else: | |
expo_print = "{} meter".format(self.expo) | |
self.llist.append([nor, expo_print]) | |
if __name__ == '__main__': | |
e = Expo_Growth(0, 10, False) | |
e = Expo_Growth(0, 10, True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment