๐Ÿ“– Python loops ยท Age 9 and up ยท 2:06

The Hundred Hellos: Python loops comic video

A comic book about Python for loops. Learn how range counts, spot the two commonest bugs and save a robot knight from a lot of typing.

โ–ถ Video ยท 2:06 The Hundred Hellos: Python loops comic video

Straight after watching

Now try it yourself

Transcript

0:00 LearnFun Comics. The Hundred Hellos. One knight. One hundred guests. One very tired keyboard.

0:07 Robot Castle

0:08 I must greet 100 guests. I shall type it 100 times!

0:13 Here is the code.

0:15 Stop! Computers love repeating. Use a loop!

0:19 Meet the for loop

0:20 Here is the code.

0:22 It prints: Hello, Hello, Hello

0:25 Line one says: do this 3 times. The spaces before print show which line repeats.

0:31 But what is this i? I have only a saucepan.

0:34 Here is the code.

0:36 It prints: 0, 1, 2

0:39 i is a counter. range(3) starts at 0 and stops before 3.

0:44 Your turn, hero! How many times does this print Hi?

0:51 The answer is 2. range(2) counts 0 and 1. That is 2 times.

0:57 Here is the code.

0:58 It prints: SyntaxError: expected ':'

1:02 Two bugs! The first line needs a colon. The next line needs its spaces.

1:07 He tries something new What does this print?

1:14 The answer is 1 2 3. range(1, 4) starts at 1 and stops before 4.

1:19 The final battle What number comes out?

1:26 The answer is 6. 0 + 1 = 1, then 1 + 2 = 3, then 3 + 3 = 6.

1:34 Two lines. One hundred guests.

1:36 Here is the code.

1:38 My saucepan salutes you!

1:40 Now try it yourself!

1:42 Remember. A for loop repeats the lines with spaces in front. range(3) gives 0, 1, 2: it stops before 3. The first line ends in a colon.

1:54 Next morning a new order arrives: every guest wants a different greeting. His saucepan starts to shake...

2:00 Read this comic and answer the questions yourself, at learn fun dot in.

More videos

Watch next

All videos โ†’
Chat on WhatsApp
Esc

Try