improved py for PEP8

This commit is contained in:
pezy_mbp
2015-05-10 10:30:46 +08:00
parent 45aceb9f1e
commit f6700c3483

View File

@@ -2,8 +2,8 @@ import math
from decimal import * from decimal import *
sec = 1000000 sec = 1000000
min = 60 * sec minute = 60 * sec
hour = 60 * min hour = 60 * minute
day = 24 * hour day = 24 * hour
month = 30 * day month = 30 * day
year = 365 * day year = 365 * day
@@ -15,39 +15,41 @@ century = 100 * year
# ==> n == exp(W(c)) # ==> n == exp(W(c))
# see http://en.wikipedia.org/wiki/Lambert_W_function#Example_2 # see http://en.wikipedia.org/wiki/Lambert_W_function#Example_2
def nlgn(c):
lower = 0.0 def n_lgn(c):
upper = 10e13 lower = 0.0
while True: upper = 10e13
middle = (lower + upper) / 2 while True:
if lower == middle or middle == upper: middle = (lower + upper) / 2
return middle if lower == middle or middle == upper:
if middle * math.log(middle, 2) > c: return middle
upper = middle if middle * math.log(middle, 2) > c:
else: upper = middle
lower = middle else:
lower = middle
# n! # n!
def defactorial(c): def de_factorial(c):
n = 0 n = 0
while True: while True:
if math.factorial(n) >= c: if math.factorial(n) >= c:
return n - 1; return n - 1
else: else:
n += 1 n += 1
# lg(n) # lg(n)
print("2 ^ 10 ^ 6") print("2 ^ 10 ^ 6")
print("2 ^ ( %d * 10 ^ 6 )" % (min/sec)) print("2 ^ ( %d * 10 ^ 6 )" % (minute / sec))
print("2 ^ ( %d * 10 ^ 6 )" % (hour/sec)) print("2 ^ ( %d * 10 ^ 6 )" % (hour / sec))
print("2 ^ ( %d * 10 ^ 6 )" % (day/sec)) print("2 ^ ( %d * 10 ^ 6 )" % (day / sec))
print("2 ^ ( %d * 10 ^ 6 )" % (month/sec)) print("2 ^ ( %d * 10 ^ 6 )" % (month / sec))
print("2 ^ ( %d * 10 ^ 6 )" % (year/sec)) print("2 ^ ( %d * 10 ^ 6 )" % (year / sec))
print("2 ^ ( %d * 10 ^ 6 )" % (century/sec)) print("2 ^ ( %d * 10 ^ 6 )" % (century / sec))
print("") print("")
# sqrt(n) # sqrt(n)
print("{:.1e}".format(Decimal(sec ** 2))) print("{:.1e}".format(Decimal(sec ** 2)))
print("{:.1e}".format(Decimal(min ** 2))) print("{:.1e}".format(Decimal(minute ** 2)))
print("{:.3e}".format(Decimal(hour ** 2))) print("{:.3e}".format(Decimal(hour ** 2)))
print("{:.5e}".format(Decimal(day ** 2))) print("{:.5e}".format(Decimal(day ** 2)))
print("{:.6e}".format(Decimal(month ** 2))) print("{:.6e}".format(Decimal(month ** 2)))
@@ -56,7 +58,7 @@ print("{:.9e}".format(Decimal(century ** 2)))
print("") print("")
# n # n
print("{:.1e}".format(Decimal(sec))) print("{:.1e}".format(Decimal(sec)))
print("{:.1e}".format(Decimal(min))) print("{:.1e}".format(Decimal(minute)))
print("{:.1e}".format(Decimal(hour))) print("{:.1e}".format(Decimal(hour)))
print("{:.2e}".format(Decimal(day))) print("{:.2e}".format(Decimal(day)))
print("{:.3e}".format(Decimal(month))) print("{:.3e}".format(Decimal(month)))
@@ -64,17 +66,17 @@ print("{:.4e}".format(Decimal(year)))
print("{:.4e}".format(Decimal(century))) print("{:.4e}".format(Decimal(century)))
print("") print("")
# n lg(n) # n lg(n)
print(nlgn(sec)) print(n_lgn(sec))
print(nlgn(min)) print(n_lgn(minute))
print(nlgn(hour)) print(n_lgn(hour))
print(nlgn(day)) print(n_lgn(day))
print(nlgn(month)) print(n_lgn(month))
print(nlgn(year)) print(n_lgn(year))
print(nlgn(century)) print(n_lgn(century))
print("") print("")
# n^2 # n^2
print(math.sqrt(sec)) print(math.sqrt(sec))
print(math.sqrt(min)) print(math.sqrt(minute))
print(math.sqrt(hour)) print(math.sqrt(hour))
print(math.sqrt(day)) print(math.sqrt(day))
print(math.sqrt(month)) print(math.sqrt(month))
@@ -82,17 +84,17 @@ print(math.sqrt(year))
print(math.sqrt(century)) print(math.sqrt(century))
print("") print("")
# n^3 # n^3
print(sec ** (1/3.0)) print(sec ** (1 / 3.0))
print(min ** (1/3.0)) print(minute ** (1 / 3.0))
print(hour ** (1/3.0)) print(hour ** (1 / 3.0))
print(day ** (1/3.0)) print(day ** (1 / 3.0))
print(month ** (1/3.0)) print(month ** (1 / 3.0))
print(year ** (1/3.0)) print(year ** (1 / 3.0))
print(century ** (1/3.0)) print(century ** (1 / 3.0))
print("") print("")
# 2^n # 2^n
print(math.log(sec, 2)) print(math.log(sec, 2))
print(math.log(min, 2)) print(math.log(minute, 2))
print(math.log(hour, 2)) print(math.log(hour, 2))
print(math.log(day, 2)) print(math.log(day, 2))
print(math.log(month, 2)) print(math.log(month, 2))
@@ -100,10 +102,10 @@ print(math.log(year, 2))
print(math.log(century, 2)) print(math.log(century, 2))
print("") print("")
# n! # n!
print(defactorial(sec)) print(de_factorial(sec))
print(defactorial(min)) print(de_factorial(minute))
print(defactorial(hour)) print(de_factorial(hour))
print(defactorial(day)) print(de_factorial(day))
print(defactorial(month)) print(de_factorial(month))
print(defactorial(year)) print(de_factorial(year))
print(defactorial(century)) print(de_factorial(century))