0% found this document useful (0 votes)
4 views61 pages

Ict 5 and 6

This document outlines a unit on Maintenance and Troubleshooting in an educational context, focusing on software installation, uninstallation, and troubleshooting techniques. It emphasizes the importance of preventative maintenance for computer systems to enhance security and efficiency. The unit includes practical scenarios, activities, and troubleshooting strategies for both personal computers and mobile devices.

Uploaded by

tsiond719
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views61 pages

Ict 5 and 6

This document outlines a unit on Maintenance and Troubleshooting in an educational context, focusing on software installation, uninstallation, and troubleshooting techniques. It emphasizes the importance of preventative maintenance for computer systems to enhance security and efficiency. The unit includes practical scenarios, activities, and troubleshooting strategies for both personal computers and mobile devices.

Uploaded by

tsiond719
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Ethiofetena.

com Ethiopian No 1 Educational Website

UNIT MAINTENANCE AND


TROUBLESHOOTING

5
Learning Outcomes
At the end of this unit, students will be able to:

„„ Practice installing and uninstalling software


„„ Explain software troubleshooting
„„ Describe network troubleshooting steps
„„ Identify network maintenance tools

Unit Overview
To ensure the safety and security of computer systems, every system user should
take preventative actions including software preventive measures. Software
preventive maintenance includes upgrading and installing software updates for
security and reliability purposes. With a strong software preventative maintenance
activity, time and money can be saved on one hand and failures can be reduced
on the other. In this unit, you will learn about the installation and uninstallation
of software, techniques used in software preventive maintenance, and basic
maintenance tools that can be applied in our day-to- task routines .

135 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

5.1. Install and uninstall software

Notes
„„ In this unit, most hands-on activities are prepared based on windows
based operating systems because of its user base and graphical based
ease to work functionality to meet the required competency. But other
operating systems can also function mentioned list of activities by
following respective instructions for each operating system. It is also
important to note that, there might be slight steps and functionality
differences even within same operating system versions. Students are
advised to refer the required steps and requirements based on types
of operating system and current software versions installed on the
computer devices.

Brainstorming 5.1

„„ Do you think the number and types of installed applications will have
an effect on the speed and efficiency of your computing devices?
Users are able to perform some truly wonderful things with their computers and
other digital devices. All of these activities including reading books, digital photo
editing, using online social media sites, playing computer games, video streaming
etc. are made possible by various kinds of software’s. You can use computers or
other handy held smart devices for even more activities by installing the required
applications thanks to the new software apps that developers are constantly
developing. Software can also be uninstalled when required following the proper
steps and instructions.

5.1.1 Installing Software


Installation, is basically the process of getting the program ready to run including
configuring hardware or software. It can also be referred as setup of computer
software which includes device drivers and software plugins.

A device driver is a special kind of software program that controls a specific


hardware device attached to a computer. Appropriate device drivers are essential

136 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

for devices to work properly on a computer with corresponding devices.

Steps for installing computer programs.

You can purchase a software program from software stores or galleries, download
it from the source, it can be shipped to you. Software comes on CD, DVD, or USB
flash disks. It is also common to download application software’s for smart devices
(Smart Phones, Smart Watches, Personal Digital Assistances, Smart TV and more)
from software’s stores like Apple (App) store, Google play store, Amazon App
store, Samsung Galaxy Apps, Huawei App store etc. In all cases, please make sure
to download or receive all software’s from reliable and trusted sources only to
protect your machines from malicious software’s.

Links
Refer Unit 5 of the Grade 10 IT Textbook Information and Computer Security
to revise concepts related to protecting computing machines from malicious
software’s.

Scenario 1: Installing software’s on personal computers

Step 1: Insert the installation CD /DVD into the PC’s optical drive or insert the
USB drive on the USB port.

Step 2: Run the installation program.

The installation program runs automatically when you insert the disc (See Figure
5.1), or, you see the AutoPlay dialog box, from which you can choose the Install
or Setup command. If the installation program does not run automatically, follow
these sub-steps :
• Open the Computer window

• Right-click the drive’s icon.

• Choose from the menu the command


Install or Run Program from your
media. If that command is not avail-
able, choose the AutoPlay command.

Figure 5.1. AutoPlay Box

137 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

Step 3: Follow the instructions on the screen.

Read the information carefully; sometimes they slip something important in there.

You may also be hit with a User Account Control (UAC) warning here. If so, type
the administrator password or click the Yes or Continue button to proceed.

Users have to agree to abide by the software license. The software may ask for a
serial number. It can be found somewhere inside the box, in the manual, or on a
piece of paper or on shipment email if it is purchased from online stores. If you are
asked to, replace one disc with another. This process may go on for some time. You
may also need to identify and locate the place to install the files in.

Step 4: Wait for the Installation program to end. You see a message telling you
whether the installation is successful or not.

Step 5: Close the installation program window.

Step 6: If prompted, restart Windows.

Step 7: Start using the program

Notes
„„ The above steps are for Windows operating systems; other operating
systems including Unix/ Linux, Mac etc. have their procedure that you
need to follow while installing software.

Scenario 2: Installing software’s on Mobile Devices

Worldwide, mobile devices has grown significantly, creating new paths for
communication for individuals. Its acceptance has allowed increased access to
public information and fundamental services to people irrespective of time and
location powered by numerous apps and gadgets. This requires the right skill and
attitude to select, install and use application software’s.

It is so important to find the right source before downloading any apps on our mobile
devices (Android, Apple or other devices). You can download no-charge and paid
apps from application stores based on your device operating systems. You can also
download apps form other unknown sources on the internet when necessary. Please
use an internet and browse the appropriate app stores to download apps to mobile
devices (android / non android based mobile devices ) and other smart devices.

138 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

Notes
„„ Your phone and personal information may be subject to damage if you
download apps from unknown sources. This includes the possibility of
data loss or damage to your phone, as well as the obvious possibility of
damage or hacking to your personal information. Review your phone’s
security settings, which scan for potentially harmful apps, alert you
when one is found, and delete the program if necessary.

Activity 5.1
1. What are major issues that should be checked before installing
software’s on our computers or other mobile devices?

2. Based on your previous experiences with installing applications,


discuss which steps were different, and reasons for differences if any.

3. Select one application software that can be used to improve your


digital literacy skills and install it to available device (computers or
mobile devices). Share the procedures to get source of the software
and followed installation steps during installation.

5.1.2 Uninstalling Software

Uninstalling unused or unwanted programs can help your computer in various


ways. It can optimize hard drive spaces and increases computer speed.

Software installed on computers or mobile devices must be properly uninstalled


and users should know the reasons to un install the software program before taking
actions. This becomes so important when it applies on computer and other devices
which belongs organizations, schools, libraries and computer laboratories where
different types of users appears with their own software requirements. This also
applies when you use other individuals’ personal devices including your friends
and families. It is recommended to consult computer technicians or owner of the
devices before making any software uninstallation process .

139 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

Scenario 1: Uninstalling software’s on personal computers

Here is how it works:

o Open the Control Panel.

o Click the link Uninstall a Program, found beneath the Programs heading.

o The Programs and Features window appears. It lists all software installed
on your PC.

o Select the program you want to uninstall.

o Click the Uninstall/Change button on the toolbar.

o If prompted by a User Account Control, type the administrator password or


click the Continue button.

o Continue reading the instructions on the screen to uninstall the program.

Figure 5.2. Software Uninstall process on Windows


The uninstall directions vary from program to program, but eventually, the
program is removed.
Scenario 2: Uninstalling software’s on Mobile Devices

You can uninstall or delete apps you have installed on your mobile phone. You
can also disable system apps that came with your phone.

140 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting
There are few steps to uninstall apps or delete apps on our mobile devices and
it is some what similar for most phones operate with different mobile operating
systems including Android, Window, Samsung, Apple, Blackberry and more.
Commonly, you can easily uninstall from manage apps and devices setting of the
device, taping the name of the apps to delete and then, uninstall. Most users also
choose to swipe up on the screen to access the apps, then long press the app icon
for more options and select Uninstall.

Activity 5.2
1. Discusses the moments and reasons you plan to uninstall computer
applications based on your previous experience.

a. What are the major reasons for uninstalling the apps?

b. List steps you followed and is there any difference from what
is stated above? What do you think are the reasons for these
differences?

2. Consult your IT teachers and make a review of installed applications


in your computer laboratory and identify potential applications that
could to be uninstalled to optimize the computer performances.
Present your lists and recommendations for the class.

3. Have you ever tried to uninstall some applications on your mobile


devices but you can’t make it? Share your experiences among your
classmates. Why do you think you can’t uninstall some apps on
mobile devices?

141 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

5.2. Software Troubleshooting

Brainstorming 5.2

„„ What would you do if you opened your computer and discovered that
you lost all of your files?

Troubleshooting is a systematic approach to locating the fault and identifying the


cause of the fault in a computer system.

In the case of computer systems, the term troubleshoot covers both hardware and
software issues. Hardware troubleshooting includes identifying and fixing the
problems when the hardware devices like mice, monitors, printers, modems, etc.
are malfunction. Software
troubleshooting includes identifying
and fixing problems encountered
while working with the operating
system and application softwares. It
also includes protecting our computer
systems from malicious damages
including viruses and worms. Figure 5.3: Hardware Troubleshooting

Not all troubleshooting


processes are the same, and
all users tend to refine their
troubleshooting skills based
on knowledge and personal
experience to manage some
common issues that can be
fixed even in the absence
of professional technicians.
Troubleshooting is a learned Figure 5.4: Software Troubleshooting
skill.

142 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

Activity 5.2
1. Assess the most common software problems caused by viruses and
worms and present your findings to the class.

2. What can you do if your computer become completely unresponsive,


or frozen and you will not be able to click anywhere on the screen,
open or close applications, or access shut-down options ? Discuss the
possible causes for the problem and possible solutions with your pair
and present your findings to class.

Even though there are constantly new software and IT issues emerging, the bet-
ter you understand these issues, the simpler it will be for you to fix them. Office
systems can be slowed down by corrupted software and incorrect software, which
can cause delays, general inefficiencies, and a lack of productivity. Let us see few
common software problems with their possible troubleshooting techniques.

Example 1 - An application is running slowly or application frozen

Possible Solutions: The first step to try is to close and reopen the application. If
the problem persists, update the application. To do this, click the Help menu and
look for an option to check for Updates. If you don’t find this option, another idea
is to run an online search for application updates (See Figure 5.5).

Figure 5.5 Window Update


Similarly, sometimes an application may become stuck, or frozen. When this
happens, you will not be able to close the window or click any buttons within the
application. This can be solved with force quit the applications. On a computer,
you can press (and hold) Ctrl+Alt+Delete (the Control, Alt, and Delete keys) on

143 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

your keyboard to open the Task Manager (See Figure 5.6) under the Processes tab,
click the frozen application and click the End Task button. If you are unable to
force quit an application, restarting your computer will close all open apps.

Figure 5.6 Task Manager

Example 2 - All programs on the computer run slowly or computer is frozen

Possible Solutions: You may have malware running in the background that is
slowing things down which needs a virus scanner with anti-virus or anti malware
software’s. Beside this, your computer may be running out of hard drive space
which needs deleting any files or programs you do not need. If you are using a PC,
you can run Disk Defragmenter and see the available disk spaces and fragment the
disk space. You will learn how to disk defragment later in this unit.

Example 3 - The sound is not working

Possible Solutions: First, check the volume level. Make sure the sound is on and
the volume is up, then click the audio button. It’s also a good idea to check the
controls on the audio player. There are many players that include separate audio
controls for audio and video. Ensure that the player’s volume is set to the highest
setting and that the sound is switched on. Check that external speakers are plugged
in, switched on, and connected to the appropriate audio port or a USB port if the
issue persists (See Figure 5.7). Make sure the wireless headphones are successfully
paired and connected in this scenario. Sound drivers’ difficulties can also be related
to the other prevalent causes. The driver version you have should be shown in
device management. Next, carry out a manual update push. When you’ve found the
audio driver, right-click it and choose Update Driver if it hasn’t already been

144 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

updated; if not, acquire the most recent sound driver for the current operating
system version from reputable sources.

Figure 5.7: Headphone plugged into laptop

Activity 5.3
• Identify possible solutions for computers with black screen

• What are the possible solutions for this problem?

Tip

If you have not been able to solve your challenge, you may need to ask for assistance
from others. Using the Internet is recommended as a starting point. It is likely that
other people have likely encountered similar issues, and solutions are frequently
shared online. Also, if you have a friend or family member who is knowledgeable
about computers, he or she may assist you, so you do not afraid to ask.

Generally, any issues can arise anytime and therefore you should know how to
avoid any problem from happening as part of preventive maintenance . But when
happened, knowing where to start troubleshooting can save you lots of time.
Most problems are software problems. Some are definitely hardware problems.
And some can be caused by one or the other. Sometimes, our software problem
can be easily resolved by running a repair utility or uninstalling and reinstalling.
It is always appreciated to know the proper troubleshooting skills to save out
time and resources. Internet can be a good resource to see similar problems and
proposed solutions for most problems easily to start with. This will also help you

145 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

to acquire better digital literacy skill which is one of the fundamental 21st skill
set for all professionals at all disciplines. Other problems may need professional
experts support to fix and maintain problems, so it is recommended to consult those
professionals and technicians based on the level of the problem and your ability to
fix it by your own.

5.3. Tools to speedup computer system

Brainstorming 5.3

„„ How does installing window updates in regularly help to maintain the


computer health and functionality?

The system tools for computer maintenance are:

• Disk defragmenter tool

• Disk cleanup tool

• Windows update

5.3.1 Disk Defragmenter

Over time, your disk may be fragmented. By fragmented disk, we mean files are
broken and stored in unmanaged space of the disk and hence the computer becomes
slow to bring the fragments together in order to open the files.

Disk Defragmenter is a system tool used to rearrange the files on the disk.
Defragmentation reduces file system fragmentation and, increases the efficiency
of data retrieval and thereby improves the overall performance of the computer. It
rearranges all the files so that each file is stored in one sequence (See Figure 5.8).

146 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

Figure 5.8. Disk Defragmenter


Notes
„„ Type ‘Disk Defragment’ on your window search box to access it.

5.3.2 Disk Cleanup

Disk Cleanup system tool deletes all the unused


and unwanted files on the hard disk to free some
disk space. The hard disk contains many files
that are unnecessary after a certain amount of
time, but they still reside on the disk. These need
to be removed manually, or an automatic Disk
Cleanup program can be scheduled (See Figure
5.9). Disk Cleanup deletes all of your unused
and unwanted files. It also deletes your garbage
and old Internet files. It should be performed
weekly.

Figure5.9. Disk Cleanup

Notes
„„ Type ‘Disk Cleanup’ on your window search box to access it.

147 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

5.3.3 Windows Update


Windows update ensures that your computer is up-to-date with new features and
the latest security. This
feature needs a connection
to the Internet. It connects
to the Microsoft server and
downloads and installs the
updates on the system. You
can click on the Windows
Update icon in the Start
menu and click on the
Download update to get the
updates (See Figure 5.10).

Figure 5.10. Window Update

Notes
„„ Type ‘Window Update’ on your window search box to access it.
There are also additional techniques to maintain the computer

Check disk

Check disk fixes the errors on your computer


when you are having problems or receiving
errors. This should be run every week just to
ensure that your computer is error free even if
you are not having any problems. You can start
the scan disk wizard, by clicking on the C drive,
selecting properties from the menu, and then
selecting the Check button (See Figure 5.11).

Figure 5.11. Disk Checkup

Notes
„„ Type ‘Disk Checkup’ on your window search box to access it.

148 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

Close Unwanted Programs

Sometimes there are programs that you do not want to run anymore or programs
that get halted due to some problems. Although the best way to close a program is
to choose the ‘Close’ or ‘Exit’ command from the ‘File’ menu but there is another
way of closing it.

Pressing the ‘Ctrl+Alt+Delete’(See Figure 5.13 )keys simultaneously brings up


the Close Program dialog box as illustrated below. You can close the program you
want to close from it, by choosing it and then pressing the ‘End Task’ button as it
can be seen in Figure 5.12. The program is closed at once.

Figure 5.13: Opening Task Manager

Figure 5.12. Window Task Manager

Activity 5.4
• Practice the windows operating system’s built-in system tools
including disk defragmentation, disk cleaning up, and cleaning
unwanted programs in your computer laboratory activities.

149 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting
5.3.4 System Restore

System restore is a system tool that is used to create a new restore point or to restore
the system to a previous restore point. It makes a secure copy of the system settings
when it is functioning normally, which is useful in case the system malfunctions.

Whenever you install a new software, it is always advisable to save the setting of
the system so that at a later stage if the system malfunctions, then that saved copy
of the system, can be restored. It helps in getting the system up and running for
use. To make a restore point, choose the System Restore from the Start->Programs-
>Accessories->System Tools->System Restore. To restore the system to a previous,
restore point and, follow the same steps, but just choose to restore rather than make
a new restore point.

Common problems and solutions

Table 5.1. Common Computer problems and solutions

Problem Solution
Slow Computer Disk Cleanup

Disk Defragmentation

Close programs

Possible risk of virus run an Antivirus program


Frozen screen Close programs

System restores

Restart your computer

Check disk

Activity 5.5
• Mention major system tools that are used to speed up computer sys-
tems and explain their benefits.

150 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

5.4. Network Troubleshooting

Brainstorming 5.4

„„ What are the possible causes for Internet network disconnection?

Two or more computers connected together to share resources (such printers and
scanners), exchange files, or enable electronic communications make up a network.
A network’s connections to its computers can be made by cables, phone lines, radio
waves, satellites, or infrared laser beams.

The collection of techniques and procedures used to locate, analyze, and fix issues
in a computer network is known as network troubleshooting. Network engineers
and technicians use a logical procedure to fix issues with networks and enhance
network performance.

When you run a network or while working in any system, there are always chances
of failure in the smooth operation owing to technical, physical, or any other faults.
For the uninterrupted running of the system, you need to resolve these raised issues
as soon as possible. Therefore, you need to detect the cause of the problem first
and then fix it. The process of detection, minimization, and resolving the faults that
arise in the network while performing the various day-to-day activities is known as
network troubleshooting.

Because of the variety of network hardware, network configurations, operating


systems, and setups, not all the following information may not apply to your network
or operating system, but it is recommended to check the following common issues
in network troubleshooting

Notes
„„ Network problems happen when something disrupts the connection
between your computer and the content you are trying to access.

151 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

Figure 5.14: Common Network problems cable problem,


switch failure, modem failure and Wi-Fi router failure

5.4.1 Basic Network Problems


Network problems include slow transmission of data and no connection at all.
The problem can be caused by the following:

Cable Problem: The cable which


is used to connect two
devices can get faulty,
shortened, or can be
physically damaged (See
Figure 5.15).

Figure 5.15: Cable problem

Connectivity Problem: The port or interface on which the device is connected or


configured can be physically down or faulty due to this the source host can
not communicate with the destination host.

152 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

Figure 5.16: LAN ports

Out of Reach Issue: with wireless networks, the wireless host may be too far from
the access point, or there could be an obstructing object between the access
point and the wireless host.

Configuration Issue: Due to a wrong configuration such as; routing problem, and
other configuration issues, network fault may arise and the services can be
affected.

Software Issue: Owing to software compatibility issues and version mismatch,


the transmission of IP data packets between the source and destination is
interrupted.

Traffic overload: If the link is over-utilized, then the capacity or traffic on a device
is more than its carrying capacity, and due to overload conditions, the
device can start behaving abnormally.

5.4.2 Basic Network Troubleshooting Steps

The first step of solving a network problem is finding the source of the problem.
Network problems are caused by a part of the network you control or outside
your control. We assume that you control your local network and do not control
anything beyond that. The way you solve the problem depends on whether or
not you control the failing part of the network. You can solve the local network
problems by yourself because you control the network. Outside network problems
require help from whoever runs that network.

153 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

Activity 5.6
Write the meaning of local network and outside network

• Give an example of a local network and an outside network based


on your context.

• Who manages the outside network in your geographical location?

Network troubleshooting is a repeatable process, which means that you can break
it down into clear steps that anyone can follow (See Figure 5.17).

Figure 5.17: Basic Network Troubleshooting steps

• Identify the Problem

As discussed earlier, the first step in troubleshooting a network is to identify the


problem. As a part of this step, you should do the following.

o Gather information about the current state of the network using


the network troubleshooting tools that are available to you.

o Duplicate the problem on a test piece of hardware or software, if


possible. This can help you to confirm where your problem lies.

o Ask users on the network to learn about the errors or difficulties


they have encountered.

154 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

o Identify the symptoms of the network outage. For example, do


they include complete loss of network connection? Does it slow
behavior on the network? Is there a network-wide problem, or are
the issues only being experienced by one user?

o Determine if anything has changed in the network before the


issues appeared. Is there a new piece of hardware that is in use?
Has the network taken from new users? Has there been a software
update or change somewhere in the network?

o Define individual problems clearly. Sometimes a network can


have multiple problems. This is the time to identify each issue so
that your solutions to one is not bogged down by other unsolved
problems.
• Develop a Scenario

Once you have finished gathering all the information that you can about the network
issue or issues, it is time to develop a working scenario. Sometimes a network
outage occurs because someone tripped on a wire or some other simple problem.
• Test the Scenario

Using the tools at your disposal, test your scenario. If your scenario is that the
network router is defective, try replacing it with another router to see if that fixes
the issue.

Notes
„„ At this stage, it is important to remember that proving your own
theories wrong does not mean that you have failed. Instead, you return
to step two, develop a new scenario, and then find a way to test that
one.
• Plan of Action

Come up with a plan of action to address the problem. Sometimes your plan can
include just one step. For example, restart the router. In other cases, your plan can
be more complex and take longer, For instance, when you need to order a new part
or roll a piece of software back to a previous version on multiple users’ computers,
you need more steps.
155 Information Technology radeG12 ~ Student Textbook
Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting
• Implement the Solution

Now you have a plan for fixing the network, it’s time to implement it. There are
some solutions that you may do by yourself, while others may require cooperation
from other network experts or users.
• Verify System Functionality

Make sure that the issue in question has been resolved, but there is also on the
lookout for other issues that may have arisen from the changes that you have made
to the network.
• Document the Issue

Make sure to document each stage of troubleshooting the problem, including the
symptoms that appeared on the network, the scenario you developed, your strategy
for testing the scenario, and the solution you have come up with to solve the issue.
Even if you do not reference this documentation, it may be helpful to other network
technicians, students, or users at your school, home, or organization in the future
and could help to shorten network downtime.

5.4.3 Network Troubleshooting Tools


When it comes to identifying and resolving network issues, you can utilize a variety
of methods. These tools may be built into the operating system of the computer,
available as stand-alone software programs, or available as hardware devices that
you can use to troubleshoot network issues. In this sub-unit, tools that exist in your
operating systems and network maintenance hardware tools are discussed.

5.4.3.1 Command-Line Tools


On Windows PCs, the command prompt can be accessed by searching for it in the
start menu or by typing “cmd” without the quotation marks into the Run
Window (See Figure 5.18).

Figure 5.18: Windows Command Prompt

156 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

The following commands can be entered into the command prompt one at a time to
reveal specific information about the network status:
ipconfig — A Windows Transmission
Control Protocol /Internet Protocol
(TCP/IP) utility that verifies network
settings and connections. It can tell
you a host’s IP address, subnet mask,
and default gateway, alongside other
important network information. Figure 5.19: ipconfig command

ping — A TCP/IP utility that transmits a datagram to another host, specified in the
command. If the network is functioning
properly, the receiving host returns the
datagram. See the fig 5.20 which shows
ping the default gateway which is
192.168.0.1 in this case. Check your
own default gateway and apply ping
Figure 5.20: ping command
command to see the results.
tracert —A TCP/IP utility that determines
the route data takes to get to a particular
destination. This tool can help you to
determine where you are losing packets
in the network, or helping to identify
problems.
Figure 5.21: tracert command

nslookup — A domain Name System (DNS) utility that displays the Internet
Protocol (IP) address of a hostname or vice
versa. This tool is useful for identifying
problems involving DNS name resolution.
See Fig 5.22 which shows google dns ip
address (8.8.8.8) with nslookup command.
Figure 5.22: nslookup command

netstat — A utility that shows the status of each active network connection. This
tool is useful for finding out what services are running on a particular system.

157 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

Notes
„„ In practice, there are many command line tools used for network
troubleshooting for different operating systems including the windows
operating system. You can search online to get, learn and apply different
commands. Those mentioned commands for windows operating
system, are subject to change when you need to apply to another
operating systems like that of Linux/ Unix or Macintosh. Please browse
the equivalent commands based on device own operating system if
any. .

Activity 5.7
Practice the most common network troubleshooting command tools
including; ‘ipconfig’, ‘ping’, ‘tracert’, ‘netstat’ and ‘nslook’ up in the
windows operating system, but do not be limited to these tools.

• Record your results

• You can use Google’s primary DNS server which is 8.8.8.8 to


practice ping command or you can practice the command using
your school Internet default gateway if applicable.

Notes
„„ You can get your device default gateway from your ipconfig command
practice using cmd. Please also note that the IP address mentioned
above can be changed due to server address changes by their respective
service providers.

In addition to command-line tools, several standalone applications can be used


to determine the status of a network and troubleshoot issues. Some of these
applications include packet sniffer, port scanner, protocol analyzer, Wi-Fi analyzer,
and more.

5.5. Network Maintenance Tools

Command-line tools and applications are software tools for troubleshooting,


but some network problems have hardware causes and solutions. Here are some
hardware tools that can help you diagnose and fix network issues:

158 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

Wire Crimpers - A wire crimper (sometimes


called a cable crimper) is a tool that attaches media
connectors to the ends of cables. You can use it to
make or modify network cables (See Figure 5.23).

Cable Testers — A cable tester (sometimes called Figure 5.23: Wire Crimper
a line tester) is a tool that verifies if a signal is
transmitted by a given cable. You can use one to
find out whether the cables in your network are
functioning properly when diagnosing connectivity
issues (See Figure 5.24).

Punch Down Tool — A punch-down tool is used Figure 5.24: UTP cable tester
in a wiring closet to connect cable wires directly
to a patch panel or punch-down block. This tool
makes it easier to connect wires than it would be to
do it by hand (See Figure 5.25).

Figure 5.25: Cable Puncher


Tone Generator — A tone generator is a device
that sends an electrical signal through one pair
of UTP wires. You can use these tools to verify
that signals are passing through the wires in your
network. They are often used to confirm phone
connectivity ( See Figure 5.26).

Figure 5.26: Tone Generator

159 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-5 Maintenance and Troubleshooting

Multimeter —is an electronic measuring instrument that takes electrical


measurements such as voltage, current, and resistance. There are hand-held
multimeter for fieldwork as well as bench-top models for in-house troubleshooting
(See Figure 5.27).

Figure 5.27: Multimeter

Unit Summary
In this unit, you have learnt about:

• common steps of installing and uninstalling software


• basic preventive maintenance and fundamentals of software
troubleshooting concepts
• common software-related problems and their alternative solutions
• basic tools to speed up computer system
• issues in system restore
• network troubleshooting and basic troubleshooting steps and tools
• common network troubleshooting applications and hardware
maintenance tools

160 Information Technology radeG12 ~ Student Textbook


Disk defragmentation - is the process of reorganizing the data stored on the
Ethiofetena.com Ethiopian No 1 Educational Website
hard drive so that related pieces of data are put back together, all lined up in
UNIT-5 Maintenance and Troubleshooting
a continuous fashion.
Disk Cleanup - Disk Cleanup helps free up space on your hard disk, creating
Key Terms
improved system performance. Disk Cleanup searches your disk and then
Disk
showsdefragmentation
you temporary files,- is the processcache
Internet of reorganizing the data stored
files, and unnecessary on the
program
hard driveyou
files that so can
that safely
relateddelete.
pieces of data are put back together, all lined up in
a continuous fashion.
Windows Update- keeps your computer up to date with security and bug
Disk Cleanup - Disk
fixes automatically, Cleanup
with helpson
little effort free up space
your on your
end. This hardyour
protects disk,computer
creating
improved system
from malicious performance.
software and fixesDisk Cleanup
known Windows searches
bugs your disk issues.
and other and then
shows you temporary files, Internet cache files, and unnecessary program
Installing software - is the act of making the program ready for execution.
files that you can safely delete.
Uninstalling Software – is a process of removing a program from your
Windows Update- keeps your computer up to date with security and bug
system which you previously installed in your system.
fixes automatically, with little effort on your end. This protects your computer
System Restoresoftware
from malicious - is a feature in Microsoft
and fixes Windows
known Windows thatand
bugs allows
otherthe user to
issues.
revert their computer’s state (including system files, installed applications,
Installing software - is the act of making the program ready for execution.
Windows Registry, and system settings) to that of a previous point in time,
Uninstalling Software
which can be used – is from
to recover a process
systemof malfunctions
removing a program from your
or other problems.
system which you previously installed in your system.
Troubleshooting - is a systematic approach to locating the fault part and
System Restore
identifying - is aoffeature
the cause the faultin in
Microsoft
a computerWindows
system.that allows the user to
revert their computer’s state (including system files, installed applications,
Network troubleshooting – is the act of discovering and correcting problems
Windows Registry, and system settings) to that of a previous point in time,
with connectivity, performance, security, and other aspects of networks.
which can be used to recover from system malfunctions or other problems.
Troubleshooting - is a systematic approach to locating the fault part and
identifying the cause of the fault in a computer system.
Network troubleshooting – is the act of discovering and correcting problems
with connectivity, performance, security, and other aspects of networks.

161 InformatIon technology grade 12 ~ Student textbook

161 InformatIon technology grade 12 ~ Student textbook


Ethiofetena.com Ethiopian No 1 Educational Website

UNIT FUNDAMENTALS OF
PROGRAMMING

6
Learning Outcomes
At the end of this unit, students will be able to:

„„ Explain program flow controls


„„ Describe conditionals program flow control
„„ Describe iteration program flow control
„„ Construct program statements using control statements
„„ Appreciate Python interpreter using Integrated Development
Environment(IDE)
„„ Analyze program statements in debugging mode
Unit Overview
A software program is written using a programming language. More than a
hundred programming languages have been introduced since the introduction of
the computer. Programming languages are designed with a specific purpose. Like
human languages, programming languages have their own specific set of rules
called syntax, which define how to write instructions in that language. Python
relies on indentation to define scope and uses new lines to complete a command.
The semantics of a Python program refers to the meaning of the set of rules.
In Grade 11, you were introduced to programming language and its generation,
basic syntax in python, and program writing.

In this unit, additional language constructs and concepts that can help you
develop a program in Python are introduced. First, Python for program flow
controls, conditionals, and loop statements are discussed followed by comments,
which enable you to provide some text description about your program. Finally,
interpreter and debugging the Python program are discussed.

164 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

6.1. Program Flow Controls and Syntax in Python

Brainstorming 6.1

„„ In what order do instructions in a Python program execute?

A program flow control is the order in which the program’s code executes. In
Python, the flow control of the program is regulated by the implementation of three
types of programming language constructs or program logic, namely sequential,
branching, and loop. The sequential flow control consists of a simple list of
statements that are to be executed in the order given. Everything you learnt about
declaring variables, printing output, and reading input from the keyboard in Grade
11 are sequential statements. In this unit, the implementation of the remaining two
language constructs: conditional and loop flow controls are focused.

Activity 6.1
• Discuss the three types of programming language constructs and
connect them with real-world problems.

6.1.1 Conditionals Program Flow Controls

Brainstorming 6.2

„„ “If it rains, then I will take an umbrella.” – what type of statement is


this?

In some cases, you may need a program to choose one out of two or more alternatives,
depending on the input given. For example, suppose you design a program that
determines whether the given number is even or odd. An even number is a number
divisible by two without a remainder, whereas an odd number is divisible by two
with a reminder. We can describe the problem with the following mathematical
equation which is called expression in python.
• num % 2 = 0  num is Even, for num any integer number.
• num % 2 ≠ 0  num is Odd, for num any integer number.

165 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

A given integer number is either even or odd (i.e. two possible options), but this
can be decided based on the remainder after dividing the number by two. Python
provides conditional or branching statement to implement such solutions. Before
starting conditional statements, it is important to learn conditional expressions in
Python.

Conditional Expression

Conditional expressions are statements that use Boolean operators (such as


AND, OR, NOT) or comparison operators (such as >,<. ≠). Like in mathematics,
comparisons of two values in Python are described with comparison signs used
in mathematics. Table 6.1 below presents comparison expressions in Python and
Mathematics.

Table 6. 1 Conditional Expression

Description Comparisons in Python Comparisons in Math-


ematics
Equals a == b a=b
Not Equals or inequality a != b a≠b
Less than a<b a<b
Greater than a>b a>b
Less than or equal to a <= b a≤b
Greater than or equal to a >= b a≥b

The comparisons in Table 6.1 are also called conditional expressions that correspond
to the Boolean values - true or false. For example, 3==4 results in false (as 3 is not
equal to 4). Note that operators used in python’s expressions are slightly different
from operators used in Mathematics (e.g. == vs. =, != vs. ≠ ). Python conditionals
can be used in several ways, most commonly in ‘if statements’ and loop statements.

166 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Activity 6.2 Work in group


1. Write the python equivalent expression for the following mathematical
equation and determine its output.
a. 21 ≠ 21
b. 97 ≥ 99
c. Price = 135
2. Write a python expression to describe the following statement.
a. Age is less than 12.
b. Student mark is equal to 95.
c. Weight less than or equal to 45.5.
3. What is the output of the following expressions (use python IDE to confirm
your answer)?
a. 19 != 20
b. age = 22 age ==22
c. ‘zenash’ == ‘zehara’
4. What is the difference between height = 2.5 and height == 2.5 in python?

Conditional or branching statements

Conditionals are statements in a program in which the program decides at runtime


whether some parts of the code should or should not be executed. From the earlier
even/odd example, a given integer number can be even or odd, but this can be
decided based on the remainder after dividing the number by two. Therefore, first:

Decide whether (num % 2 == 0) is or is not true.

If it is true, then the number is even.

If it is not, then the number is odd.


The evaluation of the conditions (i.e., num%2==0) is a test that can be checked to
see if it is true or false; as a result, executing one thing when the condition is true,
or something else when the condition is false.

In Python, a conditional statement is written using the if keyword. Like many other
programming languages, Python provides various versions of branching statements

167 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

that can be implemented using the if clause: simple if statement, if..else statement,
and if..elif…else statement.

if statement: this is the simplest implementation of a conditional statement that


decides only one part of the program to be executed if the condition is satisfied or
ignored if the condition fails. The condition is an expression that is either true or
false. If the condition (expression) is true, then do the indented statement(s) (See
Figure 6.1). If the condition is not true, then skip the indented statements.
Evaluation of the expression is either true or false.
If it is true, then the indented statement(s) is or are
executed, otherwise skip the indented statements.
This group of statements is called a block.

Figure 6. 1 Syntax for if…statement


Example – simple if statement

If your input is 1, the expression age>0 (i.e. 1>0) is true. Therefore, the two
indented statements are executed, and they display their contents on the screen.
However, if the input is -1, the expression age>0 (i.e. -1>0) is false. Therefore, the
program ignores the indented statement.
Notes
„„ The expression (if age>0:) must end with colon(:). Missing colon at
the end of expression is a syntax error.

168 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Activity 6.3
• Based on the example presented under the simple if statement above:
a. What is the output if you write age 15?
b. What is the output if you write age 0? Discuss in pair.
c. What is the output of if the second print statement is unindented?
Discuss in pair.

Notes
„„ You can have any statement before or after the ‘if statement’ which is
not considered as part of the ‘if statement’ and is executed as normal.
However, the ‘if expression’ must follow at least one statement to be
executed, otherwise it is a syntax error. See Figure 6.2 for syntactically
correct and incorrect if statements.

Example code Output description


No error, empty output

No error, output

Error, if clause must have at least one


statement.

The last statement is not part of ‘if


statement’, so execute as normal.

Figure 6. 2 syntax error in if statement

Activity 6.4
1. Modify age in the example above to check if the age is greater than 18, and
then print ‘You are Adult’

2. The following code has an error. Which part of the code does cause the error?

169 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

3. If you type -1 and 1, what is the output of the following program? What do you
noticed about the first and the last statements?

if…else statement: The ‘if...else statement’ provides two alternative statements or


blocks: one following the ‘if expression’ and another following the ‘else clause’.
‘if…else’ allows us to specify two options: one which is executed if a condition is
true (satisfied), and another which is executed if the condition is false (not satisfied)
(See Figure 6.3 below).

if expression : The interpretation of the syntax is that if the


    yes_statement1 expression evaluates to true all the yes statements
under expression are executed, and if expression
    yes_statement2
evaluates to false all the no statements under else
    ....
clause are executed.
else :
   no_statement3
   no_statement4
   ....
Figure 6. 3: Syntax for if. else statement
Now let us see an example that makes use of the above if…else syntax. Predict
what the following program prints.

As the value of age is 18, the program outputs the first print statement (See in the
example below that error: reference source not found).

170 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Output:

Figure 6. 4 Implementation of If Else Statement - Code (left) and Output (right)

The ‘if...else statement’ can make a choice between two alternative actions. Thus,
the even/odd problem discussed earlier can be accomplished with the following
python statement:

In the above program, first the expression num % 2 == 0 is evaluated (checked). If


num % 2 is true (condition satisfied), then the statement following (print (num, “is
Even number”) is executed. Otherwise, which means the condition num % 2 == 0
has not satisfied (or false), then the statement following else (print(num, “ is Odd
number”) is executed. Now it is time to learn additional syntax rules in python.

Syntax in a python program is a set of rules that defines how a python program is
written and interpreted. For instance, the expression of an ‘if statement’ must be
followed by a colon (:). Some programming languages require expressions to be
enclosed in parenthesis, but in python it is optional. So in python, “if num % 2 ==
0:” or “if (num % 2 == 0):”, this complies to Python’s syntax rule.

Another important syntax in python is indentation. In Figure 6.3, it is noted that


the ‘yes_statements’ and ‘no_statements’ must be indented. Indentation refers to
the spaces at the beginning of a code line. While in other programming languages
the indentation in code is only for readability, the indentation in Python is very
important.

Python uses indentation to indicate a block of code. For example, if you ignore the
indentation in the example ‘if statement’ above, and begin the yes_statements or

171 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

the no_statements without indentation, the code generates an error. Of course, the
number of spaces is up to you as a programmer, but it has to be at least one.

Notes
„„ Use the same number of spaces in the same block of code; otherwise,
Python gives you an error (See Figure 6.5, the last if statement). These
are important concepts when you write control statements.

It has error, missing


colon(:) at the end of
expression

It has no error, runs


correctly. Enclosing
expression with
parenthesis is
optional.

It has no error; it is
a properly indented
block.

It has an error, the


block is not indented.

It has an error
because of, an
inconsistent
indentation in the
same block.

172 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Figure 6. 5 Illustrate Syntax rules in Python ‘if statement’

Activity 6.5
1. Based on the code in Figure 6.4,

a. What is the output if the age is 20?

b. What if the number 0 is stored in age?

c. When do you get the output “You are children”?

2. A group activity. Write a Python program that read two numbers from
the keyboard and compute division of the first number by the second.
Apply appropriate if statement to check that the second number is differ-
ent from zero, otherwise print division by zero is not allowed. Do in pair
if...elif…else statement: Assume a problem that could have many options to
choose from or require several conditions. For example, you want to develop a
program that will print ‘Excellent, Very Good, Good, Satisfactory, or Fail’ based
on the student mark. In such situations, Python allows you to add any number of
alternatives using an elif clause after an if and before an else clause.

The elif is a keyword in Python to say “if the previous condition(s) are not true,
then try this condition”. The else keyword catches anything that is not caught by
all the preceding conditions. The general syntax for ‘if…elif…else’ is given in

173 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Figure 6.6 below.

if expression1:
statement1
statement2
...
elif expression2:
   statement3
   statement4
   ...
elif expression3:
   statement5
   statement6
   ....................
else:
   statement7
   statement8
...
Figure 6. 6 If…elif…else Syntax in Python

The interpretation of the above syntax is that first, each expression is evaluated
one after the other, and if the expression is found to be true, all statements in that
specific block are executed. Otherwise, if none of the expressions before the last
‘else’ statements are true, the statements under ‘else’ are executed.

The program in Figure 6.7 contains a series of conditions using ‘if…elif…else’ to


determine the status of the age (child, adolescent, adult, and senior adult). Since the
age is 80, it does not match all conditions. Therefore, the statement under ‘else’ is

174 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

executed (See the output in Figure 6.7 under the ‘Output’ column).

if…elif…else based program Output

Figure 6. 7 conditional with if…elif…else statement

Another example in Figure 6.8 below demonstrates the application of a series of


conditions using the ‘if...elif…else’ statement to get the type of a variable. type()
which is a function that returns the type of the argument, in our case price. What is
the type of price? It is a floating number. See the output in the right side of Figure
6.8 below.

if…elif…else based program Output

Figure 6. 8 Implementation of If...elif...else Statement - Code (left) and Output (right)

175 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Activity 6.6
1. Replace price =49.5 by the message = “Hello Student”, and the variable
price in all expressions by the message in Figure 6.8 above. Then,
discuss the output of the code.

2. Use appropriate conditional statements to write a Python program that


solves the following problem:

¾¾The program should prompt the user to enter her/his average mark in the
last or the current semester and then print excellent, very good, good,
satisfactory or fail based on the evaluation of the mark entered.
¾¾What necessary to write the program code?

3. Write a Python program that calculates the four arithmetic operations


(i.e. +, *, - and /).

¾¾The program asks the user to enter one of the four arithmetic symbols.
Then:
• It asks the user to enter two integer numbers.
• Based on the operator and numbers entered by the user, calculate
and display the result.
Using ‘and’ and ‘or’ with if…statement: The ‘and’, and ‘or’ keywords are
also used with ‘if...statement’ in Python. The ‘and’ and ‘or’ keywords are logical
operators and are used to combine conditional statements.

‘and’ operator in if … statement:

Output:

Figure 6. 9 and operator in ‘if statement’ - Code (left) and Output (right)
176 Information Technology radeG12 ~ Student Textbook
Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Notes
„„ Any statement that is preceded by the hash symbol (#) is a comment
and ignored by the Python interpreter. You will learn comments in
Section 6.2.

In Figure 6.9 above, the evaluation of ‘isBodyTemperatureHigh’ and ‘isCoughing’


(i.e.True and True) is True. Therefore, the indented statement following the ‘if’ is
executed.

Activity 6.7
1. Discuss the evaluation of the expression ‘isBodyTemperatureHigh’ and
‘isCoughing’, if the value is True and False (See Figure 6.9 above).

2. Test your response by substituting the value in the program.

3. Replace the ‘and’ operator by ‘or’ and discuss the output

Using ‘or’ operator with if… statement: The ‘or’ operator in Figure 6.10 is used
to combine conditional statements. The three conditional statements compare the
value of mySubject with ‘Physics’, ‘Chemistry’, and ‘Geograpy’. The evaluation
of the ‘if’ expression is True if one of these three conditions is satisfied. Otherwise,
the expression evaluates to False, and in that case, it executes the statement under
the else clause.

Figure 6. 10 Illustrates the use of ‘on’ Operator in if… Statement

Notes
„„ The ‘subject’ in Figure 6.10 is declared as array of string. An array is
a variable used to store multiple values in one single variable. In the
example, ‘subject’ stores four subject names or values.

177 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Activity 6.8
• What is the output of the program in Figure 6.10?

6.1.2 Loops or Iteration Program Flow Controls

Brainstorming 6.3

„„ How do you represent 1 to 10 by repeating some pattern?

Most of real-world problems include some action that is repeated several number of
times. For example, consider the program you designed in (Activity 6.6 Question
2) that determines the student’s mark as “Excellent”, “Very Good”, etc. If you
have 50 students in a class, then a more complete program would repeat this status
determination 50 times (i.e. once for each student in the class). A program is often
used to automate such repetitive tasks. A portion of program code that repeats a
statement or group of statements in programming is called loop.

Loops are set of statements that run repeatedly for a fixed number of times, or until
a condition is satisfied. Loop statements control a block of code to be executed
iteratively or until a certain condition fails. Loops are a useful and frequently used
feature in all modern programming languages. Python provides several language
features to make iteration/looping easier. There are two types of loops that are built
into Python: for loops and while loops. In the following section, implementation of
‘for loop’ is discussed and then followed by ‘while loop’ in python.

for loops: The for loop in python is used to iterate over a sequence. For loop in
combination with the Python’s range() function is used for counting in all kinds of
ways (See for loop with range function at the end of this section). The for loop in
python differs a bit from other like C or Pascal. In Python for loop is used to iterate
over the items of any sequence including the python list, string, tuple, dictionary,
etc. It is also used to access elements from a container (e.g. list, string, tuple) using
a built-in function range(). The general syntax of for loop is as follows.

178 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Syntax:
for variable_name in sequence :
    statement_1
    statement_2
    [....]

Figure 6. 11 For Loop Syntax in Python


The description of the above for loop syntax is:

Name Description
variable_name This represents a temporary variable that sets a new
value for each iteration of the loop.
Sequence Sequences are values that can be assigned to a
temporary variable (i.e. variable_name). Values are
provided using a list or a string or from the built-in
function range().
Statement_1, state- These represents a block of program statements.
ment_2 Python’s syntax requires this to be indented.
[..]
for loop with range() function: The range() function returns a list of consecutive
integers. The sequence of numbers starts from 0 by default, and counts by
incrementing 1(by default), and ends at a specified number. It is widely used count
controlled loops.

Notes
„„ In the syntax below, the range() function takes one, two, or three
parameters. The last two parameters are optional.

Syntax Example
range(x) range(5)generate sequence 0 to 4
range(x,y) range(2,5)generate sequence 2 to 4
range(x,y,z) range(1,10,2)generate sequence 1,3,5,7,9
Figure 6. 12 Range Function Syntax with One, Two, and Three Parameters

range(x): generates a sequence of numbers from 0 to x, excluding x, incrementing


by 1. Figure 6.13 demonstrates a simple counter program using range(5).

179 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Python script Output on IDLE Shell

Figure 6. 13 Implementation of for Loop with Range - Code (left) and Output (right)

Activity 6.9
1. The above program output is 0 to 4, not 5 (See Figure 6.13). Discuss
what the reason is with a partner.

2. Write a program that prompts the user to enter an integer number from
the keyboard and generate a sequence of numbers from 0 to user input.

Hint: use input statement to accept user input, convert the number
to a numeric type, and give as a parameter for the range function.

range(x, y): This generates a sequence of numbers from x to y excluding y,


incrementing by 1. The program in Figure 6.14 uses range to generate a sequence
of numbers from 5 to 8.

Python script Output on IDLE Shell

What is the output?

Figure 6. 14 Implementation of For Loop with Range Function

Activity 6.10
1. Write the output of the above program ( in Figure 6.14) in the space provided.

2. Write a for loop that counts from 51 to 70.

180 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

range(x, y, z): This generates a sequence of numbers from x to y excluding y,


incrementing by z. This is different from the above range function in that the
increment is set by the z value ( See Figure 6.15).
Python script Output on IDLE Shell

Figure 6. 15 Implementation of For Loop with Range Function with Three


Parameters - Code (left) and Output (right)

Activity 6.11
1. Write a program that generates a sequence of numbers from 10 to 100,
incrementing by 10.

2. Write a for loop to generate 1, 4, 7, 10, 13, 16, 19, and 22.

for loop in iterable object: Now let us see an example of a for loop in an iterable
object. Unlike the earlier example, the loop iterates while something is true. This
type of loop is called a condition controlled loop.

Python script Output on IDLE


Shell

Figure 6. 16 Implementation of For Loop - Code (left) and Output (right)


181 Information Technology radeG12 ~ Student Textbook
Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

The for loop program in Figure 6.16 is condition controlled. The ‘regionalState’
is a sequence that contains a list of regional states. When the for loop is executed,
the first item (i.e. Afar) is assigned to the ‘region’. The ‘region’ is a temporary
variable that actually represents an element in the list. After this, the print statement
executes, and the process continues until we reach the end of the list (i.e. Sidama),
or while there is an element in the list. See the output in Figure 6.16 above on the
right hand side.

Activity 6.12
Write a for loop statement that displays the following list of fruits.

• fruits = [“Mango”, “Orange”, “Banana”, “Pineapple”, “Papaya” ];

Syntax: for variable_name in string

for loop can iterate through string. The string is an iterable object in python because
it contains a sequence of characters. Thus, applying for loop in a string allows us
to access the content character by character.

Python script Output on IDLE Shell

Figure 6. 17 for Loop in a String


In the above program, in each iteration, one character is accessed from the string
value and stored in the letter variable, and printed on the screen. The iteration
continues until the last character (i.e. m) is accessed and printed on the screen.

182 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Activity 6.13
• Write for loop to get your name from the keyboard and print character by
character.

Hint: use input statement to read your name from the keyboard.
break Statement with for: The term break is a keyword in python. With
the break statement, you can stop the loop before it has looped through all the
items:
Python script Output on IDLE
Shell

Figure 6. 18 for Loop with break Statement – Code (left) and Output (right)
In the above program, the loop exits when the value of ‘language’ is ‘Python’.

Activity 6.14
1. Modify the program in Figure 6.17 (for loop in string) above to stop the loop if
the value of letter is white-space.

Hint: use ‘if statement’ to check if letter == ‘ ’

2. What is the output of Figure 6.18 if you replace the ‘if statement’ by if lan-
guage== “HTML”?

continue keyword with for loop: The term continue is a keyword in python.
With the continue statement, you can stop the current iteration of the loop, and it
continues with the next.

183 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Python script Output on IDLE


Shell

Figure 6.19 for loop with continue statement - Code (left) and Output (right)

Activity 6.15
• Modify the above statement to escape “Java” and “C++” using continue
keyword.

Hint: use the operator to combine the condition if language ==”Java” or


language==”C++”.

while Statement: The while statement in Python supports repeated execution of a


statement or block of statements that is controlled by a conditional expression. The
general syntax for the while statement is:
Syntax:
while expression: Note that in python expression must end by
colon(:). Statements under the while must be
Statement_1 indented.
Statement_2
[…]

Figure 6. 20 while loop syntax

The while loop runs as long as the condition (expression) evaluates to True
and executes the program block (statement_1, statement_2 …). The expression
is checked every time at the beginning of the loop and the first time when the
expression evaluates to False, the loop stops without executing any remaining
statement(s).

184 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Python script Output on IDLE Shell

Figure 6. 21 Implementation of While Loop - Code (left) and Output (right)

The while loop above prints the value of count as long as the count is less than
5. The last statement (count += 1) is important to increment the value of count at
every iteration and eventually terminate the loop.

Notes
„„ Don’t forget to increment count(i.e. count +=1 in Figure 6.21);
otherwise, the loop continues forever.

Activity 6.16
• Rewrite the problem described in Activity 6.11 using a ‘while’
statement.

Hint: Set the count to 10, and increments count by 10.

break and continue keywords with while loop: With the break statement, you
can stop the loop even if the while condition is true. It causes the loop to quit even
before reaching the last iteration. The loop in the program below terminates when
the value of count is 5 (in the 5th iteration).

Python Script Output on IDLE Shell

Figure 6. 22 Implementation of While Loop with break Statement - Code (left)


and Output (right)

185 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

As you have learned in for loop above, the continue statement, causes the current
iteration to stop, and continues with the next.

Python script Output on IDLE Shell

Figure 6. 23 Implementation of While Loop with continue Statement - Code (left)


and Output (right)

The above program is supposed to iterate 9 times but prints 8 values by escaping
print when the value of count is equal to escape.

Activity 6.17
• If the user input is 8, what is the output of the above ( in Figure 6.23) program?

6.2. Comments in Python

Brainstorming 6.4

„„ Have you ever noticed a comment in a program so far? What is its


purpose?

Comments are descriptive texts that exist in program source code and are ignored
by a compiler and interpreter. Comments are not executable statements or part of
the program. Using comments, a program can make code more readable for other
developers as it provides some information or explanation about what each part
of a program is doing. Depending on the purpose of your program, comments can
serve as notes to yourself or reminders.

186 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming
In python, comments are denoted by the hash symbol (#). Anything after the #
symbol is ignored by the interpreter (See the above example program code with the
# symbol). Comments can be given in a single line or may take multiple lines. In
any case, all comment lines should start with the special character (#). In general,
you can use comments to describe your program code, to make the code more
readable, or to prevent the execution of some parts of the code while testing the
code. Examples of each are given below.
Creating comment: In Python, comments start with a hash symbol (#), and the
Python interpreter ignores them.

Figure 6. 24 Illustration of Comments in Python Script

In the above example, the two comments (i.e. ones that start with #) are ignored
while executing the program.

Commenting part of the code: Comments can also be used to comment out parts
of the code that you do not want to execute while compiling or running a program.
The program in the following example has two fragments of code. The second
fragment of code (next to line pi = 3.14) is commented out to prevent that part of
the code from execution. IDLE provides features to comment out (uncomment)
parts of code in your source program.

Figure 6. 25 Illustration of Commenting out Part of Code


187 Information Technology radeG12 ~ Student Textbook
Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Commenting in IDLE: In IDLE, commenting features are found under the


‘Format’ menu. Select part of the code you want to comment out, then click on the
‘Format’ menu, and from the list, select ‘Comment Out Region’, or you can use the
short cut key ‘Alt+3’. In order to uncomment, select the part of code you want to
uncomment. Then click on ‘Format’ menu, and from the list, select ‘Uncomment
Region’, or you can use short cut key ‘Alt+4’.

To comment out

Select part of code

Click on Format
menu

From the list, select

Comment Out region


or use Alt+3

Figure 6. 26 Illustrate Commenting Tool in IDLE

Figure 6. 27 Illustrates the First Part of the Code Commented out

188 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Activity 6.18
1. Comment on the second part of the program in the above figure and run
the program. Then, write the output.

2. Uncomment the first part of the program in the above figure and run the
program. Then write the output.

3. Add comment that describes the second part of the program.


When you experience errors after writing new lines of code, then you might
comment on a few of them to see if you can troubleshoot the precise issue.

6.3. Python Interpreter

Brainstorming 6.5

„„ Describe the python program writing process.

In this section, program writing and running are discussed in more detail.
Python is an interpreted programming language, not a compiled one although
compilation is a step in Python interpreter processes. Compilation is simply a
translation that generate bytecode that you will more in the next paragraph. The
interpreter is the program that is responsible for executing each line of statements
sequentially and runs the Python code or script which refers to a simple program
stored in a plain text file. You can think of the interpreter as a layer of a program
that works between your program and your computer hardware to get your code
running. Python has a wide range of interpreters including IDLE, CPython,
Jython, PyPy, and IronPython and online Python editors. Your Python source code
is always run by one of these interpreters depending on the Python installation
you use. Therefore, first, make sure that you have correctly installed one of these
interpreters on your computer.
Links
Read your Grade 11 IT Textbook for more on Python IDE

189 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Steps in the Python Interpreter Process

Figure 6. 28 Python Interpreter Source Code Compilation Process


Given that you write and save your Python code with the extension .py, first your
source code (.py file) compiles into a format called bytecode. Compilation is a
simple translation process that generates a bytecode. In Python a compiled code is
usually stored in a file with the extension of .pyc, which can update when necessary.
Then, the bytecode (.pyc file) is loaded into the Python runtime and interpreted by
a Python Virtual Machine (PVM). The PVM is the Python runtime powerhouse.
The PVM is a piece of program that reads each instruction in the bytecode one
by one and executes whatever operation is indicated. Bytecode interpretation is
automatic, and the PVM is just part of the Python system that you have installed
on your machine. The PVM is the component that truly runs your scripts. Running
your program is just the last step of what is called the Python interpreter process.

Activity 6.19
• Describe the steps involved in the python interpreter process.

190 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

6.4. Testing and Debugging Programs

Brainstorming 6.6

„„ Why do we need to test a program?

Once you write your program source code, you save the file and run the code to
test whether the desired or expected output is generated. The program sometimes
fails to run correctly because of a bug. A bug is an unexpected problem in your
program. Bugs can appear in many forms, and some are more difficult to fix than
others. Some bugs are tricky enough that you will not be able to catch them by just
reading through your program. Luckily, Python IDLE provides some basic tools
that help you debug your programs with ease. Debugging means, having complete
control over the program execution.

Getting Started Interpreter DEBUG Mode

If you want to run your code with the built-in debugger in Python IDLE, you
need to turn to debug mode feature. To do so, select Debug → Debugger from the
Python IDLE menu bar. In the interpreter, you should see [DEBUG ON] appear
just before the prompt (>>>), which means the interpreter is ready and waiting (See
Figure 6.29 below).

When you run your Python file, the debugger window appears (See Figure 6.29
below):

191 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Figure 6. 29 Debug Control Window When Debug Mode On


In this window, you can inspect the values of your variables as your code executes.
This gives insight into how your data is being manipulated as your code runs.

Click the following buttons to move through your code:


Go: Press Go to advance execution as normal until a breakpoint is encountered (or
input is requested).

Step: Press Step to see all the internal commands that python uses to execute the
current line and go to the next one.

Over: Press the Over option to see line-by-line execution of the program.

For our purposes, we can use ‘Go’ and ‘Step’ to trace and fix the bug in the following
program. Before running the program, set a breakpoint on a statement that causes
an error in your program.

A breakpoint is a line of code that you have selected as a place where the interpreter
should pause while running your code. To set a breakpoint, right-click on the line
of code that you wish
192 Information Technology radeG12 ~ Student Textbook
Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Figure 6. 30 a breakpoint set to code in the program.

to pause(See Figure 6.30 that Error: Reference source not found). This highlights
the line of code in yellow as a visual indication that a breakpoint is set. You can
set as many breakpoints in your program code as you like. To undo a breakpoint,
right-click the same line again and select Clear Breakpoint.

Now run the program. Then from the


DEBUG control (shown on the left) press
‘Go’. This prompts you to type values for
num1 and num2. Enter the numbers from
the keyboard and press enter.

As shown below.

193 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Now press ‘Step’


from Debug Control
to execute line by
line. This displays
TypeError (highlighted
in yellow). Go to the
source code to fix the
problem by casting the
input to integer.

Then repeat the above


steps to check the bug
is fixed

Activity 6.20
• The following code could generate error if the value for num2 is zero.
Trace and debug the error using python DEBUG control.

194 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Unit Summary
In this unit, you have learnt about:

• program flow control.


• the special purpose of indentation in python.
• types of flow controls in python.
• conditional or branching statements in python – if, if…else, if…elif…
else, if with in/and/or.
• looping or iteration statements in python – for…loop, while…loop, for
loop with range(), break, and continue.
• the purpose of comment in program source code.
• using IDLE commenting features
• steps in the python interpreter process
• testing and debugging program code – Debug Control and breakpoint

195 Information Technology radeG12 ~ Student Textbook


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals of Programming

Key Terms
Program flow controls - A program flow control refers to the order of
execution of the program’s code. Python implement the flow control of the
program through the sequential statements, conditional statements and loop
statements.
Syntax in a python program - is a set of rules that define how a python
program is written and interpreted.
Indentation - Indentation refers to the spaces at the beginning of a code line.
Unlike other programming languages, python uses indentation to indicate a
block of code.
The number of spaces is up to you as a programmer, but it has to be at least
one.
Conditional statements -are statements in a program where there are points
at which the program decides at runtime whether some parts of the code
should or should not be executed.
UNIT-6 Fundamentals of Programming
Conditional statements -can be implemented by ‘if statement’. Such as
simple if, if…else, if…elif…else, nested…if
Key Terms
Iteration - This is a programming logic to automate repetitive tasks. Repeated
Program flow
execution of a setcontrols - A program
of statements flow
is called controlPython
iteration. refers provides
to the order of
various
execution
versions ofofforthestatements
program’sand code.
whilePython implement
statements the flowiteration.
to implement control of the
program through the sequential statements, conditional statements and loop
Continue -is a keyword which is used with for loop. With the continue
statements.
statement, you can stop the current iteration of the loop, and continue with
the next.in a python program - is a set of rules that define how a python
Syntax
program is written and interpreted.
Break - is a keyword which is used with for loop. With the break statement,
Indentation
you can stop -the Indentation
loop before refers tolooped
it has the spaces at theall
through beginning
theitems.of a code line.
Unlike other programming languages, python uses indentation to indicate a
Comments - are descriptive texts in program source code that are ignored by
block of code.
compilers and interpreters. Using comments, programs can make code more
The number
readable for of spacesasis itupprovides
humans to you assome
a programmer,
informationbut or itexplanation
has to be atabout
least
one.
what each part of a program is doing or about.
Conditional statements -are statements in a program where there are points
at which the program decides at runtime whether some parts of the code
196 InformatIon
should or should tnot
echnology
be executed. grade 12 ~ Student textbook

Conditional statements -can be implemented by ‘if statement’. Such as


Ethiofetena.com Ethiopian No 1 Educational Website
UNIT-6 Fundamentals
Fundamentals of
of Programming
Programming
UNIT-6

Interpreter
Interpreter isis aa special
special program
program thatthat executes
executes instructions
instructions written
written in
in aa
programming
programming language.
language. ItIt can
can either
either execute the
the source
source code
executeFundamentals directly
directly or
of Programming
code or
UNIT-6
translate
translate the
the source
source code
code inin aa first
first step
step into
into aa more
more efficient
efficient representation,
representation,
and
and execute
execute this
this code.
code.
A
A bug
bug is
is an
an unexpected
unexpected problem in in your program. Bugs
Bugs can
can appear in
in many
Interpreter is a specialproblem
program your program. instructions
that executes appear
written many
in a
forms,
forms, and
and some
some are
are more
more difficult
difficult to
to fix
fix than
than others.
others.
programming language. It can either execute the source code directly or
translate
A
A breakpoint
breakpoint is
is aa line
the source line of
code code
of in that
a first
code you
thatstep have
haveaidentified
you into as
as aa place
more efficient
identified where
where the
representation,
place the
interpreter
and executeshould
interpreter pause
pause while
this code.
should while running
running your
your code.
code.
A bug is an unexpected problem in your program. Bugs can appear in many
forms, and some are more difficult to fix than others.
A breakpoint is a line of code that you have identified as a place where the
interpreter should pause while running your code.

197 IInformatIon technology


nformatIon technology
g
grade 12 ~ Student textbook
rade 12 ~ Student textbook
197

You might also like