1
00:00:00,950 --> 00:00:07,860
At this point of the program development, we allow the user to add and show to the items.

2
00:00:07,880 --> 00:00:10,100
The user can also exit the program.

3
00:00:10,670 --> 00:00:17,420
But in this video, we want to add a new feature, a new edit feature which allows the user to edit

4
00:00:17,420 --> 00:00:19,460
existing to do items.

5
00:00:20,640 --> 00:00:24,330
So how do we go about adding a new feature?

6
00:00:24,690 --> 00:00:30,060
Well, to be able to add a new feature, you should think from the user's perspective.

7
00:00:30,510 --> 00:00:33,390
So try to be in the user's shoes.

8
00:00:33,600 --> 00:00:40,670
So let's run the program as it is now and let's think as the user.

9
00:00:40,680 --> 00:00:45,360
So this says add a type, add show or exit.

10
00:00:45,720 --> 00:00:50,460
So the first thing we want to do is we want to add here an option.

11
00:00:51,120 --> 00:00:51,810
Edit.

12
00:00:53,430 --> 00:00:57,720
So type and show, edit or exit.

13
00:00:59,320 --> 00:01:04,989
So if we run this now, we're going to get the correct prompt.

14
00:01:06,760 --> 00:01:09,880
Then the user might want to press.

15
00:01:09,880 --> 00:01:18,810
Edit Here we want to add a new case to count for that scenario.

16
00:01:18,820 --> 00:01:22,240
So Case added a column.

17
00:01:22,360 --> 00:01:28,270
Press Enter pie charm indents automatically the next line.

18
00:01:29,770 --> 00:01:32,350
And here, What can we write?

19
00:01:32,380 --> 00:01:34,570
Well, for now, let's just say print.

20
00:01:35,350 --> 00:01:36,160
Got it.

21
00:01:36,550 --> 00:01:44,260
Just something dummy and free around the program and try again to think as the user so the user wants

22
00:01:44,260 --> 00:01:45,310
to press.

23
00:01:45,310 --> 00:01:55,360
Edit But first they want to add something like add a new to do clean adds through add.

24
00:01:58,830 --> 00:01:59,970
Prepare.

25
00:02:01,890 --> 00:02:03,900
And then they want to press.

26
00:02:03,900 --> 00:02:05,730
Edit So we press.

27
00:02:05,730 --> 00:02:07,920
Edit got it was printed out.

28
00:02:07,920 --> 00:02:16,500
So that case statement is working fine, but let's think of how do we want to tell the program which

29
00:02:16,500 --> 00:02:19,320
of these items we want to edit.

30
00:02:19,770 --> 00:02:25,050
So in this command line interface, we have basically two options.

31
00:02:25,050 --> 00:02:33,660
So either we should say that we want to add its clean and we explicitly write, type down the exact

32
00:02:33,660 --> 00:02:41,040
to the item there, and then the program asks us a second question such as What do you want the new

33
00:02:41,520 --> 00:02:43,110
to do to be?

34
00:02:43,110 --> 00:02:48,900
And you write the new to do which will override the existing to do or you just say the number.

35
00:02:48,900 --> 00:02:53,400
For example, you want another two, so you want to edit number two.

36
00:02:53,610 --> 00:02:59,400
I think the second scenario where you just tell the number of the to do is more meaningful.

37
00:02:59,400 --> 00:03:06,630
So you, the user first says show it knows the order of these and then it says number two.

38
00:03:07,610 --> 00:03:15,260
Edit and then the program asks again the user to enter the new to do for that.

39
00:03:15,680 --> 00:03:16,550
To override that.

40
00:03:16,550 --> 00:03:17,060
To do.

41
00:03:17,060 --> 00:03:17,600
And so on.

42
00:03:17,600 --> 00:03:18,170
So.

43
00:03:19,550 --> 00:03:22,520
Let's close this and go to the program.

44
00:03:23,390 --> 00:03:25,160
So if the user enters.

45
00:03:25,160 --> 00:03:29,660
EDIT We want to ask the user a new question.

46
00:03:30,740 --> 00:03:34,040
Let's say number is equal to input.

47
00:03:36,590 --> 00:03:40,700
Number of the to do to edit.

48
00:03:42,290 --> 00:03:46,880
So we ask the user to enter the number of the to do item.

49
00:03:46,880 --> 00:03:52,550
So if the user enters to for example, two will be stored in the number of variables.

50
00:03:53,390 --> 00:03:55,730
Let's see if we successfully get that.

51
00:03:55,820 --> 00:03:59,390
So print number run again.

52
00:04:01,030 --> 00:04:05,800
So let's say edit two and we get out to.

53
00:04:05,830 --> 00:04:08,590
So what can we do now with this too?

54
00:04:08,770 --> 00:04:18,850
Well, we will use lists indexing system to be able to extract that item of the list, which has an

55
00:04:18,850 --> 00:04:20,589
index of two.

56
00:04:21,220 --> 00:04:24,880
So let me give you an introduction to this list Indexing system.

57
00:04:25,690 --> 00:04:31,990
Let's say we have the list to dos is equal to clean.

58
00:04:34,450 --> 00:04:36,760
Through and.

59
00:04:38,650 --> 00:04:39,610
Prepare.

60
00:04:43,080 --> 00:04:44,480
So that's the list.

61
00:04:44,490 --> 00:04:56,520
So if you want to extract that item from the list you do to do square brackets, one that will give

62
00:04:56,520 --> 00:05:04,650
you a throw, which of course you can also store that in a variable to do is equal to that to do is

63
00:05:04,650 --> 00:05:05,520
equal to throw.

64
00:05:05,820 --> 00:05:06,510
And that's the list.

65
00:05:06,510 --> 00:05:11,550
Again, sorry to dos is the list.

66
00:05:14,660 --> 00:05:16,510
And to this one gives you a throw.

67
00:05:16,520 --> 00:05:17,300
Why?

68
00:05:17,330 --> 00:05:21,740
Because this first item has an index of zero.

69
00:05:21,950 --> 00:05:24,500
This second item has an index of one.

70
00:05:24,650 --> 00:05:27,590
And the next item has an index of two and so on.

71
00:05:27,710 --> 00:05:36,110
So what we're doing here is we are accessing the item with index one, which is the item through.

72
00:05:36,530 --> 00:05:40,340
So that means if you press zero here, you get clean.

73
00:05:40,670 --> 00:05:44,630
If you do two, you get prepared.

74
00:05:44,720 --> 00:05:50,130
If you write three, you will get an error because it says index list.

75
00:05:50,150 --> 00:05:54,710
Index is out of range, so there are no items with index three.

76
00:05:57,090 --> 00:05:58,680
So back to our program.

77
00:06:02,280 --> 00:06:03,810
We get the number.

78
00:06:03,810 --> 00:06:05,160
So the index.

79
00:06:07,070 --> 00:06:17,960
And we use that index to access the to do list some number here and that will give us the to do item

80
00:06:18,410 --> 00:06:21,230
which the user wants to add it.

81
00:06:21,680 --> 00:06:22,940
And what do we do with this?

82
00:06:22,940 --> 00:06:29,600
Now, before we answer that question, let's make sure we got this correctly.

83
00:06:30,320 --> 00:06:40,010
So let's call this existing to do is equal to that and print existing to do.

84
00:06:40,550 --> 00:06:43,130
Let's see what this is going to give us.

85
00:06:43,490 --> 00:06:44,960
So I'll run this.

86
00:06:47,800 --> 00:06:50,050
Let's add a new to do.

87
00:06:51,720 --> 00:06:52,610
Clean.

88
00:06:52,620 --> 00:06:53,850
Add the new one.

89
00:06:54,780 --> 00:06:55,800
Prepare.

90
00:06:58,870 --> 00:07:01,240
Show the to do list.

91
00:07:01,480 --> 00:07:02,560
Clean prepare.

92
00:07:02,590 --> 00:07:08,230
Then press edit to edit a new one number of to do to edit.

93
00:07:08,830 --> 00:07:10,810
So that is zero.

94
00:07:10,810 --> 00:07:12,070
That is one.

95
00:07:12,070 --> 00:07:18,550
But the user doesn't know this, so the user maybe will write down one to mean that.

96
00:07:18,550 --> 00:07:21,670
So we need to adjust for that in the script.

97
00:07:21,670 --> 00:07:23,110
We will do that also.

98
00:07:23,410 --> 00:07:28,540
So let's try to enter one and we get an error.

99
00:07:29,890 --> 00:07:32,310
The error is in line 16.

100
00:07:33,370 --> 00:07:34,330
So it's here.

101
00:07:35,350 --> 00:07:36,580
It says that.

102
00:07:37,490 --> 00:07:43,670
Type error list indices must be integers or slices, not SDR.

103
00:07:44,300 --> 00:07:48,890
So it seems that the index is a string.

104
00:07:49,910 --> 00:07:50,910
What is the index?

105
00:07:50,930 --> 00:07:55,850
The index is this part here, this number that we give in here.

106
00:07:56,990 --> 00:08:04,910
But the interpreter is saying this is string and this is true because the input function always, always

107
00:08:04,910 --> 00:08:07,070
produces a string type.

108
00:08:07,070 --> 00:08:13,580
So even if the user enters a number, that number is actually a string.

109
00:08:13,590 --> 00:08:15,410
It is just text.

110
00:08:15,410 --> 00:08:19,970
It is not recognized by Python as a number.

111
00:08:20,120 --> 00:08:23,120
So let me show you what I mean by that.

112
00:08:24,080 --> 00:08:32,419
Let's say you want to store in variable A, you want to store the input, enter a number.

113
00:08:33,530 --> 00:08:36,409
So you enter a number, let's say ten, right?

114
00:08:36,409 --> 00:08:41,030
And you might think that A now is a number, right?

115
00:08:41,179 --> 00:08:51,710
So if you do a plus two, you will get an error because you are trying to concatenate a string.

116
00:08:52,100 --> 00:08:53,270
So ten is a string.

117
00:08:53,270 --> 00:08:58,700
You can also see the quotes here with a number that doesn't make sense for Python.

118
00:08:58,700 --> 00:09:02,840
The interpreter is confused, doesn't know what to do so you get an error.

119
00:09:02,840 --> 00:09:11,270
The solution here is to use a function which converts a string to a number.

120
00:09:11,660 --> 00:09:14,270
So that function is int.

121
00:09:15,770 --> 00:09:20,030
If you write ten here, it will give you a number.

122
00:09:20,420 --> 00:09:23,000
So let's say B again, is it?

123
00:09:23,780 --> 00:09:31,640
Ten type B is int, so integer is a whole number in Python.

124
00:09:32,540 --> 00:09:33,950
You can also use.

125
00:09:38,450 --> 00:09:39,320
Float.

126
00:09:40,490 --> 00:09:42,620
Let's say we had this string.

127
00:09:43,070 --> 00:09:47,810
You press enter and B now is a float.

128
00:09:47,810 --> 00:09:49,340
So it's a decimal number.

129
00:09:49,340 --> 00:09:57,680
So float converts strings to decimal numbers and it converts strings to whole numbers.

130
00:09:58,780 --> 00:10:02,110
So type B is a float.

131
00:10:03,530 --> 00:10:03,880
Right.

132
00:10:03,880 --> 00:10:09,160
So we use that to convert this into ints.

133
00:10:09,160 --> 00:10:19,000
So if you say integer and you wrap that inside end, so the output of the input function will be the

134
00:10:19,000 --> 00:10:20,800
input of the end function.

135
00:10:21,580 --> 00:10:27,850
In other words, the output of the input function is one, so one will be the input of the function

136
00:10:27,850 --> 00:10:32,620
and we get to one as a whole, as an integer, a whole number.

137
00:10:32,620 --> 00:10:37,780
So we need to work with whole numbers here because indices are all numbers.

138
00:10:37,780 --> 00:10:38,230
So.

139
00:10:40,420 --> 00:10:42,570
We had the to do list to do.

140
00:10:42,850 --> 00:10:44,620
You cannot say 1.3.

141
00:10:44,770 --> 00:10:45,790
You will get an error.

142
00:10:46,480 --> 00:10:49,060
You can only say one or two or.

143
00:10:49,270 --> 00:10:50,020
And so on.

144
00:10:50,380 --> 00:10:51,790
Right now.

145
00:10:54,540 --> 00:10:55,610
Number is on it.

146
00:10:55,620 --> 00:10:58,370
So now we shouldn't get an error anymore.

147
00:10:58,380 --> 00:10:59,820
So let's run this.

148
00:11:01,670 --> 00:11:07,100
Ad clean at through show.

149
00:11:07,490 --> 00:11:15,860
Edit I'll edit number one press enter and we get extracted the through item from that list.

150
00:11:15,860 --> 00:11:18,230
So number one extracted through.

151
00:11:18,230 --> 00:11:21,740
But as a user, I don't know about the indexing system of Python.

152
00:11:21,740 --> 00:11:26,570
I don't know that Python starts the indexing from zero.

153
00:11:27,200 --> 00:11:31,580
So we also as a programmer, we need to adjust for that.

154
00:11:32,530 --> 00:11:38,800
Lack of knowledge from the user's part about the system that Python is based on.

155
00:11:39,480 --> 00:11:41,050
That's an easy solution for that.

156
00:11:42,100 --> 00:11:46,480
We just go to our script, so we grab the number.

157
00:11:46,900 --> 00:11:52,630
Let's say the user entered one, but they meant zero, right?

158
00:11:53,620 --> 00:11:54,400
The first item.

159
00:11:54,400 --> 00:11:56,050
But the item has an index of zero.

160
00:11:56,050 --> 00:11:59,280
So we say number is equal to number.

161
00:11:59,290 --> 00:12:01,600
So one minus one.

162
00:12:01,600 --> 00:12:03,850
So we get zero if the user enters one.

163
00:12:04,150 --> 00:12:06,160
One minus one, we get zero.

164
00:12:06,190 --> 00:12:10,690
If the user enters to two minus one, we get to one answer one.

165
00:12:11,200 --> 00:12:11,440
Right?

166
00:12:11,440 --> 00:12:16,480
So that should give us the actual to do that.

167
00:12:16,480 --> 00:12:22,450
The user wants to add it, but then how do we go about replacing that to do so?

168
00:12:22,450 --> 00:12:27,850
We have the list to dos now with two dos and.

169
00:12:28,960 --> 00:12:31,630
One, we got the item.

170
00:12:31,630 --> 00:12:40,420
But if you want to replace that item, we say to do this one is equal to new item, whatever the user

171
00:12:40,420 --> 00:12:41,110
enters here.

172
00:12:41,530 --> 00:12:42,640
Press enter.

173
00:12:42,910 --> 00:12:49,060
And now if you check to this, you see that flow is replaced with that new item.

174
00:12:49,330 --> 00:12:55,630
Therefore, we go in here and instead of doing that.

175
00:12:57,840 --> 00:13:02,370
We see to do number.

176
00:13:02,410 --> 00:13:06,380
So throw is equal to new.

177
00:13:06,390 --> 00:13:08,100
To do what is new to do?

178
00:13:08,100 --> 00:13:15,240
Well, new to do is something we get from the user using again the input function enter new to do.

179
00:13:15,450 --> 00:13:25,410
So I'll run this now and you'll see that this is working well at clean, at throw at repair.

180
00:13:29,520 --> 00:13:30,570
Show.

181
00:13:32,530 --> 00:13:36,410
So we have three items and we want to add it through.

182
00:13:36,430 --> 00:13:38,770
So we count one, two.

183
00:13:38,770 --> 00:13:40,660
Oh, that's number two.

184
00:13:40,720 --> 00:13:46,720
So edit number of the to do, to edit to enter, new to do.

185
00:13:48,210 --> 00:13:50,640
How about this symbol?

186
00:13:52,870 --> 00:13:56,590
Press enter press show to see the to dos.

187
00:13:56,590 --> 00:14:08,560
And here we have disassemble is the item with number two sorry for the type of disassemble anyway exit

188
00:14:08,560 --> 00:14:10,480
and we exit the program.

189
00:14:10,480 --> 00:14:15,220
So that's the final version of the edit feature.

190
00:14:15,340 --> 00:14:17,740
Let me delete this break line.

191
00:14:19,240 --> 00:14:28,030
So what you learned in this video was how to convert from a string to a number.

192
00:14:28,090 --> 00:14:38,740
Using that in function, you also learn how to access items from a list using that syntax, and you

193
00:14:38,740 --> 00:14:43,750
also learn how to replace an item using that syntax.

194
00:14:46,060 --> 00:14:51,490
This was quite a long video, but these features are very, very crucial for you.

195
00:14:51,520 --> 00:14:58,210
You're going to use them in every application that you'll build with Python, no matter if it's a web

196
00:14:58,210 --> 00:15:01,690
development, data science or other fields of Python.

197
00:15:01,810 --> 00:15:04,300
So thank you for following and I'll talk to you later.

