← ict
Unit IV: Discussion questions
Grade 11 Ict (new curriculum) p.81
Answer the following case study questions in groups.
1. XY manufacturing company produces different types of products. The
products are described by: product ID, product name, quantity, and price.
The products are sold to different customers. The company also keeps track
of its customers’ information as customer ID, customer name, customer
address. The customer makes orders to buy products from the company
at different times. It is also necessary to keep order information, which
includes order ID, product ID, customer ID, order quantity, and order date.
Identify the entities, attributes, and relationships for the XY manufacturing
company database and construct an ERD for the data model of XY
manufacturing company.
75 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
UNIT
WEB DEVELOPMENT
Learning Outcomes
At the end of this unit, students will be able to:
Define the Web
Explain a website and its benefits
Elaborate the purpose of web design
Describe basic concepts of HTML and web development
Create webpages with images, videos, links, tables, lists, and links
Unit Overview
Web development is the process of creating websites for various purposes such
as information sharing and facilitating online businesses. In this unit, the World
Wide Web (WWW) and its foundations as well as the concept and uses of
websites are discussed. In addition, different types of HTML (Hypertext Markup
Language) elements are presented with examples of how they work.
4.1. World Wide Web
Brainstorming 4.1
What are the ways of communicating about a product or a service to a
target audience?
World Wide Web (www), commonly known as the Web, is one of the most important
services of the Internet. The Internet is a network of networks that the Web runs on.
The Web is just one of the services of the Internet, and the most popular one. There
are also many other services that are provided over the Internet such as email, file
transfer and communication services.
76 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
The Web is a collection of websites or webpages that are accessed over the Internet
using a web browser. Tim Berners-Lee invented the Web in 1989 in the famous
laboratory found in Switzerland known as CERN. When the Web was invented, it
was formed out of four essential foundations: HTML, HTTP, a web server, and a
web browser.
HTML, which stands for HyperText Markup Language, is the language that is used
to create webpages. A web browser is a software used by users to view webpages.
A web server, on the other hand, is a software that stores webpages and responds to
user requests that come through web browsers. HTTP, which stands for HyperText
Transfer Protocol, is the set of rules that web browsers and web servers use to
communicate with each other.
Links
The basics of HTML are discussed in detail in Section 4.3
A website is a publicly accessible collection of interrelated webpages. Hypertext is
used to link a webpage with other resources like another webpage, videos, images,
and the like.
Nowadays, websites are the most efficient and effective ways for organizations or
individuals to present themselves to their target audiences. As a globally accessible
platform, the web makes it possible for an organization to expand its reach to
the entire world. A website that is physically placed in one part of the world can
be accessed from any other part of the world. It is also how online transactions
are conducted by e-commerce companies. Today, shoppers use websites to make
orders of different types of products from their homes or workplaces. This avoids
the need to physically go to shops, which reduces the cost of transportation and
increases the efficient use of our limited time. Similarly, various government
e-services are accessed through websites. For example, citizens do not need to go
to the Immigration Nationality & Vital Events Agency office in person to make
applications for passports. They can simply go to the website and make their
requests online. Education is another example where websites are used to facilitate
a lot of activities. For example, the Ethiopian Ministry of Education established
a website to make educational resources accessible to students. Online learning
has also become widespread in many parts of the world, especially following the
outbreak of COVID-19.
77 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Activity 4.1
1. Explain what the Web is and how it is related to the Internet.
2. List and explain the foundations of the Web.
3. Describe some of the benefits of websites.
4. Discuss among your class mates on how you can benefit from using the
Web for educational purposes.
Grade 11 Ict (new curriculum) p.84
4.2. Website Design
Website design is concerned with the plan and design of various aspects of a website,
such as layout, navigation, appearance, and graphics. The goal of a website design
is to create a website that is appealing to its target audience. The design should also
make the search for information easy by providing a well-organized presentation.
The following are some important guidelines to consider when a website is
designed.
Target Audience
A website should be designed with the target audience in mind. The look and feel,
presentation, and all other aspects of the website should take the target audience
of the website into consideration. For example, a website that is intended for
children in educational settings should have a presentation different from one that
is designed for adults in the business environment.
Navigation
Webpages should be logically organized to allow easy navigation. A well-organized
website with easy navigation helps users find what they seek fast. A website with
poor navigation, on the other hand, confuses and drives away visitors.
78 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Figure 4.1 Navigation (Screenshot of part of the website of WHO)
As you can see from the way contents are organized on the website of WHO,
it is easier for visitors to find what they are looking for because of the logical
arrangement.
Consistency
The feel and look of webpages on a website should be similar. Better user
experience is achieved with consistent use of backgrounds, colors, typefaces, and
the like throughout the website.
Simplicity
Simplicity in website design applies to various elements of a website, such as the
use of colors, graphics, typefaces, and the like. For example, it is recommended
not to overcrowd a page with too many graphics. It is rather more helpful to use
graphics when required. It is also recommended to use a maximum of five different
colors (plus or minus two) to ensure a better user experience.
Accessibility
Designing a website with everyone in mind including people with disabilities is
highly advised to make sure that no one is excluded.
79 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Web development is the actual creation or building of websites while website
design deals with defining the layout and overall look of the website. Websites can
be developed using a WYSIWYG (What you see is what you get) software like
Adobe Dreamweaver. Simple text editors such as Notepad are the other alternative
software to develop websites. Though developing webpages using simple text
editors is a little more difficult than WYSIWYG software, it is more effective in
enabling the learner to master the language.
Activity 4.2
1. Describe the purpose of website design.
2. Discuss with your classmates the guidelines for website design.
3. Take the website of UN Women (https://www.unwomen.org/ ) and eval-
uate the website in a group using the guidelines discussed above. Then,
present the result of your evaluation including suggestions for areas of
improvement for the website.
4. Design a website layout on paper for your school taking the guidelines
given above into consideration.
4.3. HTML Basics
HTML is a markup language that is used to create webpages. The different elements
of a webpage such as headings, tables, paragraphs, images, and others are defined
using the predefined set of markup tags of HTML.
HTML has gone through multiple revisions since its invention in 1989. The current
version of HTML is HTML5.
HTML documents can be prepared using simple text editor software such as
Notepad. The documents are saved with a “.html” extension. For example, home.
html is a valid file name for an HTML document or a webpage.
4.3.1 HTML Tags and Elements p.86
HTML tags are a set of predefined names enclosed in angle brackets. Each HTML
tag has its specific meaning, and web browsers are designed to interpret or render
HTML tags according to their intended purposes. Sample HTML tags and their
meanings are shown in Table 4.1.
80 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Table 4.1 Sample HTML tags
Tag Name Meaning
<b> Bold
<p> Paragraph
<i> Italic
<h1> Heading
Links
Visit the following webpage for the list of all html tags:
https://www.w3schools.com/tags/default.asp
HTML elements are components of an HTML document and normally have
a <start tag> followed by content and an </end tag>. HTML elements are the
building blocks of a webpage. Figure 4.3 shows some examples of HTML elements
and their outputs on the browser.
HTML Code
<h1>This is a heading</h1>
<p>This is a paragraph</p>
<b>This is a bold text</b>
<i>This is an italic text</i>
Output on the Web Browser
This is a heading
This is a paragraph
This is a bold text This is an italic text
Figure 4.2 HTML elements
In Figure 4.3 that while the heading and the paragraph elements are
displayed on a separate line each, the bold and italic texts are displayed
next to each other. This is because the browser inserts a new line every
time it finds HTML elements like <h1> and <p>, but it doesn’t insert
new lines for <b> and <i> HTML elements.
81 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Activity 4.3
• Write an HTML document that has two paragraphs.
Though a significant majority of HTML elements conform to the <start tag>
content </end tag> format, there are some HTML elements that have a different
format. These HTML elements are known as void elements. The following table
shows the format of void elements and their meanings. Void elements do not have
an end tag.
Table 4.2 Void elements
HTML element Meaning
<br> Inserts a new line
<img> Inserts an image
<hr> Inserts a horizontal line
Note that the <img> element needs an attribute that indicates the
address of the image for the browser to insert the image into the
webpage. An example of how to insert an image is given in Section
4.3.3
82 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
HTML Code
<hr >
<p>This is a <br> paragraph </p>
<hr >
Output on the Web Browser
Figure 4.3 Inserting horizontal and new lines
Note that the two horizontal lines placed above and below the
paragraph are the result of the two <hr > elements. Also, note that the
text “paragraph” is shown in a new line because the <br > element is
inserted right before it, inside the <p> element.
Activity 4.4
• Create a webpage that has three paragraphs enclosed by horizontal lines.
4.3.3 HTML Attributes p.89
All HTML documents or webpages have a common structure. What changes from
one webpage to another is what goes inside the <body> and the <head> sections
of HTML documents. Figure 4.2 shows what the structure of HTML documents
looks like in HTML5.
83 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Figure 4.4 Structure of an HTML document
<!DOCTYPE html>: this element indicates the type of the document.
<html> …</html>: represents the entire document, and it is divided
into two major sections: the head (<head>..</head>) and the body
(<body>…</body>) sections.
<head>..</head>: this part of the HTML document is used to keep all
the information about the webpage such as the page title.
<body>…</body>: is the part of the HTML document where the
content of the webpage is kept. Everything that is shown in the web
browser, when the webpage is displayed, is what is contained in this
part of the HTML document.
Activity 4.5
• Open a webpage from the Internet. Right-click on any area of the webpage
and click on the “View page source” option. Then, after the complete
HTML code is displayed, identify those tags that you are familiar with,
and explore more about those that you do not recognize.
HTML attributes are used to define more properties to HTML elements. HTML
paragraphs, for example, are left-aligned by default. However, if a paragraph is
84 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
needed to be presented with the texts aligned to the right, the “align” attribute
should be used. Attributes are written inside the start tag with attribute-value pairs
(attribute=value). Figure 4.4 shows how the text of a paragraph is aligned to the
right using the “align” attribute.
HTML Code
<h1>This is a heading</h1>
<p align= right > This is a paragraph </p
Output on the Web Browser
This is a heading
This is a paragraph
Figure 4.5 HTML “align” attribute
Attributes are normally optional to many of the HTML tags. However, there are
some HTML elements that cannot function as intended without the use of some
attributes. The <img> HTML element is one such example. The <img> element
should have the src attribute, which refers to the name and location of the actual
image that is required to be inserted into the webpage. See the following example.
HTML Code
<img src= derartu tulu.jpg >
Output on the Web Browser
Figure 4.6 <img> HTML element
85 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Note that the example in Figure 4.6 assumes that the image file and the
HTML file are located in the same folder.
Activity 4.6
1. Write an HTML element that displays a heading with the text right-
aligned.
2. Write an HTML document that has three images each placed in a
separate line.
The other HTML element that uses the “src” attribute is the <video> element.
<video> element is used to add a video to a webpage as shown in the following
example.
HTML Code
<video width= 320 height= 200 controls
src= Country Landscape.mp4 >
</video>
Output on the Web Browser
Figure 4.7 <video> HTML element
86 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
The meaning of the attributes in the <video> element is given as follows:
The controls attribute adds controls like play, pause, and volume. Note
that no value is assigned to the controls attribute.
The width and height attributes control the width and height of the
video on the webpage depending on the value given.
The src attribute is used to refer to the file name of the video.
Activity 4.7
1. Get a short MP4 video and put it inside a folder.
2. Create an HTML document in the same folder and add a <video> ele-
ment in the HTML document to display the video that you just added to
the folder.
3. Open the HMTL document and see if the video opens.
4. Change the values of the height and width attributes and observe the
differences on the webpage. Observe also the change on the video when
the controls attribute is removed.
4.4. HTML Links
HTML links are used to navigate from one webpage to another or from one part
of a webpage to another. The links could come in the form of text or images and
are normally known as hyperlinks. Hyperlinks can easily be distinguished by the
hand symbol that the mouse cursor is turned to when the mouse is hovering over
the hyperlinks.
4.4.1 Links to other Pages p.93
The anchor tag (<a>) is used to create hyperlinks. An HTML element that is formed
from an anchor tag has the following format:
87 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
<a href =”URL”> clickable text </a>
<a href=”URL”>clickable text</a>
This is the part of the
hyperlink that will
This is the anchor tag.
be visible to the user
when the webpage is
href is the attribute URL stands for
displayed on the web
that the URL of the Uniform Resource
browser. When this is
destination web- Locator. It is used to
clicked, the user will
page is assigned to. reference the address
be redirected to the
of the linked web-
given URL.
page.
Figure 4.8 Format of HTML links
The example in Figure 4.9 shows how a link to Google is created and what the
hyperlink looks like when it is displayed on the web browser.
HTML Code Output on the
href is the attribute that the URL of the destination webpage is assigned to.
Web Browser
” ” Google
<a href= http://www.google.com >Google</a>
Figure 4.9 Defining a link to Google
Note that it is only the clickable link that is displayed when the webpage
is displayed on the browser. If the user clicks on Google, the user is
moved to Google’s webpage. That is because the URL of Google is
given as a value to the href attribute.
Another important attribute of the anchor tag is the “target” attribute. The value of
the “target” attribute determines where the linked document is displayed. See the
following table for the meaning of each value of the “target” attribute.
Table 4.3 The “target” attribute and its values
Value Meaning
_self The webpage is displayed in the same window/tab. (Default)
_blank The webpage is displayed on a separate window/tab.
88 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Activity 4.8
1. Using Notepad, create an HTML document that has links to Ethiopian
Airlines, ethio telecom, and Commercial Bank of Ethiopia using the
following URLs:
https://www.ethiopianairlines.com
https://www.ethiotelecom.et
https://www.combanketh.et
2. Modify the HTML code you just created above so that the pages are
displayed in a new tab.
In addition to texts, images also can be used as links that users can click on to go
to a specified webpage. To use images as a link, simply embed the image element
inside the anchor tag as shown in Figure 4.10.
HTML Code Output on the
Web Browser
<a href= http://www.google.com
target= _parent >
<img src= google.png >
</a>
Figure 4.10 Image HTML link
Note that the image element is placed between <a> and </a>. Also
note that a relative URL, as opposed to an absolute URL, is used to
reference the “google.png” image. The assumption in the way the URL
is given is that the image and the current webpage are found under the
same folder.
Absolute URL: is a URL that includes every element of a URL such
as the protocol, the hostname, as well as path of the webpage. In other
words, it will have a form such as this:
http://www.somewebsite.com/somefile.html
Relative URL: is a path given relative to the location of the current
webpage. Example: somedirectory/somefile.html
89 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Activity 4.9
• Redo the first question of Activity 4.8 using three images as hyperlinks.
4.4.2 Links to Page Sections p.96
Hyperlinks can be created not only to establish links to other pages, but also to
different parts, or sections of the same page. This is especially useful in a webpage
that has a large size content. Readers can easily go to different sections of the page
without having to scroll up and down.
To create such types of links, the <a> tag is used in two different ways: in
designating names to specific locations and in creating links to the locations from
other places on the same page. While the “name” attribute is used to designate a
name to a location, the “href” attribute is used to create links to the locations. See
the following example.
<h3>Section One
<a name=”section_one”></a>
</h3>
<a href=”#section_one”>Go to section one</a>
The HTML element you see at the bottom of the above code creates the Go to
section one link. If this link is clicked, the user is moved back to the top of the
webpage. (Note that in order to see this effect the webpage should be long enough
that the link and the top of the document cannot be seen on one screen.)
Note also that the way the value to the href attribute is given. The value
is given as the # symbol followed by the name of the section.
90 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Activity 4.10
1. Create three HTML documents in the same folder. Then create a link in
each of the HTML documents to all the others so that one can access all
the pages by simply opening only one of them.
2. Create a webpage that has a content that is grouped into at least three
sections and then create:
a. a link at the end of each section to the top of the document.
b. a link at the beginning of each section to the beginning of all the
other sections. (Note that the top of the document will be the same
as the beginning of section one)
4.5. HTML Tables
An HTML table is used to organize data in terms of rows and columns. Tables are
one way of organizing contents or defining a layout for contents in a webpage. The
major HTML tags used for creating tables and their meanings are presented in the
following table.
Table 4.4 HTML tags used for creating tables
HTML Tags Meaning
<table> Used to define the tables
<th> Used to define table headers
<tr> Used to define table rows
<td> Used to define data cells
The number of rows of a table is determined by the number of <tr> elements that
the <table> has while the number of columns is determined by the number of <td>
elements that are found in each <tr>. The example in Figure 4.5 creates a table with
3 columns and 3 rows.
91 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
HTML Code
<table border=1>
<tr>
<th>Mountain Name</th>
<th >Elevation</th>
</tr>
<tr>
<td>Ras Dashen</td>
<td>4,620 m</td>
</tr>
<tr>
<td>Tullu Dimtu</td>
<td>4,377 m</td>
</tr>
<tr>
<td>Guge</td>
<td>4,200 m</td>
</tr>
<tr>
<td>Amba Alagi</td>
<td>3,949 m</td>
</tr>
</table>
Output on the Web Browser
Mountain Name Elevation
Ras Dashen 4,620 m
Tullu Dimtu 4,377 m
Guge 4,200 m
Amba Alagi 3,949 m
Figure 4.11 HTML table
92 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Note the following points from Figure 4.11:
• The table has a “border” attribute, which is assigned the value 1.
This adds a border to the table when displayed on the web browser as
shown in the example. If the border attribute is not used, the data will
be displayed in the same way but without a border.
• The information in the table is about some of the mountains found
in Ethiopia.
Activity 4.11
1. Design a table that should look like the following when displayed on the
web browser.
column 1 column 2 column 3 column
1 2 3 4
2 4 6 8
3 6 9 12
4 8 12 16
2. Modify the table you designed in the first activity so that the output on
the browser will look something like the one shown below.
column 1 column 2 column 3 column
row 1 1 2 3 4
row 2 2 4 6 8
row 3 3 6 9 12
row 4 4 8 12 16
When the layout of the table needs the merging of multiple columns or rows,
“colspan” and “rowspan” attributes can be used respectively. For example, the
HTML code in Figure 4.12 shows how two columns are merged both for the
“Cases” and “Deaths” data cells of the table.
4.4.2 Links to Page Sections p.99
93 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
HTML Code
<table border=1>
<tr>
<th></th>
<th colspan=2>Cases</th>
<th colspan=2>Deaths</th>
</tr>
<tr>
<th>Date</th>
<th >Total</th>
<th >New</th>
<th >Total</th>
<th >New</th>
</tr>
<tr>
<td>07/29/21</td>
<td>279,629</td>
<td>3,592</td>
<td>4,381</td>
<td>61</td>
</tr>
</table>
Output on the Web Browser
Cases Deaths
Date Total New Total New
07/29/21 279,629 3,592 4,381 61
Figure 4.12 Merging columns in HTML tables
94 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Note the following points from Figure 4.12:
• The first <th> of the first <tr> does not have data as shown in the
output.
• As the value given to the “colspan” attribute of the second and third
<th> of the first <tr> is 2, the “Cases” and “Deaths” columns span the
two columns under them.
• The data shown in the table is adopted from World Health Organization
and is about the spread of COVID-19 in Ethiopia.
The “colspan” and “rowspan” attributes can also be used to define the layout of
an entire page. The following HTML code generates a typical page layout with
Header, Sidebar, Content area, as well as Footer using an HTML table as shown in
the output of Figure 4.13.
95 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
HTML Code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table width= 100% >
<tr>
<td colspan= 2 height= 100px bgcolor= #666666 >
<h1>Website Logo</h1>
</td>
</tr>
<tr>
<td width= 20% bgcolor= #cccccc height= 300px >
<h3>Sidebar</h3>
</td>
<td width= 80% bgcolor= #eeeeee >
<h3>Content</h3>
</td>
</tr>
<tr>
<td colspan= 2 bgcolor= #777777 >
Footer
</td>
</tr>
</table>
</body>
</html>
Figure 4.13(a) HTML code for Page layout using tables
96 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Output on the Web Browser
Figure 4.13(b) Page layout using tables
Note the following points from Figure 4.13(a) and Figure 4.13(b):
• The “width” attribute is given the value 100% so that the table
occupies the entire width of the page.
• “px” stands for pixel.
• The “width” of the first <td> of the second <tr> is assigned 20% so
that the “Sidebar” occupies 20% of the width of the table. 80% of the
width of the table is occupied by the second <td> of the second <tr>.
• “colspan” attribute is used to merge the top and bottom rows of the
table.
Activity 4.12
• Create a table that has the following layout:
• The table should occupy the entire width of the page.
• The width of each of the first and third data cells of the second
row occupies 20% of the width of the table.
97 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
4.6. HTML Lists
HTML lists are used to present different types of lists. The types of lists are known
as ordered lists, unordered lists, and description lists.
4.6.2 Unordered List p.104
<ol> is the tag that is used to create ordered/numbered lists. The <li> tag, on
the other hand, is used to insert individual items into the list. By default, Arabic
numerals are used for ordering purposes in ordered lists. However, using the “type”
attribute the ordering type can be changed to some other form such as the English
alphabet. See Table 4.4 for the list of values that the “type” attribute can be assigned
to and their meanings.
Table 4.5 The “type” attribute and its values for the Ordered List
Value Meaning
1 Arabic numeral (Default)
I Upper-case Roman number
i Lower-case Roman numeral
A Upper-case English alphabet
a Lower-case English alphabet
The HTML code in Figure 4.15 shows an example of an ordered list, and what the
output on the web browser looks like. (The data refers to the top 10 causes of death
in Ethiopia. Source: World Health Organization 2018)
98 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
HTML Code Output on the Web Browser
<ol>
<li>Coronary heart disease</li> 1. Coronary heart disease
<li>Influenza and pneumonia</li> 2. Influenza and pneumo-
nia
<li>Diarrheal diseases</li>
<li>Stroke</li> 3. Diarrheal diseases
<li>Tuberculosis</li>
4. Stroke
<li>Road traffic accidents</li>
5. Tuberculosis
<li>Liver disease</li>
6. Road traffic accidents
<li>Diabetes mellitus</li>
7. Liver disease
<li>HIV/AIDS</li>
8. Diabetes mellitus
<li>Breast cancer</li>
</ol> 9. HIV/AIDS
10.Breast cancer
Figure 4.15 HTML Ordered List
Activity 4.13
1. Create an ordered list of the full names of your friends.
<ul> is the tag that is used to create unordered/bulleted lists. The <li> tag and the
“type” attribute are used similarly as they are used in ordered lists. The default
bullet type is “disc”. The “type” attribute is, therefore, used to change the default
type to any of the other types. See Table 4.5 for the list of values that the “type”
attribute can be assigned to and their meanings in unordered lists.
99 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Table 4.6 The “type” attribute and its values for Unordered List
Value Meaning
Disc (Default)
square
circle
As stated in Table 4.6, the default bullet type for unordered lists is
“disc”. In the example shown in Figure 4.9, however, the output
shows the list using the “circle” bullet type. That is because the type
is explicitly changed in the list as shown in the code.
HTML Code Output on the Web
Browser
” ” Save energy
<ul type= circle > o
<li>Save energy</li> Plant trees
<li>Plant trees</li> Reduce water
waste
<li>Reduce water waste</li>
<li>Avoid plastic wherever Avoid plastic
possible</li> wherever possible
</ul>
Figure 4.16 The “type” attribute in Unordered Lists
Activity 4.14
• By changing the value of the “type” attribute, design different types of
ordered and unordered lists.
100 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Lists can be nested. Any type of list can be placed under any other type of list. The
following example in Figure 4.17 shows how an ordered list can be nested inside
an unordered list.
HTML Code Output on the Web
Browser
<ul> • Actions one can
do to stop climate
<li>Actions one can do to stop
change
climate change
1. Save energy
<ol>
<li>Save energy</li> 2. Plant trees
<li>Plant trees</li> 3. Reduce water
waste
<li>Reduce water
waste</li> 4. Avoid plastic
wherever pos-
<li>Avoid plastic
sible
wherever possible</li>
</ol>
</li>
</ul>
Figure 4.17 Nested lists
In the HTML code of Figure 4.17, observe where the <li> of the <ul>
begins and ends. As you can see, the <ol> is embedded inside the <li>
of the outer <ul>.
101 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Activity 4.15
• Create the following list.
• Fruits:
Orange
Banana
Pineapple
• Vegetables:
Carrot
Cabbage
Onion
4.6.3 Description List p.108
In a description list, the <dl> tag is used to define the whole description. The <dt>
tag, on the other hand, is used to add the item that is to be described or defined.
The description or definition is added using the <dd> tag. See the example given in
Figure 4.18 to learn how the three tags are used together.
HTML Code Output on the Web Browser
Ol
<dl>
<dt>ol</dt> -Ordered list
<dd>-Ordered list</dd> ul
<dt>ul</dt> -Unordered list
<dd>-Unordered list</dd> dl
<dt>dl</dt>
-Description list
<dd>-Description list</dd>
</dl>
Figure 4.18 HTML Description List
Activity 4.16
• Create a description list for the dictionary definition of three of your
favorite English words.
102 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Unit Summary
In this unit, you have learnt about:
• what the Web is and its relationship with the Internet
• foundations of the Web, such as HTTP, HTML, web browser, and web
server
• what is meant by a website and its uses
• what is meant by website design
• some guidelines for website design
• the difference between website design and website development
• what HTML is and the structure of an HTML document
• HTML tags and HTML elements and their differences
• how to insert basic elements like images, videos, paragraphs, headings,
and the like on webpages
• HTML attributes and how they are used to control the properties of
HTML elements
• how hyperlinks are created using the anchor tag (<a>)
• how to use images as a hyperlink
• the difference between absolute and relative URL
• how links are created to different parts of the same page using the
anchor tag (<a>)
• how HTML tables are created to define the structure of data as well as
the layout of webpages
• the three types of lists namely, ordered lists (<ol>), unordered lists
(<ul>), and description lists (<dl>)
• how lists can be nested and how one type of list is embedded under
another type
103 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Key Terms
AAbbssoolluuttee URL is a URL that includes every element of a URL such as the
protocol, the hostname, as well as path of the webpage
Description lists <dl> are used to create description/definition lists
HTML attributes are used to define more properties to HTML elements
HTML elements are components of HTML documents that normally begin
with a start tag and end with an end tag
HTML tags are a set of predefined names enclosed in angle brackets
HTML is a language that is used to develop webpages
HTTP is a protocol that browser software and web server software used to
communicate with each other
Hypertext is a link that connects webpages
Ordered Lists <ol> are used to create ordered/numbered lists
Relative URL is a path given relative to the location of the current webpage
The Web is one of the popular services of the Internet
Uniform Resource Locator (URL) refers to the address of web resources
Unordered Lists <ul> are used to create bulleted lists
Void elements are HTML elements that do not have end tags
Web Browseris a software that is used to view webpages
Web Serveris a software that is used to manage websites
Webpage is a web document that can store text, images, videos, and the like
Website is a collection of interrelated webpages
104 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Web Development <Running Header>
UNIT-4 <Unit>-<No>
Review Questions
Part I: Write True if the statment is correct and False if it is incorrect.
1. The Web and the Internet are the same things.
2. The <head> and the <body> sections are the two major sections of HTML
documents.
3. “rowspan” is the attribute that is used to merge rows of a table.
4. “circle” is a valid value to the “type” attribute in ordered lists.
5. It is only texts that can be used as hyperlinks.
Part II: Match the items given under column B with associated items in
column A
A B
1. Internet service a. Web Browser
2. Section of an HTML document where b. The Web
actual content goes c. <body>
3. User or Client-side web software d. <h1>
4. An HTML element used to create e. <dd>
headings f. URL
5. Address of webpages g. HTTP
h. .html
i. Internet
6.1.1 Types of Programming Languages p.137
1. Discuss in groups the problems organizations face if they do not take
timely backup?
2. Form a group and maintain a computer that does not work entirely. Write
down the procedures you followed to identify the problem and fix the
problem. Share your experience with the class.
131 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
UNIT
FUNDAMENTALS OF
PROGRAMMING
Learning Outcomes
At the end of this unit, students will be able to:
Define computer programs
State and describe types of programming languages
Explain syntax and semantics of programming languages
Explain variables and data types
Differentiate the concept of statements and expressions in Python
Analyze simple programs written in Python
Write simple programs with input and output
Unit Overview
A computer program is a set of instructions that commands a computer what to do.
Computers do whatever task they do by simply following the instructions stated
in programs. This unit covers topics related to computer programs including
programming languages, syntax, and semantics. The high-level programming
language known as Python is used to demonstrate the basic concepts of
programming.
6.1. Types of Programming Languages
Brainstorming 6.1
How do computers do the types of tasks we observe them doing?
Programming languages are computer languages that are used to write different
types of computer programs. They are generally grouped into machine language,
assembly language, and high-level language.
132 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Machine Language
Machine language is a low-level computer language. It is a language in which
everything including instructions, numbers, and memory locations are represented
in 1s and 0s – binary system. Machine language is the language that computers
understand directly without any need for translation. That is why it is very fast and
uses memory efficiently. However, writing programs in machine language is very
difficult.
Assembly Language
Assembly language is also a low-level computer language but, instead of 1s and
0s, it uses symbols known as mnemonics. Though it is easier than using a binary
system, assembly language is still difficult.
Since computers do not directly understand any program outside the machine
language, programs that are written in assembly language require a special type of
software. This software is known as Assembler, and it is used to translate assembly
language instructions into machine language.
High-Level Language
High-level languages are closer to human languages compared to both assembly
and machine languages. This type of language allows programmers to focus more
on the problem they want to solve than on the programming language. Examples
of high-level programming languages include C, C++, Java, C#, Python, Perl, and
Ruby.
Just like assembly language programs, high-level language programs also cannot
be directly executed by the computer. The programs have to be first translated
into a machine language using translator software. Depending on the programming
language, the translator software can be either a Compiler or an Interpreter.
Compilers translate high-level language written programs all at once into machine
language. The machine language is then executed by the computer. Examples of
programming languages that use compilers are C, C++, Java, and C#.
133 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Interpreters, on the other hand, translate and execute programs a statement at a
time. They don’t translate the whole program together as do compilers. Examples
of programming languages that use interpreters include Python, Perl, and Ruby.
6.1.2 Syntax and Semantics p.140
Like any human language, all programming languages have syntax and semantics.
Syntax refers to the rules of the programming language. It defines the structure or
grammar of the language that programs should strictly follow. The semantics of a
programming language, on the other hand, is related to the meaning of elements of
a program and what they do.
A program must be written with the correct syntax dictated by the programming
language for the program to be executed by the computer. If a program violates any
of the syntax rules of a language, the compiler or the interpreter produces an error
message. Such type of error is known as a syntax error.
A program can have no syntax error and get executed properly but can still behave
in a way different from what it is intended to. This kind of error is known as logic
error and is associated with the semantics of a language. Since compilers or
interpreters do not catch logic errors, they are far more difficult to identify and fix
than syntax errors.
Links
See Section 6.2 for practical examples of syntax and logic errors.
Activity 6.1
1. Compare and contrast the three types of programming languages.
2. Why are logic errors more difficult to fix than syntax errors?
6.2. Basics of Python
Python is one of the popular high-level programming languages in use today. It is
widely considered a much easier language to learn. This is one of the main reasons
why it is a widely chosen language for teaching programming to those who are new
to programming.
134 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Python has a free integrated development environment known as IDLE. IDLE stands
for Integrated Development and Learning Environment. To write Python codes, the
interactive interpreter or the text editor of the IDLE can be used. The interactive
interpreter is used to write one line of Python code at a time and is less convenient
to write and execute a large number of codes. Using the text editor, however, any
number of codes can be written and get executed with a single command.
6.2.1 Using the Interactive Interpreter p.141
The Interactive Interpreter contains a Python shell, which is a textual user interface
used to work with the Python language. The Interactive Interpreter is displayed
when the IDLE is opened. Figure 6.1 shows the Interactive Interpreter.
Figure 6.1 IDLE Interactive Interpreter
Links
See Section 6.4 to learn about expressions in Python.
The >>> is where codes are written and is called the prompt. After
a user writes a code and presses the enter key, the prompt (>>>)
reappears for the user to write the next code.
The following example demonstrates what the Interactive Interpreter does when
the enter key is pressed after a simple expression is written.
135 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
5+6 is a syntactically valid expression that evaluates to 11. Therefore,
the Python interpreter evaluated the expression and displayed 11. If,
for example, a syntactically invalid expression like 5+ is given, the
interpreter generates the following syntax error:
To display something on the screen, the print() function is used in Python. The
following example shows how a string is displayed using the print() function.
Note that the IDLE uses different types of colors for the different
elements of a Python code to make them easily distinguishable. By
default, outputs are displayed in blue color; functions are displayed
in purple color, and strings are displayed in green color. A string is a
sequence of characters placed under quotation marks such as ”Hello
World” as can be seen in the above example. See Table 6.1 for more
on strings and operators in Python.
Links
See Section 6.5 for more on the print() function.
Activity 6.2
• Use the print() function and display your full name on the screen using the
interactive interpreter.
6.2.2 Using the Text Editor p.142
Python codes can be written in a file using the text editor of Python’s IDLE. The
code that is kept in such files is known as a script. A file that keeps Python scripts
is saved with the .py extension and is called a script file.
136 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Figure 6.2 Opening a Text Editor
A script file can be easily created by selecting “New File” from the “File” menu
in the IDLE’s interactive interpreter as shown in Figure 6.2. Then the text editor is
opened in a separate window, and it looks something like what is shown in Figure
6.3.
Figure 6.3 Python IDLE’s Text Editor
Note that the prompt (>>>) is not shown in the text editor. The >>>
appears only when code is written in the interactive interpreter, not in
the text editor. While only one line of code is written and executed in
the interactive interpreter, as many lines of code as required can be
written in the text editor.
The example shown in figure 6.4 is a script that calculates and displays the area of
a circle for a given radius value of 3. Before the script is run/executed, the script
has to be saved with the .py extension by selecting the “save” option from the “file”
menu in the text editor. To execute the script, the “Run Module” option from the
“Run” Menu should be selected. After the script is executed, the output is displayed
in the IDLE shell/interactive interpreter in a format as shown in the figure below.
137 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Python Script Output on the IDLE Shell
Figure 6.4 Running a script file
Note the following points from the script shown above:
There are four statements in the script. However, the script is executed
with a single command.
There is no prompt (>>>) in the script. The prompt is shown only in
the interactive interpreter.
Though there are four statements in the script, only one output is
shown in the IDLE shell. This is because it is only the last statement
that produces an output.
The output of a script written in the text editor is shown in the IDLE
shell or the interactive interpreter.
Links
The * is multiplication operator in Python and ** is exponentiation operator.
Operators are discussed in section 6.3
Links
See section 6.4 to learn about statements in Python.
The example in Figure 6.5 demonstrates a logic error that is related to the semantics
of programming languages.
Python Script Output on the IDLE Shell
Figure 6.5 Logic error
138 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Note that the area of a circle in the above example in Figure 6.5 is
incorrectly calculated as “area=PI*radius*2”. The correct formula for
the area of a circle is “area=PI*radius**2”. However, the interpreter
did not generate any error and simply displayed the incorrect output.
This is a logic error: even though the program does not have any
syntax error, it does not produce the intended correct output.
The * symbol serves as a multiplication operator in Python. Table 6.1
of this chapter has a list of operators in Python and examples of how
they are used.
Activity 6.3
1. What is the difference between Python’s interactive interpreter and text editor?
2. Use the print() function to display your full name on the screen using the text
editor.
6.3. Variables and Data Types
6.3.2 Identifier p.145
Variables are computer memory locations. They are the means to store data in
computer memory. A variable is used every time user data or intermediary data is
needed to be kept.
In Python, a variable is created along with its value. Values are assigned to variables
using the assignment (=) operator, which has two operands. The operand to the left
of the operator is always a variable while the operand to the right of the operator
is either a literal value or any other type of expression. The following example
demonstrates how a variable named “x” is created with the value 5 in the interactive
interpreter.
139 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
The example that follows shows how a variable named “y” is created and assigned to
the result of an expression. The value of “y” would be the sum of 5 and 9, which is 14.
Links
See section 6.4 to learn about expressions in Python.
To see the current value of a variable, you can simply type the name of the variable
and press the enter key in the interactive interpreter. The value will then be displayed
as shown in the following example.
The value 25 that is shown in blue color is the value of the variable y. Moreover, a
variable can be assigned to another value than the one it was previously assigned
to. The following example shows how the value of y is changed from 25 to 30.
The name that is given to variables is called an identifier. Identifiers are a string
of one or more characters and have to conform to some rules in Python to be
considered valid. The rules of identifiers are:
• The first character should be either a letter or an underscore ( _ ).
• If the identifier is made up of more than one character, the characters after the
first one should be a letter, number, or underscore.
• An identifier cannot be the same as any of the keywordsin Python. See Figure
6.3.3 Data Types p.146
• Identifiers are case-sensitive. (For instance, x and X are considered as
different identifiers in Python)
140 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
and del from not while
as elif global or with
assert else if pass yield
break except import print
class exec in raise
continue finally is return
def for lambda try
Figure 6.6 Keywords in Python
Keywords are reserved words that have predefined meanings in a
programming language.
According to the above rule, the following are valid identifiers:
area
area_5
x5
The identifiers given below, on the other hand, are not valid identifiers as they
violate the rules stated above.
1x
*_5
while
X_&
The first two identifiers begin with a character that is not allowed. The
third identifier used the name that is considered a keyword in Python.
The last identifier is invalid because its last character is not allowed to
be used in identifiers.
141 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Although meeting the above requirements suffices to define a valid identifier, it is
always recommended to use identifiers that are self-descriptive. Self-descriptive
identifiers are names that express what they are intended to be used for. Using such
types of identifiers makes programs more understandable and clearer.
Activity 6.4
• Identify the valid identifiers and explain why they are so.
a. x
b. 1x
c. _x
d. x*y
A data type is a classification that specifies the type of values a variable can have,
and the type of operations defined on the values. Integer (int), floating-point number
(float), string (str), and Boolean (bool) are some of the major built-in data types in
Python.
Floating point numbers are numbers with decimal points that
represent real numbers. See Table 6.1 for more on Python operators.
Built-in data types are data types that are built into the Python
language.
The data type of variables in Python is set when values are assigned to the variables.
If an integer number is assigned to a variable, the variable will be of type int. If a
string is assigned to a variable, the variable then will be of type str. The following
example in the interactive interpreter shows how data types are set to variables
based on the value assigned to the variables.
142 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
As you can see in the above example, string values should be placed
in quotation marks.
To learn the data type of a particular variable, the type() function
can be used. Simply write type(variable_name) and press enter. The
interactive interpreter displays the data type of the variable as shown
above. In the above example, the data type of the variable x is int
while the data type of the variable y is str.
The four major built-in data types in Python and their descriptions are given in
Table 6.1. The table also contains the various types of operators that apply to the
respective data types with examples of how the operators are used.
143 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Table 6.1 Data types
Data Meanings and Associated operators Sample expressions
Type sample values
Int Integer numbers Arithmetic operators
Example: • Addition (+)
34 • Subtraction (-)
4 • Division (/)
56 • Floor Division (//)
10 • Multiplication (*)
• Modulus (%)
• Exponentiation (**)
float Floating-point Arithmetic operators
numbers.
• Addition (+)
Example:
• Subtraction (-)
4.5
• Division (/)
10.6
• Multiplication (*)
100.0
• Exponentiation (**)
Str A sequence of Concatenation (+)
characters en-
closed in a dou-
ble quotation.
Example:
”Hello world”
Bool True or False Boolean operators
values.
• and
Example:
• or
True
• not
False
144 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Note the following points on some of the operators listed in Table 6.1:
The + operator behaves differently depending on the type of the operand.
When the operands are integer or floating-point numbers, the operator
serves as a normal addition operator known in mathematics. But
when the operands are strings, the operator serves as a concatenation
operator, which combines the strings given to it into one.
The modulus (%) operator returns the remainder of the division of the
left operand by the right one.
The floor division also known as integer division (//) operator divides
and returns only the integer value of the quotient. The division (/)
operator, however, generates the exact division result including the
6.3.4 Data Type Conversion p.151
fraction part if any.
The exponentiation (**) operator raises the left operand to the power
of the right operand.
Variables can be assigned to values of a different data type than the one they
were previously assigned to. Therefore, the value of a variable, as well as
its type, can be changed to something different from what it was first set to
in Python. As you can see in the following example, the variable “x” is first
assigned to a floating-point number. Then it is assigned to a string value
Hello . The second assignment results in a change not only in the value but
also in the data type of the variable.
145 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Activity 6.5
• Write the results of the following expressions.
a. 10%2 _
b. 2.5*3 _
c. 1/3 _
Type conversion is the process of converting the value of one data type to another.
Type conversion is of two types in Python: implicit conversion and explicit
conversion.
Implicit conversion is a type of conversion in which Python does the conversion
without the involvement of the programmer. This is usually done to avoid loss of
data. See the following example.
Note the following points from the above example:
The data types of x and y are int and float respectively as shown in the
example.
The variable z is assigned to the value of x+y, and its data type is
automatically set to float. This is because Python always converts
smaller data types (int in this case) to larger data types (float in this
case) to avoid data loss. If the data type of z is set as int, the value that
will be stored in it will not be the correct value.
146 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Explicit conversion is a type of conversion of one data type to another that is done
by the programmer. The predefined functions associated with the different kinds of
data types such as int(), float(), and str() are used for explicit conversion.
The syntax for conversion is given as follows:
<required_dataType>([value])
The following example demonstrates how Python responds to an attempt to add
string and integer variables.
As shown in the above example, Python does not allow adding an
integer number with a string. If the numbers stored in the integer and
the string variables are to be added up, an explicit type conversion has
to be used. See the following example to learn how the above error is
avoided using explicit type conversion.
147 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
As shown in the above example, the code did not generate any error
this time. This is because explicit type conversion is used to convert
the value of y to int type before it is added with the value of x.
Activity 6.6
• Write the expressions used to convert the value 1.5 into integer as well as
string values?
6.4. Statements and Expressions
A statement is an instruction that the Python interpreter executes. As discussed in
the introduction section, instructions are the orders or commands that the computer
follows to do something. Assignment and print() statements are the two types of
statements that are in some ways mentioned in the previous sections. An assignment
statement, for instance, assigns value to a variable while a print() statement displays
the value that is given to it. There are several other types of statements in Python
including the “if” statement, “while” statement, and “for” statement, which are
covered in the 12th Grade IT textbook.
The example in Figure 6.7 demonstrates the use of assignment and print() statements
in Python.
Python Script Output on the
IDLE Shell
x=5
y=10
print(x+y)
Figure 6.7 Assignment and print() statements
As you can see in the output in Figure 6.7, it is only the print statement
that produces an output. The two assignment statements simply assign
values to the variables and do not produce any output.
148 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Expressions are what the Python interpreter evaluates to produce some value. An
expression could be a simple literal value, a variable, or something more complex
which is a combination of literals, variables, and operators.
Table 6.2 shows the three types of expressions, and how they are used in assignment
and print() statements.
Table 6.2 Types of expressions
Literal value expresions Variable expresions Complex expresions
x=7 x=y x=4*(y-5)
y= Helo print(x) print(x+5)
6.3.4 Data Type Conversion p.155
z=5.5
print( Python )
Note that the expressions in the above table are those encircled with
red.
Using the print() and assignment statements, Figure 6.8 further shows the differences
and relationships between statements and expressions in Python.
Figure 6.8 Statements and Expressions
149 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
If an expression is typed into the interactive interpreter, the Python interpreter
evaluates and displays the value as shown in the following example.
However, if any expression is written in the text editor, it will not be
displayed unless it is put inside the parenthesis of a print() statement.
Therefore, to see the value of expressions on the screen while using the
text editor, the print() function has to be used.
Activity 6.7
1. What is the difference between statements and expressions in Python?
2. Identify the statements from the following list that produce outputs.
x=4*3
y=”Programming in Python is fun”
print(y)
z=x/2
print(z)
y=10
print(type(x))
3. When the code given in activity #2 is executed, what would be the out-
put on the screen?
150 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
6.5. Writing a Simple Program
Programs normally accept input and process the input to produce an output. As
shown in the preceding sections, the print() function is used to produce output
on the IDLE shell. As shown in multiple examples in the preceding sections, the
print() function has the following syntax:
print([value])
A function is a piece of code that performs some task and is called by its name. It
can be passed data as input to operate on, and can optionally return data as output.
print(), input() and type() are examples of functions.
In the above syntax, the name of the function is print. The value that is given to the
print() function as input can be any type of expression that evaluates to some value.
See the example in Figure 6.9 for the different types of values that the print()
function can take as input.
A function is a piece of code that performs some task and is called
by its name. It can be passed data as input to operate on, and can
optionally return data as output. print(), input() and type() are examples
of functions.
In the above syntax, the name of the function is print. The value that is
given to the print() function as input can be any type of expression that
evaluates to some value.
See the example in Figure 6.9 for the different types of values that the
print() function can take as input.
151 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Python script Output on the
IDLE Shell
x=6.5
print(5)
print(x)
print(x*5)
print( This is a string )
Figure 6.9 Inputs of the print() function
To accept input from the keyboard, the input() function is used. The input() function
has the following syntax.
variable_name=input([prompt])
The following points are important to understand how the input() function works:
The prompt that is given as input to the input() function is a string that
tells the user what kind of value the user is expected to enter. Example
“Enter an integer number”
After the user enters a value and presses the enter key, the input()
function returns the value the user entered as str type. This means that
irrespective of the type of value that the user enters, the value that
the input() function returns is of str type. Therefore, if the value that
is required is of another type, the str type should be converted to the
required type.
Example:
x=input(”Enter an integer number”)
x=int(x)
The value the input() function returns should be assigned to a variable.
This indicates that when the input() function is used, it is used as an
expression in an assignment statement.
152 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Activity 6.8
• Write a program in the text editor that has the following elements:
° Accept the name, age, and Body Mass Index (BMI) of a person
from the keyboard using the input() function,
° Convert the values to their appropriate data type , and
° Display the values using the print() function.
The following example demonstrates how the input() and the print() functions are
used in a program. It shows how the input() function is used to accept data from the
keyboard, and how the print() function is used to display the result on the screen.
The program simply accepts the radius of a circle from the user and displays the
6.3.4 Data Type Conversion p.159
area and circumference of the circle.
Python Script
PI=3.14
x=input( Enter the radius: )
radius=float(x)
area=PI*radius**2
circumference=2*PI*radius
print( The area of the circle is: )
print(area)
print( The circumference of the circle is: )
print(circumference)
Output on the IDLE Shell
Figure 6.10 Using input() and print() functions
153 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
The following points are important to note regarding the program shown in
Figure 6.10:
The prompt given to the input() function should be written in a manner
that helps the user clearly understand what to do.
The data type of the value that is returned by the input() function is
changed to float, which is the right data type for values like the radius
of a circle.
print() function displays its outputs in separate lines. Therefore, the
strings and the values are displayed each on a separate line.
In the example shown in Figure 6.10, a print() function is used to display each
output separately. However, if multiple values are required to be displayed in one
line, the values should be given to the print() function with comma separation. See
Figure 6.11 for the modified version of the program in Figure 6.10.
Python Script
PI=3.14
x=input( Enter the radius: )
radius=float(x)
area=PI*radius**2
circumference=2*PI*radius
print( The area of the circle is: , area)
print( The circumference of the circle is: , circumference)
Output on the IDLE Shell
Figure 6.11 Displaying multiple values in one line
154 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
As shown in Figure 6.11, the string literal values and the variables are
given to the print() function with comma separation. As a result, the
results are displayed in one line.
Activity 6.9
1. Write a program that accepts two numbers from the user and displays
the product on the screen.
2. Write a program that displays the BMI of a person by accepting the
weight and height from the keyboard.
155 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Unit Summary
In this unit, you have learnt about:
• what is meant by a computer program
• the three types of programming languages, namely, machine language,
assembly language, and high-level language
• translation software, such as Assembler, Compiler, and Interpreter
• the difference between compilers and interpreters
• the concept of syntax and semantics in programming languages, and the
associated error types
• what the high-level programming language called Python is
• how to write Python scripts using the interactive interpreter and the text
editor
• how to save Python script files and how to run the scripts
• the concept of variables and data types in Python
• valid and invalid identifiers
• the basic built-in data types
• assigning values to variables using an assignment operator
• operators, such as arithmetic operators (+, -, /, //, %, *, **), Boolean
operators (and, or, not) and assignment operator (=)
• conversion of values from one data type to another using explicit and
implicit type conversion methods
• the concept of statements and expressions in Python
• the differences and relationships between statements and expressions
• how to write a simple program by reading data from the keyboard using
the input() function and displaying results using the print() function
156 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Key Terms
AAsssseemmbblleerr is a software used to translate programs written in assembly
language into machine language.
Assembly Language is a low-level programming language that uses symbols/
mnemonics.
Assignment Operator (=) is an operator used to assign values to variables.
Binary System is a system in which everything is represented in terms of 1s
and 0s.
bool is a data type that represents True or False values.
Data type specifies the type of values a variable can have and the operations
defined on the values.
Explicit type conversion is a data type conversion done by the programmer
using built-in functions.
Expression is what the Python interpreter evaluates to a certain value.
float is a data type for floating-point numbers.
Floating Point Number is a number with a decimal point.
Function is a piece of code that performs some tasks.
High-level Language is a programming language closer to human language.
Identifieris the name of variables.
IDLE shell is the same as the interactive interpreter.
IDLE stands for Integrated Development and Learning Environment.
Implicit type conversion is a data type conversion done by Python without
the involvement of the programmer.
6.3.4 Data Type Conversion p.163
int is a data type for integer values.
Keywords are reserved words that have predefined meanings in Python.
Machine Language is a low-level programming language that the computer
understands directly.
157 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Program is aset of instructions that commands the computer what to do.
Programmer is a professional who writes computer programs.
Programming Languages are computer languages used to write computer
programs.
Python is a popular high-level programming language.
Python’s Interactive Interpreter contains Python shell to write and execute
Python codes one line at a time.
Python’s Text Editor is a text editor to write unlimited lines of Python codes
that can be saved.
Script file is a file with Python scripts.
Script is codes found in a file saved with .py extension.
Semantics is related to the meaning of elements of a program and what they
do.
Statement is an instruction executed by the Python interpreter.
str is a data type for strings enclosed with a double/single quotation.
Syntax is the grammatical rules of a programming language.
Type conversion is the process of converting values from one data type to
another.
Variable is a computer memory location used to store data.
158 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Review Questions
Part I: Write True if the statment is correct and False if it is incorrect.
1. A program written in assembly language can be directly understood by
the computer.
2. It is only high-level programming languages that have syntax and
semantics.
3. Syntax errors are easier to fix than logic errors.
4. Python’s interactive interpreter can be used to execute multiple lines of
codes at a time.
5. When Python’s text editor is opened, the prompt (>>>) immediately
appears.
6. Once a variable is set to a specific data type, its type cannot be changed.
7. The results of the two expressions 5/2 and 5//2 are not the same.
8. In implicit type conversion, the programmer has to use built-in functions
to convert values from one type to another.
9. The data type “bool” has only two possible values.
10.Expressions and statements are the same things in Python.
159 I NFORMATION T ECHNOLOGY G RADE 11 ~ S TUDENT T EXTBOOK PB
Fundamentals of Programming <Running Header>
UNIT-6 <Unit>-<No>
Part II: Match the items given under column B with associated items in
column A
A B
1. Rules of a language a. Interpreter
2. A keyword such as str b. Compiler
3. Name of variables c. Machine Language
d. Assembly Language
4. That which is evaluated to some value
e. Statement
5. Meanings of elements of a language
f. Syntax
6. 1s and 0s
g. Operator
7. Interface to work with Python language
h. Semantics
8. Mnemonics
i. IDLE shell
9. Translating the whole program
j. Identifier
10.Translating one line at a time
k. Type conversion
l. Data type
m. Expression
← መጻሕፍት