Boqonnaa 6 Teeknooloojii Odeeffannoo kutaa 12
range(): where it starts, stops and steps
daqiiqaa 4 · Gaaffii qormaata darbe 2 hojjetaman
Kutaalee barnootaa
Barnoota achii jalqabee taphachiisuuf kutaa tokko tuqi.
Barnoota viidiyoo Temari daqiiqaa 4 boqonnaa 6 Teeknooloojii Odeeffannoo kutaa 12: range(): where it starts, stops and steps. Barnoonni kun Afaan Ingiliziitiin.
Dabalata boqonnaa 6
Fuulli boqonnaa kanaa wanta Temari boqonnaa kana irratti qabu kan hafe qaba, fakkeenyaaf yaadannoo gabaabaa fi gaaffii shaakalaa deebii isaanii waliin.
Fuula boqonnaa 6 baniWanta barnoonni jedhu hunda
Jechoota barnootaa kutaa kutaan. Barnoota achii jalqabee taphachiisuuf yeroo tuqi.
0:00Introduction
In Python, a for loop with range counts for you. But range has one habit that trips students up: it never reaches the number you tell it to stop at. Learn its three forms, and you can write out any sequence without running the code.
0:17A for loop counts with range
First, the loop. A loop repeats a block of statements. A for loop takes each value of a sequence in turn. Here: for i in range five, colon. The print statement is indented under it, because Python uses indentation to mark the block.
Range gives the loop its numbers. With one number, range starts at zero, counts up by one, and stops before that number. So range five gives zero, one, two, three, four. That is five values, but never five itself.
0:53Two numbers: a start
Give range two numbers, and the first one is the start. Range two, five starts at two and stops before five: two, three, four. The start is included. The stop is not.
A quick check: how many numbers? Take the stop minus the start. Five minus two is three, and there are three numbers. For range five, the start is zero: five minus zero is five numbers.
1:23Practice question 1Qormaata darbe
Here is a practice question. What sequence of numbers is generated by the Python expression, range(5)? Pause the video, and try it.
With one number, range starts at zero, and it stops before five. So: zero, one, two, three, four. The answer is C. A goes one step too far, to five. B starts at one, but the start is zero. And D also starts at one, so it loses the zero.
2:00Three numbers: a step
Now give range three numbers. The third is the step: how much it adds each time. Range one, ten, two starts at one and adds two each time: one, three, five, seven, nine.
The next number would be eleven. But the stop is ten, and the loop never goes past the stop. So the list ends at nine. Range ten, one hundred, ten would give ten, twenty, and so on up to ninety.
2:34Practice question 2Qormaata darbe
Try this one. What list of numbers is generated by the function, range(1, 10, 2)? Pause, and try it.
Start at one. Add two each time: one, three, five, seven, nine. Eleven would be next, but the stop is ten, so the list ends at nine. The answer is B. A forgets the step, and reaches the stop. C starts at two, but the start is one. And D runs on to eleven, past the stop.
3:12Summary
So remember. Range always stops before the stop number. With one number, it starts at zero. With two, the first one is the start. With three, the third one is the step. Keep practising questions like these on Temari.et.
Boqonnaa kana appii keessatti shaakali
Temari boqonnaa kana gara shaakala yeroon daangeffametti jijjiira; utuu hojjettuu ni sirreessa; wanti si hin galinis barsiisaa AI tiin ni ibsama.
Bilisaan jalqabiTemari.et appii Android qaba; Google Play irratti bilisaan argama.

