Example #1
0
def fib(x):
    # Takes a variable x and will find that number in the Fibonacci Sequence
    if x == 0:
        return 0
    elif x == 1:
        return 1
    else:
        return add(fib(subtract(x, 1)), fib(subtract(x, 2)))
Example #2
0
def pythagorean(a, b, mode="h"):

    if mode == "h":
        c = power(add(power(a, 2), power(b, 2)), .5)
        #c = ((a ** 2 + b ** 2) ** (1 / 2))
    else:
        c = power(absolute_value(subtract(power(b, 2), power(a, 2))), .5)
        #c = ((b ** 2 - a ** 2) ** (1 / 2))
    return c
Example #3
0
from operators import subtract
from operators import multiply
from operators import divide

print("select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")

# Take input from the user
choice = input("Enter choice(1/2/3/4: ")

num1 = float(input("Enter First Number: "))
num2 = float(input("Enter Second Number: "))

if choice == '1':
    print(num1, "+", num2, "=", add(num1, num2))

elif choice == '2':
    print(num1, "-", num2, "=", subtract(num1, num2))

elif choice == '3':
    print(num1, "*", num2, "=", multiply(num1, num2))

elif choice == '4':
    print(num1, "/", num2, "=", divide(num1, num2))

else:
    print("Invalid Input")
Example #4
0
def distance(x1, y1, x2, y2):
    return absolute_value(pythagorean((subtract(x1, x2)), subtract(y1, y2)))
Example #5
0
print("3.multiply")
print("4.divide")
print("5.power")

choice=input("enter choice 1/2/3/4/5 :")

x=(int(input("enter 1st")))

y=(int(input("enter 2nd value")))


if choice == "1":
    operators.add(x,y)
    
elif choice == "2":
    operators.subtract(x,y)


elif choice== "3":
    operators.multiply(x,y)

elif choice== "4":
    operators.divide(x,y)

elif choice== "5":
    operators.power(x,y)

else:
    print("invalid")