| 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️⃣
year_of_birth = 12
year_of_death = 41
age = year_of_death - year_of_birth
start_of_reign = 37
end_of_reign = 41
reign = end_of_reign - start_of_reign
print("Caligula")
print( reign / age )- Variables have types: they can be text, numbers etc.
- We cannot mix apples and oranges
- What is
“five"+5?
- Variables have types: they can be text, numbers etc.
- We cannot mix apples and oranges
- What is
“five"+5?
var1 = "5"
var2 = 5
var1_as_number = float( var1 )
var2_as_text = str( var2 )
print( var1_as_number + var2 )
print( var1 + var2_as_text )- Do exercises 2.8 and 2.9
for loop may be used to repeat commands.
for loop may be used to repeat commands.
sum = 0
for current_number in range(1,11):
print( "Adding", current_number )
sum = sum + current_number
print("The sum is", sum)- 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.
for line in open("emperors.txt"):
line = line.split(",")
name = line[0]
birth_year = float( line[1] )
death_year = float( line[2] )
start_of_reign = float( line[3] )
end_of_reign = float( line[4] )- Do Exercise 2.14
- Homework assignments: 2.15-2.16
- We want to branch the code based on a condition
- If the condition is
truewe do something, if it isfalsewe 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)
reign = end_of_reign - start_of_reign
if reign > 10:
print( name )- 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?







