Computational Thinking
Tutorial for Lecture 2
(Refer Slide Time: 0:12)
Hello students of Computational Thinking. In this tutorial video, we will try to do some of the
same procedures that the professors have done in lecture 2, except what they have done is on
the mark sheet dataset and here we will work with the shopping bills data. As you can see
here, these are the shopping bills that we are using and they are all randomised. So, this is bill
number 3, this is bill number 11, 18 and so on. So, this is not in a particular order, now let us
start looking at our first problem.
(Refer Slide Time: 0:54)
We see that, food is a very common category of purchase in our bills, so let us try to count
the number of purchases where there is no food at all or where there is only food and no other
category. So, for this we will maintain two variables one will be all food count and the other
one will be no food count. So every time a bill comes up which has only food, we shall
increment the all food count variable and wherever there is a bill without any food, we will
increment the no food count variable. And we initialise these variables to the number 0. So let
us begin with this is our first shopping bill and as you can see there is food but there is also
toiletries, so there is nothing to increment here, this is neither all food nor no food.
(Refer Slide Time: 2:19)
So the next bill here there is food, food, food, food, food and then there is one household
item, so again neither all food nor no food, so we are not incrementing anything.
(Refer Slide Time: 2:33)
And here we see everything is food, there is no non-food items in this purchase. So this one
will lead to an increment in the all food count variable, so that that makes it plus 1.
(Refer Slide Time: 2:51)
And here again we see food, food, food, food but toiletries, so we do not make any increment.
(Refer Slide Time: 3:00)
And here we see food and toiletries, no increment again in either variable.
(Refer Slide Time: 3:07)
And here we see food and apparel so no increment again in either available.
(Refer Slide Time: 3:13)
And here we see utilities and food, no increment.
(Refer Slide Time: 3:18)
Apparel, apparel, household apparel but food, so again no increment.
(Refer Slide Time: 3:24)
And now we have come to a bill where there is no food item at all, so we will increment the
no food count by 1, so both are on 1 now.
(Refer Slide Time: 3:38)
Going further, toiletries and food so no increment.
(Refer Slide Time: 3:44)
Food, apparel so no increment.
(Refer Slide Time: 3:48)
Only food, right so all food count is now incremented by 1 we are at 2.
(Refer Slide Time: 3:56)
Again all food so we are now at 3 on the all food count, no food count is still at 1.
(Refer Slide Time: 4:08)
And here we have apparel and food, so no increment.
(Refer Slide Time: 4:12)
All food again, so increment all food by 1, so we now are at 4.
(Refer Slide Time: 4:22)
No food, so that will be 2.
(Refer Slide Time: 4:28)
Food and stationery so no increment.
(Refer Slide Time: 4:32)
Food, food, food and cosmetics, so no increment.
(Refer Slide Time: 4:37)
And all household items, so no food increments by 1 so we are at 3.
(Refer Slide Time: 4:44)
Utilities, electronic, stationary and foods, so no increment.
(Refer Slide Time: 4:49)
Only stationary, so we are now at 4 on the no food count.
(Refer Slide Time: 4:56)
Household and food, so no increment.
(Refer Slide Time: 5:00)
Only food again, so increment all food count by 1.
(Refer Slide Time: 5:08)
And there is no food on this, so no food count also is incremented by 1.
(Refer Slide Time: 5:14)
All food again only food, food, food, food, so all food count is incremented by 1.
(Refer Slide Time: 5:22)
All food count is again incremented by 1.
(Refer Slide Time: 5:26)
One more increment for all food count.
(Refer Slide Time: 5:30)
And now 1 increment for no food count.
(Refer Slide Time: 5:36)
One more increment for all food count.
(Refer Slide Time: 5:41)
And one more for all food count, I think now we have reached 10 and we have also reached
the end of the dataset, this is the last card so if I close this you can see that we are at the last
card.
(Refer Slide Time: 6:02)
So these are the counts we have arrived at after iterating through the shopping bill data and
maintaining two separate variables for counting bills which have no food at all and bills
which have only food as all the purchased items. Now let us do another problem which is
similar to what the professors have done in the lecture video.
(Refer Slide Time: 6:42)
So, for that let us go to the words dataset and again here I have randomised it considerably
and this is what the data cards look like. What we shall do in this problem is we will try to
calculate the average word length in this data, so we have the letter count here, so we are
going to use this to calculate the average of the word length and for this as the professors
have done with the maths average in the lecture for the mark sheet data, we will maintain two
variables again, one would be the count of the cards, how many cards are there and the other
is the sum of the letter count. So, that way at the end of it we will have the sum of all the
letters, the total number of letters and also the total number of words.
(Refer Slide Time: 7:43)
So, if we divide the sum by the count, we should be able to get the average word length in
this data.
(Refer Slide Time: 7:52)
So, beginning with the first card we have in the order the sum we will initialise it to 0 and the
letter count also we will initialise it to 0 and now we are adding 11 to the select count.
(Refer Slide Time: 8:15)
The next card we have 10 which uses the sum to be 21 and the count is 2.
(Refer Slide Time: 8:25)
And this one again is 11 which gives us the count to be 3 and the sum to be 32.
(Refer Slide Time: 8:35)
And once again we have 10, so this is 42 count is 4.
(Refer Slide Time: 8:42)
Now, we have letter count of 8 which gives us the sum to be 50 and the count to be 5.
(Refer Slide Time: 8:50)
And again we have a 10 which gives us the sum to be 60 and the count to be 6.
(Refer Slide Time: 8:59)
And now we have a 9, the sum is 69 and the count is 7.
(Refer Slide Time: 9:05)
And we have a 10 again the sum is 79 and the count is 8.
(Refer Slide Time: 9:13)
And now we have a 9 again, so the sum is 88 and the count is 9.
(Refer Slide Time: 9:20)
Another 9, so the sum is 97 and the count is 10.
(Refer Slide Time: 9:27)
Plus one more 9, so the sum is 106 and the count is 11.
(Refer Slide Time: 9:34)
And now a 6 so the sum is 112 and the count is 12.
(Refer Slide Time: 9:40)
And now another 9, so the sum is 121 and the count is 13.
(Refer Slide Time: 9:47)
Now we have an 8 the sum is then 129 and the count is 14.
(Refer Slide Time: 9:54)
And now we have a 6 the sum becomes 135 and the count is 15.
(Refer Slide Time: 10:02)
And here we have yet another 6, the sum is 141 and the count is 16.
(Refer Slide Time: 10:09)
Now we have an 8, the sum is 149 count is 17.
(Refer Slide Time: 10:16)
Plus 5 on the sum and plus 1 on the count.
(Refer Slide Time: 10:22)
Then again plus 8 on the sum giving us 162 plus 1 on the count giving us 19.
(Refer Slide Time: 10:30)
Then we have six additionally making it 168 and we have 20 cards.
(Refer Slide Time: 10:37)
One more 6, so 174 21 cards.
(Refer Slide Time: 10:44)
Plus a 7, sum is 181 for 22 cards.
(Refer Slide Time: 10:57)
We have one more 7 which is a 188 sum for 23 cards.
(Refer Slide Time: 10:57)
Plus 6 again sum is 194, cards is 24.
(Refer Slide Time: 11:04)
Plus 4 sum gives 198 and count is 25.
(Refer Slide Time: 11:11)
Plus 3 the sum is 201 the count is 26.
(Refer Slide Time: 11:18)
Plus 4 sum is 205, cards is 27.
(Refer Slide Time: 11:24)
Plus 3 sum is 208 number of cards is 28.
(Refer Slide Time: 11:29)
Then we have a plus 7 giving us sum is 215 and number of cards is 29.
(Refer Slide Time: 11:38)
Plus 7 again, sum is 222 number of cards is 30.
(Refer Slide Time: 11:45)
Plus 4 226 and 31.
(Refer Slide Time: 11:49)
Plus 3 229 and 32.
(Refer Slide Time: 11:54)
Plus 6 235 and 33.
(Refer Slide Time: 11:59)
Plus 4 239 and 34.
(Refer Slide Time: 12:04)
Plus 2 241 and 35.
(Refer Slide Time: 12:08)
Plus 4 245 and 36.
(Refer Slide Time: 12:12)
Plus 2 247 and 37.
(Refer Slide Time: 12:17)
Plus 5 252 and 38.
(Refer Slide Time: 12:21)
Plus 2 254 and 39.
(Refer Slide Time: 12:26)
Plus 2 again 256 and 40.
(Refer Slide Time: 12:30)
Plus 2 again 258 and 41.
(Refer Slide Time: 12:35)
Plus 4 262 and 42.
(Refer Slide Time: 12:39)
Plus 4 266 and 43.
(Refer Slide Time: 12:45)
Plus 4 again 270 and 44.
(Refer Slide Time: 12:49)
Plus 4 again 274 and 45.
(Refer Slide Time: 12:54)
Plus 3 is 277 and 46.
(Refer Slide Time: 13:00)
Plus 2 is 279 and 47.
(Refer Slide Time: 13:04)
Plus 2 again 281 and 48.
(Refer Slide Time: 13:08)
Plus 3 is 284 and 49.
(Refer Slide Time: 13:13)
Plus 3 again is 287 and 50.
(Refer Slide Time: 13:19)
Plus 3 again is 290 and 51.
(Refer Slide Time: 13:23)
Plus 3 again 293 and 52.
(Refer Slide Time: 13:26)
Plus 3 again 296 and 53.
(Refer Slide Time: 13:31)
Plus 3 again 299 and 54.
(Refer Slide Time: 13:34)
(Refer Slide Time: 13:40)
306 and 56.
(Refer Slide Time: 13:42)
Plus 3 is 309 and 57.
(Refer Slide Time: 13:47)
Plus 3 again which is 312 and 58.
(Refer Slide Time: 13:52)
Plus 3, 315 and 59.
(Refer Slide Time: 13:55)
Plus 3 318 and 60.
(Refer Slide Time: 13:59)
Plus 3 321 and 61.
(Refer Slide Time: 14:04)
Plus 2 323 and 62.
(Refer Slide Time: 14:08)
Plus 2, 325 and 63.
(Refer Slide Time: 14:13)
Plus 2 is 327 and 64.
(Refer Slide Time: 14:18)
Plus 2 again gives us 329 and 65.
(Refer Slide Time: 14:25)
So, now we perform division of the sum quantity by the count quantity which is 329 by 65
which gives us an average word length of pretty much 5, roughly 5 it is 5.06 but since these
are words we can say that this paragraph has an average word length of about 5 letters a
word. Thank you.