1
00:00:05,110 --> 00:00:11,500
In this section we looked at blocks in Python and
saw how the level of indentation is crucial in determining

2
00:00:11,620 --> 00:00:14,080
which block a line of code belongs to.

3
00:00:14,080 --> 00:00:18,480
We then used if and else to test conditions
and only execute blocks of code

4
00:00:18,490 --> 00:00:25,270
If those conditions were either True or False.
We created more complex conditions and saw how to use elif

5
00:00:25,510 --> 00:00:32,659
to check several conditions in turn. Next,
we moved on to execute blocks of code repeatedly, using loops.

6
00:00:32,800 --> 00:00:35,860
The first type of loop we used was the for statement.

7
00:00:35,860 --> 00:00:42,580
It's used to iterate through a range of values.
for is used when you know in advance how many times you

8
00:00:42,580 --> 00:00:44,500
want to go around the loop.

9
00:00:44,500 --> 00:00:51,130
Next we looked at while loops. They're used to loop as long
as the condition is True. while loops are generally

10
00:00:51,130 --> 00:00:58,270
used when you don't know in advance how many times
the loop should execute. We covered continue and break

11
00:00:58,510 --> 00:01:04,180
to interrupt the normal flow of a for loop,
and else to define a block that always executes if the loop

12
00:01:04,269 --> 00:01:06,560
finishes without break.

13
00:01:06,580 --> 00:01:12,070
So this is a different use of the else keyword to how
it's used in an if statement, which is unfortunate

14
00:01:12,100 --> 00:01:20,710
and can be confusing; but that's the keyword that was chosen.
A couple of videos weren't related to Python loops.

15
00:01:20,710 --> 00:01:25,890
We digressed to look at augmented assignment and why
you should use it in preference to a normal assignment.

16
00:01:26,950 --> 00:01:30,130
We also discussed Pep 8, and the style of your python code.

17
00:01:31,280 --> 00:01:35,640
So we'll finish this section now with a short challenge,
just to give you a chance to practise what you've

18
00:01:35,660 --> 00:01:37,360
learnt in the course so far.

19
00:01:37,460 --> 00:01:41,990
You'll have a chance to make use of the string formatting,
that we covered in previous videos, as well

20
00:01:41,990 --> 00:01:45,320
as reading in input that the user types at the keyboard.

21
00:01:45,320 --> 00:01:49,900
You'll also get a chance to practise using
if to execute code depending on a condition.

22
00:01:51,130 --> 00:01:56,080
So your challenge is to write a program to print a
number of options, and allow the user to select an

23
00:01:56,080 --> 00:01:57,820
option from the list.

24
00:01:57,910 --> 00:02:02,880
The options should be numbered from 1 to 9, although
you can use less than nine options if you want to.

25
00:02:03,130 --> 00:02:06,390
Make sure that there are at least four options.

26
00:02:06,490 --> 00:02:09,150
As an example, your program might look like the following.

27
00:02:09,190 --> 00:02:14,100
So as you can see in this example, we've got a heading
at the top, we've got five options and a final option

28
00:02:14,350 --> 00:02:19,510
also added, which is zero to exit the program.
So the program should continue looping, allowing the user

29
00:02:19,510 --> 00:02:26,600
to choose one of the options each time around, and the
loop should only terminate when the user chooses zero.

30
00:02:26,620 --> 00:02:31,360
If the user makes a valid choice, the program should
print a short message and the message should include

31
00:02:31,360 --> 00:02:36,370
the value that they typed. Don't print
a different message for each choice.

32
00:02:36,370 --> 00:02:39,640
The only thing that should change is the number they typed.

33
00:02:39,640 --> 00:02:44,090
Although you could print out the description, I want to show you a much better way of doing that later.

34
00:02:44,140 --> 00:02:48,730
We're keeping this simple because there's lots of things that we still haven't covered yet.

35
00:02:48,760 --> 00:02:50,890
Now if their choice isn't one of the options in the menu,

36
00:02:50,890 --> 00:02:57,970
nothing should be printed (although you can still
see their input on the screen). As an optional extra,

37
00:02:58,090 --> 00:03:01,410
modify the program so that the menu is printed again,

38
00:03:01,540 --> 00:03:03,390
If they choose an invalid option.

39
00:03:03,580 --> 00:03:04,970
Be careful with that one.

40
00:03:05,020 --> 00:03:09,970
You may start off by duplicating the code to print the
menu but it's possible to write the program without

41
00:03:10,000 --> 00:03:12,560
duplicating the print lines.

42
00:03:12,880 --> 00:03:13,650
So that's the challenge.

43
00:03:13,650 --> 00:03:16,900
See how you go with that, and in the next
video we'll go through the solution.

44
00:03:16,900 --> 00:03:18,040
See you in that next video.

