Categories:Viewed: 4 - Published at: a few seconds ago

Write a function that generates fibbonacci series

def Fibonacci(n:int)-> int:
    if n==1:
        fibonacci = 0
    elif n==2:
        fibonacci = 1
    else:
        fibonacci = Fibonacci(n-1) + Fibonacci(n-2)
    return fibonacci

Write a function that returns sine value of the input

def sin(x:float) -> float:
    import math
    return math.sin(x)

Write a function that returns derivative of sine value of the input

def derivative_sin(x:float)-> float:
    import math
    return math.cos(x)

Write a function that returns tan value of the input

def tan(x:float) -> float:
    import math
    return math.tan(x)

Write a function that returns derivative of tan value of the input

def derivative_tan(x:float)-> float:
    import math
    return (1/math.cos(x))**2

Write a function that returns cosine value of the input

def cos(x:float) -> float:
    import math
    return math.cos(x)

Write a function that returns cosine value of the input

def derivative_cos(x:float)-> float:
    import math
    return -(math.sin(x))

Write a function that returns the exponential value of the input

def exp(x) -> float:
    import math
    return math.exp(x)

Write a function that returns Gets the derivative of exponential of x

def derivative_exp(x:float) -> float:
    import math
    return math.exp(x)

Write a function that returns log of a function

def log(x:float)->float:
    import math
    return math.log(x)

Write a function that returns derivative of log of a function

def derivative_log(x:float)->float:
    return (1/x)

Write a function that returns relu value of the input

def relu(x:float) -> float:
    x = 0 if x < 0 else x
    return x

Write a function that returns derivative derivative relu value of the input

def derivative_relu(x:float) -> float:
    x = 1 if x > 0 else 0
    return x

Write a function that returns runs a garbage collector

def clear_memory():
    import gc
    gc.collect()

Write a function that calculates the average time taken to perform any transaction by Function fn averaging the total time taken for transaction over Repetations

def time_it(fn, *args, repetitons= 1, **kwargs):
    import time
    total_time = []

    for _ in range(repetitons):
        start_time = time.perf_counter()
        fn(*args,**kwargs)
        end_time = time.perf_counter()
        ins_time = end_time - start_time
        total_time.append(ins_time)
    return sum(total_time)/len(total_time)