0% found this document useful (0 votes)
5 views

4) Write A Program To Add and Multipe Complex Number

Uploaded by

shireeshapetta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

4) Write A Program To Add and Multipe Complex Number

Uploaded by

shireeshapetta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

4)write a program to add and multiply complex number

# Function to add two complex numbers


def add_complex(num1, num2):
return num1 + num2

# Function to multiply two complex numbers


def multiply_complex(num1, num2):
return num1 * num2

# Taking input from the user


real1 = float(input("Enter the real part of the first complex number: "))
imag1 = float(input("Enter the imaginary part of the first complex number: "))
real2 = float(input("Enter the real part of the second complex number: "))
imag2 = float(input("Enter the imaginary part of the second complex number: "))

# Creating complex numbers


complex1 = complex(real1, imag1)
complex2 = complex(real2, imag2)

# Adding and multiplying the complex numbers


sum_result = add_complex(complex1, complex2)
product_result = multiply_complex(complex1, complex2)

# Displaying the results


print(f"The sum of {complex1} and {complex2} is: {sum_result}")
print(f"The product of {complex1} and {complex2} is: {product_result}")

You might also like