To write a Python program that reads two integers, creates a complex number using them, and then prints the complex number along with its real and imaginary parts.
- Read an integer input from the user and assign it to the variable
a(real part). - Read another integer input from the user and assign it to the variable
b(imaginary part). - Create a complex number
xusing thecomplex(a, b)function. - Print the complex number
x. - Print the real part of
xusingx.real. - Print the imaginary part of
xusingx.imag.
a=float(input ())
b=float(input ())
c=complex(a,b)
print(c)
print(c.real)
print(c.imag)
Thus,To write a Python program that reads two integers, creates a complex number using them, and then prints the complex number along with its real and imaginary parts is successfully verified.