Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Python Numbers code

Practice constructing complex numbers, reading their components, combining them with arithmetic, and promoting a real value to complex.

Beginner ~8 min read

Challenge 1

Create a complex value with real part 2 and imaginary part -3 using the constructor.

python Your answer
value = 
print(value)

Press Ctrl⌘Enter to check your answer

Challenge 2

Read the real component from the existing complex value.

python Your answer
value = 7 + 2j
real_part = 
imaginary_part = value.imag
print(real_part, imaginary_part)

Press Ctrl⌘Enter to check your answer

Challenge 3

Add the two complex values to combine their real and imaginary components.

python Your answer
left = 2 + 3j
right = -1 + 4j
total = 
print(total)

Press Ctrl⌘Enter to check your answer

Challenge 4

Convert a real measurement to the complex type, with an imaginary component of zero.

python Your answer
measurement = 6.5
value = 
print(value, type(value).__name__)

Press Ctrl⌘Enter to check your answer