Part of the series

Several example codes

~1 min read • Updated Sep 16, 2025

Program Overview

This Python program reads two numeric inputs from the user: one for the real part and one for the imaginary part of a complex number.
It then constructs the complex number using Python’s complex() function and displays the result.

Python Code:


real_part = float(input("Please enter the real part of the number: "))
imaginary_part = float(input("Please enter the imaginary part of the number: "))

complex_number = complex(real_part, imaginary_part)

print("The complex number is:", complex_number)

Sample Output:


Please enter the real part of the number: 3
Please enter the imaginary part of the number: 4
The complex number is: (3+4j)

Explanation:

Here’s how the program works:
- It uses the input() function to collect two values from the user
- Each value is converted to a decimal using float() for precision
- The complex() function combines the two into a complex number
- The result is printed using the print() function


Written & researched by Dr. Shahin Siami