Computational Thinking
A brief summary of Week 1
Variable: “A variable is a symbol which is used to represent a varying expression or quantity.”
OR
“A variable is a symbol used for representing an unspecified/unknown term.”
Example: 1. Counting number of cards present in the “Scores” dataset.
For that we created a variable called Count and initialized it to 0.
Then we add one to Count as we move a card from pile 1 to pile 2.
Count = 0 + 1 = 1
Iteration: “Repetition of a process”
OR
“Iteration is the repetition of a process in order to generate a sequence of outcomes”
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.
Filtering: “Some specific decision”
OR
“In an iteration if we are only interested in specific item/data which are special to us and
not all items.”
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
Arrow: Flowline: Shows the order of execution of the program steps
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”)
If (X.Gender == ‘M’ OR X.City/Town == “Chennai”)
Integer datatype: Range: ...., -3, -2, -1, 0, 1, 2, 3,.....
Operation: +, -, x, / (Result type: Integer)
<, >, == (Result type: Boolean)
Character datatype: Range: All alphanumeric: A, B,....Z, a, b,.....,z, 0, 1,.....,9
Special characters: ., $, #, @, .....
Operation: == (Result type: Boolean)
Example: ‘C’, ‘1’, ‘#’, ‘M’, ‘F’
*
String: Range: Any sequence of characters
Operation: == (Result type: Boolean)
Example: “IIT Madras”, “21F00055”, “can@1#23”
Subtype of basic datatypes: “Restrict the basic datatypes in terms of their ranges and constrained
on their operations”
Examples: Seq. No.: Ranges: 0, 1, 2, ..., Max (some reasonable number)
Operation: None of the integer operations make sense
: Boolean operations such as “==” can be performed
Marks: Ranges: 0, 1, ...., 100
Operation: Integer operation such as +, -
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
Marks: Physics marks = 80.5
Mathematics marks = 90.5
We want to add the above two subject marks.
80.5 80.5x100 = 8050
90.5 90.5x100 = 9050
Then we performed integer operation, 8050 + 9050 = 17100
After that we need to bring back in original form by using “print” (defined in lecture)
print(17100) = 171.00
Lists and Records:
List: “A sequence of data elements of same or may be of different datatypes”
Example: (i) Subject marks obtained by Clarence: [63, 88, 73]
(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}