import math import tools print "*** Hello from {}! ***".format(__name__) result = math.pi * tools.meaning() * tools.fact(4)
def subMenuOne(): while True: ex = False x = 1 print("\n\nWhich calculator would you like?") print("1) Fibonacci") print("2) Happy Numbers") print("3) Factorial") print("4) Perfect number") print("Or would you like to return back to the root menu?") print("-" * 80, end = "") print("\n" * 16) op1 = ["1", "ibon"] op2 = ["2", "appy"] op3 = ["3", "Fact", "fact"] op4 = ["4", "erf"] opBK = ["eturn", "Back", "back", "oot", "enu"] opEX = ["xit", "Close", "close"] ops = [op1, op2, op3, op4, opBK, opEX] n = tools.inputmulti(">>> ", ops) if n == "1": print("\n" * 30) x =tools.inputint("Which number are you interested in?") list = tools.inputyesno("Would you like the numbers that come before that as well?") if ex == "cancel": break tools.fib(x, list) break elif n == "2": print("\n" * 30) n = tools.inputmulti("Are you looking to create a list or to check a number?", ["list", "check", "cancel"]) y = 0 #dummy value in case of not list if n == "list": list = True x = tools.inputint("How many numbers do you want in the list?") elif n == "cancel": break else: list = False x = tools.inputint("Which number do you want to check?") if list: y = tools.inputint("These lists can take an extreme amount of time.\nPlease set a limit in seconds.") tools.HapHandler(x, y, list) break elif n == "3": print("\n" * 30) x = tools.inputint("What number do you want the factorial of?") list = tools.inputyesno("Do you want the numbers that come before it?") tools.fact(x, list) break elif n == "4": print("\n" * 30) n = tools.inputmulti("Are you looking to create a list or to check a number?", ["list", "check", "cancel"]) y = 0 #dummy value in case of not list if n == "list": list = True x = tools.inputint("How many numbers do you want in the list?") elif n == "cancel": break else: list = False x = tools.inputint("Which number do you want to check?") if list: y = tools.inputint("These lists can take an extreme amount of time.\nPlease set a limit in seconds.") tools.PerHandler(x, y, list) break elif n == "eturn": ex = False break elif n == "xit": ex = True break else: print("That command was not recognized.\n\n") return ex
''' http://projecteuler.net/problem=34 Solution: 40730 Runtime: 0.128 sec (with PyPy) ''' import time from tools import fact ''' Good enough upper bound for the solution. Though I think 9*6! might be more precise (even less than that, actually). ''' BOUND = fact(9) FACTS = {} for i in range(10): FACTS[str(i)] = fact(i) def find_largest_digit(n, largest='0'): if type(n) != str: n = str(n) if n[0] > largest: return find_largest_digit(n[1:], n[0]) else: return find_largest_digit(n[1:], largest) def sum_fact_of_digits(n): return sum([FACTS[e] for e in str(n)]) def is_candidate(n):