Computer Class 9 Book
Computer Class 9 Book
Grade - 9
Government of Nepal
Ministry of Education, Science & Technology
Curriculum Development Centre
Sanothimi, Bhaktapur
Publisher : Government of Nepal
Ministry of Education, Science & Technology
Curriculum Development Centre
Sanothimi, Bhaktapur
ISBN:
Printed at :
Price :
Preface
A textbook is a main tool for the use of students on a particular subject that
is usually developed based on a curriculum to meet its curriculum standards.
This ‘Computer Science, Grade 9’ textbook has been developed to address the
main aims of Secondary Education. It aligns with the intent pursued by the
National Curriculum Framework for School Education, 2076 and has been
developed fully in accordance with the Secondary Level Optional Computer
Science Curriculum, 2080. All components of each lesson in the textbook are
equally important and they have the specific aim of presentation so as to fulfill
the learning outcomes stated in the curriculum.
This textbook is prepared by a team that includes Mr. Sunil Kumar Gharti,
Mr. Bimal Thapa, Mr. Pratik Man Singh Pradhan, Mr. Binaya Adhikari, Mr.
Shyam Adhikari and Mr. Lav Dev Bhatta. Several people notably, the Director
General, Mr. Ima Narayan Shrestha, the subject committee chairperson,
Dr. Bed Prasad Dhakal and the subject committee members; Dr. Bal Krishna
Subedi and MS. Pramila Bakhati contributed a lot in framing the book in this
form. The contribution made by other experts and the practitioners; Dr. Shyam
Prashad Acharya, Mr. Rom Kanta Pandey, MS. Nirmala Pokhrel, Mr. Yub Raj
adhikari, MS. Salina Dangol and Mr. Shreehari Sharestha is also appreciated.
The language of the book was edited by Mr. Nabin Kumar Khadka and the
layout of the book was designed by Mr. Jayaram Kuikel. The Curriculum
Development Centre extends sincere gratitude to all of them.
This textbook may be used to deliver the foundation for the content of the
curriculum, the balance between theoretical and practical aspects is to be
maintained by the teachers. This textbook can be used as the primary resource
for classroom teaching but teachers are encouraged to make use of their own
resources to supplement the computer science learning of their students. The
Curriculum Development Centre always welcomes constructive feedback for
the betterment of its publications.
2081 BS.
1. Computer System 1
2. Number System 41
3. Block Programming 53
4. Web Technology 81
Figure 1.1
Let’s think!
a) What are the components of a computer system?
b) How are the computer systems used in a different field?
c) Which are the major input and output devices of a computer system?
Nowadays, science and technology are inseparable from our daily lives. The
rapid development of computer technology has revolutionized the modern world.
Computers are now used worldwide, regardless of a country’s development level. In
Nepal, computers play essential roles in business, banking, education, entertainment,
scientific research, law, and air traffic control. Computers have become integral to
every sphere of human activity, bringing about enormous changes.
Technology is at the heart of our existence. Computers serve as essential tools for
accessing information, expressing creativity, collaborating, and monitoring learning
outcomes. Understanding the factors behind this technology becomes even more
crucial as we build smart cities.
Computer Science , Grade 9 1
1.1 Introduction to computer systems
“Computer” comes from the Latin word “Computare,” meaning ‘to calculate.’
Nowadays, computers are everywhere and are important. We use computers at home,
school, work, and other places. They’re great at doing math fast and accurately. But
they can do much more than that! They can make documents, videos, games, music,
and presentations.
A computer is an electronic device that accepts raw data from users; processes
raw data according to a given set of instructions, and stores and gives meaningful
information. It is a programmable device that can perform specific tasks and generate
results at a very high speed. In other words, a computer is an electronic device
operating under the control of instructions stored in its memory that can accept data
(input), process the data according to specified rules, produce information (output),
and store the information for future use.
Features of a computer
Computers are powerful and useful in all areas. The uses of computers are being
increased with time. The main features or characteristics of computers are described
below:
i. Automatic
ii. Speed
iii. Accuracy
iv. Storage
A computer can perform the task repeatedly without losing speed and accuracy
for a long time. The capability of a computer to perform a task repeatedly
without losing speed and accuracy for a long time is known as diligence. Due
to this characteristic of a computer, it is also called a diligent machine. This
capability of the computer makes it useful for quality control and process
control tasks.
vi. Versatile
Storage
Figure 1.2
Due to the versatile abilities of a computer, it has become one of the most important
tools for people. People can perform tasks more quickly, correctly, efficiently, and
systematically with the help of computers. Computers make people efficient and
productive, and they also free up their time for other tasks. People are not only
using computers for preparing documents, spreadsheets, presentations, graphics,
etc. They are using computers for modern facilities like instant messaging, video
chatting, email, online gaming, online shopping, ticketing, booking, checking
and transferring money in banks, finding the latest news and information, etc.
So, computers are used in nearly every field. The following are some important
applications of computers:
Figure 1.3
Figure 1.5
Banking: Computers have
revolutionized the banking sector.
They handle various services like
accounting, updating customer
records, and generating bank
statements. Automated computers
revolutionize banking by
improving efficiency, security, and
customer service through online
and mobile banking, advanced Figure 1.6
data analytics, and AI, reducing manual processing and costs.
xii. CT scans
c) What is GIGO?
Mouse
Keyboard
The keyboard is a popular input device used to enter data into the computer by
typing. The most common keyboard layout is the “QWERTY” keyboard, named
after the first six letters in the top row of keys. A standard keyboard consists of 104
keys. A multimedia keyboard has more than 104 keys. The keys on a keyboard are
grouped into five different groups as:
a. Alphabet keys
b. Numeric keys
c. Cursor-movement keys
d. Functional keys
e. Special purpose keys Figure 1.12
All keys marked with A to Z and punctuation symbols are alphabet keys. Keys
marked with 0 to 9 and mathematical symbols are numeric keys. Keys marked with
F1 to F12 are the function keys, and they are used for entering commands. Keys
marked with arrow signs (←, ↑, →, ↓) are cursor movement keys (i.e., also known
as arrow keys), and they are used to move the cursor in the specified direction. The
Space bar, Enter key, Back Space key, Caps Lock key, Esc key, Ctrl key, Alt key,
Shift key, Delete key, Home key, End key, and Insert key are the special purpose
keys.
Figure 1.17
Computer Science , Grade 9 11
Touchpad
Figure 1.19
The CPU (Central Processing Unit) performs the following primary functions:
i. Fetching: The CPU retrieves instructions or data from the computer’s memory
(RAM).
ii. Decoding: The CPU interprets the fetched instructions to understand what
actions are required.
iii. Executing: The CPU performs the necessary actions, such as calculations,
data movement, or interacting with other hardware.
a. The Control Unit controls the working of all parts of a computer. It controls the
movement of data inside as well as outside the CPU. It communicates between
registers and the ALU and between the CPU and all the input, output, and
storage devices. It directs all the parts of the computer system to perform their
tasks.
b. The Arithmetic Logic Unit (ALU) performs all arithmetic operations like
addition, subtraction, multiplication, division, and logical operations like
greater than, less than, not equal, etc.
c. Registers are small memory units used to store immediate data, instructions,
and results while processing data.
ii. Electrical Connections: Power distribution from the PSU ensures all
components receive power through specific circuits and voltage regulators.
Data transfer occurs via electrical signals flowing through the motherboard’s
network of pathways.
iii. Communication Hub: Chipsets like the Southbridge and Northbridge manage
communication between peripherals and high-speed components like the
CPU and RAM. Internal buses, such as PCIe and SATA, act as data transfer
highways between components.
Data Bus
Buses are connected lines or electronic pathways within a microprocessor chip that
link its internal components. Data, address, and control are typically three types
of buses in a microprocessor. The data bus is a key communication pathway in a
computer system, enabling the transfer of digital data between components like the
CPU, memory, and peripherals. Made of parallel lines, it allows for efficient and
high-speed exchange of binary information. The width of the data bus, measured in
bits, determines the amount of data transferred in one go, with wider buses typically
offering faster communication and better system performance. In essence, the data
bus plays a crucial role in ensuring smooth information flow and the execution of
computing tasks.
ii. Handling Different Data Types: Various types of buses manage different kinds
of data and operate at varying speeds.
Primary memory
i. SRAM: Static Random Access Memory, retains data in a static state as long
as power is supplied to the memory. This semiconductor-based memory
stores data and instructions without the need for periodic refreshment, unlike
DRAM. While SRAM is more costly than DRAM, it offers faster performance.
Typically employed as cache memory, SRAM consumes less power compared
to DRAM.
SRAM DRAM
a. It is made up of transistors. a. It is made up of capacitors.
b. It is more expensive. b. It is less expensive.
c. SRAM doesn’t need periodic c. DRAM needs periodic refreshment.
refreshment.
d. Charges don’t get leaked from d. Data charges get leaked from
SRAM. DRAM.
e. SRAM are less dense. e. DRAM is denser.
f. It is faster than DRAM. f. It is slower than SRAM.
g. Data is stored in the form of g. Data is stored in the form of charge.
voltage.
ROM exclusively retains information that can solely be accessed for reading
purposes. Altering data stored in ROM presents a challenge. Serving as the non-
volatile memory of a computer system, ROM ensures that data and instructions
remain intact even when the power supply is disconnected. Unlike volatile memory
types, ROM doesn’t require a constant power supply to preserve stored data. The
Cache memory
The high speed memory between primary memory RAM and CPU is known as
cache memory. The cache memory is used to store frequently accessed data and
instruction during the time of processing by CPU. It is the high speed volatile
memory available to the processor for fast processing. The storage size of cache
memory is small. The CPU first searches data in cache for processing if not found
there then looks in RAM and loads to cache memory. The main importance of cache
memory is to make the CPU execution faster.
CPU register
A CPU Register is a compact storage memory situated within the microprocessor
that is distinguished by its high data transfer rate. It stores the data and instructions
used by the microprocessor during its operation.
The bit is the smallest unit of memory measurement, representing one binary digit
(either 0 or 1).
An optical storage disc is a disc that uses laser light technology to store and retrieve
data. The most commonly used optical storage discs are CDs, DVDs, Blu-ray disks,
etc.
CD (Compact Disc)
In 1980, Philips Company of the Netherland developed the first CD or optical disk,
which was 12cm in diameter and had a 72-minute audio/video storage capacity.
Laser ray technology is used to retrieve and store the data. The information on the
optical disk is stored in the form of pits, which are tiny reflective bumps.
CD is 12cm in diameter and weight 18gm and width 1mm (millimeter). The data
can be written on a CD only once and can be read many times. CD is made up of
polycarbon and both surfaces are coated with aluminium reflected. Nowadays, CDs
are commonly used in microcomputers. It can be used to transfer data from one
computer to another. The storage capacity of CD is 700MB.
DVD stands for Digital Versatile Disc or Digital Video Disc. Its storage capacity
is higher than CD. It stores multiple layers of data. The various DVD storage
capacities are
• Single Side Layer- 4.7 GB
• Single Side Double Layer-8.5 GB
• Double Layer Single Side- 9.4 GB
• Double Layer Double Side-17.08 GB
Philips, Sony, Toshiba/ Panasonics Companies developed first DVD in 1995 whose
weight 16gm. DVD Drive is used to read/write the data on DVD.
S.No. CD DVD
1 Its storage capacity is 700MB. Its storage capacity is up to 20GB.
2 It is cheaper. It is expensive.
3 It is used to store audio and software. It is used to store video and software.
4 Its types are CD-R, CD-RW, etc. Its types are DVD-RW, DVD+RW, etc.
5 It was developed by Philips and It was developed by Philips, Sony,
Sony. Toshiba, Panasonic, etc.
Flash memory
Pen drive
Cloud storage
Hard Disk Drives (HDDs) have been used for storage for many years. They use
spinning disks and read/write heads to access data. This method is reliable and
cost-effective for large storage, but it has slower speeds, usually between 80 to 160
MB/s. HDDs are good for storing a lot of data, with sizes from 500 GB to 18 TB,
and they are cheaper per gigabyte. However, their moving parts can fail more easily
and are sensitive to physical shocks. They also use more power, especially when
starting up. So, while HDDs are great for backup and storing lots of data, they are
slower than newer storage technologies.
Solid State Drives (SSDs) are a big improvement in storage technology, using
NAND flash memory with no moving parts. This makes them much faster, with
read/write speeds from 200 MB/s to over 3,500 MB/s for NVMe SSDs, and they
have lower latency. SSDs are more reliable and can handle physical shocks and
vibrations better than HDDs. They also use less power, which is great for laptops and
mobile devices. However, SSDs cost more per gigabyte, although prices are going
down. Due to their speed and performance, SSDs are best for running operating
systems, software, and games.
Flash memory includes USB flash drives, SD cards, and similar storage devices.
22 Computer Science , Grade 9
They use NAND flash technology, which means no moving parts and low latency.
Flash memory devices have different speeds and capacities; USB 3.0 drives can
reach up to 600 MB/s, and SD cards range from 10 MB/s to 300 MB/s. They are
very durable and use little power, making them ideal for portable storage and
battery-powered devices like cameras and smartphones. Although more expensive
per gigabyte than HDDs, flash memory is often similar in cost to SSDs and is great
for quick, removable storage.
Monitor
Printer
A printer is an output device that displays the data or information on the paper.
There are mainly two types of printers. They are impact and non-impact printers.
Laser printer
Laser printers utilize a laser beam to create an image on
a photosensitive drum, which is then transferred onto
the paper using toner (powdered ink). Laser printers
are known for their fast printing speeds and crisp,
professional-quality prints. They are often used in office
environments for high-volume printing.
Fig. 1.28
Ink-jet printer
Inkjet printers use liquid ink sprayed onto the paper
to create text and images. They are known for their
versatility and ability to produce high-resolution
prints. Inkjet printers are commonly used for
everyday printing tasks, such as documents, photos,
and graphics. Fig. 1.29
Dot-matrix printer
A dot matrix printer is a type of impact printer. It features
a print head containing numerous pins. When the print
head strikes an inked ribbon, it creates dotted characters
on the paper. Dot matrix printers offer a speed range of
50 to 400 CPS (Characters per second).
Fig. 1.30
Hardware ports
USB port
VGA port
Figure 1.36
The Video Graphics Array (VGA) port is a standard
analog interface used to connect monitors, projectors,
and other display devices to computers. It uses a 15-
pin connector to carry analog signals for the red, green,
and blue color channels (RGB), as well as horizontal
and vertical synchronization signals. Despite being an
older technology, VGA ports remain prevalent in many
computing environments.
Figure 1.37
Audio port
Activity 1.2
Activity Outcome:
Able to describe disassembling and reassembling computers to understand
hardware components by the teacher.
Required Resources: Computer Case, Power Supply Unit (PSU), Motherboard,
Central Processing Unit (CPU), Random Access Memory (RAM), Storage
Drives: Hard Disk Drive (HDD) or Solid State Drive (SSD), Graphics Processing
Unit (GPU), Cooling Systems, Optical Drives (optional), and Expansion Cards.
Tools needed:
● Screwdrivers: Typically Phillips head screwdrivers of various sizes.
● Anti-static wrist strap: Prevents static discharge from damaging components.
● Tweezers: For handling small screws and parts.
● Thermal paste: Used when reinstalling a CPU to maintain proper cooling.
● Plastic pry tools: For gently opening cases or removing components.
a. System software
Figure 1.40
Utility software is the helpful software that performs specific tasks related to
the maintenance of computer hardware and data. It helps to keep a computer
in a smooth functioning condition. It provides facilities for performing
tasks like transferring data and file, recovering lost data and file, searching
and removing computer viruses, disk management, etc. Backup software,
Download Accelerator (DAP), SplitFile, Anti viruses, WinZip, WinRaR, Disk
Defragmenter, Registry Cleaner, HistoryCleaner, CClearner, etc. are some
examples of utility software.
Figure 1.42
b. Application software
Packaged software is the readymade software developed for all general users
to perform their generalized tasks. Software companies like Microsoft, Adobe,
Dropbox, Corel, Oracle, Google, etc., use to develop packaged software. MS-
Office, Adobe InDesign, Sybase, SQL Server, Oracle, CorelDraw, Adobe
PhotoShop, 3DS Max, Maya, VLC Media Player, Google Meet, Zoom,
Spotify, etc. are packaged software.
Open source software is a type of software that allows its source code to be publicly
accessible. It means anyone can view, modify and use the code freely. Linux,
Apache, Audacity, OpenOffice, Android and others are open source software.
The close source software (also called proprietary software) is a type of software
that does not allow its source to be accessed by any others except the creator or
the authorized organization. The CSS usually comes with a license, and users are
required to purchase the software to use it. This leads to higher costs and restrictions
on the modification and usability of the software. Windows OS, Adobe Photoshop,
iTunes, Microsoft Office Suite, AutoCAD, and many others are CSS.
Web applications are software programs that run on web servers and are used through
web browsers over the internet. Unlike traditional desktop applications, they don’t
need to be installed on your device. You use them through a web page interface.
Examples include email services like Gmail, online office tools like Google Docs,
and social media sites like Facebook. Web applications are convenient because you
can use them on any device with a web browser and an internet connection.
Figure 1.47
Activity 1.3
Activity Outcome:
● Able to describe the main objectives of software.
Required Resources: Chart Papers, Meta Cards, Cardboards, Images, PowerPoint
Presentation, etc.
Procedure:
Your teacher will divide you into a group of 3-5 each, and let your group collect
names of software used in hospitals, hotels, the educational sector, and other
different sectors surrounding you. Present and discuss in group about the main
objectives of this software.
Result: Moderated discussion by the teacher for your reflection with feedback.
Project Work
1. Collect names of software used in the hospital, hotel, educational sector and
other different sectors surrounding you and group discussion about the main
objectives of these software.
2. Take a short interview with your teachers, friends, parents and relatives and
prepare a field report about what types of computers, laptops or other devices
they are using, what types of Operating System the device installs. Also make
a list of apps that they have used in their smartphones.
3. Carry out a practical task involving the assembly and disassembly of a computer
system, and write a detailed report documenting each step of the process.
Figure 2.1
Let’s think!
a) What is a digit? What is a computer word?
b) Define the base or radix of the number system.
c) Which language is used by computer systems, smartphones, and tablets?
The concept of numbers evolved long ago in human history when people started
using their fingers, sticks, pebbles, knots of rope, and different symbols for counting
with simple addition or subtraction. Over time, people invented various calculating
devices. At present, we use different kinds of numbers every day for different
purposes.
The decimal number system is the common number system we use in our lives. It
has a base of 10 since it uses digits ranging from 0 to 9. In this system, each digit’s
position represents a distinct power of 10, which includes units, tens, hundreds,
thousands, and so on. For example, the decimal number 719 consists of the digit 9
in the units position, 1 in the tens position, and 7 in the hundreds position.
The binary number system uses only two digits: 0 and 1. Thus, it is a base-2 number
system. It is used by computers. For example, (110111)2 is a binary number.
The octal number system is the base-8 number system that uses 8 digits (0 to 7).
Some examples of octal numbers are (207)8, (5706)8, (601022)8, etc.
The hexadecimal number system is the base-16 number system that uses 16 symbols,
i.e., 10 digits:0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and 6 letters: A, B, C, D, E, F. The letters from
A to F represent the values 10 to 15 respectively. Some examples of octal numbers
are (8F5)16, (AC4)16, (B52)16, (ACD)16, etc.
Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
The following number system chart shows the base values and the digits of different
number systems.
Binary addition
Binary numbers can be added in the same way as we add decimal numbers. The
rules for adding binary numbers are
A B A+B
0 0 0
0 1 1
1 0 1
1 1 0 with carry 1
(i.e 10)
Example:
1 0 1 1 1
-1 0 1
1 0 0 1 0
Hence, 1 0 1 1 1 – 1 0 1 = 1 0 0 1 0
2 46 Remainder
2 23 0
2 11 1
2 5 1
2 2 1
2 1 0
0 1
8 345 Remainder
8 43 1
8 5 3
0 5
16 88 Remainder
16 5 8
0 5
Note:
B B
D O[÷] O D[×]
H H
Hexadecimal number 9 A 3
Binary equivalent 1001 1010 0011
Exercises
1. Choose the correct option.
i. What is the result of the binary addition: 1101 + 1011?
a. (11010)2 b. (11000)2
c. (11110)2 d. (11101)2
ii. When adding two binary numbers, what is the carrying value in
binary addition?
a. 100 b. 1 c. 10 d. 11
iii. In binary multiplication, what is the result when multiplying any
binary digit by 0?
a. 1 b. 11 c. 0 d. The original digit
iv. What is the base of the octal number system?
a. 2 b. 7 c. 8 d. 10
v. What is binary equivalent to the octal number 64?
a. (110100)2 b. (1101111)2
c. (1110001)2 d. (11000101)2
vi. In the hexadecimal system, what does the symbol ‘A’ represent?
a. 11 b. 12 c. 10 d. 13
50 Computer Science , Grade 9
2. Answer these questions.
a) What is a number system?
b) Define the base or radix of the number system.
c) List out the different types of number systems.
d) What is a hexadecimal number system? Write down the symbols used in
the hexadecimal number system.
3. Calculate the following as indicated:
a. Perform the following binary addition:
i. (11110)2 +(1001)2 ii. (1011)2 +(1001)2
iii. (101011)2 +(11011)2 iv. (1010)2 +(110)2
v. (101001)2 +(1110)2 vi. (100001)2 +(100011)2
vii. (100111)2 +(11010)2 viii. (110001)2 +(100101)2
b. Perform the following binary subtraction:
i. (1100)2 - (1001)2 ii. (1001)2 - (110)2
iii. (11101)2 - (1010)2 iv. (101100)2 - (10011)2
v. (11111)2- (10110)2 vi. (110011)2 - (10100)2
vii. (100100)2 - (1110)2 viii. (1000001)2- (10101)2
4. Convert the given numbers as indicated:
a. Decimal to Binary Conversion
i. (56)10 ii.(78)10 iii. (123)10
iv.(345)10 v.(540)10 vi. (572)10
vii.(546)10 viii. (1098)10 ix.(2103)10
x.(445)10
b. Binary to Decimal Conversion
i. (1101)2 ii. (1010)2 iii. (10010)2
iv. (10110)2 v. (101001)2 vi. (11100111)2
vii.(111100)2 viii. (10010011)2 ix. (1011100)2
x. (100110)2
In our rapidly advancing world, more and more people are getting access to
computers. These computers help us do all sorts of things, like going online and
using different programs such as Word, Excel, Notepad, Photoshop, etc. But have
you ever wondered how games work and how awesome gadgets like smartwatches
operate? Well, it’s all because of programming. Programming is like giving
instructions to computers to make them do all the amazing things we see and use
every day. Learning programming lets you understand how computers work and
how to make them do what you want. That’s why programming is such a valuable
skill to have in today’s world.
Have you ever had a super cool idea for a game or a gadget, but felt lost on how to
bring it to life? Don’t worry, you’re not alone! Starting with programming can feel
like stepping into a new world with lots of tricky stuff to learn. It’s like trying to
understand a language with tons of confusing rules. But there is no need to worry!
There is a friendlier and easier way to get into programming, and it is called block
programming. Instead of typing out long lines of code, block programming lets you
drag and drop colorful blocks to create your programs.
Computer Science , Grade 9 53
With block programming, you can make all sorts of cool stuff like games, animations,
and gadgets without getting lost in complicated code. So, if you’re ready to turn
your ideas into reality, block programming is your new best friend!
b) Game development
Block programming is also used to create
games. Users can make different characters,
and elements, and build game logic. It
allows them to focus more on gameplay
logic without worrying about complex
coding.
Figure 3.4
c) Mobile App development
Block programming can be used to develop mobile
applications. Users can design user interfaces, define
functionalities, and assemble different code blocks to
develop Android and iOS apps without the need for
complex coding knowledge.
Figure 3.5
Computer Science , Grade 9 55
d) Robotics
Block programming is also used to program robotic
devices. Its visual programming tools allow users to
design movements of robots, define their behaviors,
and control sensors. There are devices like micro:
bit and Arduino UNO, which can be used with
block programming to create robotic projects. While
this provides a learning platform for students, it
also helps them build creativity and interest in the
Figure 3.6
experimentation of robotics projects.
e) Web development
With the help of block programming’s visual
interface, users can create interactive websites.
They can define web page elements, user
interactions, and data handling using visual
blocks. This visual approach acts as a bridge
for individuals to understand web development
concepts before advancing to traditional text-
based programming languages. Figure 3.7
f) Creative projects
Block programming is also used by artists to
create interactive projects like animations. There
are platforms like Scratch and Blockly, where
you can find many projects created till date.
Figure 3.8
g) Modeling and simulation
Modeling and simulation is the process of using
physical or logical representation of any given
system to generate data and help make predictions
about the system. Block programming is a suitable
platform that makes modeling and simulation easy
by allowing users to define different parameters,
interactions, and scenarios using visual blocks.
Figure 3.9
56 Computer Science , Grade 9
h) Data science and visualization
Block programming can also be used to design
algorithms or processes, arrange data, and
perform analysis of that data using a visual
interface. Those analyses can be visualized by
creating interactive charts and graphs using block
programming.
Figure 3.10
3.2 Introduction to Scratch
Today’s world is about technology and innovation. More
and more people are gaining access to computers and
digital devices. Our devices enable diverse tasks from
productivity software to creative tools like Photoshop.
But have you wondered about the magic behind games
and gadgets? The main thing is programming, giving
computers instructions for incredible tasks. Learning
programming unlocks understanding and empowers
us to create digital solutions. Let’s explore Scratch, a
popular and user-friendly programming platform. Figure 3.11
Scratch is one of the most popular and widely used block programming languages.
It was developed by Lifelong Kindergarten Group at MIT Media Lab, and is an
open-source platform, which means that the software is free and publicly available
to everyone. It has a large and supportive community of users, who share their
projects and help each other on the Scratch website. Scratch 3.0 is the current Version
of Scratch. Scratch a real software development tool with a colorful interface and
presentation style. It allows users to create
various things including games and interesting
gadgets while giving them an experience of
programming. Even though Scratch is fun
and engaging to use, users will face similar
challenges like a professional programmer in
terms of logic building and problem solving.
With Scratch, you can also make your dream
projects such as games and even controlling Figure 3.12
robots or devices a reality.
In the given figure, you can see a simple program that makes a cat character move
and say,” Namaste” with the help of Scratch.
Computer Science , Grade 9 57
In this section, we will learn how to build programs like this. However, first, let’s
learn how to download Scratch on your computer.
Discuss with your classmates and list out any 4 different programming platforms
like scratch on the concept of block programming. You can take the help of a
teacher.
a) b)
c) d)
Downloading Scratch on PC
Scratch is available for offline use on your computer. To use Scratch offline, you
must download the Scratch application through their website, following these steps:
Figure 3.13
2. Download the Scratch installation file. Once downloaded, open the .exe file
to install the application on your computer.
Figure 3.14
58 Computer Science , Grade 9
3. Once the installation is complete, open the Scratch application. You will find
an interface as shown below, depending on your Scratch version.
Figure 3.15
Features of Scratch
c) Data and Variable: Scratch allows variables to store and manipulate data
within a program.
e) Sounds: Allows the addition of sound and music to enhance project interactivity.
Scratch Interface
Figure 3.19
60 Computer Science , Grade 9
a. Stage: You can see the result of your
program in the stage. You can do so by
clicking on the green flag.
Concept of Block
Block programming uses colorful blocks to show actions or commands. You put
them together by dragging and dropping to make a list of things to do. It’s like
playing with building blocks, but you’re building programs! This way of coding
is easy for beginners, like you, to understand. For example, to move a character
or make it perform an action like jump, simply you can select and connect the
corresponding blocks. It helps you be creative and figure out problem solving skills.
Assess yourself!
As you already have knowledge on scratch interface, open scratch and try to
change the sprite from cat to any other object and create a basic program like
saying “Namaste!”.
- Use the looks block “say Hello!” and change the value to “Namaste!”
62 Computer Science , Grade 9
Component of Scratch
The block component of Scratch is one of the main components which makes this
programming language unique. These are pre-programmed codes with unique
functions that are represented in the form of colorful block size representation.
These blocks are like puzzle pieces that you can join to form a beautiful picture.
In Scratch, there are a total of 9 different types of blocks available in the blocks
pallete. These blocks are grouped together as per their functionality and can be used
to control the sprite’s behavior, such as:
´ Motion block ´ Looks block. ´ Sound block.
´ Events block ´ Control block. ´ Sensing block
´ Operators block. ´ Variables block ´ My block
1. Motion block
Default sprite in the A motion block “turn 90 degrees” Output of the code
beginning combined with an event block when is clicked
“when clicked”
2. Looks blocks
3. Sound block
4. Events block
Figure 3.30
5. Control block
Figure 3.31
7. Variables block
Let’s check!
Which blocks help you store data?
a) sensing block (b) variable block (c) control block (d) my block
8. My blocks
Now that you have a basic understanding of Scratch’s components, let us try to
build a game using these components.
Figure 3.35
Step 1: By default, you get a cat sprite. Delete it from the sprite info pane, and click
on “Choose a sprite” to add new sprites from the library or draw your own sprite:
the dustbin.
Figure 3.36
68 Computer Science , Grade 9
Step 2: Select the dustbin sprite from the sprite
info pane to program with the code shown
below. Find these blocks from the blocks palette
and combine them as shown. You can find these
blocks by referring to their color. For example,
“when clicked” is an event block, which is
yellow in color, look blocks like “hide “ and
“show “ are purple in color and so on.
Figure 3.37
Step 3: Now, click on the other sprites (i.e. eggs,
bottles, etc.) one by one to program them. Find the
blocks shown below and combine them. You can
copy and paste the same blocks for other sprites.
Figure 3.38
Step 4: You can also add a backdrop to your stage from the “Choose a backdrop”
option.
Figure 3.39
If you are using Scratch online, make sure you have created your account and
logged in. Once you are logged in, you should see the “Save Now” option in the top
right corner just above the stage.
Figure 3.40
If you are using Scratch offline, simply click on “File” and save your project as
“.sb3” extension for future use.
Step 6: Now that everything is completed, click on the and start playing.
Activity: 3.1
As we come to the end of the concept of scratch, you may have ideas for different
games. But for now let’s try to build a game, keeping the name of the game
“Catch the fruit”.
Game Description: Create a game where you control a basket to catch falling
fruits for points. Use motion blocks to move the basket left and right with arrow
keys. Use sprites for fruits falling from top to bottom, and event blocks for
random appearances. Display points using a variable and sensing blocks. Make
it challenging with speed variations and sound effects for catching or missing
fruits.
History of Micro:bit
Figure 3.41
Do You Know?
Micro:bit is also called BBC Micro:bit and it was developed aiming to encourage
young people to be creative digitally and upgrade their programming skills.
Components of Micro:bit
Let’s answer!
Microcontroller is a tiny ______.
a) Sensor (b) computer (c) software (d) All of the above
Applications of Micro:bit
There are many applications of micro:bit in various fields.
Some examples are:
Fitness
Figure 3.44
72 Computer Science , Grade 9
Fashion
Fun fact!
The UNO board got its name from the Italian and Spanish word “uno,” meaning
“one.” It’s called UNO because it’s the first and most basic Arduino board.
History of Arduino
The Arduino UNO platform was developed by two engineers, David Cuartielles
and Massimo Banzi in 2010. Their motive was to provide a tool, specifically for
students, to help them learn programming with the Arduino Uno microcontroller
and enhance their electronic skills at the same time. Their goal was to encourage
students to apply their knowledge in real-world cases and help develop a practical
understanding of programming and electronics.
a) Hardware
b) Software
Arduino UNO has a special software called Arduino IDE. This software helps
you write codes for your Arduino and sends it to the board. You can also add
extra features using ready-made sets of code called libraries.
Do you know?
Tinkercad is a free 3d modeling program where we can make virtual projects
with Arduino and simulate the result. While coding, we can either use other
programming languages like C, Python or we can even code blocks just like
scratch and program Arduino.
The Arduino UNO is versatile and easy to use. It means that an Arduino UNO can
be used in various fields. Here are some common applications of the Arduino Uno:
a. Education
b. Home
Figure 3.51
Computer Science , Grade 9 75
c. Robotics
Arduino Uno is popular for creating and testing robotic devices. It can be used
to control motors, sensors, and other robotic components.
d. Wearable technology
e. Data gathering
Figure 3.52
Arduino Uno can also be used as a source of collecting data with the help of
various sensors. This makes it suitable for monitoring the environment, motion
detection, GPS tracking, etc.
f. Gaming
g. Audio projects
h. Testing product
Figure 3.51
Engineers and developers also use Arduino
Uno to test electronic projects before making complex hardware.
Activity: 3.2
Build a smart dustbin designed to automatically open its lid when a user
approaches with trash. To build the project you need Arduino’s and other different
components, collect all the components necessary which are necessary to build
the project. You can take the help of your teacher to collect the components.
a) MAZE game
Game description: In this game, you control a sprite that moves through
a maze to reach a goal. You have to avoid touching the walls of the maze,
or you have to start over.
- Draw or use a sprite from the library and draw a backdrop that looks like
a maze using the paint editor. You can also use the looks block to change
the color or brightness of the maze.
- Use the motion blocks to make it move when the arrow keys are pressed.
You can also use the sensing blocks to keep the sprite inside the maze, and
to detect when the sprite touches the walls or the goal.
- To make the game more challenging, you can use the control blocks to
add a timer, and the variable blocks to show it on the stage. You can also
use the sensing blocks to detect when the timer runs out, and the control
blocks to stop the game. You can also use the sound blocks to play sounds
when the sprite moves, touches the walls, or reaches the goal.
b) Show the code editor, where you can either write codes or drag and drop
blocks.
c) Show Micro:bit’s physical parts like LED, pins, etc. in the simulator.
a) Go to https://www.tinkercad.com/circuits.
d) Write a basic Arduino code like RGB traffic lights, and show how the
circuit works.
Project works
1. Develop an individual project using the Scratch tool.
a) Think of different ideas for your project. It has to be a game project, such
as jump game, flappy bird, snake game.
b) Make sure you try to apply all the block components that you have learnt
in the chapter.
c) Save your work from time-to-time, so that you do not lose your work.
d) Once you complete your project, publish it online in your Scratch account.
If using offline, download your work and share the “<filename>.sb3” with
your teacher.
“Web technology refers to the tools, software, protocols, and languages that
individuals, businesses, and organizations use to create, develop, and manage
applications and content on the Internet.”
Figure 4.2
The landscape of web technology also includes considerations for web security,
responsive design for various devices, and adherence to web standards, ensuring
a consistent and secure online experience for the user. Overall, web technology is
the backbone of our digital interactions, shaping the way we access information,
communicate, and engage with the vast digital ecosystem of the internet.
a. HTML: Hypertext Markup Language, the standard language for creating web
pages
b. CSS: Cascading Style Sheets, the language for styling and formatting web
pages
d. PHP: A server-side scripting language for creating dynamic web pages and
web applications.
f. MySQL: A database management system for storing and retrieving data for
web applications.
The future of web technology is like an exciting journey that will change how we
do things online. It is full of creative ideas that will make our digital experiences
even better.
a. AI and Machine Learning Integration: Smart websites are being developed that
will use AI and machine learning to give users personalized content along with
suggestions and do things automatically.
a. Progressive Web Apps (PWAs): - Progressive web apps are the websites that
work like an app directly in web browsers. They work even when you’re offline
and can send you notifications.
b. Augmented Reality (AR) and Virtual Reality (VR): - Websites using AR and VR
features are being developed. Such websites will provide us with experiences
that feel real and let us interact with web content in exciting ways.
c. Responsiveness: Websites will keep getting updated making them a lot more
responsive on different devices over time.
d. Edge computing: Edge computing will enable computers to do their work close
to where the information is created which will make the performance of web
applications much faster and more efficient.
e. Web security: Shortly, websites will get smarter about keeping our data and
information safe from online threats. Web technologies will evolve to provide
Computer Science , Grade 9 83
advanced security measures such as stronger security codes, better ways to
check who you are, and breach prevention.
Stages of WDLC
2. Planning: In this stage, a basic layout and design for the website are created,
describing its general structure.
3. Design and layout: This stage involves selecting fonts, colors, and images to
give the website a look that goes well with its content or brand.
4. Content creation: In this stage, the actual content for the website is created
using text, images, audio, and videos.
5. Development: In this stage, developers use code to convert the design and
content of websites into a useful platform.
Let’s explore!
Make a group in class and research the topic of web development life cycle
methodologies, and why they are important. Can you name some common
methodologies used in web development? How do these methodologies differ in
their approach? Give examples of companies or projects that have successfully
implemented these methodologies. All researchers give the presentation in class
and share their chosen methodology.
In simple terms, the DNS (Domain Name System) is a system that gives a unique
Activity 4.1:
We have learned about the different types of domains. Now, explore the website
of the government side of Nepal. Your task is to conduct research and gather
information about various government sectors of Nepal. You can choose to focus
on areas like education, health, transportation, or any other sector that interests
you. Once you’ve gathered the information, fill out the below table and discuss
it in the classroom.
a. Choose the domain name: Choose a domain name that is unique and
memorable that identifies your website.
b. Check the availability: Verify the availability of the chosen domain using the
registrar’s domain checker tool.
d. Buy and register your domain name: Once availability has been verified and
a registrar has been chosen, buy and register your domain name.
e. Do not lose your domain name: Renew the domain registration before it
expires so that you don’t lose your domain name.
Front End:
Back End
UI (User Interface):
In this way, the UI helps in designing the visual elements such as the buttons,
colors, and layouts you see whereas UX helps in making sure that using the website
is easy and enjoyable. UI and UX work together to transform the front end into an
interactive and user-friendly experience.
Question
i. Why is UI/UX important in web technologies?
ii. Who will create the UI/UX design in web development?
iii. In which stage of WDLC, UI/UX design comes under?
Concept of wireframe
Benefits of wireframe
a. Easy to draw: Wireframe has a simple and clean layout and consists of simple
screen elements.
c. Easy to modify: You do not need to have an idea of any programming language
to make changes to a wireframe.
d. No coding required: You can draw the wireframe as if you are using a drawing
tool.
4.4 HTML
Introduction to HTML
● DHTML (or Dynamic HTML) and XML (or Extensible mark-up language)
are the other popular mark-up languages.
HTML is a computer language that uses predefined tags to define the structure
of web documents which is the industry standard computer language for creating
the skeleton of web pages. The markup has no direct effect on how a computer
90 Computer Science , Grade 9
operates, but it does help to structure and present the content. Tim Berners-Lee
created HTML in 1990 at CERN, the European Particle Physics Laboratory in
Geneva, Switzerland. The World Wide Web Consortium (W3C) is the organization
that controls the development of HTML. Without HTML, the World Wide Web
would not exist.
To create HTML documents, you can use a simple text editor like Notepad or use
special software such as:
1. Sublime Text: It is a feature-rich text editor that is both versatile and fast.
3. Notepad++: Notepad++ is a popular text editor that can be used for creating
HTML documents.
Figure 4.10.
HTML Tags
Each element on a webpage is defined by an HTML code or tag. HTML tags tell
browsers how to display data. HTML tags are predefined syntax and commands
that perform specific tasks and are enclosed by angular brackets. A tag begins with
a (less than) sign and ends with a > (greater than) sign and information on the
screen and defines a webpage’s appearance, layout, and flow. A tag consists of
three parts: element (identification of tag), attribute, and value. HTML tags are not
case sensitive which means fonts written within the tag can be both uppercase and
lowercase. HTML tags are of two types:
A container or paired tag is a type of HTML tag that has both an opening and
a closing tag, such as <b> and </b>. The opening tag starts with a less than
sign (<) such as <p> tag and the closing tag starts with a slash and a less than
sign (</) such as </p>. The opening tag activates the implementation of the tag
while the closing tag stops it.
The tag which does not have its corresponding closing tag is known as an
Empty or Unpaired tag. It has only the opening tag, but no closing tag. It is used
to perform specific actions, functions, or tasks on the webpage. An empty tag
is also called a self-closing tag or stand-alone tag. For example, <br> inserts a
blank line and <img> tag inserts an image in a web page. Both do not have a
closing tag.
Activities 4.4
Discuss in the classroom and list down some of the container or paired tag and
empty or unpaired tag.
SN Paired tags Uses Unpaired tags Uses
1
In HTML, attributes are special words used in the opening tags to control or modify
the behavior of the tags. For example, you can specify the FONT (size, color, or
face) by including the appropriate attribute with the HTML code.
Structure of HTML
Lab task
Imagine you’re creating a web page to showcase “mySecondTeacher” in a big
and bold way. Can you write some HTML code to make it happen? Once you’re
done, don’t forget to run it to see your creation come to live on the screen.
To create an HTML file, all you need is a basic text editor. Different operating
systems have their own text editors: SimpleText for Mac OS, Vim and Emacs
for UNIX/Linux, and Notepad for Windows operating system. Additionally, there
are HTML development tools like PHPEdit, Textpad, Editplus, and Notepad++,
Sublime text, VS Code etc. HTML files typically have extensions like .html or
.htm.
Here are the steps to create and save an HTML document in Sublime Text Editor:
Go to: https://www.sublimetext.com/download )
3. Sublime Text will display save as a dialogue box asking for a file name as
shown in the figure below.
4. In the file name text box, type any name followed by .html or .htm extension
and choose the drive location where you want to save the file.
Figure: 4.13
To view your web page, double click on your file and you can see the output of the
HTML document in your default browser.
Comment Tag
The comment tag is used to insert a comment in the HTML source code. It is a
way for developers to include notes or remarks within the HTML code for various
purposes, such as explanations, reminders, or temporary instructions.
The comment tag requires an exclamation mark (!) after the opening bracket.
Example 1:
The <br> tag in HTML is a special code that tells the webpage to start a new line.
It is like pressing the enter key on your keyboard. You don’t need to write anything
after the <br> tag, because it is a self-closing tag.
The web browser only identifies a single pace between the words or texts even if
there are many spaces given between words. To add additional spaces between the
text you can use  . Using single   is equal to one space, double  
provides double space and so on.
Lab work!
As we already learned about the structure of HTML, you are assigned to write
the HTML structure, comment on each line in the structure, and submit it to the
teacher. After the completion of the task discuss in the class about: -
a. Why are comments important in Coding?
b. What’s the difference between single-line and multi-line comments?
Computer Science , Grade 9 95
Text Formatting Tags
A tag is a command in a web page that performs specific actions and tells the
browser to do. After we include the structure tags, we are ready to start placing
basic content in the document body. To work with text appearing in a web browser,
we use text formatting tags. Text formatting tags are special-purpose tags that are
used to change, define, or enhance the visual appearance and style of content on a
web page. Using text formatting tags, we can make our web text content bold, italic, etc.
Heading Tags (<H1> …. <H6>): These tags are used to provide headings in an
HTML document. HTML supports six different levels of headings. The biggest
header format is <H1> and the smallest is <H6>. All the styles of headings tags
appear in BOLDFACE and the size of the heading depends on the level chosen,
i.e., <H1> to <H6>
Attributes Description
ALIGN It is used to align the line on the browser
screen (aligned to the center by default).
ALIGN=LEFT will align the line to
the left of the screen.
ALIGN=RIGHT will align the line to
the right of the screen.
ALIGN=CENTER will align the line
to the center of the screen.
96 Computer Science , Grade 9
SIZE It is used to change the size of the line.
It is used to set the width of the line. It
can be set to a fixed number of pixels,
WIDTH
or a percentage of the available screen
width.
COLOR It is used to change the color of the line.
HTML Input
Text styles
You can use these tags to change how your text looks. <B>…</B> makes it bold,
<I>… </ I> makes it italic, <U>…</ U> makes it underline. The <SUP>…</SUP>
and <SUB>…</SUB> tags are used for superscript and subscript, respectively. For
example, H <SUB> 2 </SUB> O and E = mc <SUP> 2 </SUP>.
HTML Input
<b> This text is bold. </b>
<i> This text is italicized. </i>
<u> This text is underlined. </u>
A<sup> 2 </sup> B <sup> 2 </sup>
H <sub> 2 </sub> O
Output:
This text is bold.
This text is italicized.
This text is underlined.
A2B2
H2O
< FONT > Tag: Controlling Font Size, Color and Face
HTML Input
<FONT face = “Times New Roman” Size = “5” color = “Red”> Talent is not what
you have, talent is what you do. </FONT>
You can use color codes to choose the color of your text or background on your web
page. RGB color codes are special codes that have six numbers or letters. The RGB
color codes tell the computer how much red, green, and blue should be in a color.
HTML Input
< Font color = “ #800000 “> Maroon </Font>
< Font color = “ #808080 “> Gray </Font>
< Font color = “ #00CC00 “> Green </Font>
The <marquee> tag in HTML makes your text, image, graphics, and videos move
or scroll on your web page.
HTML Input
Activity:4.5
Make a marquee to display the future of learning, mySecondTeacher.
The anchor tag is an HTML element used to create hyperlinks on web pages.
Hyperlinks are used to direct users to different sections of the same webpage,
another webpage or various types of data such as files, images, or documents.
The anchor tag is denoted by the <a> element.
href: It specifies the URL of the page or document the link navigates or jumps to.
target: Specifies where to open the linked page or document. The values of the
target attribute is:
b. Internal link: It links to the specific location of the same web page.
HTML INPUT
<HTML>
<HEAD>
<TITLE> Using External Links </TITLE>
</HEAD>
<BODY BGCOLOR = “ SkyBlue “>
<H2 ALIGN = “CENTER”> Visit the following links to explore Nepal: </H2>
<P> <A HREF = “ http://www.ntb.gov.np”> Nepal Tourism Board Website </A> </P>
<P> <A HREF = “ http://www.explorenepal.com”> Explore Nepal </A> </P>
<P> <A HREF = “ http://mofa.gov.np “> Ministry of Foreign Affairs Website </A> </P>
</BODY>
</HTML>
The # symbol identifies the word “TOP” as a named anchor point within the current
document, rather than a separate page. When a reader clicks on “TOP”, the web
Computer Science , Grade 9 101
browser will display the part of the page starting with the <A NAME = “top”> tag.
Example 3:
HTML Input
<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE> Internal Link Example </TITLE>
</HEAD>
<BODY>
<nav>
<!-- Internal links in the navigation menu -->
<UL>
<LI> <A HREF = “ #section1 “> Section 1 </A></LI>
<LI> <A HREF = “ #section2 “> Section 2</A></LI>
</UL>
</nav>
<!-- Content for Section 1 - - >
<H2 id = “section1”> Section 1</H2>
<P> This is the content of Section 1.</P>
<!-- Link back to the top of the page - ->
<P> < A HREF = “#top”> Back to Top </A> </P>
<!-- Content for Section 2 →
<H2 id = “section2”> Section 2 </h2>
<P> This is the content of Section 2.</P>
<!-- Link back to the top of the page - - >
<P> <A HREF = “ #top “> Back to Top </A> </P>
</BODY>
</HTML>
102 Computer Science , Grade 9
Email link
You can use the <A> tag to make links that open an email. When you click on an
email link, it starts a new message addressed to the set email. The email address
should be written after ‘mailto:’ in the <A HREF> tag.
Example 4:
HTML Input
<HTML>
<HEAD>
<TITLE> USING EMAIL LINK </TITLE>
</HEAD>
<BODY>
Send your email to <A HREF = mailto:[email protected]> Curriculum
Development Center, Sanothimi Bhaktapur </A>
</BODY>
</HTML>
2. HTML Lists
An Unordered list starts with the tag <UL> and ends with </UL>. Each list of
items starts with the tag <LI>. The attributes that can be specified with <LI>
are:
Output:
Some of the Heavenly Places of Nepal
I. Surma Sarovar
II. Aalital
III. Ramaroshan
An ordered list starts with the tag <OL> and ends with </OL>, each list item starts
with the tag <LI>. The attributes that can be specified with <LI> are:
Definition Lists
Definition list values appear within tags <DL> and </DL>. It consists of two parts:
<DL>
<DT> Front End
<DD> Where user interacts with the system
<DT> Back End
<DD> Where the logic of the system is written.
</DL>
As per the requirement, we can also use Nested List, a list inside another list.
Attributes Value
SRC Path or location and name of the image file
ALIGN Defines the position of the image: left / centre / right
BORDER Defines the size of border of the inserted image
WIDTH Defines the width of an image (in pixel value or percentage of
the browser’s window)
HEIGHT Defines the height of an image (in pixel value or percentage of
the browser’s window)
HSPACE Defines a space of specified size to the left and the right of the
image
VSPACE Defines a space of specified size to the top and the button of
the image
ALT Defines the alternate text-based information if the user is unable
to view the image due to server or networking issues.
106 Computer Science , Grade 9
Example 8: HTML Input
<HTML>
<HEAD>
<TITLE> Education in Nation Building </TITLE>
</HEAD>
<BODY>
<MARQUEE BGCOLOR = yellow BEHAVIOR = alternate DIRECTION =
right WIDTH = 300> Education Enlightens the Students!!! </MARQUEE>
<BR> <BR>
<HR color = Blue >
<H2 ALIGN = center> Inserting image in HTML Document </H2>
<IMG SRC = “ images/myImage.jpg “ HEIGHT = 120 WIDTH = 200 ALT
= “ Computer Education”>
<BR> <BR>
<IMG SRC = “ images / myImage2.jpg “ BORDER = 5>
</BODY>
</HTML>
Note: While saving images, you can give the full path or save the image file in your
HTML document’s location.
4. HTML Tables
Table is the combination of ROWs and COLUMNs. Tables are commonly used
objects to define the layout of a webpage. A table in HTML starts with <TABLE>
tag and closes with </TABLE> tag. Each heading row of a table is defined between
<TH> </TH> tags. Each row of a table is defined between the <TR> and </TR>
tags. Likewise, each column data of a table is defined between the <TD> and
</TD> tag.
Each table has a table header. It is defined using <TH> </TH> tag. The content of
the table header row is automatically centred and appears in boldface.
Data cells hold data to be displayed in the table. A data row is defined using <TR>
</TR> tags. The text matter displayed in a data row is left-justified by default.
Any special formatting like boldface or italics is done by including appropriate
formatting tags inside the <TR> </TR> tags. An image can also be displayed in a
data cell.
Attributes Description
BORDER It defines the border and its thickness of table. The border
thickness is specified in pixels. Default size of the border is
0.
Example: <TABLE BORDER = 3 >
Caption Tag
A caption for a <table> in HTML is defined using the <caption> tag. The caption
is usually shown on top of the table and gives a short title or summary of what the
table contains. The <caption> tag is inserted right after the opening <table> tag. The
table caption can be made to appear above or below the table structure with the help
of the attribute ALIGN as given below:
ALIGN It controls the placing of the caption with respect to the table.
Example: ALIGN = BOTTOM will place the caption immediately
below the table.
ALIGN = TOP will place the caption immediately above the table.
The ALIGN attribute controls how the content is aligned horizontally inside a
table cell. It can be used on single cells, rows, or the whole table.
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE> VISIT NEPAL - FAMOUS PLACES </TITLE>
</HEAD>
<BODY>
Figure: 4.15
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>TABLE EXAMPLES</TITLE>
</HEAD>
Computer Science , Grade 9 111
<BODY>
<CENTER> <H3> TABLE WITHOUT CELLSPACING </H3> </CENTER>
<TABLE BORDER = “1” WIDTH = “30%” ALIGN = “CENTER”>
<CAPTION> Without Cellspacing </CAPTION>
<TR >
<TH> NAME </TH>
<TH> AGE </TH>
</TR>
<TR ALIGN = “CENTER”>
<TD> Krishna </TD>
<TD> 25 </TD>
</TR>
<TR ALIGN = “CENTER”>
<TD> Shiva </TD>
<TD> 30 </TD>
</TR>
<TR ALIGN = “CENTER”>
<TD> Ram </TD>
<TD> 22 </TD>
</TR>
</TABLE>
<HR>
<CENTER> <H3> TABLE WITH CELLSPACING </H3> </CENTER>
<TABLE BORDER = “1” WIDTH = “30%” ALIGN = “CENTER”
CELLSPACING = “10”>
<CAPTION> With Cellspacing </CAPTION>
<TR>
<TH> NAME</TH>
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE> WORKING WITH ROWSPAN AND COLSPAN </TITLE>
</HEAD>
<BODY BGCOLOR = “ SKYBLUE “>
<CENTER> <B> WORKING WITH ROWSPAN AND COLSPAN </B> <./
CENTER>
<TABLE BORDER = “ 2 “ WIDTH = “ 70% “ ALIGN = “ CENTER” HEIGHT
= “200”>
</BODY>
</HTML>
HTML forms are a client-side object that provide an interface between client
and server. <FORM> tag is used to create a form in HTML documents. Form
tag can contain various input elements along with other HTML contents. This
is why the form element is also known as a container for different types of
input element.
The <input> element or tag in HTML is a flexible form tag that can make
different kinds of input fields inside a <form> tag. The type attribute with input
element decides the type of input field that includes text boxes, checkboxes,
radio buttons, submit buttons, and more.
The opening tag of the FORM tag includes the attributes: name, method and
action. Name is used for defining the name of the form. The Method attribute
can be either GET or POST. Which determines how the form data is being sent
to the server. The Action attribute is a pointer to the script that processes the
form on the server side.
Activity 4.6:
Research on the internet and collect two or more forms and try to fill out the form.
It is better if student find the gov sites form.
a. Text Fields
Text fields enable end users / clients to type text into a single line input field. A
text field is an input field where users can type text or alphanumeric characters.
To create a text field, you can either use TYPE = “TEXT” in the <INPUT>
element or leave off the TYPE specification altogether. The default TYPE for
the <INPUT> tag is “text”.
<FORM>
</FORM>
Output:
Note:
< input type = “ Password “> lets users type in sensitive information, like
passwords, securely. The actual characters they type are not shown.
Lab work!
We can add activities here like input username, age, phone number and other.
b. Text Area
The <textarea> tag in HTML creates a multiline text input field in a form. Users
can type and send multiple lines of text with it, so it is good for longer texts
or free-form content. For example, if you want to create a form that enables
readers to compose electronic mail, you might use a text area for the body of
the message.
116 Computer Science , Grade 9
Syntax: <Textarea Name = “ BodyArea” Rows = “7” Cols = “ 30”
Enter your message Here…. </Textarea>
<TextArea> Attributes
Lab work!
Make a text-area for the message for the above form.
<FORM>
<b> Comments: </b> <br>
<textarea rows = “ 7 “ cols = “25” name = “details”>
Write your comment here…..
</textarea>
</FORM>
Output:
c. Radio Button
A radio button in an HTML form is an input element that lets users pick only
one option from a group of options that cannot be picked together. If one radio
button in a list is selected, all the rest of the radio buttons in the same list get
deselected.
<FORM>
<INPUT TYPE = “Radio” Name = “result” Value = “PASS”> Pass
<INPUT TYPE = “Radio” Name = “result” Value = “Fail”> Fail
</FORM>
Output:
Activities: 4.7
Add the radio button for the age i.e., Male, Female, and others in the form.
d. CheckBox
Unlike Radio Button, checkbox allows us to choose multiple items at a time in
a Checkbox list. Each checkbox can be either checked or unchecked.
Activity:4.8
We can add the hobbies in the form such as programming language, guitar,
football, and others in the above form.
<HTML>
<HEAD>
<TITLE> Working with Select Box </TITLE>
</HEAD>
<Body>
<form>
<p> <b> Select a District </b></p>
<SELECT Name = “District”>
<option value = “MUGU”> Mugu </option>
<Option value = “Manang”> Manang </Option>
<Option value = “Panchthar”> Panchthar </Option>
<Option value = “Siraha”> Siraha </Option>
<Option value = “Kapilvastu”> Kapilvastu </Option>
</SELECT>
</form>
</Body>
</HTML>
Output:
f. Buttons
The <button> tag in HTML creates a button that can be clicked on a form or
anywhere on a webpage. The button can have text, images, or other HTML
tags inside it. It is used to perform specific tasks or perform events when it is
clicked. There are two types of Buttons:
i. Submit Button: It tells the browsers to send the form data to the server.
You should include at least one submit button on every form.
ii. Reset Button: It is used for resetting the elements of a form. It allows the
user to fill new entries all over again.
<form>
<input type = “submit” name = “submit” value = “Submit”>
<input type = “reset” name = “reset” value = “ Reset”>
</form>
Output:
The <div> (division) tag in HTML is a division or container element that is used to
divide a web document logically. It helps to organize and arrange content on a
webpage. It is a block-level container that can contain other HTML elements.
The div tag can be styled with CSS to change its appearance, size, position, and
layout. It can also have an id or a class attribute to identify it or group it with other
elements.
e. JavaScript Interaction
<!DOCTYPE html>
<html>
<head>
<title> DIV Example </title>
</head>
<body>
</body>
</html>
- To Style a specific HTML element directly, you can use the style attribute with
inline CSS.
Let’s know
a. Why is div needed while writing HTML code? With its advantages?
b. Write a HTML code using the div function to print The height of
Sagarmatha is 8848 m.
Context:
HTML is a language that uses tags to create different elements on a web page, such
as text, links, images, and videos. CSS is another language that works with HTML
to style and layout these elements. You can use CSS to change the color, font, and
size of a paragraph element. For example,
< p style = “ color : #ff0000; font-weight: bold “> CSS helps to define Style </p>
CSS is a language that works with HTML to style and format web pages. It can
change the appearance of elements such as colors, layout, and fonts. It can also
help to define responsiveness which means CSS adjusts the presentation to suit
different devices, such as desktops, mobiles, or printers.
As said in the definition, CSS can be defined in such a way that it can change
layout, colors, fonts or any other styles based on the size of the screen (PC
Computer Science , Grade 9 123
Screen, Tablet screen and mobile screen) or for printers. In a desktop computer,
screen size is large whereas in mobile screen size is small and accordingly HTML
content should be presented to webpage viewers. CSS is used to define this type of
presentation. Also, if a viewer is trying to print a web page, the presentation of the
page can be made different using CSS to make it printer-friendly.
CSS Syntax:
´ A set of properties, which have values set to update how the HTML content
is displayed. For example, I want my element’s text color to be white, and its
background to be grey.
´ A selector, which selects the element(s) you want to apply the updated property
values to. For example, I want to apply my CSS rule to all the paragraphs in
my HTML document.
´ A set of CSS rules contained within a stylesheet determines how a web page
should look.
Example 1:
<!DOCTYPE html>
<html>
<head>
<title> My First CSS Example </title>
<style>
h1 {
color : blue;
background-color : yellow;
border : 1px solid black;
}
p {
color: red;
}
</style>
</head>
<body>
<h1> Hello World! </h1>
<p> This is my first CSS example. </p>
</body>
</html>
Properties: These are the names of the aspects of the web page that you want to
modify, such as font, width, background color, etc.
Computer Science , Grade 9 125
Values: These are the specific settings that you assign to each property, such as
Arial, 50%, blue, etc.
A property and a value together form a CSS declaration. You can group multiple
CSS declarations inside a CSS Declaration Block. You can also use selectors to
specify which HTML elements the CSS Declaration Block applies to. This creates
a CSS Rule Set (or CSS Rule). Each property has a predefined set of values that are
valid for it.
4.5.2. Selectors
CSS selectors are expressions that identify, target, and select HTML elements on
a web page, and apply styles to them. Selectors are part of CSS which enable you
to change the appearance of elements without changing the HTML code. Selectors
are essential for creating the rules that control the style and layout of a web page.
1. Element selector
Example:
b{
2. ID Selector
Example:
#header {
/* Styles applied to the <p> element with id = “header” */
}
<Body>
<p id = “ header “> I am Id Selector with Id name check </p>
</Body>
3. Class Selector
The class selector is used to select and style HTML elements that have a
certain class attribute. To select elements with a certain class, a dot (.) is written
followed by the class name.
Example:
.check {
/* Styles applied to all elements with class = “ check “ */
}
<Body>
<p class = “ check “> I am Class Selector with class name check </p>
</Body>
4. Universal Selector
The universal selector (*) in CSS is a symbol that is used to select all HTML
elements on a web page. It matches any element type, allowing you to apply
styles to every element without specifying individual element names, classes,
or IDs.
i. Inline CSS
Example:
<!DOCTYPE html>
<html>
<head>
<title> My CSS Experiment </title>
</head>
<body>
<h1 style =” color :blue ; background-color :yellow ; border: 1px solid black;”>
Good Morning Class ! </h1>
<p style = “ color : red; “> This is my first CSS example of Inline styles </p>
</body>
</html>
Example:
<!DOCTYPE html>
<html>
<head>
<meta charset = “utf-8”>
<title>My First CSS Try Page </title>
<style>
h1 {
color : blue;
background-color : yellow;
border : 1px solid black;
}
p{
color : red;
}
</style>
</head>
<body>
<h1> Hello World! </h1>
<p> This is my first CSS example of an Internal stylesheet. </p>
</body>
</html>
Computer Science , Grade 9 129
iii. External CSS
External CSS is a method of styling HTML elements by placing the CSS code
in a separate external file with a .css extension. This file is then linked to the
HTML document using the <link> tag in the <head> section.
Unlike inline CSS or internal CSS, external CSS allows for the separation
of style and content, making it easier to manage and maintain styles across
multiple web pages. This approach promotes code reusability, as the same CSS
file can be linked to multiple HTML documents, ensuring consistent styling
throughout the website.
Example:
<!DOCTYPE html>
<html>
<head>
<meta charset = “utf-8”>
<title> My Experiment with External Stylesheet </title>
<link rel = “stylesheet” href = “mystyle.css”>
</head>
<body>
<h1> Visit Nepal 2020! </h1>
<p> Sagarmatha, also known as Mt. Everest, is the highest mountain on Earth
and a
symbol of both natural beauty and human determination. Here are some key
details about Sagarmatha (Mount Everest): </p>
</body>
</html>
h1 {
color: blue;
background-color: gold;
border: 1px solid black;
}
p{
font-size :14pt; font-weight : bold; text-align : justify; color : red;
}
CSS is a language that makes web pages look nice. It uses the box model to arrange
HTML elements on the page. Each element is like a box with four parts:
There are several properties in CSS that are often grouped together as box properties
which control the way browsers layout the page using the CSS box model.
For example, if we have an element (like a <h2> Element Contents </h2>) on the
page, here are the parts of its ‘box’ when drawn:
Content: It is what you see inside the box, such as words, pictures, or videos.
Border: It is the frame around the content and padding. It shows where the box
ends and the next one begins.
Margin: It is the gap between the boxes. It gives some breathing room and keeps
the boxes from touching.
CSS code:
h2 {
padding : 1em ;
border : medium dashed black ;
background-color : grey ;
}
It will make the <h2> have a gray background, with 1 em of space between the text
and the border. The space inside the border (even if it is invisible because we do not
have one) is covered with the background color and is controlled by the padding
properties.
If we want more space separating this element (and its border) from the stuff around
it, we would have to increase the margin values. It’s easy to mistake margin for
padding, especially when there is no border or background color. If you are trying
to change the space around an element (especially when the browser’s default CSS
has some space there), try setting both margin and padding to zero and work from
there.
p{
line-height: 1.5em;
}
blockquote {
margin-left : 2em;
border-left : 0.25em solid black;
}
# logoimg {
width : 120px;
height : 160px;
float : left;
margin-left : 1em;
}
Here is an example page that we can style with some of the properties above:
134 Computer Science , Grade 9
Example 5:
<!DOCTYPE html>
<html>
<head>
<meta charset = “UTF-8” />
<title> CSS Properties </title>
<link rel = “stylesheet” href = “css-prop.css” />
</head>
<body>
<h1> CSS Properties </h1>
<h2> Goals </h2>
<p> This is a page that we’re using to demonstrate various CSS properties and
techniques. Because of that, it is probably going to be ugly. </p>
<h2> Results </h2>
<p> Yes, it is turning out rather ugly, but it is important to demonstrate some CSS
stuff. Here are some of the new things: </p>
<ul>
<li> more CSS properties </li>
<li> the box model </li>
<li> the units of length used </li>
</ul>
</body>
</html>
body {
font-family : “Helvetica”, sans-serif;
}
h1 {
text-align : center ;
font-weight : bold ;
background-color : silver;
color : teal ;
padding : 0.25em ;
}
h2 {
border : medium dotted teal;
font-weight : normal ;
padding : 0.1em ;
}
Try experimenting with CSS on this page (or one you have created).
Project work
Develop a Static Web Page Using HTML and CSS.
This project will help you learn the basics of web development, which is a valuable
skill in today’s digital world. You will learn how to use HTML and CSS to create a
Computer Science , Grade 9 139
website that showcases your personal portfolio. You will also learn how to design a
website that is user-friendly, responsive, and attractive.
Website Overview
In this project, you will create a website for yourself. It will have four pages: Home,
Gallery, Contact, and Information. Each page has a different job. The Home page
welcomes visitors, the Gallery shows your personal portfolio images, the Contact
page lets people reach out to you, and the Information page shares important details
about you. This project is a chance for you to be creative and show off your skills
while helping yourself shine online!
1. Your task is to design and develop a static website for yourself.
2. The website should consist of four main pages: Home, Gallery, Contact, and
Information.
3. Each page should have a consistent navigation bar (navbar) and footer design.
4. Utilize HTML for structuring the content and CSS for styling and layout.
WireFrame
Navbar
A navbar is a part of a website that helps you find other pages on the site. It usually
has the site name and some buttons at the top. You can click on the buttons to go to
different pages.
Perform:
1. Create a navbar that is consistent across all pages.
2. Include menu items such as Home, Gallery, Contact, and Information.
3. Ensure that the navbar is responsive and functional, allowing users to navigate
between pages easily.
Footer
A footer is a part of a website that you can find at the bottom of a page. It has extra
information that is not in the main part of the page. Some things you might see in a
footer are: Copyright Information, Contact Information, Navigation Links, Social
Media Icons/Links, Sitemap, etc.
140 Computer Science , Grade 9
Perform:
Home Page
The homepage is the first page you see when you visit a website. Home page is also
known as the Index page. It is like the front door, welcoming you in and showing
you around. On the homepage, you’ll find menus to explore different parts of the
site, links to important pages, and highlights of what the website is all about.
Perform:
● At least 1 image should be inserted as a cover image of the page.
● Home page should contain a welcome message section.
● Home page should contain a section for upcoming events.
● Home page should contain a social media icon where it should hyperlink with
the social media site.
● Home page should contain a footer.
Gallery Page
● Page should contain different sections such as Events, Head of the Department,
and others.
● Page should require at least 3 or 4 photos with captions, which are needed for
each section.
Contact page:
● In the form, there should be first name, last name, phone number, address,
email, radio button- and drop-down menu and message box.
2. Create four HTML files and name them “index.html”, “gallery.html”, “contact.
html”, and “information.html” and store them in myProject folder.
4. Link the CSS file to all the HTML files using the <link> tag.
Let’s think!
a) How has the internet changed the way we access and share information
compared to traditional methods, like newspapers and letters in Nepal?
b) In what ways do you think social media has impacted our daily communication
and relationships with others?
c) Why do you think understanding online tools, such as web browsers, search
engines, and email, is essential for navigating the digital world?
Do You Know?
Approximately 4.32 billion people use their mobile to devices access the internet.
Internet and social media explore the foundational concepts governing online
communication. It begins with an overview of the World Wide Web (WWW), web
browsers, search engines, and URLs. Students delve into remote login applications,
web protocols, and Virtual Private Networks (VPNs). The unit also emphasizes
the significance of email and provides hands-on tasks, delving into social media’s
diverse applications. Online video meetings are introduced with examples and
practical tasks, leading to exploring blogs and their key features. This comprehensive
unit provides students with essential insights into the interconnected web of the
internet and social media, enhancing their ability to navigate the digital landscape
effectively.
Do you know?
Mosaic, which is the first web browser started developing
in the late 1992 which was founded by Marc Lowell
Andreessen.
Search Engine
Let’s check!
Which of the following is the most popular search engine?
a) Bing b) Google c) Yahoo d) Microsoft
Search engines use advanced techniques to help users find relevant information
online. For instance, they use algorithms to match keywords entered by users with
Computer Science , Grade 9 145
the content on web pages to check the relevance of the information found on the
web. Moreover, users can refine their searches using Boolean operators like “AND,”
“OR,” and “NOT,” ensuring that specific keywords must or must not be present in
the results.
Additionally, putting quotes around a phrase narrows down searches, while wildcard
characters like “*” broaden them to include variations of a word. Users can also
limit searches to specific websites using the “site:” operator, or find particular file
types using “filetype:” followed by the extension, like PDF or DOC.
Activity 5.1
Activity Outcome -
- Understand the impact of different search operators on search engine results
by analyzing result counts.
Required Resources: Mobile phone or computer with internet access and a search
engine (e.g., Google).etc.
1. Open a search engine on your device (such as Google).
2. Enter the keyword “search engine” using different search operators as instructed
below.
3. After each search, note down the result count displayed by the search engine.
● Without Quotes: Type search engine without any quotation marks.
● Using Quotation Marks (“ “): Type “search engine” with quotation
marks around the entire phrase.
● Using “filetype:” Operator: Type “search engine:pdf” to look for PDF
files related to the term.
● Using Asterisk (*): Type “search engine*” to include variations of the
keyword.
Quote Keyword Result number
Without using qoute search engine
Using “ ” Quote “search engine”
Using “ filetype:” Quote “search engine:pdf”
Using “*” Quote “search engine*”
Result: Group discussion on the impact of different search operators and how
they influence search results, with each group sharing their recorded data.
146 Computer Science , Grade 9
URL
Figure: 5.5
Here are the key components and concepts associated with a URL:
c. Top-Level Domain (TLD): It’s the last part of the domain, showing the
website type, like “.com,” “.org,” or “.edu.”
d. Path: This is where the specific thing is on the server, like “/path/to/resource.”
Figure: 5.6
Activity 5.2
Activity Outcome -
- Access and analyze online resources, observing available content and resource
types on the specified website.
Required Resources: Personal computer or mobile phone with internet access,
etc.
1. Open a web browser on your device.
Result: Group reflection on the types and quality of resources found on the page,
with discussion on their potential usefulness for academic learning.
Figure: 5.7
Remote Login is a process in which a user can log into a remote site i.e. computer
and use services that are available on the remote computer. With the help of remote
login, a user can understand the result of transferring and the result of processing
from the remote computer to the local computer.
Activity 5.3
Activity Outcome -
Procedure:
2. Open Anydesk and choose to sign in using your Google account or create a
new account if you do not have one.
4. Paste the Address of another Anydesk account with which you want to
connect.
6. Click on Invite and wait for the other user’s approval to begin the remote
session.
HTTP
HTTPS
Figure:5.10
Activity Outcome -
- Recognize the difference between HTTP and HTTPS protocols by identifying
websites using each protocol.
Required Resources: Personal computer or mobile phone with internet access,
etc.
Procedure:
1. Open a web browser on your device.
2. Use a search engine to find one website that uses HTTP (without encryption)
and another that uses HTTPS (with encryption).
3. Note the URL of each website, observing the security indicators (such as a
padlock icon) present in HTTPS sites but not HTTP ones.
4. Record the URLs in the table below:
Protocol Website URL
HTTP
HTTPS
Figure: 5.11
Computer Science , Grade 9 151
Figure: 5.12
Here,
In email, the “To” field indicates the primary recipient, while “Cc” (carbon copy)
allows sending a copy to additional recipients who are not the main addressee but
should still be informed. “Bcc” (blind carbon copy) serves a similar purpose as Cc
but hides the additional recipients from others.
Common email platforms like Outlook facilitate various actions such as “Reply”
for responding to a message, “Forward” for sharing it with others, “Adv” for
marking an email as an advertisement, “Dis” for marking it as spam or unwanted,
and “Attach” for including files with the message. These features contribute to the
versatility and functionality of email communication.
Uses of email
Activity 5.5
Activity Outcome -
- Learn to write a well-structured, formal email to inform a teacher about an
absence.
Required Resources: Personal computer or mobile phone with internet access,
etc.
Procedure:
1. Open your email application.
2. Write a clear subject line like: “Absence Notification for [Date(s)].”
3. Start with a polite greeting (e.g., “Dear [Teacher’s Name],”).
4. In the body of the email, include:
5. Reason for your absence (e.g., illness, family commitment).
6. The specific date(s) you will be absent.
7. A brief statement about catching up on missed work or assignments.
8. Conclude with a closing statement (e.g., “Thank you for your understanding”).
9. Sign off with “Best regards” or “Sincerely,” followed by your full name and
class information.
Result: Teacher reviews students’ emails, providing feedback on the formality,
clarity, and completeness of each email draft.
5.5 Appropriate usage of social media and safely accessing web sites
Social media
Before the invention of the internet, people used to communicate through paper
Computer Science , Grade 9 153
mail. The use of communication through such means would sometimes consume a
lot of time resulting in late delivery. With the invention of various social applications
we can now send messages in one click.
Social media is like a big online community where people can connect, share, and
talk to each other. We can make friends, share pictures, videos, and messages, and
stay updated on what’s happening with people we know or things we’re interested
in. Examples include Facebook, Instagram, Snapchat, Twitter, and WhatsApp.
Let’s learn!
Look up and research the figure, and answer the following questions:
a. What is LinkedIn?
b. Do you know LinkedIn provides learning platform?
c. How can we make the best LinkedIn profile?
Activity 5.6
Activity Outcome -
- Locate key contact information for the Cyber Bureau of Nepal, including its
website, email, and contact number.
Required Resources: Personal computer or mobile phone with internet access,
etc.
Procedure:
1. Open a search engine on your device (e.g., Google).
2. Type the keywords “cyber bureau of Nepal” into the search bar.
3. Identify and note the following details about the Cyber Bureau of Nepal:
● Link of the Website: www.nepalpolice.gov.np
● Email Address of the Cyber Bureau of Nepal
● Contact Number of the Cyber Bureau of Nepal
Fun fact!
The first video call was made between Pittsburgh Mayor Peter Flaherty and
Chairman and CEO John Harper of Alcoa on June 30, 1970.
a. Zoom: Zoom is a software that allows us to host and join online video meetings
with up to 100 participants. It is a widely used video conferencing platform that
enables users to conduct virtual meetings, webinars, and online collaboration.
It also allows us to record and save the meetings for later viewing or sharing.
Some of us have a hobby of exploring different places and capturing those special
moments on our cameras or smartphones. Those captured videos or photos can
be turned into a blog and we can upload them on different social media platforms
and websites. We can also gain widespread fame and capital by carrying out such
activities.
A blog is like an online journal or diary where people can share their thoughts,
ideas, experiences, or information on a specific topic. Blogs can cover a wide range
of subjects, such as personal stories, hobbies, travel, technology, or any other area
of interest.
Features of blog
Some of the features of a blog are:
a. Posts: Blogs consist of individual entries called posts. Each post focuses on a
specific topic or idea.
b. Authorship: Each post is written by an author, who is usually the person
maintaining the blog. Authors share their thoughts, experiences, or knowledge.
c. Comments: Readers can leave comments on blog posts, creating a space for
interaction and discussion.
d. Categories: Blogs often organize posts into categories based on topics. This
helps readers find content related to their interests.
e. Archives: Blogs have archives that allow users to access older posts. It is like
a digital history of the blog’s content.
f. Tags: Bloggers use tags to label posts with keywords, making it easier for
readers to search for specific topics.
g. Images and multimedia: Blog posts can include images, videos, and other
multimedia elements to enhance content and engage readers.
h. Social sharing: Blog platforms usually include options for readers to share
posts on social media, spreading the content to a wider audience.
i. Subscribe: Readers can subscribe to a blog to receive updates when new posts
are published.
158 Computer Science , Grade 9
Exercises
1. Write full forms of the following abbreviations.
i. editing documents
e. What are Web Protocols? List out the examples of the Web Protocols?
a. Define Search Engine. What are the uses of search engines? Write with an
example.
g. What is social media? List out the uses of social media with its examples.
5. Lab Activities
a) Apply digital signature and secure email using Gmail, Outlook or similar
mail system.
Step:
1. Open your Gmail account.
2. Go to Settings.
3. Click on See all settings.
4. Click on the General.
5. Go to Signature. There you saw the option create new
6. Click on Create New option –Add new signature –Type Signature name –
Click on Create option.
7. After that on the left side the content area is present on the content
area Type the Name, Address, and own positions and organization
name too.
Step:
1. Open your web browser: Launch your preferred web browser (e.g.,
Google Chrome, Mozilla Firefox, Safari).
3. Enter your search query: In the search bar, type your learning query.
For example, let’s say you’re looking for materials on “Python
programming for beginners.”
6. Refine your search: If the initial results are not what you’re looking
for, consider refining your search query. For instance, you might add
specific terms like “Python programming tutorials” or “Python
basics PDF.”
7. Use filters: Utilize search engine filters to narrow down results. You
can filter by type (videos, images, news) or time (past hour, past 24
hours, past week) to get the most relevant content.
8. Visit websites: Click on the search result links to visit websites that
seem promising. Look for reputable sources such as educational
institutions, official documentation, or well-known learning
platforms.
Steps:
1. Choose the platform: Identify the social media platform you want to
join (e.g., Instagram, Twitter).
4. Customize your profile: Add a profile picture, bio, and other relevant
details.
5. Connect with others: Find and connect with friends, family, or other
users. Explore and Contribute: Start exploring content, following
accounts, and contributing to the platform.
Zoom
2. Fill in the meeting details, such as topic, date, time, and other settings.
2. Send invites via email, copy the invitation link, or use other options.
1. At the scheduled time, return to the Zoom website or open the Zoom
app.
Project work
Project Outcome -
- Learn to create a YouTube channel, upload videos, and engage with the
YouTube community.
Procedure:
● If you don’t have a Google account, click on “Create account” and follow the
steps to set up a new Google account.
Step 2: Go to YouTube.
● Click on your profile picture in the top right corner of the YouTube homepage.
● Choose a unique channel name that reflects the type of content you plan to
upload.
● Upload a profile picture that visually represents your channel (e.g., a logo or
relevant image).
● Prepare a video you want to share on your channel. This can be a short
introduction, tutorial, or any content relevant to your theme.
● Click on the camera icon with a plus (+) at the top of the page and select
“Upload video.”
● Select the video file from your device and follow the prompts to add a title,
description, and tags to improve visibility.
● Review YouTube’s video settings for privacy (Public, unlisted, private), age
restrictions, and monetization if applicable.
● Add a channel description to inform viewers about the content they can
expect.
Computer Science , Grade 9 165
● Customize your channel layout (e.g., featured sections) to make it easy for
visitors to browse your videos.
● Add links to your social media profiles or website by going to the “Basic
Info” section in the customization menu.
● Use the YouTube Studio to monitor viewer statistics and get insights into your
audience.
Result:
Reflect on your experience setting up the channel, customizing it, and sharing
content. Consider what types of videos you want to produce in the future and how
you will engage with your audience.
Let’s think!
a) Discuss why cybersecurity is essential for individuals and businesses in Nepal.
b) Explain how you think your online activities impact your privacy and security.
c) Discuss the responsibilities that come with being a digital citizen.
Let’s check!
Which of the following is not cyber security?
a. Network security b. Application security.
b. Information security c. Quantum security.
Fun fact!
“qwerty”, “123456” and “password” are like the evergreen rock stars of the
digital world. Despite being about as secure as leaving your front door wide open
in a busy city, they still manage to rock the charts as the most used passwords. It’s
like they’re the classics that never go out of style, even though security experts
are constantly screaming for a change in tune!
a. Password b. Pin
a. Badge b. Smartphone
Software updates
Authentication
Use of Firewall
Figure 6.4
170 Computer Science , Grade 9
Activity 6.1
Activity Outcome
- Gain hands-on experience with antivirus software and firewall settings,
understanding their functions in protecting devices from threats.
Required Resources: Computer or device with antivirus software and firewall
options (such as Windows Defender or a third-party antivirus, Internet connection
(if needed for updates) Projector or screen (optional, for class demonstration),
etc.
Part 1: Understand use of antivirus software
Procedure:
Open the antivirus program: You should open the antivirus software installed
on the classroom’s device. If there isn’t one, they may use Windows Defender or
a free trial of an antivirus program that you can use.
a) Demonstrate a quick scan:
● Run a quick scan of the system and observe any threats detected.
b) Full scan option:
● See the difference between a quick scan and a full scan.
c) Review and quarantine threats:
● If any threats are detected, review the results and quarantine or removal the
viruses.
d) Update the antivirus:
● Update the virus definitions manually if and understand that keeping software
updated is crucial for protecting against new threats.
Part 2: Understand use of a firewall (software or hardware)
procedure:
a) Access firewall settings:
● Open firewall settings on the device (e.g., in Windows, access “Windows
Defender Firewall” through Control Panel).
b) Configure basic firewall rules:
● Allow or block applications from accessing the network using firewall rules.
Do you know?
Google reigns as the undisputed champion of search engines across the globe.
Additionally, a whopping 65.76% of internet users prefer to surf the web using
Google Chrome, making it the top choice for web browsing worldwide.
Activity 6.2
Activity Outcome -
- Demonstrate safe browsing techniques by following recommended security
practices.
Required Resources: Computer with internet access, browser, VPN application
(if needed), ad blocker software or extensions, instructional materials etc.
Procedure:
Your teacher will introduce various safe browsing techniques and demonstrate
each step.
II. Passive digital footprints: These consist of information that an internet user
unknowingly leaves behind. These kinds of footprints are difficult to monitor
and manage since they might be obtained without the approval of the user.
Web searches, online shopping, location data, and fitness trackers are some
examples of passive digital footprints.
Activity 6.3
Activity Outcome -
- Understand the concept of digital footprints by gathering and analyzing
information about digital identities and device usage.
Required Resources: Notebook or digital spreadsheet for data collection,
internet-enabled device, etc.
Procedure:
Your teacher will divide you in pairs or small groups, and you will collect digital
footprint information from classmates:
a) You will have to collect the following information:
● Name: First and last names.
● Email ID: Primary email address.
● Device: Types of devices they frequently use (e.g., smartphone, laptop).
● Social Media Username: Main usernames or handles used on social
media platforms.
b) Complete the following data table:
Name Email ID Device Social Media Username
c) Privacy Reminder: Students should obtain permission from their peers before
collecting and recording their information and handle this data responsibly.
Result: Moderated discussion on digital footprints, privacy, and online safety,
encouraging students to reflect on how their information is shared and used online.
176 Computer Science , Grade 9
Online privacy is a fundamental right in today’s digital world, focusing on
safeguarding one’s private life, home, and communication. Specifically, it pertains to
the protection of an individual’s personal information stored on the internet, including
data on digital devices and services like web searches and social networking sites.
Privacy concerns are a significant issue in the modern era, with digital footprints
serving as the primary avenue for cybercriminals to target private data. While there
are advantages to digital connectivity, such as enhanced communication and access
to information, there are also disadvantages, including the risk of privacy breaches
and unauthorized access to personal data.
Activity 6.4
Activity Outcome -
- Conduct research and identify differences between regular browsing mode
and incognito mode.
Required Resources: Computer or mobile device with internet access, etc.
Procedure:
Your teacher will divide you in pairs or small groups, and you will collect digital
footprint information from classmates:
a) Research: Individually or in pairs, you will conduct research on incognito
mode, exploring its purpose and functionality.
Focus points should include:
● How incognito mode works.
● Key differences from regular browsing mode.
● Limitations of incognito mode in terms of privacy and security.
b) Practical Exploration:
● Open a browser in regular mode and note down key features, visible history,
and saved data (such as cookies, saved passwords).
● Switch to incognito mode and compare differences, focusing on what data is
saved, visibility of browsing history, and session behavior.
Advantages:
a. Health monitoring
Smart watches and health applications utilize digital footprints to monitor and
analyse users’ fitness and health data, aiding in better health management.
b. Social connections
Digital footprints help build and foster connections with others, particularly
on social networking platforms, facilitating communication and relationship-
building.
c. Targeted advertising
Police can utilize online records to aid in investigations and prevent illegal
activities, leveraging digital footprints to gather evidence and ensure public
safety.
a. Security vulnerabilities
The use of digital footprints raises legal and moral questions regarding the
handling of sensitive information, prompting debates over privacy rights and
data protection laws.
Businesses may profit from selling user data without adequately compensating
individuals for the value of their private information, raising concerns about
fairness and ethical business practices.
d. Cybercriminal exploitation
Hackers can exploit the data contained in digital footprints to perpetrate fraud
and other criminal activities, posing significant risks to individuals’ financial
and personal security.
Detailed digital footprints can be used for spying and online abuse, jeopardizing
individuals’ safety and exposing them to various forms of cyber harassment
and exploitation.
Here are some practical steps you can take to protect yourself from the risks
of digital footprints:
e. Update software: Keep your devices and apps updated to fix security flaws.
f. Disable location tracking: Turn off location services on apps and devices
when not needed to prevent constant tracking.
Do you know?
If a person publishes or displays material against morals, etiquette, or hatred on a
computer, internet, and other electronic media, the culprit can be punished with a
fine of 1 lakh rupees or imprisonment for up to 5 years or both as per Electronic
Transactions Act 2063.
Exercises
1. Write full forms of the following abbreviations:
iii. prevention method of cyber crime iv. ways of using the internet
i. 2063 B.S ii. 2053 B.S iii. 2062 B.S iv. 2058 B.S
i. What is Cybersecurity?
iv. You use digital devices on a daily basis. What do you know about digital
society?
b. Explain about digital footprint and write the advantages and disadvantages
of it.
Project work
Project Outcome -
- Conduct research on cybercrime trends, explore real-world case studies, and
develop awareness of prevention strategies.
Required Resources: Internet-enabled device (laptop, tablet, or computer),
access to online research resources or databases, notebook or digital document
for notes, etc.
Procedure:
Your teacher will divide you in pairs or small groups
a) Topic Selection and Group Division:
● The teacher will assign you to groups, with each group focusing on one
specific type of cybercrime, such as phishing, identity theft, ransomware,
social media hacking, or online scams.
b) Research Phase:
● Each group will conduct online research to find recent case studies,
articles, and reports about their assigned type of cybercrime.
182 Computer Science , Grade 9
● Gather information on:
o Definition and characteristics of the specific cybercrime
o Real-life case study: An example where the cybercrime impacted
individuals or organizations
o Consequences: The effects on victims and organizations, such as
financial loss, reputational damage, or data breaches
o Prevention Strategies: Methods and tools used to prevent or
reduce risks related to the cybercrime
c) Documentation and Analysis:
● Organize findings in a document or presentation with the following
sections:
o Introduction: Brief overview of the assigned cybercrime
o Case Study: Description of a real-world example, detailing the
incident and its impact
o Consequences: Analyze how the cybercrime affected the victims
and the broader implications
o Prevention: Outline strategies, tools, and best practices to avoid
falling victim to this type of cybercrime.
d) Create a Report and Prevention Guide:
● Compile the research into a concise report. Include visuals, like charts or
infographics, to show trends in cybercrime.
● Prepare a one-page prevention guide summarizing the key prevention
tips for the specific cybercrime. This guide should be practical and easy
for classmates to understand.
e) Presentation and Class Discussion:
● Each group will present their findings to the class, explaining the nature
of their assigned cybercrime, its impact, and effective prevention
strategies.
● After each presentation, the teacher will facilitate a class discussion on
the broader importance of cybersecurity and personal responsibility
online.
Result: After the presentations, students will participate in a moderated discussion,
Figure 7.1
Let’s think!
a) What do you think programming is?
b) Why do you think programming is important in today’s world?
c) Define algorithm.
Just like people use languages like Nepali, Newari, Maithili, Bhojpuri, English, and
French to talk to each other, we use programming languages to communicate with
computers. These languages are what computers understand. With programming
languages, we can make all sorts of computer software. Everything from operating
systems like Windows and Linux to application software like Office Package and
web browsers is made using programming languages.
Fun Fact!
The first commercially available language was FORTRAN (FORMULA
Translation), developed in 1956 (first manual appeared in 1956, but first developed
in 1954) by a team led by John Backus at IBM.
There are two main types of programming languages: high-level and low-level.
Algorithm
● An algorithm is a set of step-by-step instructions designed to solve a specific
problem or perform a particular task.
● It begins with “start” and ends with “stop.”
● The instructions are written in simple, general language (like spoken languages).
Flowchart
● A flowchart is defined as the pictorial and graphical representation of an
algorithm.
● It utilizes shapes (oval, rectangle, parallelogram, etc.) to depict various
elements.
● The shapes have distinct meanings in a flowchart.
● The flowcharts correspond to algorithms, visually representing their steps and
structure.
The table below shows shapes used in flowchart and their meaning:
Algorithm: Flowchart:
Step 1: Start
Here, the problem is to find the greater number between two numbers using
programming logic. In order to solve the problem, firstly, the programming logic is
written in terms of algorithm and visualized through the corresponding flowchart.
The logic involves:
b. Checking if num1 is greater than num2 and making a decision on its basis
2. Testing: Once the code is written, testing is conducted to ensure the program
functions as expected. This involves running the program to identify any errors
or bugs and verifying that all parts of the program work correctly.
These three different steps are crucial for developing software that is reliable and
functions smoothly.
Imagine two friends: one speaks Nepali only, and the other speaks Sanskrit only.
They want to chat but need someone who understands both languages to translate
for them. Similarly, in computer programming, compilers and interpreters act as
translators for computers.
Compiler
For a program written in high level languages, we must convert it into its equivalent
machine language program before we can execute it on a computer. We can convert
high-level programming languages with the help of a translator program called
Computer Science , Grade 9 189
a compiler. A compiler is a translator of computer
programs that translate the entire high-level language
into machine level programming language in a single
operation on a computer. Some of the most commonly
widely used compiled languages are JAVA, C#, C, C++,
FORTRAN, etc.
Figure 7.5
Interpreter
Imagine, you’re telling a friend how to cook in a language they don’t fully
understand. You’d have to explain each step one by one, and they would follow
your instructions steps by steps. An interpreter works similarly with computer code.
It takes one instruction (line of code), translates it, and then moves on to the other
line, rather like explaining each step of the cooking process as your friend does it.
This method can be slower than having all the instructions translated at once, but
it’s useful because it can handle changes more easily. An interpreter is also more
portable than a compiler as it is not
processor dependent, you can work
between hardware architectures. The
most frequently used interpreted
language is QBASIC. It required less
memory.
Figure 7.6
190 Computer Science , Grade 9
Some examples of interpreter are:
a. JavaScript
b. Ruby
c. List processing (LISP)
d. MATLAB
e. Python
Compiler and interpreter translate program code into machine code. They
convert high-level programming language (user-friendly language) into low-level
programming language (language understood by computers, like 0s and 1s). While
both are language translators, they work differently.
A compiler translates the entire program at once, producing an executable file that
can run independently. An interpreter, on the other hand, translates code line-by-
line as it executes, without creating an independent file. Both tools serve the same
purpose: enabling computers to understand and execute human-written code.
The table below shows the difference between compiler and interpreter.
Compiler Interpreter
A compiler reads and translates An interpreter reads and translates program
program code to machine code all code to machine code line by line.
at once.
If there’s an error in the program If there is an error in the program code, it
code, it displays errors at the end. displays while running the program.
Compiled program’s execution Interpreted program’s execution time is
time is comparatively faster. comparatively slower.
Compiled programs have separate An interpreted program does not have a
files to store machine code. separate file to store machine code.
Do you know?
An Assembler is a special tool that translates programs written in Assembly
language into machine code, which the computer can understand.
Python is widely used in web development, data science and machine learning,
artificial intelligence, data analysis, automation and scripting, game development,
web scraping, cyber security, etc.
Do you know?
The name of the Python programming language comes from an old BBC television
comedy sketch series called Monty Python’s Flying Circus.
Features of Python
Python uses simple and understandable syntax, making it easy for programmers
to write and understand the code.
b. Versatile
Python can be used for a wide range of tasks like simple automating systems to
complex web development, data analysis, and Artificial Intelligence.
192 Computer Science , Grade 9
c. Beginner-friendly
Python uses simple syntax, making it a great choice for those who are new to
programming.
e. Rich ecosystem
Do you know?
Python is one of the few programming languages recognized by Google as an
official language.
Figure 7.8
Locate the downloaded installer file (usually in your Downloads folder) and double-
click on it to run the installation process.
Install Python:
Select your desired installation settings, click on Install to begin the installation
process. This may take a few minutes.
Note: You can download python file by going through this link below:
https://www.Python.org/downloads/
Comments in Python
In Python, comments are brief messages that programmers write in their code to
explain what the code is doing, like leaving helpful hints for others to understand the
program. Comments are indicated by the ‘#’ sign, and the interpreter ignores them,
treating them as notes for the programmer. They don’t affect the actual program.
In Python, a short note or comment starts with the ‘#’ symbol and goes until the
end of that line. If the note is longer and needs more than one line, each additional
line should also begin with a ‘#’ symbol. There should not be whitespace after ‘#’.
Example 1:
Example 2:
#This is an example of a Single line comment.
#This program prints what’s special about Nepal.
print(“Nepal is a famous for ADVENTURE TOURISM”)
Example:
‘’’ This is an example to demonstrate the use of multiple line comments.
This program prints what’s special about Nepal. ‘’’
print(“Nepal is home for various ethnic groups, languages, and traditions.”)
Keywords
Let’s check!
What are keywords in Python?
a. Words used as comment in code b. Identifiers for variables
c. Special words reserved for specific purposes d. User-defined functions
I/O statements help us to interact with the program. They allow us to provide our
data and instructions to the program as well as display the output on screen. In
Python, the statement used to give data and instruction to the program is an “input”
statement and the statement to display the output on screen is “print”.
Figure 7.9
Example: print(“Hello, Python!”)
2. Input Function
The ‘input’ function allows us to
provide input to the program.
We can give data to the program
as we need.
Example: number = input(“Enter
number: ”) String Formatting:
1. Old-style formatting
In earlier times, we used ‘%’ to insert values into a string. This was the old
way of formatting the string values.
name= “Ram”
age = 25
The new style string format uses ‘{ }’ placeholders and the ‘format’
method. It is used in newer generations of formatting.
name = “Sita”
age = 30
This is the most widely used method in string formatting in the current
time. In formatted string literal we use ‘f’ before the string and embedding
expressions inside { }. It is the most popular method of using string format.
name = “Shiva”
age = 35
Identifier
Identifiers are names given to program units such as variables, functions, classes, or
other entities. They are not predefined in the programming language but are defined
by programmers themselves.
Valid identifiers
Invalid identifiers
Variables are like containers that hold information. Imagine you have labelled
boxes where you can keep different types of items. Those boxes contain different
categories of item and you have labelled them accordingly. Variables are similar to
these boxes as they hold different types of data.
Python doesn’t have any command for declaring a variable. A variable is created
when the value is assigned to it.
Example:
a =15
Let’s consider the example of data type and variable with the example given below:
Variables Description
age ‘age’ is the variable name of the integer data type, and it holds the
integer value 15. In Python, it is represented as:
age=15
Height ‘height’ is the variable name of the float data type, and it holds the
float value “5.7”. In Python, it is represented as :
height=5.7
Fname ‘fname’ is the variable name of the string data type, and it holds the
string value “Sanjog”. In Python, it is represented as:
fname=“Sanjog”
is_student ‘is_student’ is the variable name of the boolean data type, and it
holds the Boolean value True. In Python, it is represented as:
is_student = True.
Imagine you’re developing a program for a bakery where customers can place
orders for cakes. You receive orders in the form of strings, but you need to convert
them into numerical values (integers or floats) to perform calculations and manage
inventory. Type casting is the process of converting a variable from one data type
to another. In this process, the compiler automatically adjusts the data type based
There are two types of casting: Implicit casting and explicit casting.
Implicit casting
Implicit type casting, also known as automatic type conversion, occurs when
the Python interpreter automatically converts one data type to another in certain
situations.
Examples:
x = 10 # integer
y = 5.5 # float
z=x+y # the integer ‘x’ is cast to a float for the addition.
print(z)
Explicit casting
In explicit type casting, the user intentionally converts the data type of a variable to
another data type. Following are the approaches of casting the data type intentionally:
Figure 7.13
200 Computer Science , Grade 9
1. int(x): Converts x to an integer.
x = 4.5
int(x) #cast x to int
print(x)
2. float(x): Converts x to a floating-point number.
x=4
float(x) #cast x to float
print(x)
3. str(x): Converts x to a string.
x = 11
str(x) #cast x to string
print(x)
1. Arithmetic operator
Activity 7.2
Activity Outcome -
Able to write a appropriate program
Procedure:
Write a simple code to print (Hello Class! My name is Your Name). Then
comment in every step of code using single line comment and multi line comment
to explain the purpose of the program and how it works..
Result: complete program.
2. Relational operator
Logical operators in Python are used to combine conditions and make decisions
based on different situations. This operator is like a tool that helps us make
decisions based on different situations. There are 3 main logical operators,
‘and’, ‘or’, and ‘not’.
AND:
Both the conditions must be true for the result to be true in the “and” operator.
Result: False
A B A and B
0 0 0
0 1 0
1 0 0
1 1 1
OR:
Only one of the conditions needs to be true for the result to be true in the “or”
operator.
Example: (5<2) or (5>3)
Result: True
A B A and B
0 0 0
0 1 1
1 0 1
1 1 1
NOT:
The logical operator “not” provides the opposite result of a given condition.
Computer Science , Grade 9 203
Example: not(5<2)
Result: True
A Ā
0 1
1 0
4. Assignment operator
Suppose we put ingredients like salt, sugar, spices, and turmeric in different
containers. To know what is there inside the particular container we put
labels outside the containers.
Example:
In this example, “my_age” is assigned the value 15. Here, my_age is like a box, and
the assignment operator “=” is putting the value 15 inside that box. Now, whenever
you use my_age in your program, it’s like opening the box and finding the number 15.
So, the assignment operator is like a labelling machine in Python that helps us keep
things organised by giving names to data.
Expressions
An expression in Python is like a formula that tells the computer to do something
with numbers and words. It is like a command that produces a value. They are like
the building blocks of our code, telling the computer what to do with the information
we provide.
Operands
Example: add = 5 + 3
Here, ‘5’ and ‘3’ are operands and ‘+’ is an operator, and it is performing an ‘addition’
operation.
Conditional statement
A conditional statement is like a decision making tool that helps our program choose
what to do based on conditions provided by the user. We can ask a question and
provide different answers based on the conditions provided. The most fundamental
form of conditional statement is if statement, “if - else” statement and “if - elif -
else” statement.
if statement
“if statement” is a conditional statement that gives us output based on the requirement
of the condition that we provide. “if statement” is written using the if keyword and
after that condition is provided and ends with indentation.
Syntax
if condition:
#statement to be executed when the condition is true
Flowchart:
Figure 7.14
206 Computer Science , Grade 9
Example:
#if statement program to check if a number is positive
number = int(input(“Enter a number: “))
if number > 0:
print(“The number is positive.”)
Figure 7.15
if-else condition
Syntax
if condition:
#statement to be executed when the condition is true
else:
#statement to be executed when the condition is false
Flowchart:
Figure 7.16
Computer Science , Grade 9 207
Example:
# Asking age to the user and providing results.
user_age = int(input(“How old are you? ”))
if user_age >= 18:
print(“You are an adult!”)
else:
print(“You are a teenager or a kid.”)
Figure 7.17
if-elif-else condition
Syntax
if condition1:
#code to be executed if condition1 is True
elif condition2:
#code to be executed if condition2 is True
else:
#code to be executed when condition1 and condition2 are False
Flowchart:
Figure 7.18
208 Computer Science , Grade 9
Example
Checking the number’s category, whether it is positive, negative or zero.
user_number = int(input(“Enter a number: “))
if user_number > 0:
print(“The number is positive.”)
elif user_number == 0:
print(“The number is zero.”)
else:
Figure 7.19
print(“The number is negative.”)
Syntax:
if condition1:
if condition:
else:
else:
Figure 7.20
Example:
age = int(input(“Enter your age: “))
if age >= 16:
print(“You are eligible for citizenship.”)
if age >= 18:
print(“You are eligible to cast a vote.”)
else:
print(“You are not eligible to cast vote.”) Figure 7.21
else:
print(“You are a minor.”)
Iteration
Do you know?
The first instance of loop was used by Ada Lovelace to
calculate Bernoulli numbers’ Ada Lovelace, a London-born
mathematician, is also referred to as the first programmer in
the world.
Figure 7.21
For loop
“For loop” is used when we know how many times we want to repeat a block of
code. A for loop in Python is a control flow structure that allows us to iterate over
a sequence. It simplifies the process of repeatedly executing a set of statements for
each time in the sequence. The basic idea is to loop through each element in the
sequence, executing a block of code for each iteration. The for loop is particularly
useful when the number of iterations is known.
Figure 7.23
Computer Science , Grade 9 211
In Python, range is a function that helps you make a list of numbers in a certain
order. It returns a sequence of numbers, starting from 0 by default and increments
from 1 (by default), and stops before a given number by user.
Pass
Example:
if condition:
# Some code here
else:
pass # Nothing happens in the “else” case
Continue
In Python, the continue keyword is used in loops (such as for or while loops). It is
used to skip the rest of the code inside the loop for the current iteration and move
on to the next iteration. It allows us to bypass certain parts of the loop based on a
condition without exiting the loop entirely.
Example:
for number in range (1, 6):
if number == 3:
continue # Skip the rest of the loop for number 3.
print(number)
Break
In Python, the break keyword is used in loops (such as for or while loops) to exit
the loop early, even if the loop’s condition hasn’t been fully satisfied. It allows us to
terminate the loop based on a certain condition.
While loop
Syntax
while condition:
count = 1
print(count)
count += 1
Figure 7.24
Let’s check!
Which loop is used when the number of iterations is known beforehand?
a. For loop b. While loop c. Do-while loop d.None of the above
Python list
Python list is one of the built-in data types in Python used to store multiple data in
a single variable. A list can contain heterogeneous types of elements which means
elements can have different data-types like integers, strings, floats, Booleans etc.
List elements are enclosed by square brackets and elements are separated by comma.
Example:
print(thislist)
Figure 7.25
List elements are indexed. The index always begins from 0. So, the first list element
always has index[0] so as the second list element has index[1] and so on.
Example:
print(thislist[2])
Figure 7.26
The output is 20 because the element associated with index [2] is 20.
Example:
print(thislist)
Figure 7.27
Lists are ordered. If we add new elements in the list, the new element will hold the
last position of the list. To add an element to the list, we use the append() method
which is joined using “.” operator with the list variable.
Example:
To remove elements from list, del keyword is used preceding the list variable
specifying the list index.
Computer Science , Grade 9 215
Example:
List length
To find the numbers of elements present in the list, we use len() function. The len()
function gives us the number of list elements present in the list.
Example:
a=len(thislist)
print(a)
Figure 7.30
We can loop through the list elements using the for loop to print all the elements
one by one.
Example:
for X in thislist:
print(X)
Figure 7.31
Python Dictionary
Picture a real-life dictionary where you look up words to find their meanings. In
Python, a dictionary is like that, but instead of words and meanings, it stores pairs
of keys and values. Think of keys as the words and values as their meanings. The
key-value pairs are stored together so that you can quickly look up a key and get its
corresponding value.
Example:
mydict= {
“student” : “pen”,
“teacher” : “marker”,
“tailor” : “needle”,
“marks” : 30,
“is_present” : True
} Figure 7.32
print(mydict)
Features of dictionary
Duplicate keys are not allowed: In the Python dictionary, two values with the same
key cannot exist. If the same key has two or more values, the new value will replace
the old value.
Example:
mydict={
“student” : “pen”,
“teacher” : “marker”,
“tailor” : “needle”,
“marks” : 30,
“is_present” : True,
“teacher” : “duster”
Figure 7.33
}
print(mydict)
After the dictionary has been created, we can add or remove values. A new value is
added to the dictionary using a new key index and value associated with it.
Example:
mydict={
“student” : “pen”,
“teacher” : “marker”,
“tailor” : “needle”,
“marks” : 30,
“is_present” : True Figure 7.34
}
mydict[“mechanic”]=”tools”
print(mydict)
The del keyword is used to remove specified key names in the dictionary.
Example:
mydict={
“student” : “pen”,
“teacher” : “marker”,
“tailor” : “needle”,
“marks” : 30,
“is_present” : True,
“mechanic” : “tools”
Figure 7.35
}
del mydict[“mechanic”]
print(mydict)
The value in the dictionary can be accessed by referring to its key name, by placing
the key name inside a square bracket.
Example:
mydict={
“student” : “pen”,
“teacher” : “marker”,
“tailor” : “needle”,
“marks” : 30,
“is_present” : True
}
a= mydict[“teacher”]
print(a)
Figure 7.36
Dictionary length
Example:
mydict={
“student” : “pen”,
“teacher” : “marker”,
“tailor” : “needle”,
“marks” : 30,
“is_present” : True
} Figure 7.37
b=len(mydict)
print(b)
We can loop through the dictionary using the for loop to print all the elements one
by one.
Example:
mydict={
“student” : “pen”,
“teacher” : “marker”,
“tailor” : “needle”,
“marks” : 30,
“is_present” : True
}
for X in mydict:
print(X) Figure 7.38
List Dictionary
A list stores elements in a A dictionary stores data in key:value pairs.
sequence.
List elements are accessed by Dictionary values are accessed by keys.
index.
List elements have an order. Dictionary values don’t have any specific order.
List elements can be added and Dictionary values are added as key:value pair
removed. and removed by key .
String functions
center()
The center() method returns a string which is padded with the specified character.
syntax
string.center(width[, fillchar])
center() Parameters
The fillchar argument is optional. If it’s not provided, space is taken as the default
argument.
Output
upper()
Python string method upper() returns a copy of the string in which all case-based
characters have been uppercased.
Syntax: str.upper()
Example:
print str.upper()
Output:
lower()
Python string method lower() returns a copy of the string in which all case-based
characters have been lowercased.
Syntax: str.lower()
Example:
print str.lower()
Output:
len()
Syntax: len(str)
Example:
Output:
Mathematical functions
Practice Tasks
1. Adding two numbers (Constant variable initialization)
number_1 = 5
number_2 = 7
add = number_1 + number_2
print (“The addition of number_1 and number_2 is: ”, add)
8. Finding the greatest between two numbers asking from the user
number_1 = input(“Enter the first number: “)
number_2 = input(“Enter the second number: “)
if (number_1 > number_2):
greater_number = number_1
else:
greater_number = number_2
print(“The greater number is: “, greater_number)
9. A program to check whether the given number is inside range (10 -100) or not
number = float(input(“Enter a number: “))
if 10 <= number <= 100:
print (“The number is within the range.”)
else:
print (“The number is outside the range.”)
11. Finding the greatest between three numbers asking from the user
number_1 = int(input(“Enter the first number: “))
number_2 = int(input(“Enter the second number: “))
number_3 = int(input(“Enter the third number: “))
14. A program that takes students’ scores as input and provides grades based
on certain criteria
score = float(input(“Enter the student’s score: “))
if score >= 90:
grade = ‘A’
elif score >= 80:
grade = ‘B’
elif score >= 70:
grade = ‘C’
elif score >= 60:
grade = ‘D’
else:
grade = ‘F’
print (f “The student’s grade is: {grade}”)
17. A program to print the sum of the first 10 natural numbers using a for loop
sum_of_numbers = 0
for number in range(1, 11):
sum_of_numbers += number
print(“The sum of the first 10 natural numbers is:”, sum_of_numbers)
OR
sum_of_numbers = 0
for number in range (1, 11):
sum_of_numbers = sum_of_numbers + number
print (“The sum of the first 10 natural numbers is : “ , sum_of_numbers)
21. A program to print star pattern as shown in the figure for i in range (1, 6):
# Program to print star pattern
for i in range (1, 6):
Print (‘*’ * i)
26. A program to print the sum of the first 10 natural numbers using a while
loop
sum_of_numbers = 0
number = 1
while number <= 10:
sum_of_numbers += number
number += 1
print (“The sum of the first 10 natural numbers is: ”, sum_of_numbers)
28. A program to reverse the number from user using while loop
number = int (input (“Enter a number: “))
reversed_number = 0
while number > 0:
digit = number % 10
29. A program to print Fibonacci series till n terms provided by the user
A Fibonacci series begins with 0 and 1. After that, each number is obtained by
adding the two previous numbers together.
Each term in the series is obtained by adding the two previous terms. For
example, 0 + 1 = 1, 1 + 1 = 2, 1 + 2 = 3, 3+5=8, 5+8=13 and so on.
0, 1, 1, 2, 3, 5, 8, 13
n = int(input(“Enter the number of terms in the Fibonacci series: “))
first_term = 0
second_term = 1
count = 0
while count < n:
print (first_term, end=”, “)
next_term = first_term + second_term
first_term = second_term
second_term = next_term
count += 1
153:
13 + 53 + 33
1 + 125 + 27 = 153
)
number = int (input (“Enter a number: “))
original_number = number
Practical Task
Download Python to your computer and install it.
Exercises
1. Answer these questions.
a) Explain programming languages with its types.
b) Differentiate between compiler and interpreter.
c) Define algorithm and flowchart.
d) Write five symbols with their functions of flowchart.
e) Create an algorithm to find whether the given number is odd or even. Also
make flowchart from the algorithm.
f) Explain Python programming with its features.
g) Describe the use of input/output statements in Python.
h) Define formatted string literals. Demonstrate its use in a simple program
where the user inputs their name and the output is displayed “Hello (user_
name)! Welcome to our program”.
h) What data type in Python is suitable for representing text and characters?
Input/Output
a) Write a program to ask input as “name” from the user and greet the user
as he/she provides their name.
d) Write a program to input 3 digits as integers and calculate their sum and
average.
a) Write a program to input a radius and find the area of circumference of the
circle.
240 Computer Science , Grade 9
b) Write a program to show the use of arithmetic operators. (Perform add,
subtract, multiply, divide, square and modulus between two numbers)
If…..else Statement
a) Write a program using the if statement to check whether the given number
is positive.
b) Write a program that takes people’s age as input and checks whether they
are eligible to vote. (Voting age is 18 and above)
c) Write a program to check whether the given number is even or odd using
an if-else statement.
d) Write a program to input two numbers and find the smallest number.
e) Write a program that takes students’ marks as an input and checks whether
the student passed or failed. (40 or greater is pass marks)
f) Write a program that takes 3 numbers as inputs and displays the smallest
number.
For loop
e) Write a program that takes an integer as input and prints the multiplication
table for that number.
While loop
e) Write a program to input multi digits numbers and display the sum of the
digits.
Lists
1. Write a Python program to create a list of 5 integers and print the list.
2. Write a Python program to print the second and fourth elements of a list.
3. Write a Python program to append a new element to the end of a list and
print the updated list.
4. Write a Python program to print the first three elements of a list using
slicing.
6. Write a Python program to iterate through a list and print each element.
8. Write a Python program to remove the third element from a list and print
the updated list.
Dictionaries
2. Write a Python program to print the value associated with a specific key
in a dictionary.
5. Write a Python program to iterate through a dictionary and print all the
keys.
6. Write a Python program to create a dictionary where the keys are numbers
from 1 to 5 and the values are their squares using dictionary comprehension.
8. Write a Python program to merge two dictionaries and print the resulting
dictionary.
Project Work
Develop a money exchange system in Python and write a report on it. Your project
should include functionalities for converting between various currencies using
exchange rates.
Steps to Follow:
Understand the Requirements:
1. Research and decide on the features to include, such as currency conversion,
displaying exchange rates, and handling errors.
2. Identify the currencies to support (e.g., USD, EUR, GBP, INR, NPR).
Design the Program:
1. Outline the structure of your program using pseudocode or a flowchart.
2. Include functions for key features like fetching exchange rates, converting
currencies, and displaying results.