Computational Thinking
Introduction to Python
& Basic Input-Output
Computational Thinking
Python?
Computational Thinking
> give instruction?
> communicate
with computer?
Computational Thinking
machine language?
Computational Thinking
Computational Thinking
we need a language
to communicate with
a computer
Computational Thinking
programming language
machine language low-level language high-level language
Consist of binary code (0 Assembly language, Language that commonly
and 1), that can be written depend on the used by programmer to
in hexadecimal code microprocessor create a program
Computational Thinking
why Python?
● Easy to learn
● Huge community
● Cross platform
● Large ecosystem
Computational Thinking
get
lets
started!
Computational Thinking
we use Google Colab as the environment to create and
develop our code in this class
Computational Thinking
Comp Thinking_Colab-new [Link]
Slideshow & Click to play video
● Go to a certain folder on your Google Drive > right click > more > Google Colaboratory
● Create and share
Computational Thinking
Comp Thinking_Colab-copy [Link]
Slideshow & Click to play video
● We can copy & paste code from one Google Colab file to others
Computational Thinking
Comp Thinking_Colab-[Link]
Slideshow & Click to play video
● Right click and then share to share your Google Colab file with others (do not forget to set the
access)
Computational Thinking
Comp Thinking_Colab-[Link]
Slideshow & Click to play video
● Write and run code in Google Colab
Computational Thinking
● print
use print() function to display texts
● variable
store data into variable
● arithmetic operation
perform simple arithmetic operation
● input
use input() function to ask an input from users
Computational Thinking
print()
Computational Thinking
function used to display or prints
‘message/text’ to the screen
the message could be string or other object
(but will be convert into string before
print()
displayed)
Computational Thinking
print (“Hello world”)
function argument/parameter
marked with (...) at the end contain inside the (...)
● lead to a certain effect ● value used by the function
● evaluate the ● “...” indicates the value is a string
value/argument (could and not a number
be more than one)
Computational Thinking
Google COLAB
write the code here
execute/run the code
the code to print “Hello World” using print() function
the result!!! :D
Computational Thinking
Google COLAB
● We can use more than one arguments with the print() function
● Use commas “,” inside () to separate the arguments
● In the results, all of the arguments will be combined as one text
Computational Thinking
variable
Computational Thinking
container used to store a data or value
The data stored in a container could be a:
● String: “this is a string”
variable ● Integer or whole number: 10
● Float or decimals: 10.000
● Boolean: Yes or No
● List or collection of items: [“banana”, “apple”, “orange”]
● etc.
Computational Thinking
● we can only use lowercase, uppercase, number
and underscore to create variable’s name
● variable name can not started with number
variable ● uppercase and lowercase count as a difference
(so Num is different with num)
● pick a name the easy to read and understand
● we can not use reserved words in Python as the
name for variable
Computational Thinking
name
first_name
variable 1st_name X
first name X
first_name? X
Computational Thinking
reserved word in Python
source: [Link]
Computational Thinking
● Use the ‘=’ sign to assign a certain value(s) into
a variable
● Hence, in Python, the ‘=’ sign read as ‘assign’
variable instead of ‘equal to’
● Value assigned to a variable can be changed
anytime
Computational Thinking
name
Google COLAB
value
Computational Thinking
Google COLAB
name value
we can use variables as different input/arguments in the print() function by utilizes
the commas
Computational Thinking
We can perform simple arithmetic
operations in python
Arithmetic operation in Python using
common symbol such as ‘+’ for addition, ‘-’
arithmetic
for subtraction, and ‘/’ for division
Arithmetic operation in Python follows the
operation
PEMDAS rule
Computational Thinking
source:[Link]
Computational Thinking
source:[Link]
Computational Thinking
Google COLAB
arithmetic operation
used directly as an
argument in print()
function
using variable to
calculate triangle
area
Computational Thinking
input()
Computational Thinking
we use input() function to read data
entered by the user
The data then can be stored in a input()
variable for further used in our
code/program
Computational Thinking
name = input(“hello, what is your name?”)
variable function string/text dialogue
● the text dialogue ask user to input a certain values/data
● user type the answer or response
● the answer/response stored inside a variable (name)
Computational Thinking
Google COLAB
place for user to
type the
values/data
Answer displayed
using print()
function
Computational Thinking
● The result from input() function is always be a
string
● Hence, if we need a number (int, float), we
typecasting have to convert the response received from
the input()
● Use int() to convert string into integer
● Use float() to convert string into float
Computational Thinking
Google COLAB
Computational Thinking
Google COLAB
Computational Thinking
Google COLAB
Computational Thinking
exercise
Computational Thinking
personal info collector
You are new member for the computing club. your first task is to
create a program that can:
● Ask and store a set of data (full name, nick name, age, height)
from five different members
● Display the data. The displayed data should be in sentence
instead of just the response (e.g. “the name of the 1st member is
Ferro Yudistira”)
● Calculate and display the average value from the data (age and
height). The average value should be display within a sentence
and not just the numeric value (e.g. “The average height of all
members is 164.75cm”)
Computational Thinking
homework
Computational Thinking
house data tracker
Imagine a house that consist of two bedrooms, one bathroom, one living
room, one kitchen and one garage. Create a program that can:
● Ask and store a set of numeric data for each room in a house, which
consist of
○ numeric data (length, width, height)
○ list of object inside the rom (e.g. “mattress”, “table”, etc.)
● Display the data for each room in the house. The data should be
displayed in sentence
● Calculate and display the area and volume for each room (in
sentence)
● Calculate and display the total area and volume for the house (in
sentence)