Download as pdf or txt
Download as pdf or txt
You are on page 1of 154

A TEXTBOOK OF COMPUTER – FOUNDATION OF INFORMATION TECHNOLOGY 8

A Textbook of Computer – Foundation of Information Technology for Class 8 is a textbook based


on Ubuntu and LibreOffice. It discusses various topics including LibreOffice Base, Python and App
Development. The book has been designed with emphasis on interactive and creative approach. It
serves as an ideal classroom support for computer education. It is based on the latest guidelines of
National Curriculum Framework (NCF), NCERT and all major state boards.
The book incorporates the features of a textbook, a workbook as well as a manual to ensure maximum
benefit to the student.

KEY FEATURES
Text is presented in a clear and simple language, with enhanced visual appeal.
All the ideas and concepts are explained with clear-cut and practical examples.

d
Lt
Each and every topic is thoroughly researched and certified by consultant teachers from schools.

t.
The illustrations given in the chapters lend enormous support as learning aids.

Pv
For the Teacher boxes provide teaching ideas and tips for the teachers.

a
Did You Know and Note boxes impart more information and interesting facts about the topic being

di
discussed.

In
An exhaustive set of questions and activities are given at the end of each chapter to reinforce

rs
learning and develop practical computer skills.

he
Revision exercises and Project work at the end of the book help to sharpen the concepts learnt in

is
the chapters.

bl
Pu
Sample questions based on National Cyber Olympiad at the end of the book help students prepare
for the Olympiads.

n
illa
ITL Education Solutions Limited (ITL ESL) is a part of the ITL group which has operations all over
the world with a significant presence in education and IT-enabled services. It specialises in handling

m
educational projects in IT domains with a dedicated R&D wing of industry experts that helps in designing

ac
and developing content.

M
We will be happy to respond to you on any query relating to the series.

©
Write to us at cs-support@macmillan.co.in

Macmillan Education listens to educators, and works to meet their


teaching-learning needs through relevant products and services.
For any requirements or feedback, write to
macmillanmarketing@macmillaneducation.com

` 435

Macmillan Publishers India Pvt. Ltd.


Weight:
www.macmillaneducation.in Customer Support Number: +91-8130588966
d
Lt
t.
Pv
a
di
In
rs
he
b lis
Pu
n
illa
m
ac
M
©

2020 Ubuntu Ed.indb 1 12-May-20 5:53:21 PM


© ITLESL, 2020

All rights reserved under the copyright act. No part of this publication may
be reproduced, transcribed, transmitted, stored in a retrieval system or
translated into any language or computer language, in any form or by any
means, electronic, mechanical, magnetic, optical, chemical, manual, photocopy
or otherwise without the prior permission of the copyright owner. Any person
who does any unauthorised act in relation to this publication may be liable
to criminal prosecution and civil claims for damages.

First published 2020


Revised edition 2021

MACMILLAN PUBLISHERS INDIA PRIVATE LIMITED


Delhi Bengaluru Chennai Kolkata Mumbai
Ahmedabad Bhopal Chandigarh Coimbatore

d
Cuttack Guwahati Hyderabad Jaipur Lucknow Madurai

Lt
Nagpur Patna Pune Thiruvananthapuram Visakhapatnam

t.
ISBN: 978-93-9006948-4

Pv
Designed and developed by the Research & Development Wing,

a
ITL Education Solutions Ltd., 2nd Floor, GD-ITL Towers,

di
Netaji Subhash Place, Pitampura, New Delhi 110 034 In
Published by Macmillan Publishers India Private Ltd,
rs

21, Patullos Road, Chennai 600002, India


he

Printed at
b lis
Pu
n
illa
m
ac

“This book is meant for educational and learning purposes. The author(s) of the book has/have taken all reasonable care to
ensure that the contents of the book do not violate any existing copyright or other intellectual property rights of any person in any
M

manner whatsoever. In the event the author(s) has/have been unable to track any source and if any copyright has been inadvertently
©

infringed, please notify the publisher in writing for corrective action.”

ACKNOWLEDGEMENTS

We are immensely thankful to Ms Anne Dias, M.A., M. Ed., Director – Special Projects, Academic and Continuous Professional
Development, Ms Tracy Cardoz, M.A. M. Ed., Vice President – Curriculum Development, Ms Jaya Venkatram, M.A, B.Ed.,
A.G.M. – Curriculum Development and Dr Shefali Bharti, Ph.D., Sr. Manager – Academics Operations, VIBGYOR Group
of Schools, Mumbai for their active interest in promoting excellence in education and their invaluable contribution in the
successful completion of the project. Their guidance in designing the content and course structure for the series with regular
quality check has made the product par excellence.

We would also like to thank the Curriculum development team members Mr Sankalp Korde and Ms Shraddha Kambli along
with the Heads of the Computer Science Department Ms Amreen Khan, Ms Shruti Kamat, Ms Puja Kumar and Ms Sarla Devi
and all the Computer teachers of the VIBGYOR Group of Schools for their constant inputs and support during the making
of this series.

2020 Ubuntu Ed.indb 2


Preface
The computer has established itself as one of the greatest innovations of humankind. Today, it
has become an integral part of our lives, be it at home, school or work. Thus, a basic knowledge
of computers has become essential for success in any sphere. Keeping pace with this, there is a
compelling need to impart computer education to children at an early stage of learning so as to
make them self-sufficient.
A Textbook of Computer – Foundation of Information Technology for class 8 is a textbook based on
the Ubuntu operating system, LibreOffice and other Free and Open-Source Software (FOSS).
FOSS refers to the software that is liberally licensed under the GNU General Public License. This
license grants users the free availability of source code of FOSS along with the right to use, study,
share, and modify it. This control and flexibility has endorsed the use of FOSS in school education,
and it is gaining more momentum day by day.

d
Lt
The book discusses various software applications including LibreOffice Base, Python and App

t.
Development. The book has been designed with emphasis on interactive and creative approach. It

Pv
serves as an ideal classroom support for computer education. It is based on the latest guidelines

a
of National Curriculum Framework (NCF), NCERT and all major state boards.

di
The book incorporates the features of a textbook, a workbook as well as a manual to ensure
In
maximum benefit to the student.
rs
he

Key Features
lis

• Text is presented in a clear and simple language, with enhanced visual appeal.
b

• All the ideas and concepts are explained with clear-cut and practical examples.
Pu

• Each and every topic is thoroughly researched and certified by consultant teachers from schools.
n

• The illustrations given in the chapters lend enormous support as learning aids.
illa

• For the Teacher boxes provide teaching ideas and tips for the teachers.
m

• Did You Know and Note boxes impart more information and interesting facts about the topic
ac

being discussed.
M

• An exhaustive set of questions and activities are given at the end of each chapter to reinforce
©

learning and develop practical computer skills.


• Revision exercises and Project work at the end of the book help to sharpen the concepts learnt
in the chapters.
• Sample questions based on National Cyber Olympiad at the end of the book help students
prepare for the Olympiads.
We will be happy to respond to you on any query relating to the series. Write to us at
cs-support@macmillan.co.in.

Rohit Khurana
Founder and CEO
ITLESL

2020 Ubuntu Ed.indb 3 12-May-20 5:53:21 PM


Contents
1 Operating Systems 1

2 Introduction to LibreOffice Base 11

3 Queries in LibreOffice Base 38

4 Algorithms and Flowcharts 55

d
Lt
t.
5 Introduction to Python 65

Pv
a
6 Advanced Features of Python di 90
In
rs
he

7 App Development 103


blis
Pu

8 Networks 122
n
illa

National Cyber Olympiad (Sample Questions) 138


m
ac
M

Project Work 141


©

Revision 143

Terminology 146

2020 Ubuntu Ed.indb 4 12-May-20 5:53:21 PM


1
Hey Ria! Do you know, just Yes, Leno! I know it is the most
as the CPU is the brain of important software that makes
the computer system, the the computer system work.
operating system is the heart
of the computer system? Today, I will tell you about
the functions, features
and different types of Okay!

d
Let’s start!

Lt
operating systems.

t.
Pv
a
di
In
rs
he
b lis
Pu
n

Contents
illa

A computer system has different parts that


together make it work. These parts are
m

‹‹ Software
ac

grouped in two categories: hardware and


‹‹ What is an Operating System?
software. Hardware refers to those parts of a
M

‹‹ User Interface computer system that we can touch and feel.


©

The keyboard, monitor, mouse, scanner, printer, speakers, web camera and
microphone are some examples of computer hardware. Computers operate according
to the instructions given to them, as they do not work or take decisions on their own.
Hence, it is necessary to instruct computers to solve a problem. These instructions are given
to the computers by software. A computer needs both hardware and software to work.
A computer with only the hardware is just like an empty box which is useless unless it is
provided with the necessary software.

1.1 SOFTWARE
Software is an organised collection of computer data and instructions. It is responsible
for controlling and managing the hardware components of a computer.
1

2020 Ubuntu Ed.indb 1 12-May-20 5:53:22 PM


The software communicates and instructs the hardware to perform specific tasks. It enables
the hardware to carry out the functions properly. In other words, the software instructs the
hardware what to display on the users’ screen, what kind of input to take from users, and
what kind of output to generate.

1.1.1 Characteristics of Software


Different individuals judge software on different basis. This is because they are involved
with software in different ways. These are the four characteristics of software.
‹‹ Reliability: The ability of the software to perform the required function under the
stated conditions
‹‹ Efficiency: The ability of the software to use system resources
‹‹ Functionality: The ability of the software to meet the specified function for which it

d
is developed

Lt
t.
‹‹ Portability: The ability of the software to be used across different platforms (different

Pv
operating systems) as well as different hardware

a
1.1.2 Types of Software
di
In
Software can be categorised into application software and system software.
rs
he

‹‹ Application software: It is defined as a set of one or more programs developed to


perform a specific task on the computer, such as creating documents, spreadsheets
lis

and databases, drawing and colouring pictures, sending e-mail, designing graphics,
b
Pu

playing games, etc. Some common examples of application software include


KolourPaint, LibreOffice and Ubuntu Calculator.
n
illa

‹‹ System software: The software that manages and controls all activities in the computer
system is known as system software. It carries out the hardware functions such as
m
ac

starting a computer, running application programs, managing memory allocation,


and so on. It acts as an intermediate between the application programs and the
M

computer hardware. The operating system is the most important system software.
©

Software

Application System
Software Software

General-purpose Specific-Purpose Operating Language Utility


Application Application
Software Software System Software Software

Fig. 1.1 Types of software


2

2020 Ubuntu Ed.indb 2 12-May-20 5:53:23 PM


Both the system software and application software are important for a computer system,
as they are complementary to one another. Without system software, computers cannot
run and without application software, computers cannot meet the requirements of users.

Did You Know


An application software may consist of a single program, such as Text Editor (for writing
and editing simple text) or a collection of programs, often called a software package
which work together to accomplish tasks such as a database management software.

1.2 WHAT IS AN OPERATING SYSTEM?

d
Lt
An operating system (OS) is a set of programs which controls the working of a computer

t.
system. It manages the computer hardware and software, and provides common services

Pv
for computer programs. It is the first program that gets loaded into the computer’s memory
when the computer is switched on. Every computer, be it a desktop, laptop, or a tablet,

a
di
needs operating system to work. Microsoft Windows (such as Windows 10, Windows 8,
In
Windows 7, Windows Vista and Windows XP), Mac OS, Linux, Ubuntu, and Android are
rs

some common examples of operating systems.


he
b lis
Pu
n
illa

(a) Microsoft Windows (b) Mac OS (c) Linux (d) Ubuntu (e) Android
m
ac

Fig. 1.2 Commonly used operating systems


M
©

1.2.1 Need and Importance of an Operating System


An operating system is the most important system software that runs on the computer.
It is the heart of a computer system. Without it, we cannot even start a computer and work
on it. It lets you communicate or interact with the computer.
You can realise the importance of an operating system because of the following activities
that it performs.
‹‹ Program execution: An operating system is responsible for the execution of various
application and system programs. It loads the program into memory and executes it.
‹‹ Accounting: An operating system keeps track of time and resources used by various
functions of the computer and the users.

2020 Ubuntu Ed.indb 3 12-May-20 5:53:23 PM


‹‹ Communication: There may be many processes executing at the same time
in a memory. An operating system is responsible for managing the exchange of
information among the processes.
‹‹ Error detection: An operating system is responsible for detecting different types of
errors and then taking appropriate actions for it.
‹‹ Resource allocation: An operating system is responsible for making sure that all the
resources available to the computer are used in a fair and an efficient manner.
‹‹ Security: The operating system prevents unauthorised access to the system’s programs
and data with the use of passwords and similar other means.

1.2.2 Features/Functions of an Operating System


Some of the major characteristic features of an operating system are as follows.

d
Lt
‹‹ Processor management: An operating system manages the allocation of the processor

t.
(CPU) to the processes in run and deallocates the processor when it is no longer

Pv
required by a process. It does it in a way that the processor remains occupied most
of the time.

a
di
‹‹ Memory management: It keeps track of the computer’s memory like what part of
In
memory is in use and by whom, and what part is free. It allocates memory to various
rs

programs or processes, whenever required.


he

‹‹ Device management: It controls the working of all the input and output devices of
lis

the computer. It keeps track of which device is busy with which process and for how
b

much time.
Pu

‹‹ File management: It manages the files and folders stored on different storage devices.
n
illa

It allocates a file (opens the file) for use and deallocates it (closes the file) after use.
m

‹‹ Security management: An operating system ensures the security of a computer


ac

system. For this, it uses various techniques such as authentication, authorisation,


cryptography, etc.
M
©

1.2.3 Types of Operating Systems


Over the years, many operating systems have been developed. These operating systems
differ from one another in terms of speed, hardware required, and the purpose for which
they are used. Based on this, operating systems are broadly classified into the following
types.
‹‹ Single-user operating system: A single-user operating system allows only one user to
use the system at a time. It may support single tasking where one user can effectively
do one thing at a time. It may also support multitasking where one user can run
multiple programs on it simultaneously. The Windows operating system installed
on PCs, Android operating system on mobiles and tablets, and Mac OS on Apple
computers are all examples of a single-user, multitasking operating system.
4

2020 Ubuntu Ed.indb 4 12-May-20 5:53:23 PM


‹‹ Multi-user operating system: A multi-user operating system allows multiple users to
use the computer’s resources simultaneously. The computers are connected to the
main system through a network.
‹‹ Multiprocessor operating system: A multiprocessor operating system, as the name
implies, runs on more than one processor in a single system for executing multiple
processes at a time. This operating system helps in improving the performance of
the system by executing more tasks in less time. In addition, failure of one processor
does not halt the system, as other processors carry on with the tasks specified to
them.
‹‹ Batch-processing operating system: In batch systems, the programmers submit their
programs to the computer operator who then groups the inter-related tasks into
batches. These batches are then executed one after the other. The users are not
allowed to interact with the computer system. Thus, the programs that do not require

d
interaction are well-served by batch operating system.

Lt
t.
‹‹ Time-sharing operating system: Time-sharing operating systems allow multiple

Pv
people, located at various terminals, to use a single computer system at the same
time. Multiple jobs are executed by the CPU by switching between the jobs at a very

a
di
high speed, making each user get immediate response. This gives a feeling to a user
In
that only he/she is using the computer.
rs

‹‹ Real-time operating system: A real-time operating system is defined as a data-


he

processing system in which the time interval required to process and respond to
lis

inputs is very small. RT Linux, Symbian OS, VX Works are some examples of real-
b

time operating system.


Pu

‹‹ Distributed operating system: Distributed operating systems use multiple central


n

processors to serve multiple real-time applications and multiple users. Data processing
illa

jobs are distributed among the processors accordingly. The processors communicate
m

with one another through various communication lines such as telephone lines.
ac

Processors in a distributed system may vary in size and function. The World Wide
M

Web (WWW) is a major example of a distributed system.


©

‹‹ Mobile operating system: A mobile operating system is specially designed and


developed to be used on mobile devices such as smartphones and tablets. Google’s
Android, Apple iOS and Symbian are the most popular mobile operating systems.

1.3 USER INTERFACE


User interface (UI) refers to the means by which the user interacts with a computer system.
It includes a set of commands that help the user communicate with the computer and make
it do the required task. For example, to instruct the computer to print a document, you can
either type the required command or press the required keys or buttons.A user interface is
broadly divided into two categories: character user interface (CUI) or command-line user
interface, and graphical user interface (GUI).

2020 Ubuntu Ed.indb 5 12-May-20 5:53:23 PM


1.3.1 Character User Interface (CUI)
A CUI-based operating system provides the user with the facility of entering
commands via an interactive terminal. The user has to type command(s) to perform
any function, such as creating a file. For this, the user needs to remember many
commands and their syntax for proper operation of the system. A CUI provides
minimum interface software to its users and a command prompt—the place where
the user types the command and feeds to the system. Though a CUI uses less amount
of computer resources as compared to a GUI, the use of CUI has decreased with the
launch of the video display monitors. MS-DOS(Microsoft Disk Operating System),
Windows command line, Terminal and the Linux command line are some examples of
CUI-based operating systems.

d
Lt
t.
Pv
a
di
In
rs
he
b lis
Pu
n
illa

Fig. 1.3 Terminal program of Ubuntu


m
ac

1.3.2 Graphical User Interface (GUI)


M

A GUI-based operating system provides users the graphical means to interact with the
©

system. The operating system displays icons, buttons, dialog boxes, etc., on the screen.
The user sends instructions by moving a pointer on the screen (generally, a mouse) and
selecting certain objects by pressing buttons on the mouse while the mouse pointer is
pointing at them. Typically, a GUI is more resource-consuming than a CUI. With advancing
technology, programmers and designers have been creating complex GUI designs that
work with more efficiency, accuracy and speed.

A GUI consists of the following elements.


‹‹ Window: A window is a rectangular area where the contents of an application are
displayed. The contents of the window can be displayed in the form of icons or lists.
It is easier for a user to navigate in a window. Windows can be moved, minimised,
resized or maximised to the size of the screen.
6

2020 Ubuntu Ed.indb 6 12-May-20 5:53:23 PM


‹‹ Menu: A menu is a set of commands, grouped together and placed at a visible place
(usually the top) inside the application window. The menu can be programmed to
appear or hide on mouse clicks.
‹‹ Icons: An icon is a small picture representing a program or an application installed on
the computer. When you click or double-click on an icon, the associated application
window is opened.
‹‹ Cursor: A cursor indicates the current position for user interaction on a computer
monitor or other displaying device. It responds to input from a text input or a pointing
device such as mouse. The mouse cursor is also called a pointer.

d
Lt
t.
Pv
a
di
In
Icon
rs
he

Pointer
blis
Pu
n
illa

Window
Menu
m
ac

Fig. 1.4 Files window in Ubuntu


M
©

1.3.3 Difference between GUI and CUI


The table below lists some differences between GUI- and CUI-based operating systems.
Differences between GUI and CUI

GUI-based operating system CUI-based operating system


In a GUI-based operating system, the user In a CUI-based operating system, the user
interacts with the system by clicking icons, interacts with the system by typing text-
pictures, menus and buttons using a mouse. based commands on the command prompt
using the keyboard.

2020 Ubuntu Ed.indb 7 12-May-20 5:53:23 PM


It provides visuals to interact with the The users need to type every command
operating system such as buttons, icons, manually in order to perform the desired
images, etc. task.

GUI systems require both the mouse and CUI systems just require a keyboard to
keyboard. work.

Windows, Linux and Mac OS are examples MS-DOS and UNIX are examples of CUI-
of GUI-based operating systems. based operating system.

Points to
Remember

d
Lt
‹‹ Software is an organised collection of computer data and instructions.

t.
Pv
‹‹ The four characteristics of software are reliability, efficiency, functionality and
portability.

a
di
‹‹ Software can be categorised into application software and system software.
In
‹‹ The operating system is the most important system software. It is a set of programs
rs
he

which controls the working of a computer system.


lis

‹‹ An operating system can be classified as single-user, multi-user, multiprocessor,


b

batch processing, time-sharing, real-time and distributed operating system.


Pu

‹‹ User interface (UI) refers to the means by which the user interacts with a computer
n

system.
illa
m

‹‹ User interfaces are broadly divided into two categories: character user interface
ac

(CUI) or command-line user interface, and graphical user interface (GUI).


M
©

Exercises
1. Tick (ü) the correct option.
a. Which of the following is responsible for managing computer hardware and
software?
(i) Operating system (ii) Utility software
(iii) Language translator (iv) None of these

2020 Ubuntu Ed.indb 8 12-May-20 5:53:24 PM


b. Which of the following techniques is/are used by the operating system to
ensure the security of a computer system?
(i) Authentication (ii)
Authorisation
(iii) Cryptography (iv) All of these

c. Which feature of an operating system allows it to prevent unauthorised


access?
(i) Accounting (ii)
Security
(iii)
Communication (iv)
Program execution

d. WWW is an example of which type of system?


(i) Real-time system (ii) Distributed system

d
Lt
(iii) Batch-processing system (iv) None of these

t.
Pv
e. Which of the following is not an element of GUI?

a
(i) Window (ii)
Icon
di
In
(iii)
Command prompt (iv)
Menu
rs

2. Fill in the blanks.


he
lis

a. An .............................. is the heart of the computer system.


b

b. In a multi-user operating system, the computers are connected to the main


Pu

system through a ..............................


n

c. .............................. refers to the ability of the software to be used across


illa

different platforms.
m
ac

d. GUI stands for.............................. .


M

e. .............................. is defined as a set of one or more programs developed


©

to perform a specific task on the computer.

3. State true or false.


a. Software should be reliable.
b. The operating system is the first program that gets loaded into the computer’s
memory when the computer is switched on.
c. GUI is less resource consuming than CUI.
d. Android is a mobile operating system.
e. A multiprocessor system runs on a single processor.

2020 Ubuntu Ed.indb 9 12-May-20 5:53:24 PM


4. Answer the questions.
a. What is software? What are two types of software?
b. List four characteristics of software.
c. List and explain any four features of an operating system.
d. State the different types of operating systems.
e. What do you mean by user interface?
f. List some differences between CUI and GUI.
g. Briefly describe the elements of GUI.

d
Lt
t.
Pv
Activities

a
1. di
Go to your computer lab and make a list of operating systems being used on the
In
computers there.
rs

2. With the help of the Internet, collect information about different types of operating
he

systems and their features. Make a presentation for the same in Impress.
b lis
Pu

For the Teacher


n
illa

‹‹ Ask students about software and its types learnt in the previous classes.
m
ac

‹‹ Explain to students about operating systems along with their features and
M

functions.
©

‹‹ Tell them about different types of operating systems.


‹‹ Familiarise the students with the two types of user interfaces, GUI and CUI.

10

2020 Ubuntu Ed.indb 10 12-May-20 5:53:24 PM


2
Leno, today our teacher taught us about Sure Ria, I will not only tell you
database and DBMS. I found the topic about DBMS but also introduce
very interesting. Will you help me know you to a commonly used DBMS
more about DBMS? software—LibreOffice Base.

d
Lt
t.
Pv
a
di
In
rs
he
b lis
Pu
n
illa

Contents
m
ac

In today’s world where everything is getting


‹‹ Database and Database digitised, storing data and retrieving information
M

Management System efficiently have become very necessary. Data


©

‹‹ LibreOffice Base and information have to be maintained for many


day-to-day operations and transactions in every
‹‹ Creating a Database
organisation. The data has to be stored in such a
‹‹ Opening an Existing way that it can be easily retrieved and updated, as
Database and when needed. A fast access to information is
‹‹ Creating Tables also necessary, as important decisions are based
on the information available at any point of time.
‹‹ Working with Tables In addition to the storage and retrieval of data, many
‹‹ Managing Fields in the other operations are needed to be performed on
Design View the data, such as addition, updation and deletion
‹‹ Closing the Database and of data. All these operations can be performed on
Exiting LibreOffice Base data using a database management system.
11

2020 Ubuntu Ed.indb 11 12-May-20 5:53:25 PM


2.1 DATABASE AND DATABASE MANAGEMENT SYSTEM
A database is an organised collection of related (similar) data or information. It organises
data in such a way that any information can be retrieved and accessed easily. Creating,
adding, modifying, deleting and retrieving data to and from a database is known as
database management. A Database Management System (DBMS) is a collection of
programs that allows you to perform functions on a database in an effective and efficient
manner so that data can be updated and presented in the desired format. Some popularly
used DBMSs are Microsoft Access, DBase and FoxPro.

2.1.1 Types of Databases


There are mainly two types of databases, as listed below.
‹‹ Flat file database: A flat file database is one that stores data in the form of a plain

d
text file. It uses a simple structure with a single table. LibreOffice Calc and Microsoft

Lt
Excel are examples of flat file databases.

t.
Pv
‹‹ Structured database: A structured database contains a number of tables arranged
in an order and interconnected with each other through special fields. LibreOffice

a
di
Base, Microsoft Access, FoxPro, DBase and Oracle are some examples of structured
In
database.
rs
he

2.1.2 Database Models


lis

Database models refer to the way of designing a database and storing information in it.
b

There are three types of database models, namely, hierarchical, network and relational.
Pu

The most commonly used database model is the relational data model in which information
n

is stored in the form of tables and different tables are related through common fields.
illa

The DBMS design based on a relational model is known as the Relational Database
m

Management System (RDBMS).


ac
M

2.1.3 Database Models


©

The basic components of a DBMS are table, record and field. A table represents data
in the form of rows and columns. In a DBMS, rows are called records and columns are
called fields. A field holds one piece of information about an item. Multiple related fields
combine to form a record and finally, multiple records combine to form a table.
Fields

Employee_no Ename Basic Salary


101 Aman 23000
Records
102 Ridhi 24000
103 Manthan 27000
Fig. 2.1 Basic components of a DBMS
12

2020 Ubuntu Ed.indb 12 12-May-20 5:53:25 PM


2.1.4 Advantages of a DBMS
Conventionally, records are stored in the form of files. A set of application programs is
written to add records to or extract records from the appropriate files. However, this way
of managing data has many disadvantages. The database approach provides a solution
to all such problems as in this approach, the data is stored at a central location and is
shared among a number of users. This centralised nature of a database system has many
advantages.
Some of the major advantages of a DBMS are listed below.
‹‹ Easy to learn: Most of the database management systems are easy to learn and use.
No specialised training is required to work on a DBMS.
‹‹ Reduced redundancy: Redundancy implies duplication (or repetition) of the same
data at different places. In the conventional file system, the same data was stored

d
in many files. However, in database management systems, the data is stored at a

Lt
central location and shared by all the users. As a result, data redundancy is reduced.

t.
Pv
‹‹ Reduced inconsistency: When there are two or more files containing the same data
and one file is updated, while the other file contains the old data, the data is said to

a
di
be inconsistent. Most of the database management systems are designed to eliminate
In
data inconsistency as data is stored at a central location.
rs

‹‹ Sharing data: The data stored in the database can be shared by a number of users
he

or application programs easily.


lis

‹‹ Data security: Due to centralised storage of data, security constraints can be easily
b

enforced. This ensures that the data is accessed only through authorised channels.
Pu

Various security tools such as user codes and passwords can be used to control
n

access to the database.


illa

‹‹ Extensive help: The database management systems include an extensive built-in


m

help feature. This feature can be used whenever a user faces some problem while
ac

using any database management system.


M

‹‹ Backup and recovery: Most of the DBMSs come with backup and recovery tools that
©

help in recovering the data in case of hardware or software failures.

2.2 LIBREOFFICE BASE


LibreOffice Base is a powerful, yet easy-to-use RDBMS, which forms a part of the
LibreOffice suite of products. It can be used effectively to create databases at many places,
for example:
‹‹ in schools, to keep records of students, their addresses, results, etc.
‹‹ in organisations, to keep records of the employees’ salaries, attendance, expenses, etc.
‹‹ in banks, to maintain customer records, account details, etc.
‹‹ in hospitals, to keep records of patient details.
13

2020 Ubuntu Ed.indb 13 12-May-20 5:53:25 PM


‹‹ in libraries, to keep records of books of different subjects according to their author
name, date of issue, etc.
Base provides a set of objects, which help in the management of the database.
These objects are listed below.
‹‹ Table: It represents the data in the form of a grid, which comprises rows (records)
and columns (fields). A database can contain one or more tables. A table is the main
object used in Base.
‹‹ Form: It provides a medium of entering, editing and viewing the information in the
tables.
‹‹ Query: It defines a mechanism to retrieve and process the data stored in the database.
It enables the users to obtain a ‘subset’ of data from a table. A query can be based
on one table or on multiple related tables.

d
Lt
‹‹ Report: It defines a medium through which you can present data in a professional
format. Generally, a report is used to obtain a ‘printed copy’ of the data.

t.
Pv
Starting LibreOffice Base

a
To open LibreOffice Base, follow these steps.
di
In
1. Click the Show Applications icon ( ) at the bottom of the Launcher.
rs

The Applications screen appears listing icons of commonly used applications.


he

2. Type LibreOffice Base or Base in the search bar if it is not already listed.
lis

The LibreOffice Base icon ( ) appears.


b
Pu
n
illa
m
ac
M
©

Fig. 2.2 Starting LibreOffice Base


14

2020 Ubuntu Ed.indb 14 12-May-20 5:53:26 PM


3. Click the icon to open the application. The Database Wizard window appears which
displays options to create a new database, open an existing database or connect to
an existing database.

d
Lt
t.
Pv
a
di
In
rs
he
b lis

Fig. 2.3 Database Wizard window


Pu
n

2.3 CREATING A DATABASE


illa
m

To create a new database, follow these steps.


ac

1. In the Database Wizard window, select the Create a new database option
M

(see Fig. 2.3).


©

2. Click the Next button to move to the next screen of the wizard. Here, you can find
the following options.
„„ Yes, register the database for me: Select this option if you want to register your
database with the LibreOffice website.
„„ No, do not register the database: Select this option if you do not want to register
your database with the LibreOffice website. Since we are in the learning phase,
it is recommended to choose this option for now.
„„ Open the database for editing: Select this check box if you want the database
to open immediately after you save it. It saves the time to reopen the database.
„„ Create tables using the table wizard: Select this check box if you want to create
tables in the database through Table Wizard.
15

2020 Ubuntu Ed.indb 15 12-May-20 5:53:26 PM


d
Lt
t.
Pv
a
di
In
rs
he

Fig. 2.4 Selecting options for creating the database


lis

3. Choose the desired option and click the Finish button. This displays the Save dialog
b

box.
Pu

4. Specify the location where you want to save your database from the left pane of the
n

dialog box.
illa

5. Type a suitable name for your database in the Name box.


m
ac
M
©

Fig. 2.5 Save dialog box


16

2020 Ubuntu Ed.indb 16 12-May-20 5:53:26 PM


6. Click the Save button. If you have chosen the option to create tables in the database
through the table wizard, the Table Wizard window opens up. Otherwise, the Database
window opens up (see Fig. 2.6). Creating tables using the Table Wizard is discussed
in Section 2.5.2.

Note
In LibreOffice Base, a database is saved with the .odb extension.

Database Window
The Database window is divided into five sections as shown in Fig. 2.6.
Description
Tasks

d
section

Lt
section

t.
Pv
a
di
In
rs
he
b lis
Pu
n
illa
m
ac
M
©

Database Tables Document


section section section

Fig. 2.6 Database window

‹‹ The Database section displays icons for the objects that you can create in your
database.
‹‹ The Tasks section displays the options for creating the object selected in the Database
section.
‹‹ The Description section provides description of the option you select or point with
the mouse in the Tasks pane.
17

2020 Ubuntu Ed.indb 17 12-May-20 5:53:26 PM


‹‹ The Tables section lists all the tables in the database. Note that if you click any other
icon in the Database section, this section lists all the objects of that type in your
database. For example, if you click Queries in the Database section, this section lists
all the queries in your database. In addition, the name of this section also changes
to Queries.
‹‹ The Document section displays the contents of the table selected under the Tables
section. For this, select a table and then select the Document option from the shortcut
menu that appears when you click the down arrow at the top-right corner in the
Document section.

2.4 OPENING AN EXISTING DATABASE


If you are currently working on a database and want to open another database,

d
then follow these steps.

Lt
1. Click the File menu and then click Open.

t.
Pv
OR
Click the Open icon ( ) on the Standard toolbar.

a
The Open dialog box appears.
di
In
2. Locate and select the database you want to open.
rs
he
b lis
Pu
n
illa
m
ac
M
©

Fig. 2.7 Open dialog box

3. Click the Open button.


18

2020 Ubuntu Ed.indb 18 12-May-20 5:53:27 PM


2.5 CREATING TABLES
Once a database is created, we can enter data into it by creating tables. In LibreOffice
Base, you can create a table in two different ways: in the Design view and using the Table
Wizard. Let us learn to create tables in both ways.

2.5.1 Creating a Table in the Design View


The Design view is used to create and organise the structure of a table. It enables you to
create a table by specifying the field names along with their data types and properties.
To create a table in the design view, first you need to open the Table Design window.
For this, follow these steps.
1. In the Database window, click the Tables icon under the Database section.

d
Lt
t.
Pv
a
di
In
rs
he
lis

Fig. 2.8 Selecting an option to create a table in the Design view


b
Pu

2. Click the Create Table in Design View option under the Tasks section. The Table
n

Design window appears.


illa
m
ac
M
©

Fig. 2.9 Table Design window


19

2020 Ubuntu Ed.indb 19 12-May-20 5:53:27 PM


The Table Design window is divided into two sections: Field Definition at the top and Field
Properties at the bottom.
‹‹ Field definition section: This section has three columns, namely, Field Name, Field
Type and Description. Under the Field Name column, you can specify the name of
the fields to be used in your table such as Roll Number, Name, etc. Under the Field
Type column, you can specify the type of data to be stored in the field, such as text,
number, date, etc. Under the Description column, you can specify the purpose of the
particular field, if required.
The available data types in LibreOffice Base are listed in Table 2.1.
Table 2.1 Data types in LibreOffice Base
Type of Data Data Type in Base Description
Text Text (fix) [CHAR] It stores exactly the length of the text
specified by the user. If the length is

d
Lt
specified as 25 and you store only six

t.
characters then trailing spaces are padded

Pv
with blanks. The default length of this data
type is 100.

a
Text [VARCHAR]
di
This is the default data type that stores
In
only the characters entered by the user,
rs

maximum up to the specified length.


he

Text [VARCHAR_ It is similar to Text[VARCHAR] type.


lis

IGNORECASE] The only difference is that it ignores the


b

case of letters that you enter and converts


Pu

the text into uppercase as you type.


n

Memo [LONGVARCHAR] It is used for storing large text entries.


illa

This data type can store up to 2 GB of data.


m

Numeric Tiny Integer [TINYINT] It can store integers or whole numbers


ac

(numbers without decimal) of maximum 3


M

digits.
Small Integer [SMALLINT] It can store integers or whole numbers.
©

The default length is 5 digits.


Integer [INTEGER] It can store integers with a fixed length of
10 digits.
BigInt [BIGINT] It can store integers with a fixed length of
19 digits.
Float [FLOAT] It can store whole numbers as well as
floating-point numbers (numbers with
decimal).
Real [REAL] It is similar to Float[FLOAT] data type.
The difference lies in the method of storing
data.
20

2020 Ubuntu Ed.indb 20 12-May-20 5:53:27 PM


Double [DOUBLE] It is also similar to Float [FLOAT] data type
but can handle double amount of data
than the float data type.
Number [NUMERIC] It can store whole numbers as well as
numbers with decimals. There is virtually
no limit on its size; it is limited by the
computer’s resource limits.
Decimal [DECIMAL] It is used to store numeric data with decimal.
Its size is also limited by the computer's
resource limits.
Date/Time Date [DATE] It is used to store date by storing information
on month, day and year. Various formats

d
are available for entering dates; the default

Lt
format is MM/DD/YY.

t.
Pv
Time [TIME] It is used to store time values by storing
information on hours, minutes and seconds.

a
di
Various formats are available for entering
In
time; the default format is HH:MM:SS.
rs

Date/Time [TIMESTAMP] It is used to store both date and time.


he

Image It can store an image in binary form. It can


lis

[LONGVARBINARY] store up to 2 GB of information.


b
Pu

Binary [VARBINARY] It can store any kind of binary code.


n

Binary (fix) [BINARY] It can store binary code such as


illa

Binary[VARBINARY] data type. The only


m

difference is that it should be set to have


ac

a fixed length. It can store up to 2 GB of


Special
M

information.
©

Yes/No [BOOLEAN] It can store one of the two Boolean values:


Yes ('1') or No ('0').
Other [OTHER] It can store any type of data: an image, a
sound file, etc. This data type is specifically
used when you find no other type
appropriate for your data.

‹‹ Field Properties section: This section is used to define the properties of the fields in
a table. The properties of the fields are dependent on the data types. Each data type
has a different set of properties. Some of the common properties are Entry required,
Length, Decimal places, Default value and AutoValue.

21

2020 Ubuntu Ed.indb 21 12-May-20 5:53:27 PM


Suppose you want to create a table with the field names, data types and field properties,
as listed in Table 2.2.
Table 2.2 A sample table

Field Name Data Type Field Properties


Roll Number Integer [INTEGER] Entry required: Yes
Name Text [VARCHAR] Entry required: Yes
Length: 20
Maths Number [NUMERIC] Entry required: Yes
Length: 10
Information Technology Number [NUMERIC] Entry required: Yes
Length: 10
English Number [NUMERIC] Entry required: Yes

d
Lt
Length: 10

t.
To create the sample table in the Table Design window, follow these steps.

Pv
1. In the Field Definition section, type the name of the first field of your table (that is,

a
di
Roll Number) under the Field Name column. In
2. Select the required data type for the field, that is, Integer [INTEGER], from the drop-
rs

down list under the Field Type column.


he

3. Type a description about the field under the Description column, if required.
lis

4. In the Field Properties section, specify the desired properties for the field. For example,
b

select the Yes option from the Entry required drop-down list.
Pu

5. Similarly, enter other fields of the table and specify the desired properties.
n
illa
m
ac
M
©

Fig. 2.10 Creating a table in the Table Design window


22

2020 Ubuntu Ed.indb 22 12-May-20 5:53:27 PM


6. Once the table is created, it is necessary to save it for future reference. To save the
table, click the File menu and then click Save or click the Save icon( ) on the
Standard toolbar. The Save As dialog box appears.
7. Enter the name of the table, for example, Result, in the Table Name text box.

Fig. 2.11 Saving the table

8. Click OK. A message window appears that prompts you to create a primary key for

d
the table. Click Yes to let Base automatically create a primary key for the table, click

Lt
No if no primary key is required and click Cancel to remain in the design view.

t.
Pv
a
di
In
rs
he
b lis
Pu
n
illa

Fig. 2.12 Message window


m
ac

Setting the Primary Key


M

A primary key is the field that has a unique value across all occurrences in the table.
©

In other words, when a field is set as a primary key, it ensures that no two records in the
database contain the same value for that field. It is the field that uniquely identifies the
records in a table. For example, the roll number of a student is unique as two students
cannot have the same roll number in the same class. Hence, in a table containing data
about students, the roll number is the primary key.
You can also create a primary key even after creating a table. For example, to set the
Roll Number field as the primary key in the Result table, follow these steps.
1. Select the Roll Number field. To select, click on the grey area on the leftmost corner
of the field. The entire row gets highlighted.
2. Right-click on the green arrow icon( ) beside the selected field and select the
Primary Key option from the shortcut menu that appears.
23

2020 Ubuntu Ed.indb 23 12-May-20 5:53:27 PM


d
Lt
t.
Pv
a
di
Fig. 2.13 Setting the primary key
In
rs

A key symbol ( ) appears to the left of the field.


he

3. Click the Close button ( ) on the top-right corner of the Table Design window to
lis

close the table. Base prompts a message window that asks you to save changes.
b
Pu

4. Click Yes to save the changes and close the table.


n
illa
m
ac
M
©

Fig. 2.14 Save changes confirmation box

2.5.2 Creating a Table using Table Wizard


Table Wizard provides some sample fields and tables to guide and help you in creating
tables. You can define the table structure, data types and the field sizes according to the
available sample tables and fields. To create a table using Table Wizard, follow these steps.
1. In the Database window, click Tables under the Database section and then click Use
Wizard to Create Table option under the Tasks section (see Fig. 2.8). This displays
the Table Wizard window.
24

2020 Ubuntu Ed.indb 24 12-May-20 5:53:28 PM


2. Select the category of table you want to create by selecting either the Business or
Personal option under Category. A list of sample tables available in the chosen
category appears in the Sample tables drop-down list.
3. Select the desired sample table from the Sample tables drop-down list, for example,
we have selected Library. All the fields of the selected table appear in the Available
fields list box.

d
Lt
t.
Pv
a
di
In
rs
he

Fig. 2.15 Selecting the sample table in the Table Wizard window
lis

4. Click on the field you want in your table in the Available fields list box. To select
b
Pu

multiple fields, hold down the Ctrl key and then click on the field name.
5. Click the ( ) button to move the selected field(s) from the Available fields list box
n
illa

to the Selected fields list box. If you want to include all the available fields in your
table, simply click the ( ) button.
m
ac
M
©

Fig. 2.16 Selecting fields for the table


25

2020 Ubuntu Ed.indb 25 12-May-20 5:53:28 PM


6. Click the Next button to move to the next screen of Table Wizard. Here, you can
change the name and data type of the selected fields and set their properties. To do
this, select the desired field from the Selected fields list box and make the required
changes under the Field information section.

d
Lt
t.
Pv
a
di
In
Fig. 2.17 Setting field types and formats
rs
he

7. Click the Next button. The next screen of Table Wizard appears which prompts you
lis

to set the primary key of the table.


b
Pu

8. Select the desired option, for example, we have selected Automatically add a primary
key option for now, and click the Next button.
n
illa
m
ac
M
©

Fig. 2.18 Setting the primary key


26

2020 Ubuntu Ed.indb 26 12-May-20 5:53:28 PM


9. In the next screen of the Table Wizard window, you have to specify a name for your
table and then select one of the Insert data immediately, Modify the table design and
Create a form based on this table options. For example, we have selected Insert data
immediately option.

d
Lt
t.
Pv
a
di
In
rs
he

Fig. 2.19 Defining a name for the table


b lis

10. Click the Finish button. You can see the table you just created listed under the Tables
Pu

section in the Database window. Also, the Table Data View window opens up where
n

you can enter records in your table.


illa
m
ac
M
©

(a) Tables listed in the Database window


27

2020 Ubuntu Ed.indb 27 12-May-20 5:53:28 PM


d
(b) Table Data View of table created

Lt
Fig. 2.20 Table created using Table Wizard

t.
Pv
2.6 WORKING WITH TABLES

a
di
In this section, you will learn how to open a table, enter and edit data in a table, modify
In
the structure of a table, sort records in a table, etc.
rs
he

2.6.1 Opening a Table


lis

You can open a table in the Table Design view or Table Data view. If you want to modify
b

the structure of a table, you should open it in the Table Design view. On the other hand,
Pu

if you want to enter or edit data in the table, you should open it in the Table Data view.
n

To open a table, first click the Tables icon under the Database section in the Database
illa

window and then perform any of these steps.


m

‹‹ To open in the Table Design view, right-click on the table you want to open under
ac

the Tables section in the Database window and then select the Edit option from the
M

shortcut menu that appears.


©

(a) Selecting option (b) Table Design window


Fig. 2.21 Opening a table in the design view
28

2020 Ubuntu Ed.indb 28 12-May-20 5:53:29 PM


‹‹ To open in the Table Data View, double-click on the table name under the Tables
section.

d
Lt
Fig. 2.22 Opening a table in the Table Data View

t.
Pv
2.6.2 Entering and Editing Data in a Table

a
Once the structure of a table is defined, you can enter data into it. Suppose you want to
di
In
enter the data given in Table 2.3 in the table Result that you created earlier.
rs

Table 2.3 Sample data


he

Roll Number Name Maths Information Technology English


lis

1 Aditya 77 56 67
b

2 Bhanu 89 78 82
Pu

3 Nidhi 67 66 92
n

4 Rani 67 88 85
illa

5 Ruchi 78 90 88
m
ac

6 Tanvi 56 87 90
M

To enter the sample data in the table Result, follow these steps.
©

1. Open the table Result in the Table Data View. You will see a blank row to add a new
record.
2. Type 1 in the Roll Number field. As you start typing, a new blank row automatically
appears below the current row with an asterisk symbol ( ) in the row selector.
A pencil icon ( ) appears on the row selector of the current row, indicating that the
record is being entered or edited.
3. Press the Tab or Enter key to go to the next field in the same row and type Aditya
under the Name field.
4. Similarly, type values in the remaining fields of this record and press the Tab or Enter
key to move to the Roll Number field of the next record. This way, you can add other
records in the table.
29

2020 Ubuntu Ed.indb 29 12-May-20 5:53:29 PM


Once you have entered all the records, your screen resembles as shown in Fig. 2.23.

Fig. 2.23 Data entered in Result table

5. Save the table by clicking the Save icon ( ) on the Standard toolbar.

d
You can also make changes in the values that are already entered in the fields. To make

Lt
changes in the value of any field, follow these steps.

t.
Pv
1. Move the cursor to the location where you want to modify the data.
2. Type the new value for the field and press the Enter or the Tab key.

a
di
In
2.6.3 Deleting Records from a Table
rs

You can delete the existing records, if required. Suppose you want to delete the record of
he

the student named Nidhi from the table. To delete this record, follow these steps.
lis

1. Select the record.


b
Pu

2. Click the Edit menu and then click the Delete Record option.
n

OR
illa

Right-click on the selected row and then select the Delete Rows option from the
m

shortcut menu that appears.


ac
M
©

(a) Selecting option from Edit menu


30

2020 Ubuntu Ed.indb 30 12-May-20 5:53:29 PM


d
Lt
t.
(b) Selecting option from the shortcut menu

Pv
Fig. 2.24 Deleting a record from a table

a
A message box appears that asks you to confirm the deletion. Click Yes to confirm the
di
In
deletion and No to keep the record in the table.
rs
he
b lis
Pu
n
illa
m
ac

Fig. 2.25 Message box for deletion confirmation


M
©

Note
You can also delete the selected record by pressing the Delete key on the
keyboard.

2.6.4 Navigating in a Table


While working with large tables, you should know the fastest way of moving from one
record to another in the table. For this, you can either use the horizontal or the vertical
scroll bar. The vertical scroll bar is used to move up or down the records and the horizontal
scroll bar is used to move left or right around the fields. You can also use the Arrow keys
to move to the left, right, up and down a record.

31

2020 Ubuntu Ed.indb 31 12-May-20 5:53:29 PM


2.6.5 Sorting Records in a Table
Arranging the records in a table in an ascending or a descending order is known as
sorting. You can sort the records in a table based on any field. To sort the records of a
table, follow these steps.
1. Open the table in the Table Data View.
2. Select the desired field by clicking on its name. For example, we have selected the
Information Technology field of the Result table.

d
Lt
t.
Pv
Fig. 2.26 Selecting the field for sorting the records

a
2. Click the Sort Ascending (
di
) or Sort Descending icon ( ) present on the Standard
In
toolbar to arrange the records in ascending or descending order, respectively.
rs

Figure 2.27 shows the records of the Result table arranged in the descending order
he

according to the Information Technology field.


b lis
Pu
n
illa
m
ac
M
©

Fig. 2.27 Records in sorted order

2.7 MANAGING FIELDS IN THE DESIGN VIEW


Base allows you to modify the design of a table even after creating it. For example,
you can add new fields, delete existing fields, etc.

2.7.1 Inserting a Field


To insert a new field in an existing table, follow these steps.
1. Open the table in the design view.

32

2020 Ubuntu Ed.indb 32 12-May-20 5:53:29 PM


2. Type the name of the new field under the Field Name column after the last field of
the table (for example, Social Science in our case).
3. Specify the data type and description for the field under Field Type and Description
column, respectively.
4. Specify the desired properties for the field in the Field Properties section.

d
Lt
t.
Pv
a
di
In
rs

Fig. 2.28 New field inserted in the table


he

5. Save the table.


b lis

2.7.2 Deleting a Field


Pu

To delete an unwanted field from an existing table in the Table Design view, follow these
n

steps.
illa

1. Select the field that you want to delete.


m
ac

2. Right-click and select the Delete option from the shortcut menu that appears.
M
©

Fig. 2.29 Deleting a field from a table


33

2020 Ubuntu Ed.indb 33 12-May-20 5:53:30 PM


2.8 CLOSING THE DATABASE AND EXITING
LIBREOFFICE BASE
To close a database and exit LibreOffice Base, follow any of these steps in the Database
window.
‹‹ Click the File menu and then click Close.
‹‹ Click the Close button ( ) in the top-right corner of the window.
If you have made some changes in the database but not saved those changes, Base displays
a message box (see Fig. 2.30) that prompts you to save the changes before closing the
database. Click Save to save the changes, Discard to close the database without saving
the changes, and Cancel to abort the closing and continue working in the database.

d
Lt
t.
Pv
a
di
Fig. 2.30 Message box
In
rs
he

Points to
lis

Remember
b
Pu

‹‹ A database is an organised collection of related data or information.


n

‹‹ Creating, adding, modifying, deleting and retrieving data to and from a database
illa

is known as database management.


m

‹‹ DBMS is a collection of programs that allows you to perform functions on a


ac

database in an effective and efficient manner so that data can be updated and
M

presented in the desired format.


©

‹‹ There are mainly two types of databases, flat file database and structured database.
‹‹ Database models refer to the way of designing a database and storing information
in it. There are three types of database models, namely, hierarchical, network and
relational.
‹‹ The most commonly used database model is the relational data model in which
information is stored in the form of tables and different tables are related through
common fields.
‹‹ The DBMS design based on a relational model is known as the Relational
Database Management System (RDBMS).

34

2020 Ubuntu Ed.indb 34 12-May-20 5:53:30 PM


‹‹ The basic components of a DBMS are table, record and field. A table represents
data in the form of rows and columns. In a DBMS, rows are called records and
columns are called fields.
‹‹ LibreOffice Base is a powerful, yet easy-to-use RDBMS, which forms a part of the
LibreOffice suite of products.
‹‹ Base provides a set of objects, which help in the management of the database.
Some of the commonly used objects are table, form, query and report.
‹‹ In LibreOffice Base, there are two ways of creating a table: using Design view and
using Table Wizard.
‹‹ The Table Design window is divided into two sections: Field Definition and Field
Properties. In the Field Definition section, you specify the fields of the table and

d
in the Field Properties section, you specify the properties of the fields in the table.

Lt
‹‹ A primary key is a field that has a unique value for all records in the table. When

t.
Pv
a field is set as the primary key, it ensures that no two records in the database
contain the same value for that field.

a
di
‹‹ Table Wizard provides some sample fields and tables to guide and help you in
In
creating tables. You can define the table structure, data types and the field sizes
rs

according to the available sample tables and fields.


he
b lis
Pu
n
illa

Exercises
m
ac

1. Tick (ü) the correct option.


M

a. Which of the following is a database object in LibreOffice Base?


©

(i) Table (ii) Query


(iii) Form (iv) All of these
b. Which of the following fields uniquely identifies the records in a table?
(i) Primary key (ii) Secondary key
(iii) Super key (iv) Candidate key
c. Which of the following data types is used to store both date and time?
(i) Time [TIME] (ii) Date [DATE]
(iii) Date/Time [TIMESTAMP] (iv) None of these

35

2020 Ubuntu Ed.indb 35 12-May-20 5:53:30 PM


d. Which of the following is not a part of the Field Definition section in the
Table Design window?
(i) Field Type (ii) Field Size
(iii) Field Name (iv) None of these
e. Which of the following data types is used to store numeric data with decimal?
(i) DOUBLE (ii) FLOAT
(iii) REAL (iv) None of these

2. Fill in the blanks.


a. A .............................. is an organised collection of related data or
information.

d
Lt
b. A .............................. represents data in the form of rows and columns.

t.
c. LibreOffice Base saves a database with .............................. extension.

Pv
d. The .............................. view is used to create and organise the structure of

a
di
a table. In
e. The .............................. section in the Table Design window is used to
rs

define the properties of the fields in a table.


he
lis

3. State true or false.


b

a. Multiple records combine to form a field.


Pu

b. Memo [LONGVARCHAR] data type can store up to 2 GB of data.


n
illa

c. A query provides a medium of entering, editing and viewing the information


in the tables.
m
ac

d. Integer [INTEGER] data type is used to store numeric values with decimal.
M

e. Table Wizard provides some sample fields and tables to guide and help you
©

in creating tables.

4. Answer the questions.


a. Define database and database management system.
b. What are the basic components of a DBMS?
c. Mention any three advantages of DBMS.
d. Explain the commonly used objects of LibreOffice Base.
e. Describe different parts of the Table Design window of a table.
f. Write the steps for creating a table in the Table Design view.
g. Write the steps for sorting records in a table.

36

2020 Ubuntu Ed.indb 36 12-May-20 5:53:30 PM


Activities
1. Create a table named ‘Books’ to store information about your school library.
This is the sample data for the table.
Book Code Book Name Author No of Copies
1 Great Expectations Charles Dickens 5
2 Gone with the Margaret Mitchell 3
Wind
3 Scarlet Letter Nathaniel 4
Hawthorne

d
Lt
4 Pride and Prejudice Jane Austen 5
5 Middlemarch George Eliot 1

t.
Pv
a. Set ‘Book Code’ as the primary key.

a
b. Delete the record ‘Middlemarch’ from the table.
di
In
c. Sort the table according to the field ‘Author’.
rs
he
b lis

For Teacher
Pu

the
n

‹‹ Initiate the discussion with the basics of a database. Explain the concept of
illa

database with the example of an attendance register which is the database of all
m

the students in a class.


ac

‹‹ Introduce to students the Base window and explain its various components.
M

‹‹ Demonstrate the steps for creating tables in a database and perform various
©

operations.

37

2020 Ubuntu Ed.indb 37 12-May-20 5:53:30 PM


3
Hey Ria! You have learnt to create tables
in LibreOffice Base till now. But you
know you can create queries, forms and
Wow! That’s great!
reports also in Base.
Let us start.

d
Lt
t.
Pv
a
di
In
rs
he
b lis
Pu
n
illa

Contents
m

The database of any organisation may consist of multiple


ac

‹‹ What is a Query? tables. Each table may further contain several records.
M

With this, it becomes quite cumbersome to retrieve specific


‹‹ Creating Queries
©

records from a table. LibreOffice Base provides a solution


‹‹ Creating Forms for this problem through queries.A query is a database
‹‹ Creating Reports object used to retrieve the data based on the conditions
specified by the user. It enables the users to obtain a
subset of data from one or more tables in a database.

3.1 WHAT IS A QUERY?


In simple terms, a query means request for information. In Base, query is a basic tool
for retrieving information from one or more tables in a database based on some search
conditions. For example, suppose you want to view the ID, title and price of the books
having price less than or equal to 200 from a table named Book. For this, you have to
design and execute a query that will retrieve only the desired records from the table.
38

2020 Ubuntu Ed.indb 38 12-May-20 5:53:31 PM


Queries can be used to view, sort and analyse the data in different ways. You can also
update or delete records with the help of a query.

Note
Queries are made on tables and their results are also displayed in form of
tables containing the rows and columns that match the specified criteria.

3.2 CREATING QUERIES


Base allows you to create queries in the following three ways:
‹‹ Create a query in the Design View

d
‹‹ Use the Query Wizard to create a query

Lt
t.
‹‹ Create a query in the SQL View

Pv
Let us learn to create a query in Design View.

a
Creating a Query in the Design View di
In
rs

Suppose you want to create a query to view the roll number, name and marks of students
he

who have scored more than 75 marks in Maths from the table Result of Student database
(you created in previous chapter). To create this query in the Design View, follow these steps.
b lis

1. Open the Student database.


Pu

2. In the Database window, click Queries under the Database section.


n

3. Click Create Query in Design View option under the Tasks section.
illa
m
ac
M
©

Fig. 3.1 Selecting options to create a query


39

2020 Ubuntu Ed.indb 39 12-May-20 5:53:32 PM


This opens the Query Design window and displays Add Table or Query dialog box.
Here, you have to specify the tables and/or queries on the basis of which you want to
design the query.
4. Select the Tables option in the dialog box (by default, selected). This lists all the
tables of your database in the dialog box.
5. Select the desired table(s), for example, Result in our case and then click Add.

d
Lt
t.
Pv
a
di
In
rs

Fig. 3.2 Query Design window with Add Table or Query dialog box
he

6. Click the Close button to close the Add Table or Query dialog box. This displays the
lis

fields of Result table in the top section of the Query Design window, named Object
b
Pu

Relationship pane.
n
illa
m
ac

Object
Relationship pane
M
©

Design Grid

Fig. 3.3 Result table added in the Query Design window


40

2020 Ubuntu Ed.indb 40 12-May-20 5:53:32 PM


7. Now, you have to specify the fields to be displayed in the result of query. For this,
in the bottom section of Query Design window, that is, Design Grid, click in the first
column of the Field row, click the down arrow and then select Result.Roll No from
the drop-down list.

d
Lt
t.
Pv
a
di
In
rs

Fig. 3.4 Selecting the field to be displayed in the result of query


he
lis

8. Similarly, select Result.Name and Result.Maths in the next two columns of the Field
b

row.
Pu

9. In the Criterion row, specify the criterion, that is, type >75 under the Result.Maths
n

column. Now, the Query Design window resembles as shown in Fig. 3.5.
illa
m
ac
M
©

Fig. 3.5 Specifying the criterion for the query


41

2020 Ubuntu Ed.indb 41 12-May-20 5:53:32 PM


10. To view the result of query, click the Run Query icon( ) on the Query Design
toolbar or press the F5 key on the keyboard. The result of query is displayed in the
topmost section of the Query Design window.

d
Lt
t.
Pv
a
di
In
rs

Fig. 3.6 Query output


he
lis

11. Save your query for future reference by clicking the Save button ( ) on the Query
b

Design toolbar. The Save As dialog box appears.


Pu

12. Type a suitable name for the query in the Query name text box and click OK.
n
illa
m
ac
M
©

Fig. 3.7 Saving the query

13. Click the Close button ( ) on the


top-right corner of the Query Design
window to close it.
Now, when you click Queries under the
Database section in the Database window,
the query you have created is displayed
under the Queries section. You can simply
double-click on it to view its result.

Fig. 3.8 Query displayed in the Database window


42

2020 Ubuntu Ed.indb 42 12-May-20 5:53:33 PM


3.3 CREATING FORMS
Forms provide an interface to insert, update and delete records in the table. They generally
display one record at a time on the screen. A form can be customised to display all or only
selected fields from the table. Base allows you to create a form in following two ways.
‹‹ Create a form in the Design View
‹‹ Use the Form Wizard to create a form
Let us learn to create a form using the Form Wizard.

Creating a Form using the Form Wizard


To create a form using the Form Wizard, follow these steps.
1. Open the desired database.

d
Lt
2. In the Database window, click Forms under the Database section.

t.
3. Select the Use Wizard to Create Form option under the Tasks section.

Pv
a
di
In
rs
he
b lis
Pu
n
illa

Fig. 3.9 Selecting options to create the form


m
ac

The Database Form window opens up displaying the Form Wizard window.
M
©

Fig. 3.10 Database Form window with Form Wizard window


43

2020 Ubuntu Ed.indb 43 12-May-20 5:53:33 PM


4. Select the table to be used for creating the form from the Tables or queries drop-down
list. As you select, all the fields of the selected table are displayed in the Available
fields list box.
5. Select the field that you want to include in the form from the Available fields list and
click the ( ) button to move it to the Fields in the form list. You can also click the
( ) button to include all the fields of the table at once.

d
Lt
t.
Pv
a
di
In
rs
he

Fig. 3.11 Selecting the desired table and fields for the form
lis

6. After you have selected the desired fields, click the Next button to move to the next
b

step of the Form Wizard.


Pu

7. Here you can choose to add a subform—a form within a form that lets you add more
n

specific data to the original form—by selecting the Add Subform check box. You can
illa

also include fields from other tables at this point.


m
ac
M
©

Fig. 3.12 Adding a subform to the original form


44

2020 Ubuntu Ed.indb 44 12-May-20 5:53:33 PM


8. Click the Next button to move to the next step of the Form Wizard.
9. Here, you can specify the arrangement of controls on your form. Select the desired
layout for the form under the Arrangement of the main form section.

d
Lt
t.
Pv
a
di
Fig. 3.13 Selecting the layout of the form
In
10. Click the Next button to move to the next step of the Form Wizard.
rs
he

11. Select the desired data entry mode for the form. Here you have two options. If you
want to use the form only for entering new data, select the first option. However,
lis

if you want the form to display all the data, select the second option.
b
Pu
n
illa
m
ac
M
©

Fig. 3.14 Selecting the data entry mode for the form

12. Click the Next button to move to the next step of the Form Wizard.
13. Select the desired style for your form from the Apply styles list and select the desired
option for the field border from the Field border section.
45

2020 Ubuntu Ed.indb 45 12-May-20 5:53:34 PM


d
Lt
t.
Pv
Fig. 3.15 Choosing style for the form

a
14. Click the Next button to move to the next step of Form Wizard.
di
In
15. Type a suitable name for your form in the Name of the form text box and select the
rs

desired option to specify How do you want to proceed after creating the form?.
he
b lis
Pu
n
illa
m
ac
M
©

Fig. 3.16 Specifying the name of the form

16. Click the Finish button. The Database Form window opens up displaying the form
you have created. You can navigate through the records using the record navigation
buttons on the Form Navigation toolbar at the bottom of the Database Form window.
These buttons are used to move to the first, last, next, previous or any specific record
in a table.
46

2020 Ubuntu Ed.indb 46 12-May-20 5:53:34 PM


Form
Navigation

d
toolbar

Lt
t.
Pv
a
di
Fig. 3.17 Database Form window displaying the form
In
rs

17. Save the form by clicking the Save button ( ) on the Standard toolbar.
he

18. Click the Close button ( ) on the top-right corner of the Database Form window
lis

to close it.
b
Pu

Now, when you click Forms under the Database section in the Database window, the
form you have created is displayed under the Forms section. You can simply double-
n

click on it to open the form in Database Form window.


illa
m
ac
M
©

Fig. 3.18 Form displayed in the Database window

47

2020 Ubuntu Ed.indb 47 12-May-20 5:53:34 PM


3.4 CREATING REPORTS
Once the data is entered in the tables, it needs to be printed. Although tables and queries
can be printed, they do not look very professional as they are not designed for printing
purposes. To print the data stored in the database in a professional format, reports are
used. Reports take the data from one or more tables and/or queries and display it in a
professional format.
Like forms, Base allows you to create reports in following two ways.
‹‹ Create a report in the Design View
‹‹ Use the Report Wizard to create a report
Let us learn to create a report using the Report Wizard.

Creating a Report Using the Report Wizard

d
Lt
To create a report using the Report Wizard, follow these steps.

t.
Pv
1. Open the desired database.

a
2. In the Database window, click Reports under the Database section.
3. di
Click the Use Wizard to Create Report option under the Tasks section.
In
rs
he
b lis
Pu
n
illa
m
ac
M
©

Fig. 3.19 Selection options to create the report

The Report Wizard window appears.

48

2020 Ubuntu Ed.indb 48 12-May-20 5:53:34 PM


d
Lt
Fig. 3.20 Report Wizard window

t.
Pv
4. Select the table to be used for creating the report from the Tables or queries drop-

a
down list. As you select, all the fields of the selected table are displayed in the
Available fields list box.
di
In
5. Select the field that you want to include in the form from the Available fields list and
rs

click the ( ) button to move it to the Fields in report list. You can also click the
he

( ) button to include all the fields of the table at once.


lis

6. After you have selected all the fields, click the Next button to move to the next step
b
Pu

of the Report Wizard.


n
illa
m
ac
M
©

Fig. 3.21 Selecting the desired table and fields for the report

7. Specify the labels for the fields included in the report. Label is the text that will
appear in the report in place of the field name.
49

2020 Ubuntu Ed.indb 49 12-May-20 5:53:34 PM


Fig. 3.22 Specifying labels for the fields

8. Click the Next button to move to the next step of the Report Wizard. Here you have

d
Lt
to define the grouping levels for the fields. Simply, click the Next button to skip this
step and move to next step of Report Wizard.

t.
Pv
9. Specify the fields based on which you want to sort the records in ascending or
descending order and click the Next button.

a
di
In
rs
he
b lis
Pu
n
illa
m
ac

(a) Adding grouping levels (b) Specifying the sort options


M

Fig. 3.23 Specifying the grouping levels and sort order


©

10. Choose the desired layout for the


report from Layout of data and
Layout of headers and footers list. You
can also select the desired orientation
(Landscape or Pobrtrait) from the
Orientation section.
11. Click the Next button to move to the
next step of the Report Wizard.
12. Specify a suitable title for the report in
the Title of report text box and other
Fig. 3.24 Choosing layout and orientation
options as per your requirement.
for the report
50

2020 Ubuntu Ed.indb 50 12-May-20 5:53:35 PM


Fig. 3.25 Specifying the title for the report and other options

13. Click the Finish button. The report you have created opens up in a Writer document.

d
Lt
t.
Pv
a
di
In
rs
he
b lis
Pu

Fig. 3.26 Report created


n
illa

14. Click the Close button ( ) on the top-right corner of the Writer window to close the
report.
m
ac

Now, when you click Reports under the Database section in the Database window,
the report you have created is displayed under the Reports section. You can simply
M

double-click on it to open it.


©

Fig. 3.27 Report displayed in the Database window


51

2020 Ubuntu Ed.indb 51 12-May-20 5:53:35 PM


Points to
Remember
‹‹ A query is a database object used to retrieve the data based on the conditions
specified by the user.
‹‹ In Base, query is a basic tool for retrieving information from one or more tables
in a database based on some search conditions.
‹‹ Base allows you to create queries in the three ways: Create Query in Design View,
Use Wizard to Create Query and Create Query in SQL View.
‹‹ Forms provide an interface to insert, update and delete records in the table.
‹‹ Base allows you to create a form in two ways: Create Form in Design View and
Use Wizard to Create Form.

d
Lt
‹‹ Reports take the data from one or more tables and/or queries and display it in a

t.
professional format.

Pv
‹‹ In Base, you can create reports in two ways: Create Report in Design View and

a
Use Wizard to Create Report.
di
In
rs
he
lis

Exercises
b
Pu

1. Tick (ü) the correct option.


n
illa

a. Which of the following database objectshelps to present data in a professional


format?
m

(i) Table (ii) Query


ac
M

(iii)
Form (iv) Report
©

b. Which key should be pressed to run a query?


(i) F5 (ii) F6
(iii)
F7 (iv) F8
c. In Base, queries, forms and reports can be designed:
(i) In design view (ii) Using wizard
(iii) Both (i) and (ii) (iv) None of these
d. Which of the following cannot be created in Base?
(i) Queries (ii) Tables
(iii)
Presentation (iv) Forms

52

2020 Ubuntu Ed.indb 52 12-May-20 5:53:35 PM


e. Which of the following provides an interface to insert, update and delete
records in a table?
(i) Report (ii) Form
(iii)
Table (iv) Query

2. Fill in the blanks.


a. The Query Design window is divided into two sections, ..............................
and ...............................
b. A .............................. is a database object used to retrieve the data based
on the conditions specified by the user.

d
c. The result of a query is displayed in the form of a .............................. .

Lt
d. .............................. generally display one record at a time on the screen.

t.
Pv
e. The .............................. section in Database window displays different

a
options to create a report.
di
In
3. State true or false.
rs
he

a. A query can include fields from multiple tables.


lis

b. We cannot run a query without saving it.


b
Pu

c. A report provides a medium of entering, editing and viewing the information


n

in the tables.
illa

d. A form can be customised to display all or only selected fields from the
m

table.
ac
M

e. You can create a report using the Report Wizard.


©

4. Answer the questions.


a. What is a query?
b. List the three ways in which a query can be created in Base.
c. Differentiate between forms and tables.
d. Name the two parts of the Query Design window. What does each part
display?
e. In how many ways, can forms be designed in Base?
f. What is a report? In how many ways can you create a report in Base?

53

2020 Ubuntu Ed.indb 53 12-May-20 5:53:35 PM


Activities
Create a database named ‘Inventory’ for storing details of various products. In this
database, create a table named ‘Product’ the fields shown in the following table.
Book Code Book Name Author No of Copies
1 Great Expectations Charles Dickens 5
2 Gone with the Wind Margaret Mitchell 3
3 Scarlet Letter Nathaniel 4
Hawthorne
4 Pride and Prejudice Jane Austen 5

d
Lt
5 Middlemarch George Eliot 1

t.
Now, perform the following operations.

Pv
a. Set ‘Product_No’field as the primary key.

a
di
b. Add 10 records in the table. In
c. Make the following queries to retrieve the records.
rs

„„ Products with quantity more than 20


he

„„ Products with price less than 5000


b lis

d. Create a form for the table using the Form Wizard to add 5 records in it.
Pu

e. Create a report for the table displaying only the Product_Name, Price and Qty-
n

in_hand fields.
illa

f. Create a report for the table, grouping the records according to ‘Reorder_Level’
m

field and then sorting each record under a group according to ‘Product_Name’
ac

field.
M
©

For the Teacher


‹‹ Familiarise the students with other database objects besides tables that can be
created in Base.
‹‹ Explain to them the use of queries, forms and reports.
‹‹ Help students in creating the queries, forms and reports.

54

2020 Ubuntu Ed.indb 54 12-May-20 5:53:36 PM


4
Hey Ria. Do you
remember algorithms Yes, Leno! They both
and flowcharts? present the stepwise
solution of a problem.
Let us learn more
about algorithms

d
and flowcharts.

Lt
t.
Pv
a
di
In
rs
he
b lis
Pu
n
illa
m
ac

Contents There are many kinds of tasks that you do in your


M

daily life. To do each task, certain steps are followed.


©

‹‹ Algorithm For example, to prepare a cake, you have to follow a step-


‹‹ Flowchart by-step approach as given below.

1. Collect all the ingredients.


2. Mix all the ingredients in a bowl.
3. Pour the mixture in a baking
tray.
4. Bake the cake in an oven for a
specific time.
5. Take the cake out of the oven. Fig. 4.1 Tasks to be carried out for preparing a cake
The cake is ready.
55

2020 Ubuntu Ed.indb 55 12-May-20 5:53:38 PM


Thus, everything you do, be it cooking food, getting ready for school, doing homework,
etc., is a step-by-step process.
Similarly, a computer also follows a sequence of steps to perform any task. This step-by-
step approach to solve a problem is called an algorithm in computer terms. In addition
to algorithms, you will learn one more problem-solving tool called the flowchart in this
chapter.

4.1 ALGORITHM
An algorithm is a step-by-step processof solving a problem. It is written in a simple
language such as English, so that anyone can understand the problem-solving logic.
It is an important part of program development.

d
Note

Lt
The instructions of an algorithm when written in any programming language

t.
Pv
form a computer program.

a
di
In
4.1.1 Characteristics of an Algorithm
rs

An algorithm should have the following characteristics.


he

‹‹ Finiteness: An algorithm must terminate after performing a finite number of steps.


lis

An algorithm that goes on performing a set of steps infinitely is not of any use.
b
Pu

‹‹ Definiteness: An algorithm should be clear and unambiguous. Each step and its
input/output must be clear. There must be no ambiguity in any instruction.
n
illa

‹‹ Input: An algorithm should have zero or more well-defined inputs.


m

‹‹ Output: An algorithm must result into one or more well-defined outputs.


ac

‹‹ Effective: An algorithm must be effective, which means each step in the algorithm
M

must be simple and basic so that any person can carry out these steps easily and
©

effectively using a pen and paper.


‹‹ Independent: An algorithm should contain step-by-step instructions, which should
be independent of any programming language.

4.1.2 Rules for Writing a Good Algorithm


There are some rules that you should follow while writing algorithms.
‹‹ An algorithm should be clear, precise and well-defined.
‹‹ It should always begin with the word ‘Start’ and end with the word ‘Stop’.
‹‹ Each step should be written in a separate line.
‹‹ Steps should be numbered as Step 1, Step 2, and so on.
56

2020 Ubuntu Ed.indb 56 12-May-20 5:53:38 PM


4.1.3 Some Simple Algorithms
Let us consider a real-life example to understand the concept of algorithm.

Algorithm to make tea


Step 1 : Start.
Step 2 : Fill water in a kettle.
Step 3 : Switch on the gas stove.
Step 4 : Put the kettle on the gas stove.
Step 5 : After the water starts boiling, add tea leaves in it.
Step 6 : Add sugar and milk.
Step 7 : Boil the mixture.
Step 8 : Filter the tea and serve.

d
Step 9 : Stop.

Lt
Similarly, you can write algorithms for the operations to be performed by the computer.

t.
Pv
Algorithm to add three numbers

a
di
Step 1 : Start. In
Step 2 : Take three numbers as inputs, say A, B and C.
rs

Step 3 : Add A, B and C and store the result in D.


he

Step 4 : Display the value of D.


lis

Step 5 : Stop.
b
Pu

Algorithm to calculate the perimeter of a rectangle


n

Step 1 : Start.
illa

Step 2 : Read Length, Breadth.


m

Step 3 : Perimeter = 2 * (Length + Breadth)


ac

Step 4 : Print Perimeter.


M

Step 5 : Stop.
©

Algorithm to find greater of two numbers


Step 1 : Start.
Step 2 : Read A, B.
Step 3 : Check if A is equal to B. If true then go to Step 4, else go to Step 5.
Step 4 : Print “A is equal to B” and go to Step 8.
Step 5 : Check if A is greater than B. If true then go to Step 6, else go to Step 7.
Step 6 : Print “A is greater” and go to Step 8.
Step 7 : Print “B is greater”.
Step 8 : Stop.
57

2020 Ubuntu Ed.indb 57 12-May-20 5:53:38 PM


4.2 FLOWCHART
A flowchart is a pictorial representation of an algorithm. Like an algorithm, a flowchart
also represents a step-by-step solution of a problem.The difference is that it represents
the instructions in a graphical form. It uses different box-like shapes (called symbols) to
represent different types of steps in an algorithm. All the symbols used in a flowchart are
connected with arrows in the sequence in which the steps are to be followed.

4.2.1 Symbols Used in a Flowchart


Different symbols used in a flowchart are described in Table 4.1.
Table 4.1 Symbols used in a flowchart

Symbol Name Description

d
Lt
Start/Stop box An oval represents the beginning and the end
of a flowchart.

t.
Pv
Input/Output box A parallelogram represents the input and
output instructions in a flowchart.

a
Process box di
A rectangle represents the processing
In
instructions in a flowchart.
rs
he

Decision box A diamond represents the instructions that


lis

involve a condition with two options ('Yes' and


b

'No') to choose from.


Pu

Flow lines The lines with arrowheads show the direction


n

of flow of data and instructions in a flowchart.


illa

They are used to connect different symbols in


m

a flowchart.
ac

Connectors A circle is used to connect different sections of


M

a flowchart together.
©

Off-page It is used to connect the parts of a flowchart on


connectors different pages.

4.2.2 Rules for Drawing a Flowchart


Certain rules that must be followed while drawing a flowchart are given below.
‹‹ A flowchart should consist of only standardised and acceptable symbols.
‹‹ There can be only one start and one stop symbol in a flowchart.
‹‹ Only one flow line can come out from the start and process symbol.
‹‹ Only one flow line can enter into a stop symbol and a decision symbol. However,
two or three flow lines may come out from the decision symbol.
58

2020 Ubuntu Ed.indb 58 12-May-20 5:53:38 PM


‹‹ The flow lines should not cross each other.
‹‹ The direction of flow of information in a flowchart is either from top to bottom or
from left to right.
‹‹ A flowchart should have short, clear and readable statements written inside the
symbols.

4.2.3 Some Simple Flowcharts


Let us draw some simple flowcharts that will help you understand the representation of
solutions to some problems.
Example 1: A flowchart to add three numbers
Start

d
Lt
t.
Input A, B, C

Pv
a
D=A+B+C
di
In
rs
he

Print D
b lis
Pu

Stop
n
illa

Example 2: A flowchart to find the average of four numbers


m
ac

Start
M
©

Input A, B, C, D

Avg = (A+B+C+D)/4

Print AVG

Stop

59

2020 Ubuntu Ed.indb 59 12-May-20 5:53:38 PM


Example 3: A flowchart to find the greater of two numbers

Start

Input A and B

Yes
Is A = B?

No Print “A and B are equal.”


Yes No
Is A > B?

d
Lt
t.
Print “A is greater.” Print “B is greater.”

Pv
a
di
In
rs

Stop
he

Example 4: Draw a flowchart to find the sum and average of marks in four tests. If average
lis

is greater than or equal to 65 then print ‘Eligible’, else display ‘Not Eligible’.
b
Pu

Start
n
illa

A
m
ac

Input M1, M2, M3


AND M4
M

Yes Is Average No
©

>=65?
Sum = M1 + M2 + M3 + M4

Print Print
“Eligible” “Not Eligible”
Average = Sum/4

A Stop

60

2020 Ubuntu Ed.indb 60 12-May-20 5:53:39 PM


4.2.4 Advantages and Limitations of a Flowchart
Table 4.2 lists certain advantages and limitations of a flowchart.
Table 4.2 Advantages and limitations of a flowchart

Advantages Limitations
‹‹ The symbols used in a flowchart ‹‹ In case of large programs, the
are self-explanatory. This makes a flowcharts may continue to many
flowchart easier to understand. pages. This makes them difficult to
‹‹ Being a graphical representation, understand.
flowcharts are better to communicate ‹‹ It takes a lot of time to represent
the problem-solving logic to the users. a problem diagrammatically as
‹‹ With the help of a flowchart, a problem compared to writing algorithms.

d
Lt
can be analysed in an effective way. ‹‹ Any changes or modification in a

t.
flowchart usually requires redrawing

Pv
the entire flowchart.

a
‹‹ If the problem logic is complicated,
di
flowcharts become complex.
In
rs
he

Points to
lis

Remember
b
Pu

‹‹ An algorithm is a step-by-step process of solving any problem. It is written in a


n
illa

simple language such as English so that anyone can understand the problem-
solving logic.
m
ac

‹‹ A flowchart is a pictorial representation of an algorithm.


M

‹‹ A flowchart uses different box-like shapes (called symbols) to represent different


©

types of steps in an algorithm.


‹‹ All the symbols used in a flowchart are connected with arrows in the sequence in
which the steps are to be followed.

61

2020 Ubuntu Ed.indb 61 12-May-20 5:53:39 PM


Exercises
1. Tick (ü) the correct option.
a. An algorithm should always end with this word.
(i) Finish (ii) Stop
(iii) End (iv) Terminate
b. Which of the following symbols represents processing instructions in a
flowchart?
(i) (ii)

Lt
t.
(iii) (iv)

Pv
a
c. How many flow lines can come out from a process symbol in a flowchart?
(i) One (ii) di
Two
In
rs

(iii) Three (iv) Four


he

d. Which of the following symbols is used only once in a flowchart?


lis

(i) Start (ii) Process


b
Pu

(iii) Decision (iv) Flow lines


e. Which of the following is not true about an algorithm?
n
illa

(i) Each step should be written in a separate line.


m

(ii) An algorithm should be clear, precise and well-defined.


ac

(iii) An algorithm must have a finite number of steps.


M
©

(iv) An algorithm may result into no output.

2. Fill in the blanks.


a. An ............................... is a step-by-step process of solving any problem.
b. The ............................... symbol is used to connect different sections of a
flowchart together.
c. A ............................... is a pictorial representation of an algorithm.
d. An algorithm begins with the word ............................... .
e. In a flowchart, the flow lines should not ............................... each other.

62

2020 Ubuntu Ed.indb 62 12-May-20 5:53:39 PM


3. State true or false.
a. Only one flow line can enter into a decision symbol in a flowchart.
b. If the problem logic is complicated, flowcharts become complex.
c. There can be more than one stop symbol in a flowchart.
d. A diamond-shaped box is used to represent the input/output instructions in
a flowchart.
e. An algorithm is the pictorial representation of a program.

4. Answer the questions.

d
a. Define algorithm.

Lt
t.
b. List three rules that should be kept in mind while writing algorithms.

Pv
c. Explain any three symbols used in a flowchart.

a

di
d. What is the difference between an algorithm and a flowchart?
In
rs

e. Mention four rules that you must follow while drawing a flowchart.
he

f. Describe any three characteristics of a good algorithm.


b lis

g. Write two advantages and disadvantages of flowcharts.


Pu
n
illa
m

Activities
ac
M

1. Draw a flowchart for the following algorithm.


©

Step 1: Start.
Step 2: Take five numbers A, B, C, D, E.
Step 3: Add A, B, C, D, E and store the result as Total.
Step 4: Divide Total by 5 and store result as Average.
Step 5: If Average is greater than or equal to 65, display ‘Eligible’.
Step 6: If Average is less than 65, display ‘Not eligible’.
Step 7: Stop.
2. Write an algorithm for how you go to school.

63

2020 Ubuntu Ed.indb 63 12-May-20 5:53:39 PM


3. Complete the following flowchart to find the smallest of three numbers.

...................

Input ................

No
Is A < B?

Yes Is ....... < .......?

d
Yes

Lt
Yes No
Is A < C?

t.
Print “....... is smallest.”

Pv
No

a
Print “A is smallest.”
di
Print “....... is smallest.”
In
rs
he
b lis
Pu

.................
n
illa

4. Write an algorithm and draw a flowchart to perform the following tasks.


m

a. Accept age and print ‘Cannot vote’ if age < 18 and print ‘Can vote’ if age
ac

>= 18.
M

b. Input marks and print ‘Fail’ if marks < 40 and print ‘Pass’ if marks >= 40.
©

For the Teacher


‹‹ Ask students about the steps they follow for doing routine tasks such as setting the
school time table, making chapatis, going to school, etc.
‹‹ Explain to them what an algorithm is. Help them write algorithms for simple
problems.
‹‹ Tell them the importance of flowcharts. Demonstrate to them how to draw a
flowchart.

64

2020 Ubuntu Ed.indb 64 12-May-20 5:53:39 PM


5
Ria, you already know about the
KTurtle programming language. Wow! That’s great!
Today, I will help you learn a new Let us start.
programming language—Python.

d
Lt
t.
Pv
a
di
In
rs
he
b lis
Pu
n
illa

Contents
m

As you know, there are many languages that


ac

‹‹ What is Python? we can use to write a computer program—a


M

well-defined set of instructions that directs


‹‹ Downloading and Installing
the computer to do a particular task. In the
©

Python on Ubuntu
previous class, you learnt a programming
‹‹ Working with Python language named Scratch. Now, you will learn
‹‹ Tokens another language named Python which is
one of the most widely used programming
‹‹ Data Types languages today. It is a dynamic object-
‹‹ Variables and Assignments oriented language that has applications in a
‹‹ Input and Output variety of areas. In Python, you can develop
simple programs for solving mathematical
‹‹ Comments in Python problems as well as large web-based
‹‹ Some Simple Python Programs applications, games, 3D applications and
almost everything that any object-oriented
programming language can do.
65

2020 Ubuntu Ed.indb 65 12-May-20 5:53:40 PM


5.1 WHAT IS PYTHON?
Python is an amazingly powerful modern computer programming language. It was written
by a Dutch programmer Guido Van Rossum in the late 1980s. It is a general-purpose,
interpreted, interactive, object-oriented and high-level programming language that can
run on different operating systems such as Windows, Mac, Linux, etc. It has a simple
English-like syntax and highly readable code that makes it an excellent choice for coding
for beginners. It is easy to learn and does not require prior knowledge of any programming
language.

Note
Python was created as a successor of a language called ABC (All Basic
Code) and released publicly in 1991.

d
Lt
t.
5.1.1 Features of Python

Pv
The following are some features of Python that have made it so popular.

a
di
‹‹ Easy to learn and use: Python is a great language for beginner-level programmers
In
because it uses simple English words and has a simple syntax.
rs

‹‹ An interpreted language: Python uses an interpreter that processes the Python


he

programs line by line at runtime. The interpreter takes the source code and then
lis

translates each statement to portable byte-code and executes it immediately.


b

This makes the process of debugging easier.


Pu

‹‹ Free and open source: Python is available on the Internet for free and you can
download it from the official website of Python. It is an open-source program, which
n
illa

means the source code of Python is also available. Anyone can read its source code,
m

copy it, make changes and use pieces of it in new programs.


ac

‹‹ Interactive: It provides an interactive shell that allows you to directly interact with the
M

interpreter to write and test your programs.


©

‹‹ Extensible: The code written in some other language such as C, C++, CORBA and
Java can be merged with Python programs and run to give scripting capabilities to
that program.
‹‹ Object-oriented language: Other than functional and structured programming
methods, Python also supports object-oriented programming (OOP) approach
that encapsulates code within objects. It provides a simple yet powerful way of
implementing OOP, especially in comparison to languages such as C++ or Java.

5.1.2 What Can Python Do?


Besides the features mentioned above, Python has many more uses, which are as follows.
‹‹ It can be used for developing desktop-based applications, games, web applications, etc.

66

2020 Ubuntu Ed.indb 66 12-May-20 5:53:40 PM


‹‹ It is great as a server-side scripting language.
‹‹ It can be used as an alternative to PHP, ASP.NET and Ruby.
‹‹ It is ideal for complex mathematical and scientific programming as it has a number
of libraries for matrices, algebra, calculus, etc.
‹‹ It provides connectivity with all major database systems.

5.2 DOWNLOADING AND INSTALLING PYTHON ON


UBUNTU
Python is available for all major operating systems such as Windows, Linux, Mac OS, etc.
A number of versions of Python have been released till yet. Python 3.8 is the latest major
release till March 2020.

d
Python 3.8 is not available in Ubuntu’s default repositories. You can download it from

Lt
Python’s website using the following link.

t.
Pv
https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz

a
After you have downloaded the software, extract the folder and then install it on your
system by following these instructions.
di
In
1. Open the Terminal program.
rs
he

2. Type the following command to update the packages list and press the Enter key.
lis

sudo apt update


b

3. Ubuntu asks for your password. Type the password and press the Enter key.
Pu
n
illa
m
ac
M
©

Fig. 5.1 Updating the packages list


67

2020 Ubuntu Ed.indb 67 12-May-20 5:53:40 PM


4. Type the following command to install the prerequisites. Press the Enter key after
typing the command.
sudo apt install software-properties-common

d
Lt
t.
Pv
a
di
In
rs
he
b lis

Fig. 5.2 Installing the prerequisites


Pu

5. Add the deadsnakes PPA to your system’s sources list by typing the following
n
illa

command and pressing the Enter key.


m

sudoadd-apt-repositoryppa:deadsnakes/ppa
ac

During the process, whenever prompted, press the Enter key to continue.
M
©

(a) (b)
Fig. 5.3 Adding the deadsnakes PPA to the list of the system’s sources

68

2020 Ubuntu Ed.indb 68 12-May-20 5:53:41 PM


7. Once the repository is enabled, install Python 3.8 by typing the following command
and pressing the Enter key. Ensure that the Python3.8 folder that you have
downloaded is in the directory you are currently in.
sudo apt install Python3.8

d
Lt
t.
(a) (b)

Pv
Fig. 5.4 Installing Python

a
di
In
5.3 WORKING WITH PYTHON
rs

Once Python has been installed, you can use it in two modes:
he
lis

‹‹ Command-line mode
b

‹‹ IDLE mode
Pu

In Python programming from command-line mode, you can type the code directly into the
n

Python interpreter at the prompt (>>>). The Python interpreter immediately returns the
illa

output for each command that you enter. Open the Terminal window and type python3.8
m

at the prompt. Python opens up in the command-line mode.


ac
M
©

Fig. 5.5 Python in command-line mode


69

2020 Ubuntu Ed.indb 69 12-May-20 5:53:41 PM


On the other hand, the IDLE (stands for Integrated Development Environment or
Integrated Development and Learning Environment) mode provides a graphical user
interface to work with Python. It has a Python Shell window where you can write and run
Python programs. Let us learn to work with Python using IDLE.

Did You Know


Usually, the IDLE gets installed on your system when you install Python. However,
if it does not get installed, you can type the following command at the prompt in the
Terminal window to install the IDLE.
sudo apt install idle-python3.8

d
Lt
5.3.1 Starting Python (IDLE)

t.
Pv
IDLE is the standard and the most popular Python development environment. It lets you
edit, run, browse and debug Python programs from a single interface.Once Python IDLE

a
has been installed, you can start it by following these steps.
di
In
1. Open the Terminal window.
rs

2. Type the following command and press the Enter key.


he

idle-python3.8
lis

The Python Shell window opens up with a cursor blinking at the prompt >>>.
b
Pu
n
illa
m
ac
M
©

(a) Typing command to open IDLE (b) Python Shell window


Fig. 5.6 Starting Python IDLE

You can use Python IDLE in two different ways:


‹‹ You can type commands directly at the prompt (>>>) in the PythonShell window.
As you type any Python expression/statement/command and press the Enter key, the
Python interpreter will execute it and display its result as shown in Fig. 5.7. This is
referred to as the interactive mode of IDLE.

70

2020 Ubuntu Ed.indb 70 12-May-20 5:53:41 PM


d
Lt
t.
Pv
a
di
In
rs
he
b lis

Fig. 5.7 Entering commands at the prompt in the Shell window


Pu

‹‹ You can create a new file, write the Python program (script) in it and then use the
n
illa

interpreter to run the script and obtain the output. This is referred to as the script
mode of IDLE.
m
ac
M

Did You Know


©

Python, in interactive mode, is good enough to learn, experiment or explore, but its
only drawback is that we cannot save the statements for further use and we have to
retype all the statements to re-run them.

5.3.2 Creating a Simple Program


To create a simple program in Python script mode, follow these steps.
1. In the Python Shell window, click the File menu and then click the New File option
to create a new file. A new Python Edit window opens up.

71

2020 Ubuntu Ed.indb 71 12-May-20 5:53:41 PM


(a) Selecting option to create a new file (b) Python Edit window
Fig. 5.8 Creating a new file

d
2. Type the code for your program in the window.

Lt
t.
Pv
a
di
In
rs
he
b lis
Pu
n
illa
m
ac
M

Fig. 5.9 Writing the program code


©

Observe that the ‘#’ symbol in the program code shown in Fig. 5.9 indicates that the first
line is a comment.

Note
You can also press Ctrl + N to create a new file.

5.3.3 Saving the Program


After writing the program, you should save it for future reference. To save the program,
follow these steps.
72

2020 Ubuntu Ed.indb 72 12-May-20 5:53:42 PM


1. Click the File menu and then click the Save option. Alternatively, you can press
Ctrl + S on the keyboard. The Save As dialog box appears [see Fig. 5.10(b)].
2. Type a suitable name with the extension .py in the File name text box.
3. Click the Save button.

d
Lt
t.
(a) Choosing the Save option (b) Save As dialog box

Pv
Fig. 5.10 Saving the program

a
di
In
5.3.4 Running the Python Program
rs

After you have written and saved a program, the next step is to execute it. To run a Python
he

program, click the Run menu in the Python Shell window and then click the Run Module
lis

option. The program will run and the output will be displayed in the Python Shell window.
b

You can also run a program by pressing the F5 key on the keyboard.
Pu
n
illa
m
ac
M
©

(a) Choosing option to run the program (b) Output of the program
Fig. 5.11 Running the Python program

5.4 TOKENS
A token is the smallest individual unit of a program. It is defined as a set of characters that
logically belong together. Python tokens include keywords, identifiers, literals, operators
and punctuators. Let us learn about these one by one.
73

2020 Ubuntu Ed.indb 73 12-May-20 5:53:42 PM


5.4.1 Keywords
Keywords are the predefined words that have special significance in any language. Every
keyword is reserved for a specific purpose and hence, cannot be used as user-defined
names (identifiers). A partial list of keywords in the Python programming language is
given in Table 5.1.
Table 5.1 Python keywords

False and del from not


None while as elif global
True or with assert else
For if pass yield break
lambda except import print class
Try exec in raise continue

d
finally is return def

Lt
t.
Pv
5.4.2 Identifiers

a
Identifiers refer to the names given by a programmer to different parts of a program such
di
as variables, functions, lists, objects, dictionaries, etc., in order to identify them uniquely.
In
They are the basic building blocks of a program.
rs

While defining identifiers in Python, programmers must follow the rules given below.
he

‹‹ The name of an identifier must be unique in a program.


b lis

‹‹ It must contain only uppercase and lowercase letters, underscore (_) and digits 0 to 9.
Pu

‹‹ It must start with a letter or an underscore followed by zero or more letters, underscores
n

and digits 0 to 9. No blank spaces are allowed in the name of an identifier.


illa

‹‹ Python is a case-sensitive language. This means an identifier in uppercase is different


m

from that in lowercase. For example, nUM, num, Num, and NUM are considered
ac

four different identifiers.


M

‹‹ You cannot use a keyword as the name of an identifier.


©

‹‹ Python does not allow the use of punctuation characters such as $, @, and % in the
name of identifiers.
Some valid identifiers are listed below.
Numvar NEWVAR _chk Pvar P_var123 _DISK
The following are some invalid identifiers.
982ds invalid; as it starts with a digit
Num@Var invalid; as it contains the special character @
lambda invalid; as it is a keyword

74

2020 Ubuntu Ed.indb 74 12-May-20 5:53:42 PM


5.4.3 Literals
Literals, also known as constants, are the identifiers whose values do not change during
program execution. That is, literals have a fixed value. Based on the type of value, Python
literals are classified into the following.
a. String literals b. Numeric literals
c. Boolean literals d. Special literal (None)

String Literals
String literals refer to an ordered sequence of any number of characters enclosed in either
single (‘ ’) or double quotes (“ ”). For example, ‘g’, ‘K’, ‘7’, “India”, “Rahul” and
“date” are some valid string literals. Here it is important to note that the quotes are not
part of the string. They only tell the computer where the string literal begins and ends.

d
Lt
Python also allows you to use certain non-graphic characters (which cannot be typed from

t.
the keyboard) such as tab space, new line, carriage return, etc. within the string values.

Pv
These characters can be represented by using escape sequences. An escape sequence is
nothing but a special character that has a specific function. It is represented by a backslash

a
di
(\) followed by one or more characters. Table 5.2 lists some of the escape sequences in
In
Python.
rs

Table 5.2 Escape sequences


he
lis

Escape sequence Non-graphic character printed by


b

\n New line character


Pu

\t Horizontal Tab (TAB)


n

\r Carriage Return
illa

\b ASCII Backspace
m

\\ Backslash (\)
ac

\’ Single quote (’)


M

\” Double quotes (”)


©

\f ASCII Formfeed (FF)


\v ASCII Vertical Tab (VT)
Python allows you to use two types of strings in your program: single line and multiline
strings. The strings that terminate in single line can be created in the same way as discussed
earlier (by enclosing in single or double quotes). In contrast, there are two different ways
to create strings that spread across multiple lines (multiline strings). These ways are as
follows.
‹‹ By adding a backslash (\) at the end of a continuing line. For example,
Strvar = “Welcome\
Back!”
75

2020 Ubuntu Ed.indb 75 12-May-20 5:53:42 PM


‹‹ By enclosing the multiline string in triple quotes. For example,
Strvar = ‘‘‘Welcome
Back!
How are you?’’’
The only difference between the above two methods is that a triple quoted multiline string
also counts the end-of-line (EOL) character (which is ’’’) in the size of the string, while the
multiline string with backslash method does not count the backslash (\) in the size of the
string.

Numeric Literals
Numeric literals refer to the numbers consisting of a sequence of digits (with or without
decimal point) that can be either positive or negative. However, by default, numeric literals

d
are positive. In Python, there are four types of numeric literals, as given below.

Lt
‹‹ int: The numeric literals of int type are signed integers—the positive or negative

t.
Pv
whole numbers with no decimal point.

a
‹‹ long: The numeric literals of long type are also signed integers but with unlimited
di
size. They are written like integers and followed by the letter L (in uppercase or
In
lowercase).
rs

‹‹ float: The numeric literals of float type are real numbers, that is, the numbers
he

with a decimal point that separates the integer and fractional part.
lis

‹‹ complex: The numeric literals of complex type are complex numbers of the
b
Pu

form a+jb, where a is the real part of the number and b is the imaginary part.
n
illa

Did You Know


m
ac

The integer numeric literals (of type int and long) can be represented by three
M

different number systems, namely, decimal (base 10), octal (base 8) and hexadecimal
©

numbers (base 16). The octal constants are preceded by a 0 (zero) and contain only 0
to 7 digits, while the hexadecimal constants are preceded by a 0x and contain only 0
to 9 digits and A to F or a to f letters.

Boolean Literals
A Boolean literal is used to represent one of the two Boolean values: True or False.
That is, the value of a Boolean literal can be either True or False.

Special Literal (None)


Python provides a special literal None which is used to indicate something that has yet
not been created. In other words, it is used to signify the absence of a value in a situation.
76

2020 Ubuntu Ed.indb 76 12-May-20 5:53:42 PM


5.4.4 Operators
Operators are the symbols that define the type of operation (such as addition, subtraction,
and so on) to be performed on the data items used in a program. The data items on which
operators act are known as operands. Based on the number of operands required to work
upon, operators are classified into unary and binary operators.
‹‹ Unary operators are the operators that need only one operand to act upon.
Some of the unary operators in Python are unary plus (+), unary minus (-) and
logical negation (not).
‹‹ Binary operators are the operators that need two operands to act upon. Table 5.3
lists some binary operators in Python.
Table 5.3 Binary operators

d
Arithmetic operators + (addition), - (subtraction), * (multiplication),

Lt
/ (division), ** (exponent), % (remainder/

t.
modulus), // (floor division)

Pv
Relational operators <(less than), >(greater than), <= (less than or

a
equal to), >= (greater than or equal to), ==
di
(equal to), != or <>(not equal to)
In
Logical operators and (logical AND), or (logical OR)
rs

Bitwise operators &(bitwise AND), | (bitwise OR), ^ (bitwise


he

exclusive OR)
lis

Assignment operators = (assignment), += (assign sum), -= (assign


b
Pu

difference), *= (assign product), /= (assign


quotient), %= (assign remainder), **= (assign
n

exponent), //= (assign floor division)


illa

Shift operators <<(shift left), >>(shift right)


m

Identity operators is (is the identity same?), is not (is the


ac

identity not same?)


M

Membership operators in (whether variable in sequence), not in


©

(whether variable not in sequence)

Note
The combination of values (constants), variables and operators form an
expression, which generates a single value. For example, x+5 is an expression.
The expression values can also act as operands for operators.

5.4.5 Punctuators
Punctuators, also known as separators, are the tokens that serve different purposes based
on the context in which they are used. Some punctuators are used as operators, some are
77

2020 Ubuntu Ed.indb 77 12-May-20 5:53:42 PM


used to demarcate a portion of the program, and so on. Some common punctuators of
the Python language are
() {} [] ‘ “ @ \ : , = ; #

5.5 DATA TYPES


A data type defines the type of data and the operations that can be performed on it.
Figure 5.12 shows the various data types available in Python.
Data Types

Numbers None Sequences Sets Mappings

d
Lt
Floating Complex String Tuple List Dictionary

t.
Integer

Pv
Point

Boolean

a
di
Fig. 5.12 Data types in Python
In
Let us learn about these data types.
rs
he

5.5.1 Numbers
lis

The number data types are used to store numeric values. The data types in Python which
b
Pu

can store numbers are as follows:


‹‹ integers
n
illa

‹‹ floating-point numbers
m

‹‹ complex numbers
ac
M

Integers
©

Integers are the whole numbers (positive or negative) with no decimal point. In Python,
the data types, int, long and bool are used to store integers.
‹‹ int: This data type is used to store signed integer values, for example, 82, −356,
etc. It uses 4 bytes (32 bits) to store a value. The range of an integer in Python can
be from −2147483648 to 2147483647.
‹‹ long: This data type is used to store long integers, for example, 5436723L,
78634467238L, etc. A long integer has unlimited range subject to available memory.
When we want a value to be treated as a very long integer value, we append ‘L’ to
the value. Such values are treated as long integers by Python.
‹‹ bool: It is a unique data type, consisting of two constants, True and False. A Boolean
True value means a non-zero, non-null and non-empty, while a Boolean False means
a zero value.
78

2020 Ubuntu Ed.indb 78 12-May-20 5:53:42 PM


Floating-point Numbers
Numbers with fractions or a decimal point are called floating-point numbers. In Python,
the float data type is used to hold floating-point numbers, for example, 0.7, 1.35, -1.67,
etc. A floating-point number is accurate up to 15 decimal places.

Note
Even though the value 1 is an integer, the value 1.0 is a floating-point number.

Complex Number
A complex number is of the form A+Bj where A is the real part, B is the imaginary part
and j represents √(-1). The complex data type used to store a complex number in

d
Python is made up of two floating-point values, one each for real and imaginary parts.

Lt
For accessing different parts of a complex number (say, x), we will use x.real and

t.
x.image.

Pv
a
5.5.2 None
di
In
This is special data type with a single value. It is used to signify the absence of value/false
rs

in a situation. It is represented by None.


he
lis

5.5.3 Sequences
b
Pu

A sequence is an ordered collection of items, indexed by positive integers. Three types of


sequence data type available in Python are strings, lists and tuples.
n
illa

Strings
m

A string is an ordered sequence of letters or characters. In Python, strings are represented


ac

by enclosing them in either single quotes or double quotes, for example, ‘a’, ‘abc’,
M

‘Kevin’, “ritu 123”, “Her’s”, etc. There can be a string with no characters in it, such
©

as ‘’. Such a string is known as a blank string.

Lists
A list in Python is a list of values of any data type enclosed within square brackets [] and
separated by commas. The individual values in the list are called elements or items and
are indexed. Lists are mutable which means individual elements of a list can be modified.
Examples:
‹‹ [1, 2, 3, 4, 5]
‹‹ [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
‹‹ [89, 75.3, “Saachi”]
79

2020 Ubuntu Ed.indb 79 12-May-20 5:53:42 PM


Tuples
A tuple, similar to a list, also represents a list of comma-separated values of any data type.
The difference is that the values are enclosed within parentheses () in place of square
brackets. In addition, tuples are immutable, which means we cannot change the individual
elements of a tuple once it is assigned whereas in a list, the elements can be changed.
Examples:
‹‹ (1, 2, 3, 4, 5)
‹‹ (‘h’, ‘e’, ‘l’, ‘l’, ‘o’)
‹‹ (89, 75.3, ‘Saachi’)

Note
A set can have any number of items and they may be of different types

d
Lt
(integer, real, tuple, string, etc.). But a set cannot have a mutable element,

t.
such as a list, set or dictionary, as its element.

Pv
5.5.4 Sets

a
di
In
A set is an unordered collection of items. Every element must be unique (no duplicates)
and must be immutable (which cannot be changed). However, the set itself is mutable.
rs

We can add or remove items from it. A set is created by placing all the items (elements)
he

inside curly braces {}, separated by commas.


lis

Examples:
b
Pu

‹‹ {1, 2, 3}
n

‹‹ {1.0, “Hello”, (1, 2, 3)}


illa

‹‹ {“apple”, “banana”, “cherry”}


m
ac

5.5.5 Mappings
M

A mapping data type is unordered and mutable. Dictionaries fall under mappings.
©

Dictionary
Dictionary is an unordered collection of items enclosed within curly braces {} and separated
by commas. Each item in a dictionary is expressed as a key:value pair. While values
can be of any data type and can repeat, keys must be of immutable type (string, number
or tuple with immutable elements) and must be unique. The values in a dictionary can be
accessed with the help of the key.
Examples:
‹‹ {1:‘a’,2:‘b’,3:‘c’}
‹‹ {1: ‘apple’, 2: ‘ball’}
‹‹ {‘name’: ‘John’, 1: [2, 4, 3]}
80

2020 Ubuntu Ed.indb 80 12-May-20 5:53:43 PM


5.6 VARIABLES AND ASSIGNMENTS
A variable is a name that represents a memory location which stores a value of a specific
data type. The data stored at a particular location can be accessed using the variable
name. The name given to a variable is known as identifier. The value of a variable can be
used and changed any time during the program execution.

5.6.1 Defining Variables


In Python, it is not required to declare variables before using them in the program.
The Python interpreter automatically detects the type of the variable by the data it contains.
You can create a variable by just assigning to it some value of a particular data type such
as a numeric value, a string, etc. You can assign a value to a variable using the assignment
operator (=). For example, consider the following statement.

d
num = 75

Lt
Here, num is a variable and an integer value of 75 is assigned to it. Now, consider these

t.
Pv
statements.

a
pi = 3.14
Name=‘Sanaya’ di
In
rs

In the first statement, pi is a variable that has been assigned a floating-point value 3.14,
he

while in the second statement, Name is a string variable that has the text Sanaya stored in it.
b lis

Note
Pu

The rules for naming variables are same as those of identifiers.


n
illa
m

5.6.2 Multiple Assignment


ac

Python lets you assign a single value to multiple variables at the same time. You can even
M

assign different values to multiple variables simultaneously.


©

Python lets you assign a single value to multiple variables at the same time using a single
statement. For example, the following statement assigns the value of 20 to three variables
x, y and z, simultaneously.
x = y = z = 20
You can also assign different values to multiple variables in a single statement. For example,
the following statement assigns the values 20, 30 and 40 to three variables x, y and z,
respectively, at the same time.
x, y, z = 20, 30, 40
Note that the above statement assigns values order-wise, that is, the first value is assigned
to the first variable, the second value to the second variable, and so on.

81

2020 Ubuntu Ed.indb 81 12-May-20 5:53:43 PM


If you need to swap the values of two variables (say x and y), you can do this using a
single statement as shown below.
x, y = y, x

5.7 INPUT AND OUTPUT


A program needs to interact with the user to accomplish the desired task. This is
accomplished through the input-output facility. Input means getting data entered
by the user and output means presenting the result to the user. Python provides the
raw_input() and input() functions to obtain input from the user and the print()
function to display the output. Let us learn about these functions.

5.7.1 The raw_input() Function


The raw_input () function reads a single line of text from the keyboard and returns it as

d
Lt
a string. To understand, type the following statement at the prompt >>> in the interactive

t.
mode and press the Enter key.

Pv
>>>x=raw_input()

a
The cursor blinks and waits for you type a value. Type the value and press the Enter key.
di
Whatever you type, the raw_input () function converts it into a string and then assigns it
In
to the variable on the left-hand side (x in our case).
rs
he

The raw_input() function can also display a message and then wait for the input.
For example, type the following statement at the prompt >>> in the interactive mode
lis

and press the Enter key.


b
Pu

>>>x=raw_input(“Enter your name: ”)


This statement first displays the message Enter your name: and then waits for the
n
illa

user to enter a value.


m

We can use the raw_input() function to enter numeric data also. In that case, we
ac

typecast (change) the string of digits entered by the user to an appropriate numeric type
M

using the function. For example, type the following statement at the prompt >>> in the
interactive mode and press the Enter key.
©

>>>y=int(raw_input(“Enter your roll no: ”))


This statement displays the message Enter your roll no: and then waits for you to
enter a value. As you type a value (say, 17) and press the Enter key, the raw_input()
function will convert the entered string (that is, 17) to an integer before assigning it to the
variable y.

5.7.2 The input() Function


The input() function evaluates the input entered by the user and returns the value
accordingly. It is used in the same form as raw_input(). For example, type the following
statement at the prompt >>> in the interactive mode and press the Enter key.
>>>y=input(“Enter your roll no: ”)
82

2020 Ubuntu Ed.indb 82 12-May-20 5:53:43 PM


This statement displays the message Enter your roll no: and then waits for you
to enter a value. Now if you type a value 15, the input() function will automatically
evaluate it to the numeric 15 and assign it to the variable y. Instead of typing a value,
you can also input an expression that evaluates to a number. For example, if you type an
expression 7+8, the input() function evaluates the expression and assigns the result
(that is, 15) to the variable y.

Note
In the latest Python release 3.x, the raw_input() function has been
renamed as input() function and the old input() function (of release
2.x) that we discussed above has been removed.

d
Lt
5.7.3 The print()Function

t.
Pv
The print() function lets you display a constant, the value of a variable or the result of
an expression. For example, consider the following statements.

a
print(8) displays 8 di
In
rs

While entering numeric values using raw_input(), ensure that the values entered by
he

you must be numeric convertible, otherwise Python will produce an error.


b lis

5.8 COMMENTS IN PYTHON


Pu

Comments are the non-executable statements that are used in a program to increase
n

its readability. They are used to explain the program code to anyone who views your
illa

program.
m

In Python, you can use either a single-line or a multiline comment in a program. A single-
ac

line comment starts with a hash ‘#’ symbol. For example, the statement given below is a
M

single line comment.


©

#This is a single-line comment.


If you want to add a comment in your program that expands to more than one line, enclose
the comment within triple quotes (“”” “””). For example, consider the statement given
below.
“””This

is a

multiline comment.”””

83

2020 Ubuntu Ed.indb 83 12-May-20 5:53:43 PM


5.9 SOME SIMPLE PYTHON PROGRAMS
Let us write some simple programs in Python.
Example 1: A Python program to add, subtract, multiply and divide two numbers

(a) Program code (b) Output

d
Lt
Fig. 5.13 Program to add, subtract, multiply and divide two numbers

t.
Pv
Example 2: A Python program to compute the simple interest

a
di
In
rs
he
b lis
Pu
n
illa
m

(a) Program code (b) Output


ac

Fig. 5.14 Program to compute simple interest


M
©

Example 3: A Python program to convert number of days into hours, minutes and seconds

(a) Program code (b) Output


Fig. 5.15 Program to convert days into hours, minutes and seconds

84

2020 Ubuntu Ed.indb 84 12-May-20 5:53:43 PM


Example 4: A Python program to convert temperature in Fahrenheit to temperature in
Celsius

(a) Program code (b) Output


Fig. 5.16 Program to convert temperature in Fahrenheit to Celsius

d
Lt
Example 5: A Python program to find the perimeter and area of a square

t.
Pv
a
di
In
rs
he
b lis
Pu

(a) Program code (b) Output


n
illa

Fig. 5.17 Program to compute perimeter and area of a square


m
ac

Example 6: A Python program to find the square and cube of a given number
M
©

(a) Program code (b) Output

Fig. 5.18 Program to find the square and cube of a number

85

2020 Ubuntu Ed.indb 85 12-May-20 5:53:44 PM


Example 7: A Python program to find area of a circle

(a) Program code (b) Output

Fig. 5.19 Program to find the area of a circle

d
Lt
Points to

t.
Remember

Pv
a
‹‹ A well-defined set of instructions that directs the computer to do a particular task
is called a program. di
In
rs

‹‹ Python is an amazingly powerful modern computer programming language.


he

It was written by Guido Van Rossum in the late 1980s.


lis

‹‹ Once Python has been installed, you can use it in two modes: command-line
b

mode and IDLE mode.


Pu

‹‹ IDLE has a Python Shell window where you can write and run Python programs.
n
illa

‹‹ You can use Python IDLE in two different ways: interactive mode and script
mode.
m
ac

‹‹ A token is the smallest individual unit of a program. It is defined as a set of


M

characters that logically belong together. Python tokens include keywords,


identifiers, literals, operators and punctuators.
©

‹‹ A data type defines the type of data and the operations that can be performed on
it. Various data types available in Python are numbers (integer, floating-point and
complex numbers), None, sequences (strings, tuple and list), sets and mappings
(dictionary).
‹‹ A variable is a name that represents a memory location which stores a value of a
specific data type. The data stored at a particular location can be accessed using
the variable name.
‹‹ You can create a variable by just assigning to it some value of a particular data
type such as a numeric value, a string, etc. You can assign a value to a variable
using the assignment operator(=).

86

2020 Ubuntu Ed.indb 86 12-May-20 5:53:44 PM


‹‹ Python lets you assign a single value to multiple variables at the same time using
a single statement. You can also assign different values to multiple variables in a
single statement.
‹‹ Python provides the raw_input() and input() functions to obtain input
from the user and the print() statement to display the output.
‹‹ Comments are the non-executable statements that are used in a program to
improve its readability. They are used to explain the program code to anyone
who views your program.

d
Exercises

Lt
t.
Pv
1. Tick (ü) the correct option.
a. Which of the following identifiers is invalid in Python?

a
(i) _var123 (ii)
Var_Num di
In
rs

(iii) def (iv) NEWVAR


he

b. Which symbol can you use to include a multiline comment in Python?


lis

(i) // (ii)
#
b
Pu

””” (iv)
(iii) @
n

c. Which of the following is a keyword in Python?


illa

(i) import (ii)


yield
m
ac

break
(iii) (iv) All of these
M

d. The values in a tuple are enclosed within


©

(i) () (ii)
[]
{}
(iii) (iv) None of these
e. Which of the following statements is not true for Python?
(i) It is an object-oriented and high-level programming language.
(ii) It can run on different operating systems.
(iii) It is available free of cost.
(iv) Its source code cannot be modified.

87

2020 Ubuntu Ed.indb 87 12-May-20 5:53:44 PM


2. Fill in the blanks.

a. A Python program is saved with a ............................... extension.

b. Press ............................... to create a new file in the Shell window.

c. Python uses an ............................... that processes the Python programs


line by line at runtime.

d. A ............................... is the smallest individual unit of a program.

e. ............................... are the symbols used to perform computation on the


operands.

3. State true or false.

d
Lt
a. Python is a case-sensitive language.

t.
Pv
b. The statement print(5>=3) displays 5.

a
c.
di
In Python, a floating-point number is accurate up to 10 decimal places.
In
d. In Python, strings are represented by single quotes only.
rs
he

e. In Python, a variable name cannot start with a digit.


b lis

4. Answer the questions.


Pu

a. List some important features of the Python language.


n
illa

b. Why is Python called an interpreted language?


m
ac

c. What is meant by the IDLE mode of Python language?


M

d. Write the steps to run a program in Python.


©

e. Discuss the data types used to store numeric values in Python with examples.
f. Mention any three rules that must be followed while defining identifiers in
Python.
g. How can you assign a single value to multiple variables at the same time?
Explain with the help of an example.
h. Differentiate between single-line and multiline comments.
i. Discuss the two input functions provided in Python release 2.x. What change
has been made in Python release 3.x?

88

2020 Ubuntu Ed.indb 88 12-May-20 5:53:44 PM


Activities
1. Start up Python in the IDLE mode and do the following.
a. Create a new file.
b. Write a program to add three numbers.
c. Save the program with the name ‘Addition.py’.
d. Run the program.
e. Add comments at appropriate places in the program.

d
Lt
2. Write a Python program to input the length and breadth of a rectangle and then

t.
print its perimeter and area.

Pv
3. Write a program in Python to read distance in kilometres and print it in miles.

a
di
4. Write a program in Python to input the radius of a circle and print its circumference.
In
5. Write a program in Python to input a number n and print the sum of n, n2 and
rs

n3.
he
blis
Pu

For the Teacher


n
illa

‹‹ Introduce students to the Python programming language. Explain about the


m

features of Python that make it a powerful programming language.


ac

‹‹ Help students open Python in command-line as well IDLE modes. Explain the
M

difference between the two modes.


©

‹‹ Demonstrate the steps to create, save and run a Python program in the IDLE
mode.
‹‹ Tell students about the different programming elements of Python, including,
tokens, variables, data types, and input and output functions.
‹‹ Guide students write some simple programs in Python and execute them.

89

2020 Ubuntu Ed.indb 89 12-May-20 5:53:44 PM


6
Ria, in the previous chapter, you learnt how
to work in Python and the programming Okay, Leno! I am so
elements of Python. Now, let me tell you eager to learn!
about the use of conditional statements.

d
Lt
t.
Pv
a
di
In
rs
he
b lis
Pu
n
illa

Contents
m
ac

By default, the statements in a program are


‹‹ Operators
M

executed in the same order in which they appear


in the program and each statement is executed
©

‹‹ Conditional Statements
only once. However, the serial execution of
‹‹ Some More Python Programs
statements makes a program inflexible and
unsuitable for most practical applications.
To make a program more flexible, control statements are used to alter the flow of control
of the program.
In Python, the control statements are broadly classified into conditional statements and
iteration (looping) statements. All these control statements are commonly used with
the logical tests or test conditions to alter the flow of control conditionally. To alter the
flow conditionally, a particular condition is evaluated to control the flow of execution.
In this chapter, you will learn about conditional statements only. Before that let us have a
recap of the commonly used operators available in Python and how they work.

90

2020 Ubuntu Ed.indb 90 12-May-20 5:53:45 PM


6.1 OPERATORS
The control statements involve a condition which is basically an expression formed of
literals/variables joined by different operators. You have already read about different
operators available in Python. Let us know how some of these operators work.

6.1.1 Arithmetic Operators


Arithmetic operators are used to perform the basic arithmetic operations on the operands.
Table 6.1 lists various arithmetic operators available in Python.
Table 6.1 Arithmetic operators

Operator Description Example Result


(if x=5 and y=2)

d
+ Adds the value of its two operands. x+y 7

Lt
- Subtracts the value of the right operand x-y 3

t.
Pv
from the left operand.
* Multiplies the value of its two operands. x*y 10

a
/ Divides the value of the left operand by the x/y
di
In 2.5
right operand and gives the quotient.
% Gives the remainder on dividing the two x%y
rs

1
he

operands.
// Integer division; returns the floor of the x//y
lis

2
b

quotient.
Pu

** Exponent; computes the power. x**y 25


n
illa

6.1.2 Relational Operators


m

Relational operators are used to compare two values or expressions. These operators
ac

can work with all numeric data types, strings, lists, tuples and Boolean values and return
M

either True or False.Table 6.2 lists the working of various relational operators available in
©

Python.
Table 6.2 Relational operators

Operator Description Example Result (if x=5 and y=2)


< Returns True if the value of the x<y False
left operand is less than that of the
right operand and False otherwise.
> Returns True if the value of the left x>y True
operand is greater than that of the
right operand and False otherwise.

91

2020 Ubuntu Ed.indb 91 12-May-20 5:53:45 PM


<= Returns True if the value of the x<=y False
left operand is either less than or
equal to that of the right operand
and False otherwise.
>= Returns True if the value of the left x>=y True
operand is either greater than or
equal to that of the right operand
and False otherwise.
!= or Returns True if the value of the left x!=y True
<> operand is not equal to that of the
right operand and False otherwise.
== Returns True if the value of the x==y False

d
left operand is equal to that of the

Lt
right operand and False otherwise.

t.
Pv
a
Note
di
In
When floating-point values are compared using relational operators,
rs

the comparison is done after removing trailing zeros after the decimal point.
he
lis

When relational operators are used with strings, these rules are followed.
b
Pu

‹‹ Values are compared on the basis of lexicographical ordering, that is, the order in
which they appear in a dictionary.
n
illa

‹‹ Capital letters are considered smaller than lowercase letters.


m

For example, the expression ‘Rahul’ < ‘Ruhani’ returns True, while ‘RUHANI’ > ‘Ruhani’
ac

returns False.
M
©

Note
The operators ==and != are also known as equality operators as they
are used for checking the equality of operands.

6.1.3 Logical Operators


Logical operators combine multiple operands/expressions and return either True or False.
Table 6.3 illustrates the working of logical operators available in Python.

92

2020 Ubuntu Ed.indb 92 12-May-20 5:53:46 PM


Table 6.3 Logical operators

Operator Type of Description Examples Result


operand
R e l a t i o n a l Returns True if any (3==2)or(6!=6) False
expressions one or all of the (4>2) or (8<9) True
expressions evaluate
to True.
If all the expressions
evaluate to False then
only, it returns False.
or
N u m b e r s , If the first operand has 9 or 0 9
strings, lists or False truth-value then 9 or 0 9

d
tuples it returns the second

Lt
‘Python’or’’ ‘Python’
operand as the result.

t.
‘d’or’m’ ‘d’

Pv
Otherwise, it returns
the first operand as the

a
result.
di
(3==2)and(6!=6) False
R e l a t i o n a l Returns True only
In
expressions if all the relational (4>2) and(8<9) True
rs

expressions evaluate
he

to True and False


lis

otherwise.
b
Pu

N u m b e r s , If any of the operands 9 and 0 0


strings, lists or has False truth-value 0 and 9 0
n

and
illa

tuples then it returns that 9 and 8 8


operand (which has
m

‘Python’and’’ ‘’
False truth-value).
ac

If both operands have ‘’ and ‘Python’ ‘’


M

True truth-value, it ‘d’and’m’ ‘m’


©

returns the second


operand as the result.
R e l a t i o n a l Returns True if the not(3==2) True
expressions relational expression not(4>2) False
evaluates to False and
vice versa.
not N u m b e r s , Returns True if the not 9 True
strings, lists or operand's truth-value not 0 False
tuples is False and vice versa. not ‘d’ False
not ‘’ True

93

2020 Ubuntu Ed.indb 93 12-May-20 5:53:46 PM


Did You Know
The operator or evaluates the second argument only if the first one has False truth-
value. In contrast, the operator and evaluates the second argument only if the first
one is True. The not operator simply negates the truth-value and always returns a
Boolean value.

6.1.4 Precedence and Associativity of Operators


Generally, an expression consists of more than one operator. Hence, the interpreter needs
to know which operator is to be evaluated first. For this, it is important to determine the

d
precedence of operators. The order in which different operators in an expression are

Lt
evaluated is determined by the precedence of operators. The operators with a higher

t.
precedence are evaluated before the operators with a lower precedence. Table 6.4 lists

Pv
different operators in Python in the order of higher to lower precedence.

a
Table 6.4 Precedence of operators
di
In
Operator Description
rs

() Parentheses
he

** Exponentiation
lis

+, - Unary plus, unary minus


b
Pu

*, /, %, // Multiply, divide, modulo and floor division


+, - Addition, subtraction
n
illa

<, <=, >, >=, <>, Comparison operators


m

==, != Equality operators


ac

%=, /=, //=, -=, +=, *= Assignment operators


M

not, and, or Logical NOT, logical AND, logical OR


©

The order in which operators of the same precedence are evaluated is determined by the
associativity of operators. The associativity of an operator can be either from left to the
right or from right to left. The operators with left-to-right associativity are evaluated from
the left-hand side while the operators with right-to-left associativity are evaluated from the
right-hand side.
The order of operations of mathematical operators in Python is same as that in
mathematics. The ** operator is evaluated first, the *,/,// and % are evaluated next
from left to right, and the + and – operators are evaluated last (also from right to left).
You can use parentheses to override the usual precedence if you need to change the order.
Consider the following statement.
x=5+4*2

94

2020 Ubuntu Ed.indb 94 12-May-20 5:53:46 PM


Here, x will be evaluated to 13 not 18. It is because the operator * has higher precedence
than +. Therefore, firstly, 4*2 will be evaluated and then 5 will be added to it.

6.2 CONDITIONAL STATEMENTS


The conditional statements, also known as decision control statements or selection
statements, are used to make decisions based on a given condition. If the condition
evaluates to True, a set of statements is executed; otherwise, another set of statements is
executed. Python provides conditional statements in the form of the if and if...else
statements.

6.2.1 The if Statement


The if statement selects and executes the statement(s) based on a given condition. If the

d
condition evaluates to True, then a given set of statement(s) is executed. However, if the

Lt
condition evaluates to False, the program control passes to the statement following the if

t.
statement.

Pv
Syntax:

a
di
if<conditional_expression>: In
statement(s)
rs

The if statement is a compound statement. A compound statement consists of a header


he

line and a body. The header line of the if statement begins with the keyword if followed
lis

by a conditional_expression and ends with a colon (:). The indented statement(s)


b

that follow form the body of the if statement and are called a block or suite. The first
Pu

unindented statement marks the end of the block. Each statement inside the block must
n

have the same indentation.


illa

Here, it is important to note a few things about the if statement.


m
ac

‹‹ The colon (:) is significant and required. It separates the header of the statement
from the body.
M

‹‹ The body of the if statement may consist of a single statement, compound statement
©

or just a pass statement.


‹‹ The statement(s) after the colon must be indented. It is standard in Python to use
four spaces for indenting.
‹‹ All statements indented the same amount after the colon are considered a part of the
body of the if statement and will be executed whenever the conditional expression
evaluates to True.

Note
Sometimes, it is useful to have a body with no statements. In that case, we
can use the pass statement.This statement does nothing.
95

2020 Ubuntu Ed.indb 95 12-May-20 5:53:46 PM


To understand how the if statement works, consider the following code segment.
a = 35
b = 100
if b>a:
print(“b is greater than a”)
In this example, we have two variables, a and b, which are used as part of the if the
statement to test whether the value of b is greater than that of a. Since a is 35, and b is
100, the condition is satisfied and the message b is greater than a is displayed.
If you have only one statement to execute, you can put it in the same line as the if
statement, as shown below.
if b>a:print(“b is greater than a”)

d
Lt
Figure 6.1 illustrates the operation of the if statement.

t.
Pv
False

a
Condition?

di
In
True
rs
he

Body of if
b lis
Pu
n

Fig. 6.1 Operation of the if statement


illa
m
ac

Did You Know


M
©

Python relies on indentation to define the scope in the code. If the statement after the
colon is not indented, Python will raise an error. That is, the following code will result
in an error.
if b>a:
print(“b is greater than a”)

6.2.2 The if...else Statement


The if...else statement causes one of the two possible sets of statements to execute,
depending on the outcome of the condition. It comprises two parts: if and else. If the condition evaluates
to True, the statements indented below if are executed.
96

2020 Ubuntu Ed.indb 96 12-May-20 5:53:46 PM


However, if the condition evaluates to False, the statements indented below else are
executed.
Syntax:
if<conditional_expression>:
statement(s)
else:
statement(s)

To understand how the if...else statement works, consider the following code segment.
a=39
b=21
if b>a:

d
print(“b is greater than a”)

Lt
else:

t.
Pv
print(“b is not greater than a”)
In this example, since a is greater than b, the condition b>a evaluates to False. So we go

a
to the else part and the message b is not greater than a is displayed on the
di
screen.
In
rs

Figure 6.2 illustrates the operation of the if...else statement.


he
lis

False
b

Condition?
Pu
n

True Body of else


illa

Body of if
m
ac
M
©

Fig. 6.2 Operation of the if...else statement

6.2.3 Nested Condition


Python allows you to use a condition within another condition. Such a condition is known
as a nested condition. To understand, consider the following code segment.
a=35
b=27
if b>a:
print(“b is greater than a”)

97

2020 Ubuntu Ed.indb 97 12-May-20 5:53:46 PM


else:
if b==a:
print(“a and b are equal”)
else:
print(“b is less than a”)
In this example, a complete if...else statement is nested inside the else part of the
outer if statement.

6.2.4 Using the elif Keyword


The elif (an abbreviation of else...if) keyword is Python’s way of saying “if the
previous conditions were not true, then try this condition”. To understand, consider the
following code segment.
a=78

d
Lt
b=33
if b>a:

t.
Pv
print(“b is greater than a”)
elif a==b:

a
print(“a and b are equal”)
di
In
else:
rs

print(“a is greater than b”)


he

In this example, a is greater than b, so the first condition is not true, also the elif
lis

condition is not true, so we go to the else part and the message a is greater than
b

b is displayed on the screen.


Pu
n
illa

Note
There is no limit on the number of elif statements but only a single (and
m
ac

optional) final else statement is allowed and it must be the last branch in
M

the statement.
©

6.3 SOME MORE PYTHON PROGRAMS


Let us now write some programs that make use of different conditional statements.
Example 1: A program to check whether a given number is positive or negative
#A program to check whether a number is positive or negative
num=int(input(“Enter a number: “))
if num>=0:
print(“You entered a positive number.”)
else
print(“You entered a negative number.”)

98

2020 Ubuntu Ed.indb 98 12-May-20 5:53:46 PM


Output:
Enter a number: -8
You entered a negative number.

Example 2: A program to find the smallest of three numbers


#A program to find the smallest of three numbers
x=int(input(“Enter the first number: “))
y=int(input(“Enter the second number: “))
z=int(input(“Enter the third number: “))
min=x
if y<min:
min=y
if z<min:

d
min=z

Lt
print(“Smallest number is”, min)

t.
Pv
Output:
Enter the first number: 67

a
di
Enter the second number: 89 In
Enter the third number: 52
rs

Smallest number is 52
he

Example 3: A program to check whether a number is positive, negative or zero


lis

#A program to check whether a number is positive, negative


b
Pu

or zero
x=int(input(“Enter a number: “))
n
illa

if x>0:
print(“Number is positive.”)
m
ac

elif x==0:
print(“Number is zero.”)
M

else:
©

print(“Number is negative.”)
Output:
Enter a number: -5
Number is negative.

Example 4: A program to check whether a character entered by the user is an alphabet,


digit or a symbol.
#A program to check whether a character is an alphabet, a digit
or a symbol
ch=input(“Enter a character: “)
if (ch>=’a’ and ch<=’z’) or (ch>=’A’ and ch<=’Z’)):
print(ch, “is an alphabet.”)
99

2020 Ubuntu Ed.indb 99 12-May-20 5:53:46 PM


else
if (ch>=’0’ and ch<=’9’):
print(ch, “is a digit.”)
else:
print(ch, “is a symbol.”)
Output:
Enter a character: &
& is a symbol

Points to
Remember
‹‹ To make a program more flexible, control statements are used to alter the flow of

d
control of the program.

Lt
‹‹ In Python, the control statements are broadly classified into conditional statements

t.
Pv
and iteration (looping) statements.
‹‹ The control statements involve a condition which is basically an expression

a
di
formed of literals/variables joined by different operators.
In
‹‹ The conditional statements, also known as the decision control statements or
rs

selection statements, are used to make decisions based on a given condition.


he

‹‹ Python provides conditional statements in the form of if and if...else


lis

statements.
b
Pu

‹‹ The if statement selects and executes the statement(s) based on a given condition.
If the condition evaluates to True, then a given set of statement(s) is executed.
n
illa

‹‹ Python allows you to use a condition within another condition. Such a condition
m

is known as a nested condition.


ac

‹‹ The elif (an abbreviation of else...if) keyword is Python’s way of saying


M

“if the previous conditions were not true, then try this condition”.
©

Exercises
1. Tick (ü) the correct option.
a. Which of the following is used to define a block in Python?
(i) [ ] (ii)
{ }
(iii) ( ) (iv) Indentation

100

2020 Ubuntu Ed.indb 100 12-May-20 5:53:47 PM


b. Which of the following operators gives the remainder on dividing the two
operands?
(i) / (ii) //
% (iv)
(iii) **
c. How many times can the elif keyword be used while using conditional
statements in a program?
(i) Any number of times (ii) Only once
(iii) Only twice (iv) Maximum four times
d. If the body of a conditional statement has no statements, which statement
can be used?

d
Lt
(i) empty (ii)
pass

t.
Pv
elif
(iii) (iv) None of these

a
e. What will be the output of the code segment given below?
di
In
if 5>=5:
rs

print(5)
he

(i) 1
b lis

(ii) 5
Pu

(iii) 5 is printed infinitely until you close the program explicitly


n
illa

(iv) Error in code


m

2. Fill in the blanks.


ac
M

a. A ............................... statement consists of a header line and a body.


©

b. It is standard in Python to use ............................... spaces for indenting.

c. A condition used within another condition is called a ...............................


condition.

d. The indented statements that form the body of a conditional statements are
called a ............................... .

e. The ............................... symbol separates the header of the compound


statement from its body.

101

2020 Ubuntu Ed.indb 101 12-May-20 5:53:47 PM


3. State true or false.
a. Control statements are used to alter the flow of control of the program.
b. Relational operators are used for comparing two values or expressions.
c. The unary plus (+) operator has higher precedence than the exponentiation
(**) operator.
d. Each statement inside a block must have the same indentation.
e. The serial execution of statements makes a program more flexible.

4. Answer the questions.


a. Briefly describe the need of control statements in a program.

d
b. Which type of control statements are supported in Python?

Lt
t.
c. What are conditional statements?Which conditional statements are provided

Pv
by Python?

a
d. Differentiate between the if and if...else statements.
di
In
e. Define nested condition. Explain with the help of an example.
rs

f. What is the use of the elif keyword?


he
b lis
Pu
n
illa

Activities
m

1. Write a Python program to check whether a number provided by the user is even
ac

or odd.
M

2. Write a program in Python to input a character and check if it is a consonant or


©

a vowel.
3. Write a Python program to input a number and check if it is divisible by 5 or not.

For the Teacher


‹‹ Tell students how different types of operators provided by Python work.
‹‹ Familiarise students with the various conditional statements available in Python.
‹‹ Discuss the use of the elif keyword.

102

2020 Ubuntu Ed.indb 102 12-May-20 5:53:47 PM


7
You know Leno, my Sure! I will
Okay, Ria! Do you know
father has many tell you about
that a variety of apps are
apps installed on different type
available nowadays and you Really! Would
his smartphone. of apps, how to
can easily download any you tell me install an app
app from an app store? more about and develop your
apps?

d
own app.

Lt
t.
Pv
a
di
In
rs
he
b lis
Pu
n
illa
m

Contents
ac

Application software (or simply application) is a


M

‹‹ Difference between
Application Software and computer program or a set of programs that lets
©

Apps you perform specific tasks on the computer, such


as creating documents, spreadsheets, databases,
‹‹ Types of Apps sending e-mails, designing graphics, and even
‹‹ Uses of Common Apps playing games. An app (abbreviation for the
‹‹ Downloading and Installing word “application”) is a small piece of software
an App from an App Store designed for a single purpose. Gmail, Calculator,
Clock, Calendar, Photo Gallery, Camera, Music
‹‹ Developing an App Player, WhatsApp, Google Drive, Facebook and
Twitter are some common examples of apps.
The term app was originally referred to an application meant for mobile devices such as
smartphones and tablets. However, in the latest operating systems designed for personal
computers (PCs), the programs running on the computer are also referred to as apps,
103

2020 Ubuntu Ed.indb 103 12-May-20 5:53:49 PM


for example, Windows 8, Windows 10, etc. So nowadays, there is not much difference
between apps made for smartphones, tablets and PCs. For example, Gmail and Google
Drive are all available as apps for smartphones, tablets as well as for PCs.

7.1 DIFFERENCE BETWEEN APPLICATION SOFTWARE


AND APPS
There are some specific differences between application software and apps. Some of
these differences are listed in Table 7.1.
Table 7.1 Differences between application software and apps

Application Software Apps


Application software is a computer program An app is a type of application software

d
that enables you to complete various tasks designed to run specifically on a mobile

Lt
on a computer. device, such as a smartphone or tablet

t.
computer.

Pv
Application software may or may not be Apps are executable.

a
executable.
di
In
Application software may not be specific to Apps are often operating-system specific.
one operating system. For example, apps designed for Android
rs

may not run properly for iOS.


he
lis

7.2 TYPES OF APPS


b
Pu

Thousands of apps have been designed till date---some of which can be downloaded for
n

free, while others must be purchased from an app store. These apps can be categorised
illa

into the following types.


m
ac

7.2.1 Desktop Apps


M

An application that is designed to run standalone in a desktop or laptop computer is


©

referred to as a desktop application (or desktop app). These were the first apps to be
invented for PCs. However, with the introduction of the Internet and online commerce,
the development of mobile and Web apps gained more importance.Some examples of
desktop apps are Facebook, Microsoft Office, Web browsers, Instagram, Calculator, etc.

Did You Know


Desktop apps were only called application software before the introduction of Windows
8 by Microsoft. After the introduction of tiles in Windows 8, all the programs and
applications in a computer were also called apps.

104

2020 Ubuntu Ed.indb 104 12-May-20 5:53:49 PM


7.2.2 Mobile Apps
A mobile application (or mobile app) is a type of application software designed to run
specifically on a mobile device, such as a smartphone or a tablet. They provide similar
services to those as on PCs. Like desktop apps, even mobile apps need an operating
system and system utilities in order to run. Mobile applications are also known as end-
user programs as they were designed for end users. Some examples of mobile apps are
Facebook, Camera, photo-editing apps, etc.

7.2.3 Web Apps


A Web application (or Web app )is a program that runs on a web server and must be
accessed through a web browser. Web apps have several advantages over desktop apps.
Since they run inside web browsers, developers do not need to develop Web apps for

d
multiple platforms separately. For example, a single application that runs in Chrome will

Lt
work on both Windows and OS X.

t.
Pv
Note

a
di
The apps that combine the features of both mobile and Web apps are referred
In
to as hybrid apps.
rs
he
lis

7.3 USES OF COMMON APPS


b
Pu

Nowadays, there are a number of apps available for use.There is an app for every purpose
and need. Let us learn about some of the common apps specific to different fields.
n
illa

7.3.1 Educational Apps


m
ac

Educational mobile apps are the software programs that help individuals to facilitate
learning on their terms and their location choices. These apps provide the same access
M

to learning material irrespective of the place you are in. The use of educational apps is
©

changing the way students study around the world. A lot of educational websites and
applications are available even in the remotest areas of the world through which anyone
can attain education. Some examples of educational websites and apps are Todo Math,
edX, BYJU’S, Khan Academy,etc.

Fig. 7.1 Educational apps

105

2020 Ubuntu Ed.indb 105 12-May-20 5:53:49 PM


7.3.2 Social Networking Apps
Social networking refers to the use of online platforms such as websites or applications
by the people to build social relationship with other people who share similar interests.
A social networking website or application provides a virtual space for people to keep
in touch with each other. However, to use any social networking site, you first need to
register as a member and create your personal profile that you share with whom you want
to connect to. Some of the examples of social networking apps which are available on the
Web and on any smartphone’s app store are Facebook, Twitter, LinkedIn, Instagram, Hike
messenger, etc.

d
Lt
Facebook Twitter Instagram Hike messenger

t.
Pv
Fig. 7.2 Social networking apps

a
7.3.3 Entertainment Apps di
In
Entertainment means leisure activities such as listening to music, playing games, and
rs

commerce activities such as blogging, shopping and podcasting. You can find unlimited
he

entertainment apps on the Internet. Some examples are YouTube, Netflix, Spotify, etc.
b lis
Pu
n
illa
m

YouTube Spotify Netflix


ac

Fig. 7.3 Entertainment apps


M
©

7.3.4 E-Commerce Apps


E-commerce refers to buying or selling of goods and services online. Applications available
on the Internet such as Amazon, Flipkart and Myntra provide such e-commerce facilities.
More and more companies now try to reach their customers directly through the Internet,
using tools such as digital coupons, social media marketing and targeted advertisements.

Amazon Flipkart Myntra


Fig. 7.4 E-commerce apps

106

2020 Ubuntu Ed.indb 106 12-May-20 5:53:50 PM


7.4 DOWNLOADING AND INSTALLING AN APP FROM
AN APP STORE
An app store refers to an online shop from where you can choose and download mobile
applications for free or by paying a fee. You can download applications from Google Play
Store in Android smartphones, from App Store in iOS smartphones, and from Microsoft
Store in Windows smartphones.
To download and install an application from Google Play Store, follow these steps.
1. Tap the Google Play Store icon ( ) in your smartphone. The application is executed.
2. Search for the app of your choice. Various options start appearing below the Search
textbox.

d
Lt
t.
Pv
a
di
In
rs

(a) Searching the app (b) Preparing to install the app


he
lis

Fig. 7.5 Searching for the app in Google Play Store


b
Pu

3. Select the app you want to download and tap the ( ) button. The app will
start downloading.
n
illa
m
ac
M
©

Fig. 7.6 App under download process

Once the app is downloaded, it automatically starts installing in your smartphone.


Once the application is installed, you can start the application by opening it.
107

2020 Ubuntu Ed.indb 107 12-May-20 5:53:50 PM


7.5 DEVELOPING AN APP USING MIT APP INVENTOR
In addition to using existing apps available on the Internet, you can also develop your own
app. There are a number of websites and applications available which let you develop an
app of your own. Here, you will learn to create an app using MIT Inventor App.
App Inventor is an open-source web application originally developed by Google, and
now maintained by the Massachusetts Institute of Technology (MIT). It lets you develop
apps for the Android operating system. It is so user-friendly that people having only little
knowledge of programming skills can create apps.
Using App Inventor, you can develop apps for Android phones using a web browser and
a connected phone. The app you create appears on the phone step-by-step as you add
pieces to it. So, you can test your work as you create it. Besides, you also need to have a
Gmail account to use the App Inventor.

d
If you do not have a connected Android phone, you can build your apps using the Android

Lt
Emulator, which is a software that runs on your computer and behaves just like the phone.

t.
Pv
In this chapter, you will learn to build the apps using a phone.
In App Inventor, you build apps by working with the following.

a
• 
di
App Inventor Designer: Here, you design the user interface by selecting the
In
components for your app.
rs

• 
App Inventor Blocks Editor: Here, you assemble the program blocks that specify
he

how the components should behave.


lis

Let us build a simple app called HelloPuppy in which you create a button that has a
b
Pu

picture of a pup on it and then program the button so that when it is clicked the phone
will make a bow-bow sound. To build this app, we need a picture of a pup and an mp3
n

file of dog sound. So, before starting to build the app, download the image and sound file
illa

and save them on your computer.


m
ac

7.5.1 Designing with App Inventor Designer


M

Now, start designing the HelloPuppy app by following these steps.


©

1. Open your web browser.


2. 
Type http://appinventor.
mit.edu/ in the Address bar
and press the Enter key.
The home page of App
Inventor appears.
3. 
Click on the Create Apps!
button. The Sign in page
of Google appears.

Fig. 7.7 Home page of App Inventor


108

2020 Ubuntu Ed.indb 108 12-May-20 5:53:51 PM


4. 
Type your user name and password to log into MIT App Inventor with your Gmail
account.

Fig. 7.8 Typing the user name Fig. 7.9 Typing the password

d
The Welcome screen appears.

Lt
t.
Pv
a
di
In
rs
he
b lis
Pu
n
illa

Fig. 7.10 Welcome screen of MIT App Inventor


m
ac

Click on the START A BLANK PROJECT button. The Create new App Inventor
5. 
M

project dialog box appears.


©

6. 
Type a name for your project in the Project name text box. Remember that spaces
and underscores are not allowed.

Fig. 7.11 Project name text box


109

2020 Ubuntu Ed.indb 109 12-May-20 5:53:55 PM


7. 
Click OK. Now, you are in the Designer window. Here, you lay out the look and
feel of your app, and specify what functionalities it should have. You can choose
things for the user interface such as buttons, images, and text boxes, and other
functionalities. The Designer window is divided into the following panes.
• Palette: Here, you can choose your components.
• Viewer: Here, you can arrange the components.
• Components: Here, you can view the list of components in the project.
• Properties: Here, you can change the properties of the components.

d
Lt
t.
Pv
a
di
In
rs
he
lis

Fig. 7.12 Designer window


b
Pu

8. 
From the User Interface palette, drag and drop the Button control onto Screen1 in
the Viewer pane.
n
illa
m
ac
M
©

Fig. 7.13 Screen1 and Viewer pane


9. 
Now, give the button the image of a puppy. For this, in the Properties pane, under
Image, click on the text None and click the Upload File button. This displays the
Upload File dialog box.

110

2020 Ubuntu Ed.indb 110 12-May-20 5:53:57 PM


Fig. 7.14 Properties pane Fig. 7.15 Upload File dialog box
10. 
Click the Browse button. This displays the File Upload dialog box where you can locate
and select the desired image (for example, Pup.jpg in our case) you downloaded
earlier.

d
Lt
t.
Pv
a
di
In
rs
he
lis
b
Pu
n

Fig. 7.16 File Upload dialog box


illa

11. 
Click the Open button. The File Upload dialog box closes and you come back to the
m

Upload File dialog box with the name of the image file appearing beside the Browse
ac

button.
M
©

Fig. 7.17 Upload File dialog box with name of image file
111

2020 Ubuntu Ed.indb 111 12-May-20 5:54:01 PM


12. 
Click OK to upload the file and close the Upload File dialog box. The selected image
appears on the button on Screen1.
13. 
Now, change the button’s Text property in the Properties pane. Delete Text for
Button1, leaving the button’s text property blank so that there is no writing over the
pup’s image.

d
Lt
t.
Pv
Fig. 7.18 Button with blank text property field

a
14. 
From the User Interface palette, drag and drop the Label component below the
di
picture of the puppy in the Viewer pane. It will appear under your list of components
In
as Label1.
rs

15. 
Change the following properties of Label1 control in the Properties pane.
he

• Text: Delete the existing text (Text for Label1) and write Touch Me!.
lis

• Font Size: Change the font size from 14 to 30.


b
Pu

•  BackgroundColor: Click on the box below the property and choose the desired
colour from the list of colours.
n
illa

•  TextColor: Click on the box below the property and choose the desired colour
from the list of colours.
m
ac
M
©

Fig. 7.19 Label1 properties


16. 
Now, add a sound that plays on clicking the button. For this, click on the Media
drawer under the Palette pane, drag out the Sound component and place it in the
Viewer pane. Wherever you drop it, it will appear in the area at the bottom of the
Viewer marked Non-visible components.
112

2020 Ubuntu Ed.indb 112 12-May-20 5:54:03 PM


Fig. 7.20 Sound component in Viewer pane
17. 
In the Properties pane, see that the Source property currently says None. Click the

d
word None and then click the Upload File button to open the Upload File dialog

Lt
box. Click the Browse button to display File Upload dialog box. Locate and select

t.
the desired sound file (for example, Bow bow.mp3 in our case)

Pv
a
di
In
rs
he
b lis
Pu
n

Fig. 7.21 Upload File dialog box Fig. 7.22 File Upload dialog box
illa

18. 
Click the Open button in the File Upload dialog box and then click OK in the Upload
m

File dialog box to upload the selected sound file.


ac
M
©

Fig. 7.23 Selected sound file uploaded

113

2020 Ubuntu Ed.indb 113 12-May-20 5:54:06 PM


7.5.2 Programming with the App Inventor Blocks Editor
As you have arranged your app’s screen and components in the Designer, which is in
a web browser window, now it is time to start programming the behaviour of the app.
For this, you need to go to the Blocks Editor window by clicking the Blocks button in the
upper-right side of your screen. Here, you can find many built-in blocks that handle things
such as math, logic, text and blocks that are with the components in your app.

d
Lt
t.
Pv
a
di
In
Fig. 7.24 Blocks Editor window
rs
he

Now, you can start programming your app with blocks by following these steps.
lis

1. On the left side of the Blocks Editor window, click the Button1 drawer to open it.
b

The bunch of blocks related to your components appears in the Viewer pane. These
Pu

mustard-coloured blocks called event-handler blocks.


n
illa
m
ac
M
©

Fig. 7.25 Event-handler blocks

2. Drag and drop the block from the Viewer pane to the work area

(the white area on the right).


114

2020 Ubuntu Ed.indb 114 12-May-20 5:54:09 PM


3. Click the Sound1 drawer on the left side of the Blocks Editor window, and drag

the block and add it to the do section of the block.

Both blocks connect like puzzle pieces and you can hear a voice of clicking when
you they connect.

d
Lt
t.
Pv
a
di
Fig. 7.26 Sound added by dragging blocks
In
The purple blocks are called command blocks, which are placed in the body of event
rs

handlers. When an event handler is executed, it runs the sequence of commands in its
he

body. A command is a block that specifies an action to be performed (for example, playing
lis

sound) when the event (for example, pressing Button1) is triggered. Now you can see that
b

the command block is in the event handler. This set of blocks means: “when Button1 is
Pu

clicked, Sound1 will play.” The event handler is like a category of action.
n
illa

7.5.3 Connecting App Inventor to Phone for Live Testing


m

You have three options for setting up live testing on your phone while you build apps.
ac

1. If you are using an Android device and you have a wireless Internet connection, you
M

can start building apps without downloading any software to your computer. You will
©

need to download and install the App Inventor Companion app on your device.
2. If you do not have an Android device, you will need to install software on your
computer so that you can use the on-screen Android Emulator.
3. If you do not have a wireless Internet connection, you will need to install software on
your computer so that you can connect to your Android device over USB.
Let us use option 1 to connect your Android device (phone or tablet) to App Inventor by
following these steps.
1. Open Google Play Store in your Android phone or tablet.
2. Start typing mit ai2 companion in the search bar. As you type, a list of search results
appears.
3. Tap on MIT AI2 Companion in the list.
115

2020 Ubuntu Ed.indb 115 12-May-20 5:54:09 PM


d
Lt
t.
Pv
a
Fig. 7.27 Searching and opening MIT AI2 Companion
di
In
4. Tap the Install button to download and install the app on your device.
rs

5. After finishing the installation of the app in the phone or tablet, find the app in your
he

phone.
lis

6. Ensuring that your phone and computer are connected on the same Wi-Fi network,
b
Pu

open the MIT AI2 Companion app in your Android phone or tablet.
n
illa
m
ac
M
©

Fig. 7.28 Connecting MIT A2 Companion to phone


116

2020 Ubuntu Ed.indb 116 12-May-20 5:54:14 PM


7. In the computer’s MIT App Inventor menu, click the Connect tab and then choose
the AI Companion option from the list.

d
Lt
t.
Pv
Fig. 7.29 Connect tab of MIT App Inventor menu

a
di
The Connect to Companion dialog appears showing a QR (Quick Response) code and a
In
connect code.
rs
he
b lis
Pu
n
illa
m
ac
M
©

Fig. 7.30 Connect to Companion dialog box with QR code


8. Type in the 6-character connect code appearing on your computer in the text box in
AI Companion app in your Android device and tap the connect with code button.
OR
Tap the scan QR code button in the AI Companion app in your Android device and
scan the QR code appearing in your computer’s MIT App Inventor.
If your connection is successful, you can see your app on the connected device.
117

2020 Ubuntu Ed.indb 117 12-May-20 5:54:18 PM


Fig. 7.31 App on a connected device

d
Lt
7.5.4 Packaging Your App

t.
As long as your Android device remains connected to App Inventor, your app runs in real

Pv
time on your device. Once you disconnect your device, the app will vanish. However, you

a
can always make it return by reconnecting the device.
di
In
To have an app running without being connected to App Inventor, you must package the
app to produce an application package (.apk file). To package the app to install on your
rs
he

device or to send to someone else, click the Build tab at the top of the MIT App Inventor
screen on your computer. There are two options available for you to choose from.
b lis

• 
App (provide QR code for .apk): You can generate a QR code with this option.
Pu

When you scan this code using a QR scanner app on your phone, a link is generated
which you can use to install the app on the phone. You can also share this code with
n
illa

others, but they have to use it within two hours of after generating it.
m

• 
App (save .apk to my computer): You can download the app to your computer as an
ac

.apk file, which you can distribute and share as you like by manually installing it on
M

other devices.
©

Fig. 7.32 Packaging the app


118

2020 Ubuntu Ed.indb 118 12-May-20 5:54:20 PM


Points to
Remember
‹‹ Application software is a computer program or a set of programs that lets you
perform specific tasks on the computer.
‹‹ An app (abbreviation for the word “application”) is a small piece of software
designed for a single purpose.
‹‹ Apps can be categorised into three types: desktop apps, mobile apps and Web
apps.
‹‹ An application that is designed to run standalone in a desktop or laptop computer
is referred to as a desktop application (or desktop app).
‹‹ A mobile application (or mobile app) is a type of application software designed to

d
run specifically on a mobile device, such as a smartphone or a tablet.

Lt
t.
‹‹ A Web application (or Web app)is a program that runs on a web server and must

Pv
be accessed through a web browser.

a
‹‹ Nowadays, there are a number of apps available for use such as educational,
social networking, entertainment and e-commerce apps.
di
In
‹‹ An app store refers to an online shop from where you can choose and download
rs

mobile applications for free or by paying a fee.


he

‹‹ You can download applications from Google Play Store in Android smartphones,
lis

from App Store in iOS smartphones, and from Microsoft Store in Windows
b
Pu

smartphones.
‹‹ There are a number of websites and applications available which let you develop
n
illa

an app of your own.


m
ac
M

Exercises
©

1. Tick (ü) the correct option.


a. Which of the following apps can you use to keep in touch with your friends?
(i) Spotify (ii) Facebook
(iii) Amazon (iv) BYJU’S
b. Which type of app is Twitter?
(i) An educational app (ii) An e-commerce app
(iii) An entertainment app (iv) A social networking app

119

2020 Ubuntu Ed.indb 119 12-May-20 5:54:20 PM


c. Which of the following lets you build your own mobile app?
(i) MIT App Inventor (ii) Instagram
(iii) Flipkart (iv) None of these
d. Which of the following apps can you use to shop online?
(i) Amazon (ii) Flipkart
(iii) Myntra (iv) All of these
e. Hybrid apps combine the features of
(i) Mobile and desktop apps (ii) Mobile and Web apps
(iii) Desktop and Web apps (iv) Desktop, mobile and Web apps

d
Lt
2. Fill in the blanks.

t.
Pv
a. Spreadsheets are an example of ................................ software.

a
b. An application that is designed to run standalone in a desktop or laptop
di
computer is referred to as a ............................... .
In
rs

c. ............................... are executable.


he

d. ............................... refers to buying or selling of goods and services online.


b lis

e. A social networking application provides a ............................... for people


Pu

to keep in touch with each other.


n

3. State true or false.


illa
m

a. Application software is always specific to one operating system.


ac

b. A Web app runs on a web server.


M
©

c. Hike messenger is an entertainment app.

d. You can create an app of your own.

e. MIT App Inventor is a free web application to create apps.



4. Answer the questions.

a. Define the following terms.


(i) Application (ii) Social networking
(iii) E-commerce (iv) App store

120

2020 Ubuntu Ed.indb 120 12-May-20 5:54:20 PM


b. Differentiate between app and application software.

c. What is the difference between mobile apps and Web apps?

d. What are social networking applications? Explain.

e. Write the steps to download an application using Google Play Store in your
mobile.

Activity

d
Lt
t.
Take the help of your computer teacher or parents and try to build an app using the

Pv
“Appy Pie” application on a smartphone. It is very easy and you will have fun doing it.

a
di
In
For the Teacher
rs
he

‹‹ Illustrate the use of Web, desktop and mobile apps to the students.
lis

‹‹ Tell them about the uses of some common mobile apps.


b
Pu

‹‹ Help students understand how to build an app online using a Web or mobile
application.
n
illa
m
ac
M
©

121

2020 Ubuntu Ed.indb 121 12-May-20 5:54:21 PM


8
Leno, there is only one printer in our Ria, it is possible because
computer lab. We all can take printouts the computers in your lab are
from that printer only. How is it possible connected to each other. This is
if the printer is not directly connected called computer networking. Come,
to our computer? let me tell you about this in detail.

d
Lt
t.
Pv
a
di
In
rs
he
b lis
Pu
n
illa

Contents
m

In our daily life, we come across different types


ac

‹‹ Computer Network of networks, such as telephone network, mobile


M

‹‹ Types of Networks network, cable television network, and many


more. A network is simply an interconnection
©

‹‹ Network Architecture of devices to share their resources with each


‹‹ Internet, Intranet and Extranet other. Creating a network of different devices
‹‹ Protocols is termed networking. In today’s world, fast
communication and exchange of information
‹‹ Data Transmission Media
have become the need of everyone. It has
‹‹ Network Topology become possible through networking of
‹‹ Network Devices computers. Let us learn about computer
networks in detail.
8.1 COMPUTER NETWORK
A computer network is a group of computers and other peripheral devices
(such as printers and modems) connected by means of communication links.
122

2020 Ubuntu Ed.indb 122 12-May-20 5:54:22 PM


The main purpose of a computer network is to facilitate sharing of data and hardware
resources among a wide range of users. The computers in a network can be linked through
cables, telephone lines, radio waves, etc. The complexity of a computer network may
vary from just two computers connected together to a network connecting millions of
computers all over the world.

Note
The Internet is the world’s largest computer network.

When you connect your computer to a network via a cable or some other communication
means, you become a network user and your computer becomes a workstation
(or sometimes, called node) on the network. Your computer can access all its local resources
such as local hard drives or printers as usual. In addition, it can use the network resources,

d
Lt
including printer, disk storage space, etc. For example, you can print a document on the
printer attached to some other computer on the network.

t.
Pv
8.1.1 Advantages of a Computer Network

a
di
A networked environment of computers has a number of advantages. Some of these are
In
given below.
rs
he

‹‹ S
peed: You can share and transfer files within a computer network very rapidly.
It saves time while maintaining the integrity of files.
b lis

‹‹ C
ommunication: A computer network facilitates communication via e-mail,
Pu

videoconferencing and instant messaging.


n

‹‹ Information sharing: In a networked environment, the information can be kept on


illa

a single computer known as the server. All the other computers in the network can
m

access the information stored on the server.


ac

‹‹ R
esource sharing: The primary aim of networking is to share resources regardless of
M

the physical location for better communication. Resource sharing involves the sharing
©

of both the hardware and software resources among multiple users connected to the
network.
‹‹ P
reservation of information: It is easy to take backup of data in a networked
environment rather than on a number of stand-alone computers.
‹‹ C
ost-effectiveness: Due to the interconnection of computers, it is easier to access and
transfer a large amount of data from a large distance in a cost-effective manner and
in a short period of time.
‹‹ Reliability: The backup facility in networking makes it a reliable mode for
communication and sharing files. In case one computer in a network fails, the file
can be accessed from other computers.

123

2020 Ubuntu Ed.indb 123 12-May-20 5:54:22 PM


8.1.2 Disadvantages of a Computer Network
Some of the disadvantages of a computer network are given below.
‹‹ Security issues: One of the major drawbacks of computer networks is the security.
If proper network security check is not performed, there is a possibility of the theft of
confidential and private data.
‹‹ D
ependency on server: If the server breaks down, the working of all the computers
on the network is disrupted and the entire system becomes useless.
‹‹ R
apid spread of computer viruses: If any computer in a network gets affected by
a computervirus, other computers can also be affected. There is a possibility that
important data can be corrupted by that virus.
‹‹ E
xpensive: The setup cost of a computer network can be high, depending on the
number of computers to be connected.

d
Lt
‹‹ D
egraded performance: If the traffic of data increases on the network, the performance

t.
of the system degrades, if it is not designed properly.

Pv
a
8.2 TYPES OF NETWORKS
di
In
Computer networks can be categorised based on their size, the distance they cover and
rs

the links used for their interconnection. According to the physical distance a computer
he

network covers, it can be categorised into four types, namely, Personal Area Network
(PAN), Local Area Network (LAN), Metropolitan Area Network (MAN) and Wide Area
lis

Network (WAN).
b
Pu

8.2.1 Personal Area Network (PAN)


n
illa

A PAN is the smallest possible network intended for one person. It is used to interconnect
m

personal devices such as a computer, laptop, mobile phone, tablet or any other hand-
ac

held device of an individual. The devices in a PAN are linked together either using cables
M

or wirelessly. In a wired PAN, the devices communicate through a USB cable, while
in a wireless PAN, Bluetooth and infrared technologies are used for communication.
©

This network can cover an area of only a few metres (less than 10 metres).

Printer

PDA

Desktop Laptop
Computer
Mobile

Fig. 8.1 Personal area network (PAN)


124

2020 Ubuntu Ed.indb 124 12-May-20 5:54:22 PM


8.2.2 Local Area Network (LAN)
A LAN is a network that covers a relatively small area such as a residence, a building
or a campus. It generally comprises interconnected personal computers, each of which
is capable of accessing and sharing data and devices such as printers and scanners,
anywhere on the LAN. A LAN does not exceed an area of two to three square kilometres.
It may serve as few as two or three users to as many as hundreds of users. LANs are
owned, controlled and managed by a single person or an organisation.

LAN

d
Lt
t.
Pv
a
di
Fig. 8.2 Local area network (LAN)
In
rs

8.2.3 Metropolitan Area Network (MAN)


he
lis

A MAN is a network that covers an area larger than a LAN, for example, a city. It is basically
b

formed by connecting multiple LANs. It may be owned by one or more organisations. An


Pu

example of a MAN is the cable TV networks that are spread over a city. It is more efficient
and provides high-speed connection using fibre-optic cables.
n
illa
m
ac
M
©

Fig. 8.3 Metropolitan area network (MAN)

8.2.4 Wide Area Network (WAN)


A WAN is a network that spans a large geographical area such as several cities or even
countries. It connects different smaller networks, including LANs and MANs. Computers
in a WAN are often connected through public networks such as telephone systems.
125

2020 Ubuntu Ed.indb 125 12-May-20 5:54:22 PM


Sometimes, satellites are also used to connect computers in a WAN. The Internet is an
example of a widely used WAN.

d
Lt
t.
Pv
a
di
In
rs
he

Fig. 8.4 Wide area network (WAN)


b lis
Pu

Did You Know


n
illa

A WAN owned and controlled by a single company is often called an enterprise


m

network.
ac
M
©

8.3 NETWORK ARCHITECTURE


Network architecture refers to the layout of a computer network that specifies how a
computer network is configured to facilitate information exchange and resource sharing.
The two major types of network architectures are client-server and peer-to-peer network.

8.3.1 Client-Server Network


In a client-server network, many workstations (called clients) are connected to a centralised
host computer known as server. To accomplish any task, the client requests a service like
data retrieval from the server and the server responds by providing the service. In addition
to providing service to clients, the server controls access to hardware, software and other
network resources.
126

2020 Ubuntu Ed.indb 126 12-May-20 5:54:22 PM


Server

Client
Client

d
Lt
Client Client

t.
Pv
Fig. 8.5 Client-server network

a
8.3.2 Peer-to-Peer Network
di
In
A peer-to-peer network does not rely on a central server for communication. Instead,
rs

the computers having equal capacity and capability (called peers) are connected to each
he

other to use the resources on the network. Each computer on a peer-to-peer network can
lis

act both as a server and a client.


b
Pu
n
illa

Client Client
m
ac
M
©

Client Client
Fig. 8.6 Peer-to-peer network

8.4 INTERNET, INTRANET AND EXTRANET


The Internet is the largest network that connects millions of computers worldwide to
share information and services. People all over the world can use the Internet for various
purposes such as accessing web pages, send e-mails, watch videos, play online games
and download data.
127

2020 Ubuntu Ed.indb 127 12-May-20 5:54:23 PM


An intranet is a private computer network owned by a company or an organisation
and is accessible only to its employees. It is closely related to the Internet, but has a
protecting system to prevent unauthorised access from external computer networks. Thus,
it has a limited number of users. It uses the Internet protocols, network connectivity and
telecommunication system to share a part of the organisation’s information or operations
with its employees.
An extranet is a computer network that allows outside users to have limited access to
the part of the orgranisation’s information. These users include vendors, suppliers or
customers that may need to access orgranisation’s information for some business purposes
or customer services.

8.5 PROTOCOLS

d
The communication between computers is possible by using a protocol that offers

Lt
a standard format and method for communication. A protocol is a formal set of rules

t.
and conventions that governs how computers exchange information over a network.

Pv
There are a large number of protocols that can be used in a network depending on the
need they fulfil. Two of these are discussed here.

a
‹‹ T
di
CP/IP (Transmission Control Protocol/Internet Protocol): It is the suite of
In
communication protocols which is used as a standard for transmitting data over
rs

networks. TCP/IP consists of two protocols, namely, TCP and IP. The TCP is responsible
he

for dividing the message or file into small packets at the source computer that are
lis

transmitted over the network. Then at the destination computer, it reassembles the
b

packets into the original message or file. On the other hand, the IP handles the
Pu

address part of each packet so that it reaches the right destination. Any computer or
a device which is connected to the Internet must be supported by TCP/IP.
n
illa

‹‹ H
TTP (HyperText Transfer Protocol): It is the Internet protocol responsible for
m

transferring and displaying web pages. It provides a way for web clients and web
ac

servers to communicate with each other by sending and receiving messages.


M
©

8.6 DATA TRANSMISSION MEDIA


A data transmission media refers to the medium used for transmitting data between the
connected devices in a network. Transmission media can be broadly classified into guided
and unguided media.
‹‹ G
uided media: A guided media (also called wired media) provides a physical path
between the communicating devices in a network. It is mainly used for small LANs.
Different types of guided media include twisted pair cable, coaxial cable and fibre-
optic cable.
‹‹ U
nguided media: An unguided media (also called wireless media) is a type of
transmission media that sends or receives the data through air or space. It does not
involve any cable between two communicating devices. The data is transmitted in
128

2020 Ubuntu Ed.indb 128 12-May-20 5:54:23 PM


the form of waves. This transmission medium is useful for the networks that need to
transmit signals over vast distances. Different types of unguided media include radio
waves, microwaves, infrared waves, Bluetooth and Wireless Fidelity (Wi-Fi).
Let us learn two commonly used data transmission media.

8.6.1 Bluetooth
Bluetooth is a wireless technology used for exchanging data over short distances. It is used
to create a wireless PAN that lets the electronic devices such as computers, cell phones,
PDAs and wireless keyboards to communicate with each other within the range of 10
metres. It uses radio waves to facilitate communication among devices. Thus, it is not very
expensive and has a low power consumption.

d
Lt
t.
Pv
a
di
In
rs
he
b lis

Fig. 8.7 Bluetooth


Pu
n
illa

Did You Know


m
ac

The name Bluetooth has come from the Danish king Harald Blatand (Bluetooth in
English).
M
©

8.6.2 Wireless Fidelity (Wi-Fi)


Wi-Fi is widely used for creating wireless
LANs and also for providing wireless Tablet Internet
Internet access. To create a wireless
LAN, the devices in the network such
as computer, laptop and PDA should be Wi-Fi-router
equipped with a wireless network interface
card to send and receive Wi-Fi signals.
A Wi-Fi enabled device should be within a
Smartphone Laptop
specific range (up to 50 metres) from the
network to connect to it. Fig. 8.8 Wi-Fi
129

2020 Ubuntu Ed.indb 129 12-May-20 5:54:23 PM


8.7 NETWORK TOPOLOGY
The way in which the network components (cables, computers and other peripheral
devices) are connected together in a network is known as the network topology. Some of
the basic topologies are bus, ring, star and mesh network.

8.7.1 Bus Topology


In a bus topology, the computers and other devices are connected to a single cable called
the bus (or backbone). This cable has terminators at both the ends. Whenever a message
is transmitted on the network, it is passed to all the workstations connected through the
bus.

d
Lt
t.
Pv
a
Terminator
di
In
rs

Fig. 8.9 Bus topology


he
lis

Advantages
b
Pu

‹‹ It is easy to install and reconfigure.


‹‹ It incurs less cost as it requires less amount of cabling.
n
illa

Disadvantages
m
ac

‹‹ There is a limit to the number of devices that can be connected.


M

‹‹ The entire network becomes unusable in case of failure of the bus or backbone.
©

‹‹ It is difficult to identify where the problem is, if the entire network shuts down.

8.7.2 Ring Topology


In a ring topology, the computers and other
devices are connected to each other in such
a way that they form a closed loop (ring).
Every workstation in a ring topology has
exactly two neighbours. All the messages
are transmitted through a ring in the same
direction (clockwise or counterclockwise)
until they reach their destination.
Fig. 8.10 Ring topology
130

2020 Ubuntu Ed.indb 130 12-May-20 5:54:23 PM


Advantages
‹‹ It is also easy to install.
‹‹ It is a low-cost topology because the least amount of cabling is required.
‹‹ It is easier to identify the fault in a ring network.

Disadvantages
‹‹ A failure in any cable or device breaks the loop and can take down the entire network.
‹‹ I t is a little slow as the message is passed through all the workstations between the
sender and the receiver.
‹‹ T
he addition and removal of a device or a workstation from the network require
rewiring and rerouting of all the cables.

d
Lt
8.7.3 Star Topology

t.
Pv
In a star topology, the workstations are not directly connected to each other; rather they
are connected to a centralised network device known as a hub. The hub acts as a central

a
di
controller and the workstations are connected to it via cable segments. If a computer
In
wants to send data to another computer on the network, it sends the message to the hub,
rs

which then sends the message to the intended computer.


he
b lis
Pu
n

Hub
illa
m
ac
M
©

Fig. 8.11 Star topology

Advantages
‹‹ The network is not disrupted even if a workstation fails or is removed from the
network.
‹‹ New workstations can be added easily in the network by just upgrading the central
hub.
‹‹ Fault detection and removal of faulty parts are easier in a star network.
131

2020 Ubuntu Ed.indb 131 12-May-20 5:54:23 PM


Disadvantages
‹‹ It requires more cable length than a bus network.
‹‹ If the hub fails, the entire network breaks down.
‹‹ The cost of the hub makes the star network expensive as compared to the bus and
ring networks.

8.7.4 Mesh Topology


In mesh topology, each node is linked to every other node in the network. This enables
every node to have direct communication with all other nodes on the network.

d
Lt
t.
Pv
a
di
In
rs
he

Fig. 8.12 Mesh topology


b lis
Pu

Advantages
n

‹‹ The use of large number of links eliminates network congestion.


illa

‹‹ Communication between any two nodes is very fast.


m
ac

‹‹ If one link fails, it does not disable the entire network.


M

Disadvantages
©

‹‹ The amount of cabling required is very large.


‹‹ As every node is connected to the other, it becomes difficult to install and reconfigure
the network.
‹‹ It is the most expensive network as there are many redundant connections.

Note
A fully connected mesh network with n devices has n(n − 1)/2 physical links.
For example, if an organisation implementing the mesh topology has 8
nodes, then 8(8 − 1)/2, that is, 28 links are required.

132

2020 Ubuntu Ed.indb 132 12-May-20 5:54:24 PM


8.8 NETWORK DEVICES
Network devices are the components that help the computers to connect to a network for
an efficient communication. Let us discuss some of the network devices.

8.8.1 Ethernet Cable


Ethernet cable (also called networking cable) is used to connect two devices in a network.
It can be used to connect:
‹‹ a computer with a modem, switch or hub
‹‹ two computers directly without any hub or switch
‹‹ a hub with a switch
‹‹ two switches or hubs

d
Lt
Each Ethernet cable has RJ-45 connectors at both

t.
ends with each connector usually having eight pins.

Pv
These connectors look similar to telephone jacks
Fig. 8.13 Ethernet cable
which may have four or six pins.

a
di
In
8.8.2 Modem
rs

A modem (an acronym of modulator/demodulator)


he

is a device that enables a computer to transmit data


lis

over telephone lines. In a computer, the information


b

is stored digitally, whereas the information transmitted


Pu

over telephone lines is in analog form. The job of a


n

modem is to convert data from digital to analog form


illa

at the sender’s end and then convert it back to digital


m

form at the receiver’s end. This conversion of data


ac

from the digital to the analog form and back to the Fig. 8.14 Modem
M

digital form is known as modulation/demodulation.


©

8.8.3 Network Interface Card (NIC)


The Network Interface Card (NIC), commonly
referred to as Ethernet card, is a hardware
device that enables a computer to connect
to a network. It allows the computer to
communicate over the network. Earlier, these
cards were available as small circuit boards
that could be inserted onto the motherboard.
Nowadays, they come pre-installed in the
computers by the manufacturer.
Fig. 8.15 Network interface card (NIC)

133

2020 Ubuntu Ed.indb 133 12-May-20 5:54:24 PM


Did You Know
In a wireless network, wireless network cards are used instead of normal network cards
as used in wired networking. Most laptops have built-in wireless network cards. Radio
waves are used to enable communication among different devices.

8.8.4 Hub
A hub is a small rectangular device that connects multiple
devices on a network so that they can communicate with
one another. It gathers the signals from a device connected
to the network and transmits them to all other connected

d
devices. A hub has multiple ports ranging from 4 to over

Lt
400. Fig. 8.16 Hub

t.
Pv
8.8.5 Switch

a
di
A switch, like a hub, is also a multiport device that connects
In
computers to a network. The only difference is in the way of
rs

handling data. It checks the arriving data packets, determines


he

the source and destination of each data packet, and then


passes them to the intended receiver. A switch is also called
lis

an intelligent hub as it does not broadcast the packet to all


b

Fig. 8.17 Switch


Pu

the computers, making the network more efficient.


n
illa

8.8.6 Router
m

A router is a networking device used for interconnecting two or more networks.


ac

It determines the next network point to which a received data packet should be forwarded
M

towards its destination.


©

A router can be wired or wireless. A wired router connects computers and other devices
to the network through cables. On the other hand, a wireless router connects devices
through radio signals. It has wireless antennas that enhance the range of communication
of radio waves. It allows greater mobility to portable computers such as laptops, tablets
and smartphones.

(a) Wired router (b) Wireless router


Fig. 8.18 Router
134

2020 Ubuntu Ed.indb 134 12-May-20 5:54:24 PM


Points to
Remember
‹‹ A
network is simply an interconnection of devices to share their resources with
each other. Creating a network of different devices is termed as networking.
‹‹ A
computer network is a group of computers and other peripheral devices (such
as printers and modems) connected by means of communication links.
‹‹ A
ccording to the physical distance that a computer network covers, it can be
categorised into four types, namely, PAN, LAN, MAN and WAN.
‹‹ N
etwork architecture refers to the layout of a computer network that specifies
how a computer network is configured to facilitate information exchange and
resource sharing. The two major types of network architectures are client-server

d
are peer-to-peer network.

Lt
‹‹ T
he Internet is the largest network that connects millions of computers worldwide

t.
Pv
to share information and services. An intranet is a private computer network
owned by a company or an organisation and is accessible only to its employees.

a
An extranet is a computer network that allows outside users to have limited access
di
In
to the part of the orgranisation’s information.
rs

‹‹ A
protocol is a formal set of rules and conventions that governs how computers
he

exchange information over a network. Two protocols used in networking are


lis

TCP/IP and HTTP.


b

‹‹ A
data transmission media refers to the medium used for transmitting data
Pu

between the connected devices in a network. Transmission media can be broadly


n

classified into guided and unguided media.


illa

‹‹ T
he way in which the network components (cables, computers and other
m

peripheral devices) are connected together in a network is known as the network


ac

topology. Some of the basic topologies are bus, ring, star and mesh network.
M

‹‹ N
etwork devices are the components that help the computers to connect to a
©

network for an efficient communication.

Exercises
1. Tick (ü) the correct option.
a. NIC stands for:
(i) Network Interface Card (ii) Network Internet Card
(iii) National Interface Card (iv) National Internet Card

135

2020 Ubuntu Ed.indb 135 12-May-20 5:54:25 PM


b. Which of the following computer networks allows outside users to have
limited access to the part of the organisation’s information?
(i) Intranet (ii) Extranet
(iii) Internet (iv) None of these
c. Which type of network is basically formed by connecting multiple LANs?
(i) PAN (ii) LAN
(iii) WAN (iv) MAN
d. In which topology, each node is linked to every other node?
(i) Ring (ii) Mesh
(iii) Star (iv) Bus
e. Which protocol is responsible for transferring and displaying web pages?
(i) TCP (ii) IP

d
Lt
(iii) HTTP (iv) SMTP

t.
Pv
2. Fill in the blanks.

a
a. A ............................... provides a physical path between the communicating
di
devices in a network.
In
rs

b. In a ............................... topology, the computers and other devices are


he

connected to a single cable.


lis

c. The ............................... is the world’s largest computer network.


b
Pu

d. In a ............................... network, many workstations are connected to a


centralised host computer.
n
illa

e. A ............................... is a formal set of rules and conventions that governs


how computers exchange information over a network.
m
ac

3. State true or false.


M

a. It is easy to take backup of data in a networked environment.


©

b. A MAN does not exceed an area of two to three square kilometres.


c. Wi-Fi stands for Wireless Federation.
d. Ethernet cable is used to connect two devices in a network.
e. A switch is also called an intelligent hub.

4. Answer the questions.


a. Define a computer network. List its three advantages and disadvantages.
b. Define network architecture. What are the two major types of network
architectures?

136

2020 Ubuntu Ed.indb 136 12-May-20 5:54:25 PM


c. Give the difference between the following.
(i) Internet and intranet
(ii) Hub and switch
(iii) Guided and unguided transmission media
d. What is protocol?
e. Give the full forms of the following.
(i) TCP/IP (ii)
Wi-Fi (iii)
LAN
(iv)
NIC (v)
PAN (vi)
MAN
f. Explain about the different types of computer networks.
g. Define network topology. Briefly describe the different types of topologies.

d
h. Write short notes on the following.

Lt
(i) Modem (ii) Hub (iii) NIC (iv) TCP/IP

t.
Pv
a
di
In
rs

Activities
he
lis

1. Collect information on various guided and unguided transmission media using


b

the Internet. Make a presentation on the same. Apply different formatting and
Pu

animation effects to make your presentation impressive.


n

2. Prepare a chart to show comparison among different types of network topologies


illa

in a tabular form.
m

3. Go to your computer lab and find out the various network devices being used
ac

there. Make a list of them in your notebook.


M
©

For the Teacher


‹‹ E
xplain to students the basic concepts of nvetworking, its advantages and
disadvantages.
‹‹ Discuss with them the various types of networks and protocols.
‹‹ Familiarise the students with the term network architecture and describe its types.
‹‹ Explain the difference among Internet, intranet and extranet.
‹‹ Discuss with them the types of guided and unguided transmission media.
‹‹ Describe to students the different network topologies and network devices.

137

2020 Ubuntu Ed.indb 137 12-May-20 5:54:25 PM


National Cyber Olympiad
Sample Questions
1. Which of the following is a type of guided media?
(a) Coaxial cable (b) Radio waves
(c) Infrared waves (d) Wi-Fi
2. Which of the following can be used to create a table LibreOffice Base?
(a) Table Wizard (b) Design view
(c) Both (a) and (b) (d) Neither (a) nor (b)
3. Which field uniquely identifies the records in a table?
(a) Primary key (b) Foreign key

d
Lt
(c) Both (a) and (b) (d) None of these

t.
4. Which is the smallest computer network intended for one person?

Pv
(a) PAN (b) LAN

a
di
(c) MAN In (d) WAN
5. Which of the following is not an operating system?
rs

(a) Ubuntu (b) Google Chrome


he

(c) Microsoft Windows (d) Android


lis

6. Which shape represents the input/output instructions in a flowchart?


b

(a) Parallelogram (b) Rectangle


Pu

(c) Oval (d) Diamond


n
illa

7. In Python, the elements of a list are enclosed within


(a) ( ) (b) [ ]
m
ac

(c) { } (d) None of these


M

8. Which of the following is an entertainment app?


©

(a) YouTube (b) Spotify


(c) Netflix (d) All of these
9. The default format of a Python file is
(a) .py (b) .pyt
(c) .pyth (d) .python
10. In which network topology is the message broadcasted to all the connected
workstations?
(a) Ring (b) Star
(c) Mesh (d) Bus

138

2020 Ubuntu Ed.indb 138 12-May-20 5:54:25 PM


11. Which key needs to be pressed to run a program in Python?
(a) F6 (b) F5
(c) F7 (d) F8
12. Which of the following is a type of unguided media?
(a) Radio waves (b) Microwaves
(c) Infrared (d) All of these
13. Which section in the Database window displays icons for the objects that you can
create in your database?
(a) Database (b) Tasks
(c) Document (d) Description
14. Which of the following is not an element of GUI?
(a) Window (b) Icon

d
Lt
(c) Command prompt (d) Menu

t.
15. Which of the following symbols is used only once in a flowchart?

Pv
(a) Process (b) Flow lines

a
(c) Decision (d) Stop
di
In
16. Which of the following devices enables a computer to transmit digital data over
analog telephone lines?
rs
he

(a) Hub (b) Switch


lis

(c) Modem (d) Ethernet card


b

17. Which of the following network devices now comes pre-installed in the computers by
Pu

the manufacturer?
n

(a) NIC (b) Switch


illa

(c) Hub (d) Router


m

18. Which of the following is used to define a block in Python?


ac

(a) [ ] (b) Indentation


M

(c) { } (d) ( )
©

19. Which feature of an operating system allows it to prevent unauthorised access?


(a) Accounting (b) Security
(c) Communication (d) Program execution
20. Which of the following data types is used to store both date and time in Base?
(a) Date [DATE] (b) Time [TIME]
(c) Date/Time [TIMESTAMP] (d) None of these
21. Which of the following is not an educational app?
(a) Todo Math (b) edX
(c) Instagram (d) BYJU’S

139

2020 Ubuntu Ed.indb 139 12-May-20 5:54:25 PM


22. Which of the following is a keyword in Python?
(a) except (b) for
(c) class (d) All of these
23. Which of the following data types in Base stores exactly the length of the text specified
by the user?
(a) Text (fix) [CHAR] (b) Text [VARCHAR_IGNORECASE]
(c) Text [VARCHAR] (d) Memo [LONGVARCHAR]
24. In which topology are the workstations connected to a centralised network device?
(a) Star (b) Ring
(c) Bus (d) Mesh
25. WWW is an example of which type of system?
(a) Real-time system (b) Distributed system

d
Lt
(c) Batch-processing system (d) None of these

t.
26. In Base, queries, forms and reports can be designed

Pv
(a) In the design view (b) Using the wizard

a
(c) Both (a) and (b) (d) None of these
di
In
27. An algorithm should always begin with the word:
(a) Begin (b) Start
rs
he

(c) Initialise (d) None of these


lis

28. Which computer network allows outside users to have limited access to the part of
b

the organisation’s information?


Pu

(a) Internet (b) Extranet


n

(c) Intranet (d) None of these


illa

29. Which of the following protocols is responsible for transferring and displaying web
m

pages?
ac

(a) SMTP (b) TCP/IP


M

(c) FTP (d) HTTP


©

30. Which network covers a relatively small area such as a residence, a building or a
campus?
(a) LAN (b) PAN
(c) WAN (d) MAN

ANSWERS
1. (a) 2. (c) 3. (a) 4. (a) 5. (b)
6. (a) 7. (b) 8. (d) 9. (a) 10. (d)
11. (b) 12. (d) 13. (a) 14. (c) 15. (d)
16. (c) 17. (a) 18. (b) 19. (b) 20. (c)
21. (c) 22. (d) 23. (a) 24. (a) 25. (b)

140 26. (c) 27. (b) 28. (b) 29. (d) 30. (a)

2020 Ubuntu Ed.indb 140 12-May-20 5:54:25 PM


Project Work
Students are required to complete this project work, which has been designed to sharpen
their skills in LibreOffice Base and Python programming language. The tools/ commands
required to complete this project have already been discussed in the respective chapters
and students will find the exercises easy.

LibreOffice Base
1. Create a database for your class named Class_Database containing these tables.
a. A table named Student_Details with these fields to store the details of the
students in your class.

d
Lt
Field Name Data Type

t.
Roll Number Integer [INTETGER]

Pv
Sname Text [VARCHAR]

a
Address di
Text [VARCHAR]
In
rs

Phone Number Integer [INTETGER]


he
lis

b. A table named Exam_Marks with these fields to store the marks of the students
b

in all subjects.
Pu
n

Subject Data Type


illa

English Number [NUMERIC]


m
ac

Maths Number [NUMERIC]


M

Science Number [NUMERIC]


©

Social Studies Number [NUMERIC]


Total Number [NUMERIC]

2. Enter the data of all the students in your class in both the tables.
3. Create a query on the Student_Details table to display only Sname and Phone
Number.
4. Create a report using the Exam_Marks table in which the records are sorted in a
descending order of the Total field.

141

2020 Ubuntu Ed.indb 141 12-May-20 5:54:25 PM


Python
1. Write a program to input salary of an employee and then determine his/her
designation based on some conditions. If the salary is less than or equal to ` 30000,
the designation is ‘Programmer’. If the salary is between ` 30000 and ` 50000,
the designation is ‘Manager’. If the salary is between ` 50000 and ` 70000, the
designation is ‘Managing Director’. Otherwise, the designation is ‘CEO’.
2. Write a program to accept marks in three subjects. Compute the percentage and
display the grade as per the following table.

Percentage Grade
90 or above A

d
80–89 B

Lt
70–79 C

t.
Pv
60–69 D

a
di
50–59 In E
Less than 50 F
rs
he
b lis
Pu
n
illa
m
ac
M
©

142

2020 Ubuntu Ed.indb 142 12-May-20 5:54:25 PM


Revision
Worksheet 1
(Based on Chapters 1, 2, 3 and 4)
1. Tick (ü) the correct option.
a. Which of the following is not a mobile operating system?
(i) Android (ii) Ubuntu
(iii) iOS (iv) Symbian
b. Which of the following is not a data type in Base?
(i) Text [VARCHAR] (ii) Integer [INTEGER]
(iii) Small Integer [SMALLINT] (iv) Big Integer [BIGINT]

d
Lt
c. Which of the following is used to connect different symbols in a flowchart?

t.
(i) Flow lines (ii) Connector

Pv
(iii) Process (iv) None of these

a
di
d. Which key needs to be processed to run a query in Base?
In
(i) F5 (ii) F6
rs

(iii) F7 (iv) F8
he

e. Which of the following is not a characteristic of an algorithm?


lis

(i) An algorithm should have zero or more well-defined inputs.


b
Pu

(ii) An algorithm must terminate after performing a finite number of steps.


n

(iii) An algorithm may result into no output.


illa

(iv) An algorithm should be clear and unambiguous.


m

2. Fill in the blanks.


ac

a. .............................. operating systems use multiple central processors to serve


M

multiple real-time applications and multiple users.


©

b. The two ways of creating a report in Base are using .............................. and
using .............................. .
c. There are three types of database models: .........................., ..........................
and ............................... .
d. The result of a query is displayed in the form of a...............................
e. A ............................... is a pictorial representation of an algorithm.
3. State true or false.
a. Command prompt refers to the place where the user types the command and
feeds to the system.
b. In Base, forms define a medium through which you can present data in a
professional format.
143

2020 Ubuntu Ed.indb 143 12-May-20 5:54:25 PM


c. We cannot run a query in Base without saving it.
d. GUI systems require both mouse and keyboard.
e. Algorithm is the pictorial representation of a program.
4. Answer the questions.
a. What is a primary key? Write the steps for setting the primary key in the Design
view of a table.
b. Give two differences between GUI and CUI-based operating systems.
c. List and explain the characteristics of a good algorithm.
d. Name the two parts of the Query Design window. What does each part display?
e. Give some advantages and disadvantages of a flowchart.

d
Lt
Worksheet 2

t.
Pv
(Based on Chapters 5, 6, 7 and 8)
1. Tick () the correct option.

a
a. In Python, a mapping data type is
di
In
(i) Unordered (ii) Mutable
rs
he

(iii) Both (i) and (ii) (iv) None of these


lis

b. Which of the following operators in Python is used for exponentiation?


b

(i) ** (ii) ^
Pu

(iii) % (iv) #
n

c. In which type of network topology is each note linked to every other note in the
illa

network?
m

(i) Mesh (ii) Ring


ac

(iii) Star (iv) Bus


M

d. Which of the following is a social networking app?


©

(i) Facebook (ii) Instagram


(iii) Twitter (iv) All of these
e. Which network device is commonly referred to as Ethernet card?
(i) Hub (ii) Modem
(iii) Switch (iv) Network Interface Card
2. Fill in the blanks.
a. An .............................. is a private computer network owned by a company or
an organisation.
b. A .............................. enables a computer to transmit digital data over analog
telephone lines.
144

2020 Ubuntu Ed.indb 144 12-May-20 5:54:25 PM


c. In Python, a .............................. is an ordered collection of items, indexed by
positive integers.
d. It is standard in Python to use ........................ spaces for indenting.
e. ………………………. refers to buying or selling of goods and services online.
3. State true or false.
a. Each computer on a client-server network can act both as a server and a client.
b. Bluetooth is not very expensive and has low power consumption.
c. A hybrid app combines the features of both mobile and Web apps.
d. Logical operators are used for comparing two values or expressions.
e. In Python, the None data type is used to signify the absence of value in a
situation.

d
4. Answer the questions.

Lt
a. Explain different sequence data types available in Python.

t.
Pv
b. Differentiate between guided and unguided media.
c. Write a short note on personal area network (PAN).

a

di
d. Describe the use of the if...else statement in Python.
In
e. What is the difference between mobile apps and Web apps?
rs
he
b lis
Pu
n
illa
m
ac
M
©

145

2020 Ubuntu Ed.indb 145 12-May-20 5:54:25 PM


Terminology
Algorithm: a step-by-step process of solving a problem
App store: an online shop from where you can choose and download mobile applications
for free or by paying a fee
App: abbreviation for the word “application”—a small piece of software designed for a
single purpose
Application software: a set of one or more programs developed to perform a specific task
on the computer
Base: a powerful, yet easy-to-use RDBMS, which forms a part of the Microsoft Office suite
of products

d
Batch-processing operating system: an operating system in which the instructions, data

Lt
and some control information are submitted to the computer in the form of batches

t.
Pv
Bluetooth: a wireless technology used for exchanging data over short distances
Client-server network: a computer network in which many workstations (called clients)

a
di
are connected to a centralised host computer known as server
In
Comments: non-executable statements used in a program to increase its readability
rs

Computer network: a group of computers and other peripheral devices (such as printers
he

and modems) connected by means of communication links to share their resources with
lis

each other
b
Pu

Data transmission media: the medium used for transmitting data between the connected
devices in a network—can be classified as guided and unguided media
n
illa

Database model: the way of designing a database and storing information in it


Database: an organised collection of related (similar) data or information
m
ac

DBMS: stands for Database Management System—a collection of programs that allow
you to create, add, modify, delete, and retrieve data to and from a database
M

Desktop app: an application designed to run standalone in a desktop or laptop computer


©

Distributed operating system: an operating system that uses multiple central processors to
serve multiple real-time applications and multiple users
E-commerce: buying or selling of goods and services online
Extranet: a computer network that allows outside users to have limited access to a part of
the organisation’s information
Field: holds one piece of information about an item
Flat file database: a database that stores data in the form of a plain text file
Flowchart: a pictorial representation of an algorithm
Form: provides a medium of entering, editing, and viewing the information in the tables
in Base
146

2020 Ubuntu Ed.indb 146 12-May-20 5:54:25 PM


HTTP: stands for HyperText Transfer Protocol—the Internet protocol responsible for
transferring and displaying web pages
Hub: a small box that connects the individual devices on a network so that they can
communicate with one another
Identifiers: the names given by a programmer to different parts of a program such as
variables, functions, list, objects, dictionaries, etc., in order to identify them uniquely
Internet: the largest network that connects millions of computers worldwide to share
information and services
Intranet: a private computer network owned by a company or an organisation and
accessible only to its employees
Keywords: predefined words having special significance in any programming language
LAN: stands for Local Area Network—a network covering a short distance such as a

d
building or a campus

Lt
Literals: the identifiers whose values do not change during program execution

t.
Pv
MAN: stands for Metropolitan Area Network—a network that connects a large area such
as a city or an area up to 100 sq. km.

a
di
Mobile app: a type of application software designed to run specifically on a mobile device,
In
such as a smartphone or a tablet
rs

Mobile operating system: an operating system specially designed and developed to be


he

used on mobile devices such as smartphones and tablets


lis

Modem: stands for Modulator/Demodulator—enables a computer to transmit digital data


b

over analog telephone lines


Pu

Multiprocessor operating system: an operating system that runs on more than one
n

processor in a single system for executing multiple processes at a time


illa

Multi-user operating system: an operating system that allows multiple users to use the
m

computer’s resources simultaneously


ac

Network devices: devices which help computers to get connected in a network for efficient
M

communication
©

Network topology: the way in which computers and other devices are connected to each
other in a network
NIC: stands for Network Interface Card—a hardware device that enables a computer to
connect to a network using an Ethernet cable with a RJ-45 connector
Operating system: a set of programs which controls the working of a computer system
Operators: the symbols that define the type of operation (such as addition, subtraction,
and so on) to be performed on the data items used in a program
PAN: stands for Personal Area Network—smallest computer network for one person’s use
Peer-to-peer network: a computer network in which the computers having equal capacity
and capability (called peers) are connected to each other to use the resources on the
network
147

2020 Ubuntu Ed.indb 147 12-May-20 5:54:25 PM


Primary key: the field that has a unique value across all occurrences in the table
Program: a well-defined set of instructions that directs the computer to do a particular task
Protocol: a formal set of rules and conventions that governs how computers exchange
information over a network
Punctuators: tokens with different purposes based on the context in which they are used
Python: an amazingly powerful modern computer programming language written by a
Dutch programmer GuidoVan Rossum in the late 1980s
Query: defines a mechanism to retrieve and process the data
RDBMS: stands for Relational Database Management System—the DBMS designed on a
relational data model
Real-time operating system: A data-processing system in which the time interval required
to process and respond to inputs is very small

d
Record: a group of related fields

Lt
Relational data model: a data model in which information is stored in the form of tables

t.
and different tables are related through common fields

Pv
Social networking: the use of online platforms such as websites or applications by the

a
people to build social relationship with other people who share similar interests
di
Software: an organised collection of computer data and instructions
In
Structured database: a database that contains a number of tables arranged in an order
rs

and interconnected with each other through special fields


he

System software: the software that manages and controls all activities in the computer
lis

system
b
Pu

Time-sharing operating system: an operating system that allows multiple people, located
at various terminals, to use a single computer system at the same time
n
illa

Token: smallest individual unit of a program—a set of characters logically belonging


together
m
ac

User interface: the means by which the user interacts with a computer system
Variable: a name representing a memory location which stores a value of a specific data
M

type
©

Web app: a program running on a web server and to be accessed through a web browser
Wi-Fi: stands for Wireless Fidelity—widely used for creating wireless LANs and also for
providing wireless Internet access
Report: defines a medium through which you can present data in a professional format
Table: represents the data in the form of a grid which comprises rows (records) and
columns (fields)
TCP/IP: stands for Transmission Control Protocol/Internet Protocol—the suite of
communication protocols which is used as a standard for transmitting data over networks
WAN: stands for Wide Area Network—a network that spans several cities or even countries

148

2020 Ubuntu Ed.indb 148 12-May-20 5:54:25 PM


A TEXTBOOK OF COMPUTER – FOUNDATION OF INFORMATION TECHNOLOGY 8
A Textbook of Computer – Foundation of Information Technology for Class 8 is a textbook based
on Ubuntu and LibreOffice. It discusses various topics including LibreOffice Base, Python and App
Development. The book has been designed with emphasis on interactive and creative approach. It
serves as an ideal classroom support for computer education. It is based on the latest guidelines of
National Curriculum Framework (NCF), NCERT and all major state boards.
The book incorporates the features of a textbook, a workbook as well as a manual to ensure maximum
benefit to the student.

KEY FEATURES
Text is presented in a clear and simple language, with enhanced visual appeal.
All the ideas and concepts are explained with clear-cut and practical examples.

d
Lt
Each and every topic is thoroughly researched and certified by consultant teachers from schools.

t.
The illustrations given in the chapters lend enormous support as learning aids.

Pv
For the Teacher boxes provide teaching ideas and tips for the teachers.

a
Did You Know and Note boxes impart more information and interesting facts about the topic being
di
discussed.
In
An exhaustive set of questions and activities are given at the end of each chapter to reinforce
rs

learning and develop practical computer skills.


he

Revision exercises and Project work at the end of the book help to sharpen the concepts learnt in
is

the chapters.
bl
Pu

Sample questions based on National Cyber Olympiad at the end of the book help students prepare
for the Olympiads.
n
illa

ITL Education Solutions Limited (ITL ESL) is a part of the ITL group which has operations all over
the world with a significant presence in education and IT-enabled services. It specialises in handling
m

educational projects in IT domains with a dedicated R&D wing of industry experts that helps in designing
ac

and developing content.


M

We will be happy to respond to you on any query relating to the series.


©

Write to us at cs-support@macmillan.co.in

Macmillan Education listens to educators, and works to meet their


teaching-learning needs through relevant products and services.
For any requirements or feedback, write to
macmillanmarketing@macmillaneducation.com

` 435

Macmillan Publishers India Pvt. Ltd.


Weight:
www.macmillaneducation.in Customer Support Number: +91-8130588966

You might also like