Quantum computing basics · Lesson 1 of 3
Quantum computing basics · Lesson 1 of 3
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.
Write probabilities(state), which takes [a, b] and returns the list [p0, p1] of measurement probabilities.
All checks pass. Well done.
Next lesson: Gates change the stateAn AI tutor that gives hints, not answers. It sees your code, its output and this lesson. It can be wrong.