Professional Documents
Culture Documents
1
What is a computer?
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?
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
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
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.
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
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”)
20
Let’s Interact with Python
Open Wing IDE.
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.
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)
25