Professional Documents
Culture Documents
Hello Word Kids Book 8 First Sessional-Merged
Hello Word Kids Book 8 First Sessional-Merged
-
I
Let's learn
Book8
coding!
Make sure you have bought a
genuine Paramount book and
not a pirated edition ..
• Always check the ANTI-PIRACY SECURITY LABEL applied to the title
cover before purchasing/paying for a Paramount book.
• The pirated books can be identified by the inferior quality paper,
reduced printing quality, sub-standard binding, blurred images and
unclear or hazy text. These all give a textbook second-rate quality
and poor texture and appearance but you still pay the price of a
genuine book.
• Do not accept a book if the label is missing, is being torn or
tampered, or you are unable to find the security features and
authentication marks as shown below:
Coin reactive
U.Vvisible
SICPASTAR®
High Security
multilevel ink
Colour shift from
=-t-i-----..;___
Pink to Green
Up-Conversion
responds to
hand-held devices
By:
Hello World Kids team
Designed By:
@Waleedlutfe
I I
2
~ \
Index
Unit Exercises 27
Unit2
Lesson 1
Lists and Functions
Hello Lists
-
30
Unit Exercises 41
Unit3
Lesson 1
Lesson 2
Conditions and Loops
Introduction to If Statement
If Statement in Python
-
44
45
Unit Exercises 54
Unit4 Classes and Objects
Lesson 1
Modules in Python
Time in Python
II
64
Lesson 2 Random 65
Lesson 3 Built-ins 67
Unit Exercises 74
II
-
Unit-6 Challenges · · ·
Dear student!
5
. .t~
II
II
II
C!
.: .
~- I
7
C on ·t Introduction to P thon
outcomes: After this lesson, you should be familiar with the term ID
and you should be able to mention some of its feature/
Introduction:
Why do we need to learn computer programming?
Programming helps you ~nk differently, easily_ and
~ a s i_t ~nds on log~c and e_roblem solving. With
programming, you create things from almost nothing!
u-1
12
8
illlll&....;:a ...
Why Python?
Python is an easy-to-learn programming language that has some
useful features for a beginner programmer. The code is quite easy
to read when compared to other programming languages, as you
can easily write your codes and see them run. Also, it is one of the
programming languages which provides a simple way to create
programs with slightly more advanced graphics and animation.
' • 1 _- . ' • •
. ,:
f- - ·~ .•
. - .~ - . .. , ,.. \ ,;- -
-~
( Exercises
Mention some of the programming languages you know, or
search to know some.
+± _ /' 91-r. ·. '.: . -~: · i .. ; -:,::._ ·_·. :-:·; .. >:
c.. ... ... ···························~·IJ[)..?.\ ···r·······························································
...
... 3.0:-;V.o.... .......·.................................................................................................. .
..V1i~..... B.ab.~.r;........................................................................................
1,
Class Discussion - - - - - - - - - - - - - - - - - . . .
"You cannot run before you walk!". .
What does this mean? How is this related to programming?
9
___,,,,,,_____esson Introduction to Python
IDE installation:
Step 1:
To download and install Python IDE, visit the official website of
Python: http://www.python.org/downloads ..
and choose your version. We have chosen python version 3.7.3
e, _ _ ,,,_... .
+- 0 , ,__.,.,_II/SI,_ _ ;Oc;rn: zmzrrriliir -
',:t f)LJthon
,\,,r,1JI rir,1,11'.rJ,,d·.
• •, f ,1,,,
- D
python
flli ti': lnstlll llunchtr for II UMf'I (rlcommended)
windows Add Python 17 to PATH [ CIIIIII ]
- C X
python
for
windows
S o t ~ 11 tllil ,._
"Close".
Disablt path length llmlt
· $ °"""'.,..,,-1w,omp_to _ _ _ inclucing Python, to
"""'lhtllOcllot- "MAX,.MTH" llmlltion.
python
for
windows
Step 5:
Installing PyCharm:
Step A
Visit the website: www.jetbrains.com/pycharm/download and
click on the "DOWNLOAD " button under the Community section.
j • OowNotd P)(Nffll!PythonlOI IC l+
4" 0 I jl1bf1IM,com/pyd,ilm/-Dod/f-lOO• -
Download PyCharm
( Wlodowl_ ) IM<OI """'"
ProfessIona I Community
VtfllOft• 20113
For both Scientific and Web For pure
l1,11k1 112 1121 101
Python development. With Python development
.J,,JjyJ,4, J01f HTML, JS, and SOL 1upport.
ouwru•J"'LJ
Introduction to P thon
Step B
Once the download is
complete, run the .exe
file to install PyCharm.
The setup wizard should
have started. Click
"Next ".
. -
PyChMm Community Edilion So1up
a--.-a-
0
)(
Step C
In the next screen, ,-----------==
lit ea-._.,. ., 0-lho faldorlnwlidtloinotlll!'yOwo,
-
PyChlffll Community Edllion s.._. - X
Step D
You can create a
desktop shortcut if you · . ~PAlMvnbll~lllldllll
: 0Addllunct.9*tohN1H I
Step E - o X
,.
··. ':-
I .. 1
liiJ PyCham, Community Ed;,;o,, Setup - u
Step F
Wait for the installation
,_de_ ,_..=_::_
~xlract py1han......,..••• 100'11,
to finish. - - - - - -·- - -
1~-__
<- jf ..... > J L Can<d=-:J
Once installation is
finished, you should
receive a message , ,
Extract py1han..est.jor ••• 10()'11,
r Flnllh J
Py 'h;11 rn
13
Les~ 2 Python Specials
Outcomes: By this lesson, you should _be_ able to mention sorne 0
Python language characteristics. f
Introduction:
Why should I choose Python as a ~rogramming language">
Python is one of the programming languages that ·
model the real world. It focuses on obje~ts as it is ca~:~
ObJ·ect-Oriented. Below
. . .are some of its unique and
important characteristics.
14
~ -Lesson
- - - - -3
- - Variables
- - - - _ _in
. .Python
_ ______
-4 Outcomes: By this lesson, you should know the term variable with
its data types and rules.
-4 Introduction:
What is a variable and why do we use it?
A Python variable is a reserved memory location to store
values. In other words, the variable in Python program
gives data to the computer for processing.
There are other data types such as: List, Tuple and Dictionary; but the
focus will be on numbers and strings. ·
Variable syntax:
Variable Name = Value or Variable Name= "Value"
...
The variable name shoul·d be given so you can assign a value.
15
,
al
Leii:on 3 Variables in Python
Let see examples.
Example 1: Variable with Numerical data type
II
II
Here, the variable a" is assigned
with a numerical value: 100
a= 100
Print (a)
16
-
Example 2: Variable with String data type
we will declare the" a" variable as string, and print it using Python.
. ·-·----- - --- - - - -
17
~
.-
Lesson 3 , Variables in P thon
'Note - - - - - - - - - - - - - - - -
lf you can see, the string ~alue should be assigned With
the symbol " " . If you missed the double quotations
Syntax Error will be shown as the following: a
You can add anything you want for the string value·, it can be letters,
words, symbols, letters mixed with numbers and symbols.
But the main condition is to add the " " sign so Python will understand
that you are declaring a string variable.
e.g:
a= "Hello World Kids teaches programming"
Print (a)
i I ·--
,
l
' !
18
l~ -
Example 3: Variable with Boolean data type
The Boolean data type has the value of either True or False. In
Python, Boolean variables are defined by the True and False
reserved words with the upper case first letter, using a lower-case
value returns an error.
a= True
Print (a)
b~
[ '&) Exercises
Try to assign (true) instead of (True) for the variable "a". What
do you expect? Why?
·· ············ ··········· ····· ··· ·········· ······ ···· ········ ········ ····· ·· ·· ····· ··· ··········· ······· ············ ··········
· ·················································································································· ·········· 19
~1
Lesson 3 Variables in P thon
'\
Python Variable Name Rules l
In any programming language, there are some rules that you s j
follow when you name a variable. Below are some of them: houtd
Must begin with a letter (a-z, A-2) or underscore (_).
Other characters can be letters, numbers or underscore (_).
Case sensitive: It matters if it is upper case or lower case.
Can be any reasonable length.
Should not have spaces.
Never use reserved words. as variable names as they are being used
by Python for other t hmgs.
(
b~ Exercises
Write down five variable names that will be accepted
Python without errors. . ·. -.. •·
.. .. . ... ....... =............................................................... : ........................... ,. ·········· ·· ·· · ··
• • • ,• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • .• • • • • • ·.- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . • • • • • • • • • • • • • • • • • • • •
•'. ' ·
.
........ ................................................
- .
........................................
.
...............................
...............................................................................................................................
... .... ......... ; .............................................................................................................
- _
·•:," .
20
Lesson 4 Input and Output in Python (1/0~
4 outcomes: By this lesson, you should be able to use the built-in
functions, Print() and Input() to perform (1/0) tasks.
4 Introduction:
First let's talk about something called a "parameter".
lm_agine you wan~ to give your friend a gift in a bag, in
~his case the bag 1s the parameter and what's in the bag
1s a value you want to pass from you to your friend.
~Input()
·· Input Syntax:
e.g.:
Suppose that you want to write a program which needs different data
to be entered in each time you run the code or you need to accept
data directly from the user that runs the code. In this case, the Input
. function is a must. ·
Input means: The function that Python uses to accept data directly
from the user. ·
The value
Example:
entered by the
val= input("Enter your value:" )
user is 123
print(val)
Output:
Enter your value: 123
/
123 21
on 4 .5 In ut and Out ut in P thon (1/0)
String and Numeric Input
The _inpu_t() function, by default, will convert all ~he information i i
receives into a string. Which means that• the data will be• taken as ·t.
I ISt :.
I
Output
Enter your Age 19
19
Here, when the int() function is called, the input data will be acce t d
as a number not as a string. Pe
( Exercises
Write a Python code that accepts a student marks in the
Mathematics subject.
22
~ t Nu-meric Input: Float()
floa
float() function will be used to represent th l b .
rhe .
decimal pom . t e rea num ers with
challenge: . _
Can yo_u write the Python code which accepts a Math m k
a floating number? ar as
Hint: You can just replace the "Int" word with "Float".
Output()
I
·• The output function is used to send data to the output device (Screen) .
. The most used function for Output() is the Print() function .
.Print() Function
The print() function prints the specified message to the screen.
Print () syntax:
Print (Message)
As the message is the value that will be shown on the screen.
Output: t n the
This sentence will be _
shown as outpu o
screen 23
~r P thon {1/Q
•
4 ;
. In ut and Out ut 1n
an one object
Example 2: Printing more th
A = 10
pr int('The value of A is' , A)
Output:
The value of A is 10
68~ Exercises
u think the ou tp ut w ill be for the code below:
What do yo
rry ")
X = (" apple ", "banana ", "che
print(x)
.......;.............
Output: ..... ..... ........................................
..... ...................... ..... .. . ... ···········································
I
I
I
l
I
24