theme | _class | paginate | backgroundColor | footer | marp |
---|---|---|---|---|---|
gaia |
lead |
true |
Computational Thinking and Social Science | :copyright: Matti Nelimarkka | 2023 | Sage Publishing |
true |
- Understand the role of computational thinking and algorithms in solving social science problems through computation
- Develop computational thinking skills connected with variables, repetition, and conditions
- Know how to use variables, repetition, and conditions
- Know how to read data from files using
- Know how to use logical expressions to control the flow of programming
- Recognise programming patterns that can be used in programming
Programming is all about transforming the problem into an algorithm and then turning the algorithm into a computer-understandable formulation.
- Computational thinking: Reformulating the problem as an algorithm (the cognitive component of programming)
- Programming: Reformulating the algorithm into an executable program (the technical component of programming)
- Running the program executes the algorithm and produces results
- Results solve the initial problem
A problem: Calculate a person’s age using a computer program.
An algorithm:
- Print out the person’s name
- Calculate the person’s age. Person's age is their dead year subtract by their birth year
- Print out the calculated age
A Problem: How old was Caligula, the third emperor of ancient Rome? Caligula was born in 12 AD and died in 41 AD.
An algorithm:
- Print out ‘Caligula’
- Calculate what is 41−12
- Print the outcome of the calculation
Code is just a text written in a specified syntax.
Code is just a text written in a specified syntax.
print("Caligula")
print(41-12)
- Discuss the code editor you are using
- Demonstrate Code Example with chosen IDE
- Ask students to print their own name and age (Exercise 2.10)
A variable is a box that has both a label (its name) and some content that gets stored (the value).
Problem: Emperor Caligula reigned from 37 to 41 AD. What proportion of his life was this?
An algorithm:
- compute the difference between 41 and 12 (how long he lived)
- compute the difference between 41 and 37 (the years he was in power)
- divide the number of years of his reign by how many years he lived
We need to store results 1 and 2 to memory so we can later access them.
We created variables with names 1️⃣ and 2️⃣ to allow us storing them into memory.
1️⃣ = 41-12 2️⃣ = 41-37
Proportion of life as emperor: 2️⃣ ÷ 1️⃣
- Variables have types: they can be text, numbers etc.
- We cannot mix apples and oranges
- What is
“five"+5
?
- Do exercises 2.8 and 2.9
for
loop may be used to repeat commands.
- Files are read line-by-line, repating the same commands for each line.
- An iterator is a variable that changes its value after each loop.
- Do Exercise 2.14
- Homework assignments: 2.15-2.16
- We want to branch the code based on a condition
- If the condition is
true
we do something, if it isfalse
we do something else (or do nothing) - This is known as
if
-structure
Problem: Study only emperors who reigned for more than 10 years?
An algorithm:
- calculate the length of the emperor’s reign
- check whether the reign length is greater than 10 years
- if it is, then print the details of that emperor (condition is true)
- if it is not, then do nothing (condition is false)
- The most-wanted holder
- The gatherer
- The flag
- The follower
- In-class: Do Exercise 2.18
- In-class: What purposes do each of the four design patterns serve?
- Homework: Do Exercise 2.19, 2.20, 2.24
- Why are variables important in programming?
- What purposes does a for loop serve?
- What purposes does an if structure serve?
- What types of logical expressions are there?
- Can you sketch out a visual program for the most-wanted holder, gatherer, flag, and follower patterns?