You are on page 1of 25

What is a computer?

Tally sticks (~19000 BC)


Abacus (~2500 BC)

Slide Rule (~1625 AD)

1
What is a computer?

ENIAC (~1946) Baby (~1948)

2
What is a computer?

Modern computers...
A Computer is …

• Ancient definition:
• A specialised tool to aid humans doing calculations
• The human does the work, the tool supports them

• Modern definition:
• A general-purpose device that performs tasks
• The human programs the computer, and the computer
runs the tasks automatically

4
What is a program?

• A series of instructions that a modern computer can execute

• A program allows you to tell a computer what to do

• We write programs that allow us to solve problems on computer

• Instructions contain expressions , operators, variables

• We use Python language to learn basic computer programming

5
7
8
Variables
Parcel Delivery
Question:
How does Mr.
Postman
identify each
parcel?

He has so many
parcels to
deliver everyday

10
Parcel Delivery – Name Tags
Answer:
Label the parcel
boxes with
name tags that
Tom Sue Alice state the
recipient names.
Lisa Joe
Yes, now Mr.
Postman knows
The name tags such as which parcel
Tom, Sue etc. identify belongs to
the parcels. which recipient
and get to
deliver them in
time.
11
Parcel Delivery - Boxes

Different types of boxes can store different


types of contents.

12
Variable
• A How
Q1: computer
manyprogram works with
variables are values
there?or data. These values or data are stored in the
computer memory slots like parcel boxes.

Q2:AHow
variable is like a “parcel box” in the computer memory for storing a value.
many values are stored in each variable?

Variable
Variable is_student
age
Variable
True
5 price Variable
message
99.99
“Hello World”
13
Variable
• Variable is like the parcel box.
 Variable value is like the content inside the box.
 Variable name is like the name tag given to the box. It
identifies the variable.
 Variables of different data types are like the different
types of boxes, which have different sizes and are used to
store different types of content.

14
Data Types
 We will focus on 4 main data types in this lesson.
Integer - represents whole numbers
Float - represents numbers with decimal points
String - represents set of characters in between single or double quotes
Boolean - represents one of two values: True, False

Boolean

Integer

Float
String

15
*Exercise 1 – Identifying Data Types
Identify the data type for each value below.
Integer Float String Boolean

Value Data Type


i False
ii “Python”
iii “Yes”
iv 100
v True
vi 100.08
vii “S140001”
viii “100”

16
Programming Tips
Don’t worry about making mistakes
in the upcoming exercises! In fact,
making mistakes and figuring out
how to search and fix them is one of
the best ways to pick up
programming.

In programming, your mistakes don’t


usually cost you anything except a bit
of time. So make lots of them, learn
lots from them, have fun.

17
Creating a Variable
1. Variable names can be made up of letters, numbers, and the
underscore character (_ ) but they can’t start with a number.
2. Pick a meaningful name for your variable based on what it represents.
For example, the variable that will store the age value should be
called age.
3. Assign value to your variable.
Value 5 is assigned to variable age Variable

Python code: age Integer

age = 5 5
Variable name
Value
18
Displaying Information – Example 1
Value
Value 55isisplaced
assigned to variable
into variable a age
Variable
Python code:
age Integer
age = 5
5
Variable name
Value

Python code:
print(age)
print function will print the value in
variable age. 19
Displaying Information – Example 2

Python code:
print(“Your grade is A today”)

print function will print the set of characters


that are surrounded by double quotes.

20
Let’s Interact with Python
Open Wing IDE.

The three greater-than signs (>>>) are


called the prompt.
21
Working with Values and Variables
print(1 + 2)
1. Type and

one = 1
2. Type two = 2
print(one + two)

22
*Exercise 2 - Working with Variables
When entering a multiplication calculation in Python, you use the
asterisk symbol (*) instead of a multiplication sign (×).

one = 10 Question:
two = 20 Fill in the blank and use the
print( ____________ ) variables to find out the
result of 10 multiply by 20.

What is the output?

23
Python can handle basic arithmetic
Example
Operator Name Code
When x = 2 and y = 1
Plus x+y x + y will give 3.
Minus x–y x – y will give 1.
Divide x/y x / y will give 2.
Multiply x*y x * y will give 2.
You must use * instead of x for multiplication.
x to the power of y x ** y x ** y means 2 to power of 1 and will give 2.
Modulus x%y x % y will give 0.
0 is the remainder from 2 divides by 1.

24
*Exercise 3 – Using Modulus %
x = 10 Question:
1. Type y =and
2  What does the modular sign, %
print(x % y) do?
 What are the outputs?
x = 11
2. Type y = 2
print(x % y)

3. What are the outputs of print(10//2)? What is the


difference of operator // and / ?

25

You might also like