0% found this document useful (0 votes)
23 views12 pages

Lesson 6 Digi Trailblazers Course 2

Uploaded by

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

Lesson 6 Digi Trailblazers Course 2

Uploaded by

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

Lesson 6 - Testing and Improving Programs 1

Course 2
Inspiring the next generation of digital innovators
Lesson 6 – Testing and Improving
Programs 1
By the end of the lesson you will understand more
about:

• How to use tools to test a program

03
Activity 1

All programs need to be tested to ensure they work correctly.

Different programming software has different tools to break, watch and step code.

Break: A place in a program where execution is stopped in order for the programmer to inspect the lines of
code following on from the break.

Watch: Opening a new window to display the variable and its contents. The developer can execute each line
of code and see what happens to the content of the variable.

Step: Each line of code is executed one at a time. During the step by step execution the program stops and
waits for user inputs and behaves as if it were being executed normally.

The tools used to break, watch or step code are known as code visualiser or debugging tools.

04
Activity 1 – continued
Let’s
Check
Together Look at the code in the example below
Four variables Quantity, UnitPrice,
# testing.py
Discount and Total are created
# This program contains a 3 stage calculation to demonstrate how a program
# inspection works. and initialised in this code.

Quantity = 0 The user inputs a quantity as an


UnitPrice = 0
Discount = 0 integer, a price which can be input
Total = 0 as a float (number with decimal
point), and a discount percentage
Quantity = int(input ('Please input the quantity: '))
expressed as a decimal (eg 0.1 =
UnitPrice = float(input ('Please input the price: '))
Discount = float(input ('Please input the discount rate eg 0.2 = 20%: ')) 10%, 0.15 = 15%, 0.5 = 50%).
Total = (Quantity * UnitPrice) - (Quantity * UnitPrice * Discount)
print ('The price for this order is: ', Total) The program calculates the Total
and places the result of the
calculation in the Total variable
05 before outputting it on the screen.
Activity 1 – continued
To see this program in action and
view each line of code separately as
it executes, a programmer will use a
visualiser or debugger.
The variables
In the example, the green arrow have been
shows the last line that executed created and
and the red arrow is the next line. initialised
The program is waiting for the user
to input the quantity.

The program is
waiting for the quantity
to be input by the user
before moving on.
06
Activity 1 – continued
A few lines later, you can see values have been added to the Quantity variable and the Unit Price variable.

The Quantity and


Unit Price have
their values, and
the program is
now waiting for
the Discount rate.

07
Activity 1 – continued
When the program has finished executing the programmer can check the code,
the values input, the values in the variables and the final outputs.

08
Activity 1 – continued
Use the Python inspection tool to step through at least three Python programs that you have created and
saved.

Make sure one of these programs contains a user defined function.

Executing line by line and watch the contents of the variables change.

Make a record of the programs you have inspected.

Make sure you inspect all the selections, loops and calculations.

Following the example in the first line, write down the program names in the table, including the features in
each and which lines have been inspected.
Program name Features Comments
eg Temperature.py If statement, while Temperature
loop, user defined conversion from
function Celsius to Fahrenheit
09
Terminology
• Break - a break is when a line of code is selected as the hold point
during the execution of a program so that debugging can take place

• Debugging tools - are tools that either exist within programming


software that are designed to allow the code to run under more
controlled conditions so that the developer can use techniques to walk
through the execution of the code line by line and correct it accordingly

• Step - (sometimes also called step over) is a technique that enables


the programmer to advance the code one line at a time to see what it is
doing

• Watch - is used by developers so that they can see how a variable is


operating and which lines of code cause the content of the variable to
change. This is particularly useful when the same variable is used
repeatedly and is being changed by different lines of code. Using a
watch means that any errors are that much easier to find
10
• Use debugging tools
• Break – a point in the code where the debugger is made to

Lesson Summary stop (particularly useful when a program has hundreds or


thousands of lines of code
• Watch – a view of the contents of a variable (particularly
– Understand useful when the same variable is used a number of times in
a program)
How to Use Tools • Step – execution of code line by line to see what the code is
doing as it happens.

to Explore the • Inspecting loops, selections and function execution


Execution of a is crucial to understanding how a program is
working.
Program

11
NCC Education Head South Africa Malaysia China Singapore
Office UK 1 Bridgeway Road Unit No.C-7-4 LG2-T1, Tower C 100 Victoria Street
The Towers Bridgeways Precinct Wisma Goshen, Plaza Pantai COFCO Plaza #13-01/02
Towers Business Park Century City No.5 Persiaran Pantai Baru No. 8 Jianguomennei Avenue National Library Building
Wilmslow Road Cape Town 59200 Kuala Lumpur Dongcheng District Singapore
Didsbury 7441 Malaysia Beijing 100005 188064
Manchester M20 2EZ South Africa China
United Kingdom
+27 21 830 5242 +60 3 2284 6200 +86 10 6520 4030 +65 6580 4555
+44 (0) 161 438 6200
Monday to Friday Monday to Friday Monday to Friday Monday to Friday
Monday to Friday 08:30 – 17:00 09:00 – 17:00 09:30 – 18:30 09:30 – 17:00
08:30 – 17:00

You might also like