📜  用于复数乘除的Python程序

📅  最后修改于: 2022-05-13 01:56:56.405000             🧑  作者: Mango

用于复数乘除的Python程序

给定两个复数。任务是乘以和除以它们。

复数的乘法:在Python中,可以使用*运算符将复数相乘

例子:

Input: 2+3i, 4+5i 
Output: Multiplication is : (-7+22j) 

Input: 2+3i, 1+2i
Output: Multiplication is : (-4+7j) 
# Python program to demonstrate
# multiplication of complex numbers
  
  
def mulComplex( z1, z2):
    return z1*z2
   
      
# driver code
z1 = complex(2, 3)
z2 = complex(4, 5)
  
  
print("Multiplication is :", mulComplex(z1,z2))

输出:

Multiplication is : (-7+22j)

复数除法:在Python中,可以使用/运算符来除复数。

例子:

Input: 2+3i, 4+5i
Output: Division  is : (0.5609756097560976+0.0487804878048781j)

Input: 2+3i, 1+2i
Output: Division is :(1.6-0.2j) 
# Python program to demonstrate
# division of complex numbers
  
  
def divComplex( z1, z2):
    return z1 / z2
  
# driver code
  
z1 = complex(2, 3)
z2 = complex(4, 5)
  
print( "Division is :", (divComplex(z1, z2))

输出:

Division is : (0.5609756097560976+0.0487804878048781j)