ENGG1003 08 ComputationalThinking(1)
ENGG1003 08 ComputationalThinking(1)
Computational Thinking
First ThingS in the Morning
• Do you break-fast with an empty stomach?
• Any urgency in answering the call of nature?
• Need to boil some drinking water?
• When do you brush teeth?
• Do you wash face?
• Blink and send first message to your loved ones?
• Lab activities
Problem Scenario
• A visitor wants to go to Sir Run Run Shaw Hall from
MTR University Station. Let's plan a route.
https://www.cuhk.edu.hk/english/images/visitors/P1090449_215_215px.jpg by CUHK
Assimilation
• Employ computational thinking in daily life.
https://www.cuhk.edu.hk/v6/en/media/presskit/chungchiweiyuanlake.html by CUHK
Coders and Programmers
• We perceive problems using generalization.
Move
Copy
Share
AC 220
http://www.publicdomainfiles.com/show_file.php?id=13534621212335 weather symbols by sivvus in Open Clip Art Library is under Public Domain.
Expressing a Solution -
Coding
• Use a computer programming language, Python
• Employ readily available modules and objects:
• urllib for reading data from an URL like https://...
• json for processing data from HK Observatory
Application Programming Interface (API)
• Python built-in abstract data types list and dict
• Apply simple logic to automate advice generation
• if-else branching construct
• number comparison operator, >, greater than
Carry Out – Running/
Execution
• Write a complete Python program.
• Store the program in a code file/ executable for
repeated execution and distribution.
• Run the Python program
• on a computer standalone OR
• on a browser using Jupyter Notebook over the web.
• Sample code follows…
weather_to_bring_umbrella.py
Relax, this is just a proof-of-
concept!
#!/usr/bin/env python3
import urllib.request
import json
# INPUT
HKO_API = "https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=rhrread&lang=en"
apiURL = urllib.request.urlopen(HKO_API)
data = apiURL.read()
report = json.loads(data)
# PROCESS
for record in report["rainfall"]["data"]:
if record["place"] == "Sha Tin":
shatin_rainfall = record["max"]
uvindex = report["uvindex"]["data"][0]["value"]
It looks scary!
# OUTPUT
if shatin_rainfall > 2 or uvindex > 6:
print("Bring an umbrella!")
else:
print("Neither rainy nor shinny")
Four Components of
Computational Thinking
• Decomposition – break down a problem
• Suppose given 5 weight data in kg: 67, 32, 54, 60, 45.
Old School
Search-and-find Lost-and-not-found
Summary
• Computational Thinking
- Thinking like a computer scientist
• Employ computational thinking in daily life
• Solving a Problem
• Definition of Goals and Objectives
• Use of Tools, Strategies and Algorithms
• Solution Implementation and Adaptations
Take Away Outcomes for
Today
• Understand computational thinking in daily life