How many halvings?
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
This one builds on a lesson you haven't finished yet. Do that lesson first:
Python Basics · While loops →
How many halvings?
n starts at 40. Halve it with n = n // 2 until it reaches 0, counting the steps in steps.
// divides and throws the remainder away, so 5 // 2 is 2. Counting how many times a loop went round needs its own variable, going up by one each turn.
n starts at 40. Halve it with n = n // 2 until it reaches 0, counting the steps in steps.
Click Run to see the output here.