0% found this document useful (0 votes)
22 views61 pages

Slide Tư Duy Tính Toán 2 (Nguyen Duy)

The document is an introductory lecture on Computational Thinking at the University of Engineering and Technology, focusing on problem-solving strategies using computer science concepts. It covers key topics such as the definition of Computational Thinking, programming basics, and practical applications using Python. The lecture emphasizes the importance of decomposition, pattern recognition, abstraction, and algorithm design in problem-solving.

Uploaded by

pduc122007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views61 pages

Slide Tư Duy Tính Toán 2 (Nguyen Duy)

The document is an introductory lecture on Computational Thinking at the University of Engineering and Technology, focusing on problem-solving strategies using computer science concepts. It covers key topics such as the definition of Computational Thinking, programming basics, and practical applications using Python. The lecture emphasizes the importance of decomposition, pattern recognition, abstraction, and algorithm design in problem-solving.

Uploaded by

pduc122007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computational Thinking

Lecture 1: Introduction
University of Engineering and Technology
VIETNAM NATIONAL UNIVERSITY HANOI
Outline
▪ Real-life Examples
▪ Problem-solving Thinking
▪ What is Computational Thinking?
▪ What is Programming?
▪ Getting Started with Python

1
Real-life Examples
Single-Player Games

Tetris Sudoku

Computational Thinking 3
Multiplayer Games

Rock Paper Scissors Tic Tac Toe

Computational Thinking 4
The notion of ‘Problem’
Problem
(to be solved)

Win the game!


(Optimal solution)

Thinking
(Decomposition, Pattern Recognition, Abstraction, Algorithm, etc.)

Computational Thinking 5
Real-life Problem – Expense Management

Problem:You have X million


VND/month to cover your
living cost in Hanoi.

Factors: Unexpected
expenses, necessity.

Algorithm?

Computational Thinking 6
Real-life Problem – Optimal Route Finding

Problem: Find an optimal


route from location A
(e.g.,“Nga Tu So”) to location
B (e.g.,VNU-UET)

Factors: Traffic jams,


weather, transportation
means.

Algorithm?

Computational Thinking 7
Problem-solving Thinking
Problem-solving Thinking
Problem-solving thinking is the process of understanding a problem,
exploring possible solutions, and designing a clear, step-by-step
method (algorithm) to solve it.

Problem Solution Idea Algorithm

A question or A general idea to A clear, step-by-step


situation that needs to reach the goal. procedure or
be solved. instructions

Computational Thinking 9
The Power of Computers
in Supporting Problem-solving

Vs.

Aspect Human Brain Computer


Creativity Creative, intuitive, can imagine new ideas No creativity, only follows instructions
Problem Handles only small-scale or simple Can solve very large, complex problems
Size problems effectively with big data
Extremely fast with millions of
Speed Slow with large-scale calculations
operations
Accuracy Prone to errors, distraction, fatigue Always precise, consistent, no fatigue

Computational Thinking 10
Problem-solving with Computational Thinking

Problem Solution Idea Algorithm Code


Python
Given a list of Value comparison Instructions via
implementation
numbers, find the Pseudo code
largest one.

Computational Thinking 11
Problem-solving with Computational Thinking
Scope of Computational Thinking

Problem Solution Idea Algorithm Code


Python
Given a list of Value comparison Instructions via
implementation
numbers, find the Pseudo code
largest one.

Computational Thinking 12
What is Computational
Thinking?
Computational Thinking
Computational Thinking (CT) is a problem-solving approach that
uses concepts from computer science to design solutions which
can be carried out by humans or computers.

Computational
Thinking

Pattern Algorithm
Decomposition Abstraction
Recognition Design

Computational Thinking 14
Decomposition
Break a big problem into smaller, manageable parts.

Example: Write a program to calculate area of a rectangle

Decompose the big problem → smaller steps are easier to solve.

Computational Thinking 15
Pattern Recognition
Find similarities or repeated elements.

Example: Print even numbers from 1–10

Patterns help us create general rules for many cases.

Computational Thinking 16
Abstraction
Focus on important details, ignore the irrelevant

Example: Write a function: Add two integer numbers.

Simplify complexity by showing only the useful details.

Computational Thinking 17
Algorithm Design
Create step-by-step instructions to solve the problem.

Example: Find the largest number in a given list

Algorithms are precise recipes to solve problems.

Computational Thinking 18
What is programming?
What is programming?
Given a set of instructions and a task, write a sequence of
instructions that do the task.

This is Scratch
at code.org
Kids' games,
actually

https://studio.code.org/courses/express-2025/units/1/lessons/1/levels/6

Computational Thinking 20
What about programming in Python?
Same process: same task,
a different set of instructions

https://www.programiz.com/python-programming/online-compiler/

Computational Thinking 21
More complicated tasks?
Your turn.

https://studio.code.org/courses/express-2025/units/1/lessons/1/levels/11

Computational Thinking 22
A little bit about
variables, values, and expressions
▪ Values/Objects
▪ Numbers 1 -2.5
▪ Logical values True False
▪ Strings 'Hello' "Hello" "It's a good day, today"
▪ List [1,2,3] ["it's", "a", "good", "day"]
▪ Tuple ('Math', 8.4) (‘John', ‘English', 84)
▪ Dictionary {'Math': 8.4, 'English': 9.0, 'Physics': 6.5}

https://studio.code.org/courses/express-2025/units/1/lessons/1/levels/11

Computational Thinking 23
Expressions
▪ An expression represents something
▪ Python evaluates it (turns it into a value)
▪ Similar to a calculator
▪ Examples:
▪ 2.3
▪ (3 * 7 + 2) * 0.1

Computational Thinking 24
Storing and Computing Data
What data might we want to work with?
(What’s on your computer?)

▪ Values/Objects
▪ Numbers 1 -2.5
▪ Logical values True False
▪ Strings 'Hello' "Hello" "It's a good day, today"
▪ List [1,2,3] ["it's", "a", "good", "day"]
▪ Tuple ('Math', 8.4) (‘John', ‘English', 84)
▪ Dictionary {'Math': 8.4, 'English': 9.0, 'Physics': 6.5}

Computational Thinking 25
Variables
We need names to refer to pieces of data
▪ Variables: names of objects
▪ x = 5
▪ x = 10 * 2
▪ numbers = [1,2,3]
▪ numbers is now a name of the list [1,2,3].
▪ numbers = [1.2, 354.2, 7.3]
▪ numbers is now a name of the second list

Computational Thinking 26
Variables…
We need to define a name before it can be used

score is used before


being defined

score is used after


having been defined

Computational Thinking 27
More games

https://studio.code.org/courses/express-2025/units/1/lessons/1/levels/7

Computational Thinking 28
Loops

https://studio.code.org/courses/express-2025/units/1/lessons/1/levels/7
Computational Thinking 29
Loops

https://studio.code.org/courses/express-2025/units/1/lessons/1/levels/7
Computational Thinking 30
Repetition In Python
You can do other things in a for loop

Computational Thinking 31
More games

https://studio.code.org/courses/express-2025/units/1/lessons/27/levels/3
Computational Thinking 32
More games

https://studio.code.org/courses/express-2025/units/1/lessons/27/levels/3
Computational Thinking 33
More complicated logic
▪ Using as few
blocks as
possible to get
the bee to take
all the flower’s
nectar

▪ What are the


tasks that are
pretty much the
same?
https://studio.code.org/courses/express-2025/units/1/lessons/14/levels/5
Computational Thinking 34
More complicated logic

https://studio.code.org/courses/express-2025/units/1/lessons/14/levels/5
Computational Thinking 35
More complicated logic
▪ Using as few
blocks as
possible to
get the
zombie to the
flower
▪ What are the
tasks that are
pretty much
the same?

https://studio.code.org/courses/express-2025/units/1/lessons/14/levels/8

Computational Thinking 36
More complicated logic

Computational Thinking 37
More complicated logic

Computational Thinking 38
Important point: Dividing into subtasks
▪ Divide main task into subtasks, find patterns

Computational Thinking 39
Important point: Dividing into subtasks
▪ Divide further

Computational Thinking 40
More games?
You can practice by playing games here
▪ https://studio.code.org/courses/express-2025/units/1/less
ons/14/levels/1
▪ https://studio.code.org/courses/express-2025/units/1/less
ons/15/levels/1

Computational Thinking 41
Selection
Check underneath every cloud to see if it is hiding a flower before
you get nectar.
If there is a flower
underneath the cloud, the bee will
need to get nectar
once.
Remember:
Not all clouds
hide the same
thing!

https://studio.code.org/courses/express-2025/units/1/lessons/17/levels/3
Computational Thinking 42
Selection
Collect all of the nectar or make all the honey.
You can only collect
nectar from flowers
and make honey
from honeycombs.
Check any space
to see
if there is a flower
or honeycomb.
There will only ever
be one flower
or one honeycomb
behind each cloud.

https://studio.code.org/courses/express-2025/units/1/lessons/17/levels/12
Computational Thinking 43
Selection
Collect all of the nectar or make all the honey.
You can only collect
nectar from flowers
and make honey
from honeycombs.
Check any space
to see
if there is a flower
or honeycomb.
There will only ever
be one flower
or one honeycomb
behind each cloud.

https://studio.code.org/courses/express-2025/units/1/lessons/17/levels/12
Computational Thinking 44
Selection in Python

Computational Thinking 45
Scratch vs. Python

Can you see how similar a “program in Scratch” to a program


in Python?

Computational Thinking 46
So… what is programming?
▪ In this game
▪ Arrange the blocks in the right sequence
▪ Run to see if it does the job correctly
▪ See where it goes wrong
▪ Fix the sequence
▪ In professional terms
▪ Write some code
▪ Test the code
▪ Debug
▪ Fix errors

https://studio.code.org/courses/express-2025/units/1/lessons/1/levels/11
Computational Thinking 47
But… how?
▪ Think in the given
programming language
▪ How to tell the machine to
do the task using that
language?
▪ Divide the task into smaller
subtasks
▪ Keep dividing subtasks into
even smaller ones, until each
task can be done by one
instruction in the given set.

https://studio.code.org/courses/express-2025/units/1/lessons/1/levels/11
Computational Thinking 48
Not sure what that means?

Don't worry.
Try playing with Scratch at code.org.
Practice solving problems by programming.
Bit by bit, you'll see!
Happy coding!

Computational Thinking 49
How to run a Python program
Getting Started with Python
▪ Designed to be used from the “command line”
▪ OS X/Linux: Terminal
▪ Windows: PowerShell
▪ Preferred over cmd
▪ See Lab instructions
▪ Install, then type “python”
▪ Starts the interactive mode
▪ Type commands at >>>
▪ Quit by typing quit()
then pressing Return

Computational Thinking 51
Running a module
Module text file add.py

x = 'Hello'
y = x + ' World'

From the command line, type:


python <module filename>
Nothing happen?
Actually, something did
Example: happen: Python executed all
the commands in that file.
C:\> python add.py
They just don't do anything
except assign some variables.

Computational Thinking 52
Running a module
Edit the file add.py

x = 'Hello'
y = x + ' World'
print("y = " + y)

Run it again:
C:\> python add.py
y = Hello World

Now it showed something!


That's the result of the print statement.

Computational Thinking 53
Running a more interesting module
Module file guess.py

"""A really bad guessing game."""


user_guess = input('What word am I thinking of? ')
print('Wrong. I am not thinking of '
+ user_guess + '.') The input
function displays
Command line: a prompt and
C:\> python guess.py waits for an
What word am I thinking of? cat input.
Wrong. I am not thinking of cat.
Here, we typed
cat as an input

Computational Thinking 54
Interactive mode _ typing code

C:\> python
Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23…
Type "help", "copyright", "credits" or "license" for more …
>>> x = 'Hello'
>>> y = x + ' World'
>>> y
'Hello World'
>>>

Computational Thinking 55
Interactive mode _ import a module
Import a .py file
C:\> python
>>> import add
y = Hello World
>>>

Remember the file add.py? x = 'Hello'


The statement import add y = x + ' World'
(no extension .py) runs the print("y = " + y)
script add.py

Computational Thinking 56
Summary: Three ways to execute code
1. Typing code in interactive mode.
2. Importing a module.
3. Running a script.

Now you can go ahead installing Python in your computer


and run all the sample codes.
Have fun!

Computational Thinking 57
If you do not want to install Python,
how can we do?

There are numerous


Online IDE that
support python
programming:

online-python.com
pythononline.net
onlinegdb.com

Computational Thinking 58
Jupyter Notebook with Google Colab

https://colab.research.google.com/

Computational Thinking 59
Summary - Key Takeaways
▪ Problem-solving (with Computational) Thinking
▪ Problem → Solution Idea → Algorithm → Code
▪ Computational Thinking
▪ Decomposition, Pattern Recognition, Abstraction, Algorithm
Design
▪ What is Programming
▪ Programming = writing instructions so that a computer
can perform a task.
▪ Getting Started with Python
▪ Variable,Value, Expression, Loops, Selection
▪ Learning by doing
Computational Thinking 60

You might also like