Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import log, log2, log10, e
- # The available calculations are these: log, ln, powers
- calcsAvailable = ["log2", "log10", "ln", "e^"]
- # Function 1
- def recursion(calculation, times, number):
- if calculation not in calcsAvailable:
- print("We cannot perform the act '" + str(calculation) + ")")
- return -1
- # Now, we continue
- # Case-0
- if calculation == calcsAvailable[0]:
- result = number
- pretty = ""
- for time in range(int(times)):
- result = log2(result)
- if time != times - 1:
- pretty += "log2("
- else:
- pretty += "log2(" + str(number)
- for time in range(int(times)):
- pretty += ")"
- pretty += " = " + str(result)
- print(pretty)
- return result
- # Case-1
- if calculation == calcsAvailable[1]:
- result = number
- pretty = ""
- for time in range(int(times)):
- result = log10(result)
- if time != times - 1:
- pretty += "log10("
- else:
- pretty += "log10(" + str(number)
- for time in range(int(times)):
- pretty += ")"
- pretty += " = " + str(result)
- print(pretty)
- return result
- # Case-2
- if calculation == calcsAvailable[2]:
- result = number
- pretty = ""
- for time in range(int(times)):
- result = log(result)
- if time != times - 1:
- pretty += "ln("
- else:
- pretty += "ln(" + str(number)
- for time in range(int(times)):
- pretty += ")"
- pretty += " = " + str(result)
- print(pretty)
- return result
- # MAIN FUNCTION
- print()
- print(recursion("log2", 4, 2**16))
- print()
- print(recursion("log10", 2, 10**100))
- print()
- print(recursion("ln", 2, e**(e**4)))
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement