1
00:00:04,500 --> 00:00:07,500
Alright, so how did you get on with the
challenge that I introduced in the

2
00:00:07,500 --> 00:00:11,400
last video? Did you manage to complete it?
If your program behaves correctly, then

3
00:00:11,400 --> 00:00:14,700
well done. You may have written your code
differently to the solution you'll see in

4
00:00:14,700 --> 00:00:18,660
this video, but as long as it works, then
that's fine. I'm gonna start out by

5
00:00:18,660 --> 00:00:29,840
creating a new Python file here. I'm
gonna call this one summarychallenge.

6
00:00:29,840 --> 00:00:34,700
So I'm gonna start with a few lines that
print the menu, print parenthesis please

7
00:00:34,710 --> 00:00:43,019
choose your option from the list below :
there. We want a double quote and right

8
00:00:43,019 --> 00:00:46,230
parenthesis. Alright, so we'll go with
five options; print parentheses double

9
00:00:46,230 --> 00:00:53,159
quotes 1 colon backslash t to indent the
code, Learn Python, closing off the line

10
00:00:53,159 --> 00:01:00,149
there. Print parentheses again, double
quotes 2 : backslash t Learn Java closing

11
00:01:00,149 --> 00:01:08,420
off the line, print parentheses double
quotes 3 colon backslash t go swimming,

12
00:01:08,420 --> 00:01:12,690
closing off the line again. I'm sure, by now,
you know you need to do a double quote

13
00:01:12,690 --> 00:01:16,560
and a parenthesis there, as I'm doing.
Next we're gonna do a 4 in double

14
00:01:16,560 --> 00:01:23,880
quotes, colon backslash t Have dinner, 
and then on line six, print parentheses

15
00:01:23,880 --> 00:01:29,730
double quotes 5 colon backslash t Go to
bed. Then the last option was the exit,

16
00:01:29,730 --> 00:01:37,590
print parentheses double quotes 0 colon
backslash t Exit. Okay. So I've used a tab

17
00:01:37,590 --> 00:01:41,250
to separate the option numbers from the
descriptions. The menu might look better

18
00:01:41,250 --> 00:01:45,680
with just a single space, but I want you
to see escape characters used in strings.

19
00:01:45,680 --> 00:01:49,830
We've only seen tabs used in strings in
one video - the escape character in the

20
00:01:49,830 --> 00:01:54,030
last section. It's not something you'll
probably do very often, which means it's

21
00:01:54,030 --> 00:01:56,550
something that you might forget about.
Alright, so the next part of the

22
00:01:56,550 --> 00:02:00,450
challenge was to keep looping. So we need to
introduce a while loop to do that. So I'm

23
00:02:00,450 --> 00:02:06,540
gonna do a while true, start that on line 9
Next thing we need to do is to get

24
00:02:06,540 --> 00:02:12,030
the user's input, or the user's choice, so
we're going to type choice is equal

25
00:02:12,030 --> 00:02:17,580
to input parentheses. Now our loop is
going to keep looping around forever so

26
00:02:17,580 --> 00:02:20,099
we need to
break out of it somehow, and we can do

27
00:02:20,100 --> 00:02:23,940
that by checking to see if they've typed
zero. So I'm going to do that on line 12.

28
00:02:23,940 --> 00:02:32,280
If choice is equal to, two equal signs,
zero and double quotes : break.

29
00:02:32,280 --> 00:02:36,180
Alright. So next we need to check for a valid
option. You may have used a series of

30
00:02:36,180 --> 00:02:41,549
elif blocks here, but a more concise way
is to use in. So I'm going to tab

31
00:02:41,549 --> 00:02:47,280
back here and go to the elif here,
matching up with the if we've got on line 12.

32
00:02:47,280 --> 00:02:54,120
So elif choice in, and in double quotes,
1 2 3 4 5, closing off the double quote

33
00:02:54,120 --> 00:03:01,140
and colon, print parentheses double
quotes You chose, left and right curly

34
00:03:01,140 --> 00:03:06,810
braces, double quote dot format and
choice in parentheses. For this

35
00:03:06,810 --> 00:03:10,739
particular program, using in results in
much simpler code than a series of

36
00:03:10,739 --> 00:03:15,540
elifs, and if you're not sure how that
works, review the in and not in video, earlier

37
00:03:15,540 --> 00:03:20,160
in this section. Alright, so that's the
first part of the challenge completed.

38
00:03:20,160 --> 00:03:24,180
Run the program and test it with various
inputs. Entering 1 to 5 should print the

39
00:03:24,180 --> 00:03:29,200
message - anything else except a 0 will be
ignored. When 0 is entered, the program

40
00:03:29,200 --> 00:03:32,480
terminates. As I said, you may have done
things a little bit differently from

41
00:03:32,489 --> 00:03:35,849
what you're seeing here. The main thing is
that you get the same output and the same

42
00:03:35,849 --> 00:03:40,169
results. So basically, if your solution
behaves correctly, then well done, you've

43
00:03:40,169 --> 00:03:44,250
completed the challenge. Alright, so
moving on. In the next video, I'm going to

44
00:03:44,250 --> 00:03:47,740
go over my solution to the optional
extra part of the challenge.

45
00:03:47,740 --> 00:03:50,740
See you in the next video.

