Example #1
0
from tools import fib
from time import time
start = time()

print sum([even for even in fib(4000000) if even%2==0])

end = time()
print end-start
Example #2
0
from tools import fib
from time import time
start = time()

print sum([even for even in fib(4000000) if even % 2 == 0])

end = time()
print end - start
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