Ejemplo n.º 1
0
def run():
    x = int(input("enter the first_real part:"))
    y = int(input("enter the first_imaginary part:"))
    p = int(input("enter the second_real part:"))
    q = int(input("enter the second_imaginary part:"))

    obj1 = Complex(x, y)
    obj1.display()
    obj2 = Complex(p, q)
    obj1.addition(obj2)
    obj1.substraction(obj2)
    obj1.multiplication(obj2)
    obj1.division(obj2)
Ejemplo n.º 2
0
from complex import Complex

input_data = input(
    "Calculator, format: real,img'operator'real,img - example: 1,1+2,2\n")

if '+' in input_data:
    left, right = input_data.split("+")
    left = Complex.convert_from_string(left)
    right = Complex.convert_from_string(right)
    Complex.print(Complex.addition(left, right))
elif '-' in input_data:
    left, right = input_data.split("-")
    left = Complex.convert_from_string(left)
    right = Complex.convert_from_string(right)
    Complex.print(Complex.subtraction(left, right))
elif '*' in input_data:
    left, right = input_data.split("*")
    left = Complex.convert_from_string(left)
    right = Complex.convert_from_string(right)
    Complex.print(Complex.multiplication(left, right))
elif '/' in input_data:
    left, right = input_data.split("/")
    left = Complex.convert_from_string(left)
    right = Complex.convert_from_string(right)
    Complex.print(Complex.division(left, right))
else:
    print("Wrong input format")