How many halvings? · Combien de demi-réductions ?
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.
Combien de demi-parties ?
n commence à 40. Divisez-le par deux avec n = n // 2 jusqu'à ce qu'il atteigne 0, en comptant les étapes dans steps.
// divise et jette le reste, donc 5 // 2 est 2. Compter combien de fois une boucle a tourné a besoin de sa propre variable, augmentant d'une à chaque tour.
n starts at 40. Halve it with n = n // 2 until it reaches 0, counting the steps in steps. · n commence à 40. Divisez-le par deux avec n = n // 2 jusqu'à ce qu'il atteigne 0, en comptant les étapes dans steps.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.