1
00:00:02,290 --> 00:00:07,960
Hey, in this video, you will learn how to have your program take decisions.

2
00:00:09,450 --> 00:00:16,830
In other words, you can make your program more intelligent so that it responds to different ways depending

3
00:00:16,830 --> 00:00:19,020
on the user inputs.

4
00:00:19,230 --> 00:00:26,320
So exactly what we'll be doing is we will allow the user to decide what they want to do.

5
00:00:26,340 --> 00:00:34,650
So whether they want to add a new to do or to see the existing list of two zoos, because currently

6
00:00:34,650 --> 00:00:41,040
the way the program works is that the user can enter it to do and they see the list of to dos, they

7
00:00:41,040 --> 00:00:42,720
enter another to do.

8
00:00:44,050 --> 00:00:45,490
They see the list again.

9
00:00:45,940 --> 00:00:54,430
So how about not showing the list by default, but only showing that if the user wants to see it, we

10
00:00:54,430 --> 00:00:58,000
can implement that using the match case statement.

11
00:00:58,030 --> 00:01:03,820
Now, Match Case is only available in Python 3.10 or newer versions of Python.

12
00:01:03,850 --> 00:01:10,210
Therefore, for this to work you need to use at least Python 3.10.

13
00:01:11,300 --> 00:01:11,570
Right.

14
00:01:11,570 --> 00:01:14,900
So how do we implement this decision making?

15
00:01:16,790 --> 00:01:25,760
Well, first, we want to ask the user if they want to add a new to do or if they want to see the to

16
00:01:25,760 --> 00:01:26,450
dos.

17
00:01:26,600 --> 00:01:36,020
So what I'm thinking is of changing the message here to type, add or show.

18
00:01:38,310 --> 00:01:40,830
So that's just a string.

19
00:01:41,400 --> 00:01:43,140
The string goes in here.

20
00:01:45,240 --> 00:01:54,660
I would simplify this actually, and just put the string directly here so we don't have so many layers.

21
00:01:55,590 --> 00:01:57,630
Both versions are fine.

22
00:01:58,440 --> 00:02:01,710
But I do think this is a bit more readable.

23
00:02:02,790 --> 00:02:07,080
So by looking at this, you understand that you are asking the user for input.

24
00:02:07,080 --> 00:02:13,440
Since this is an input function and you see what message you are showing to the user.

25
00:02:13,890 --> 00:02:22,350
Now the user is expected to enter, add or show and add or show will be stored in this variable.

26
00:02:23,400 --> 00:02:27,630
So to do will be equal to either add or show.

27
00:02:28,200 --> 00:02:32,580
But I want to change the name of this variable now to make it more meaningful.

28
00:02:34,140 --> 00:02:37,530
User action would make more sense.

29
00:02:39,370 --> 00:02:40,690
And then we say.

30
00:02:42,830 --> 00:02:47,240
Match user action.

31
00:02:48,750 --> 00:02:57,290
A column and press enter and you'll see that points are automatically indents the next line.

32
00:02:57,300 --> 00:03:01,380
So this match is a block match.

33
00:03:01,380 --> 00:03:10,830
Case statement is a block just like while through so much user action case and.

34
00:03:13,390 --> 00:03:15,520
To do is equal to input.

35
00:03:17,080 --> 00:03:18,880
Enter a to do.

36
00:03:22,020 --> 00:03:24,810
Let me complete this and explain it to you.

37
00:03:24,840 --> 00:03:28,020
What I'm doing is show.

38
00:03:30,430 --> 00:03:32,500
Print to dos.

39
00:03:38,050 --> 00:03:42,010
And this will go down here.

40
00:03:43,360 --> 00:03:45,340
And this will be deleted.

41
00:03:45,670 --> 00:03:48,010
And that's the complete code for this video.

42
00:03:48,040 --> 00:03:50,830
Now, let me explain to you what this means.

43
00:03:50,950 --> 00:03:53,320
So we start here, match user action.

44
00:03:53,320 --> 00:03:56,200
This variable, as I said, is this one here.

45
00:03:56,200 --> 00:03:58,390
It will be either add or show.

46
00:03:59,590 --> 00:04:03,970
So we're trying to check here the value of that variable.

47
00:04:04,360 --> 00:04:06,490
We're trying to match that variable.

48
00:04:06,490 --> 00:04:16,180
So if the value of that variable is ad, so if the case is ad, then what we do is we ask the user for

49
00:04:16,180 --> 00:04:21,130
A to do so, they will be prompted again to enter some inputs.

50
00:04:21,130 --> 00:04:23,920
They will enter it to do such as clean the bag.

51
00:04:25,200 --> 00:04:28,200
That to do will be appended to the list.

52
00:04:28,200 --> 00:04:29,460
To that list.

53
00:04:31,370 --> 00:04:32,180
And that's it.

54
00:04:33,170 --> 00:04:39,580
If the user action was show, So if the case is true, then we print out to dos.

55
00:04:39,620 --> 00:04:41,780
So let me execute this.

56
00:04:44,660 --> 00:04:49,550
And so we get this user prompt type ad or show.

57
00:04:49,580 --> 00:04:56,480
If I press, show and press enter, we're going to get an empty list because currently there are no

58
00:04:56,480 --> 00:04:57,190
to dos.

59
00:04:57,290 --> 00:05:01,430
So if I press add, then I get this.

60
00:05:03,360 --> 00:05:05,610
Prompt to enter a new to do.

61
00:05:05,880 --> 00:05:12,480
Clean the bag, press enter again we get type, add or show.

62
00:05:13,200 --> 00:05:15,090
Why do we get again?

63
00:05:15,090 --> 00:05:16,380
Type and or show?

64
00:05:16,410 --> 00:05:22,800
Well, because when we were asked to enter a to do, we were at this point.

65
00:05:24,030 --> 00:05:27,030
And we entered it to do this was executed.

66
00:05:27,660 --> 00:05:29,010
And so.

67
00:05:30,940 --> 00:05:38,620
The loop will be repeated again, so it will go and ask for type at or show again.

68
00:05:39,800 --> 00:05:48,010
So a user enters, add for example, add a stored in the user action variable.

69
00:05:48,020 --> 00:05:49,970
The match case again checks.

70
00:05:49,970 --> 00:05:52,700
If it's ads, it does those things.

71
00:05:52,700 --> 00:05:59,690
If it's show, it does that thing, and then goes back again to the first line of the wild through loop,

72
00:05:59,690 --> 00:06:01,430
which is this line here.

73
00:06:01,670 --> 00:06:06,020
And so the loop iterates over and over again.

74
00:06:07,710 --> 00:06:11,910
Now, how about adding one more option here?

75
00:06:12,690 --> 00:06:17,220
Type at show or exit?

76
00:06:18,140 --> 00:06:20,150
So the user can also enter exits.

77
00:06:20,150 --> 00:06:24,170
In that case, we want to add another case or case exit.

78
00:06:25,550 --> 00:06:27,170
We want to exit the program.

79
00:06:27,170 --> 00:06:32,390
At this point, the way we do that is using the break statement statement.

80
00:06:32,390 --> 00:06:37,250
So it just writes break there and that will break the while loop.

81
00:06:38,250 --> 00:06:43,920
And so since there are no more lines of code down here.

82
00:06:45,320 --> 00:06:52,820
The program will end or you can add here print by and let's see how this works.

83
00:06:52,820 --> 00:06:54,950
So we run the script.

84
00:06:57,170 --> 00:06:59,960
Type ads show or exit ad.

85
00:07:01,900 --> 00:07:08,050
Prepared the highly copter type and show or exit exits.

86
00:07:08,230 --> 00:07:17,380
We get by and the process, the program finishes its execution and that is the complete code for this

87
00:07:17,380 --> 00:07:17,950
video.

88
00:07:17,980 --> 00:07:18,550
Thank you.

89
00:07:18,550 --> 00:07:19,330
I'll see you later.

