Week 1-3 Summary Merged
Week 1-3 Summary Merged
Example: In the previous example we saw that every time we move cards from pile 1 to pile 2, we
add one to variable Count. This is nothing but an iteration.
Example: If we want to only count students from Chennai. In this case also we will move all cards
from pile 1 to pile 2 but we will add one to variable Count only when we find students from
Chennai.
Multiple filtering: For example if we want to find number of female students from Chennai.
Filters: (i) Checking gender: Male/Female
(ii) Checking City/Town
So, here total two filters are required to get the number of female students from Chennai.
Flowchart: “Pictorial representation of an algorithm”
OR
“A flowchart is a step-by-step diagrammatic representation using some defined shaped boxes to
solve a task.”
Rectangular box: Process or activity: Set of operations that change the value of data/variables
Diamond: Decision: Determines which path/direction the program will take (True/False)
Oval shaped box: Terminal: Indicates the start or end of the program.
Datatypes: (Lecture 1.7): “Defines the values that the variable can take, and the set of operations
that are permitted.”
Basic datatypes:
Boolean datatype: Range: Has only two values: True and False
Operation: AND, OR (Result type: Boolean) Result will be Boolean type
either True or False
Example:
If (X.Gender == ‘M’ AND X.City/Town == “Chennai”)
Subtype of basic datatypes: “Restrict the basic datatypes in terms of their ranges and constrained
on their operations”
Transformation of sub-datatypes:
Date: 15 Jan : It is a string datatype.
Questions: What will be the date after 3 days?
We assume, 1 Jan : 0
2 Jan : 1
3 Jan : 2
--------
15 Jan : 14
-------
18 Jan: 17
-------
31 Dec : 364 (for non-leap year)
15 Jan Tranform 14
Integer operation
14 + 3
Print
18 Jan 17
print(17100) = 171.00
Lists and Records:
(ii) Details of Clarence: [9, “Clarence”, ‘M’, “6 Dec”, “Bengaluru”, 63, 88, 73, 224]
Record: “Stores data with multiple fields: each of which has a name and a value”
Example: A card of the Scores dataset.
{“Seq. No.”: 9, “Name”: “Clarence”, “DoB”: “6 Dec”, “Town/City”: “Bengaluru”,
“Mathematics”: 63, “Physics”: 88, “Chemistry”: 73, “Total”: 224}
A brief Summary of Week 2
Conditional termination in iteration:
Examples: (i) Find a card in which all subject marks are above 90 from the “Scores” dataset.
(ii) Find a card in which three different category of items are present from the “Shopping
Bills” dataset.
Example:
A = True
while(Pile 1 has more cards and A){
Read card X
if(X.City == “Chennai”) {
A = False
}
Move card X to Pile 2
}
Equality statement: A == B
A=3
B=5
A == B --- False
B=3
A == B --- True
Conditional execution:
(i) One time: if (condition) {
---------
}
: if (condition) {
--------
}
else {
-------
}
8 1
15 23
Eg:
Procedure pro2 ( a, b)
c=a+b
c = 0.5*c
return(c)
End proc2
Truth Tables:
A B A AND B
True True True
True False False
False True False
False False False
(ii) OR Table
A B A OR B
True True True
True False True
False True True
False False False