Save
SQA - National 5
Computing Science
3. Software Design and Development
Save
Share
Learn
Content
Leaderboard
Learn
Created by
lite
Visit profile
Cards (21)
Pre-defined functions
Length
- returns
number
of
characters
Pre-defined function - Round
Rounds
decimal
number to
specified number
of
decimal
place
Example:
x = 12.12836
print(round(x, 2))
Output: 12.13
Pre-defined function - Random
Generates random
number
Example:
import random
print(random.randint(1, 6))
Output: 3
Pre-defined function - Length
Returns number
of
characters
Example:
x = "Blackpink"
print(len(x))
Output: 9
Running Total with Loop
> total =
0
-
> items = int(input("Enter number of items"))
-
> for
counter
in
range
(
items
):
>> value = int(input("Enter value " + str(counter+1)+": "))
>>
total
=
total
+
value
> print("The total is ", total)
Input Vaildation
> number = int(input("Enter a number between 1 and 10"))
>
while
number
<
0 or number
>
10:
>> print("Error: Invalid number")
>> number =
int
(
input
("Re-enter number again: "))
> print("Number is ", number)
Selection Statements
AND
- when both conditions are true
OR
- when one condition is true
NOT
- when condition is not true
Types of Test Data
Normal
test data -
within
the
boundaries
of the program
Example: user's number needs to be between 1 and 5
Test data would be: 1, 2, 3, 4, 5
Types of Test Data
Extreme
test data - the
boundaries
of the program
Example: user's number needs to be between 1 and 5
Test data would be: 1 and 5
Types of Test Data
Exceptional
test data - anything
outside
the boundaries of the program
Example: user's number needs to be between 1 and 5
Test data would be: -2, 0, "one"
Types of Errors
Syntax
error - a line of
code
not formed
properly
, caused by the
programmer
Example: "pirnt", instead of "print"
Types of Errors
Execution
error -
occurs
while the program is
running
, which the programs
stops
Examples:
attempting to divide by 0,
attempting to assign one data type to a variable of a different data type, e.g. str value to int variable
Types of Errors
Logic
error - Does
not
produce
the
expected
output
Examples:
using the wrong formula in a calculation,
entering infinite loop,
outputs not matching the labels, e.g. "Age: Jim"
Evaluation - Fitness for purpose
If it meets
all
the
functional requirements
, then it's
fit
for
purpose
If it
fails
to meet at least
one functional requirement
, then it's
not
fit
for
purpose
Evaluation - Efficiency of code
Repetition
- loops to repeat the same task
Arrays
- instead of variables
Selection statements
- else if, and else to select which code to run
Logical operators
- AND, OR to reduce complexity of selection statements
Evaluation - Robustness
If it
doesn't crash
when entering
exceptional data
, then the program is considered
robust
Evaluation - Readability
Making your program
easy
for you, and other programmers to
understand
your
code
, by using:
Internal
comments
;
Meaningful
variables
;
Indentation
;
Whitespace
Evaluation - Readability: Internal commentary
Comments
that you
leave
to yourself, or other programmers to
explain
your
code
Example: ## this is an internal comment
Evaluation - Readability: Meaningful variables
Using
variables
that help you
understand
your program
Evaluation - Readability: Indentation
Makes it
clear
what
loops
, or if
statements
code
belongs
to
Evaluation - Readability: Whitespace
Blank lines
between
lines
of
code
, making it
easier
to see what
belongs together