for knows from the start how many turns it takes. Sometimes you cannot know: "until the number runs out", "until the wall". while asks a question and keeps going as long as the answer is true.
steps = 0while key > 1:key = key // 2steps += 1return steps
// is whole division: it drops the fraction (7 // 2 is 3). This loop halves the number each turn and counts how many turns it takes to reach 1.Ask yourself two things about every while: is there something inside the loop that changes the condition, and is my answer right if the loop never runs? The second usually shows up at the edges, with 0 or an empty list.