AI Launch Lab
Sign in FR Get updates

Quantum computing basics · Lesson 1 of 3

Bits and qubits

A classical bit is 0 or 1. A qubit is described by two numbers called amplitudes, one for 0 and one for 1. We can write the state as a pair [a, b].

When the qubit is measured, the result is 0 with probability |a|² and 1 with probability |b|². The two probabilities always add up to 1. Amplitudes can be negative or even complex numbers (Python writes the imaginary unit as j, as in 0.8j); abs() gives their size.

The state [1, 0] always gives 0. The state [0.7071, 0.7071] gives 0 or 1 with equal chance: this is a superposition.

Your turn

Write probabilities(state), which takes [a, b] and returns the list [p0, p1] of measurement probabilities.

Loading Python (about 12 MB, once)…

    Checks

    • ○ [1, 0] always gives 0
    • ○ complex amplitudes work
    • ○ negative amplitudes work

    Output

    All courses