How many halvings? · 要减半几次?
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
This one builds on a lesson you haven't finished yet. Do that lesson first: · 此任务基于您尚未完成的课程。请先完成以下课程:
Python Basics · Python 基础 · While loops · while 循环 →
English
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 从 40 开始。用 n = n // 2 不断减半直到变成 0,把步数记在 steps 里。
// 相除并丢掉余数,所以 5 // 2 是 2。要数循环转了多少轮,需要一个自己的变量,每轮加一。
n starts at 40. Halve it with n = n // 2 until it reaches 0, counting the steps in steps. · n 从 40 开始。用 n = n // 2 不断减半直到变成 0,把步数记在 steps 里。
Click Run to see the output here. · 点击“运行”查看此处输出。