0% found this document useful (0 votes)
6 views27 pages

BASIC Programming LessonNote SS2

This lesson note covers BASIC programming for Senior Secondary School 2 students, focusing on key concepts such as programming definitions, characteristics of good programs, and the use of operators. Students will learn to write and analyze BASIC code, including arithmetic, relational, and logical operators, while also understanding the importance and applications of programming in various fields. The lesson aims to equip students with foundational programming skills and problem-solving abilities through practical examples and exercises.

Uploaded by

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

BASIC Programming LessonNote SS2

This lesson note covers BASIC programming for Senior Secondary School 2 students, focusing on key concepts such as programming definitions, characteristics of good programs, and the use of operators. Students will learn to write and analyze BASIC code, including arithmetic, relational, and logical operators, while also understanding the importance and applications of programming in various fields. The lesson aims to equip students with foundational programming skills and problem-solving abilities through practical examples and exercises.

Uploaded by

noblexfabrics
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

COMPUTER STUDIES
LESSON NOTE
Topic: BASIC Programming
Class: Senior Secondary School 2 (SS2) | Subject: Computer Studies
Duration: 80 Minutes | Term: Second Term

LESSON INFORMATION

ITEM DETAILS REMARKS

Subject Computer Studies Core subject

Class SS2 Ages 15–17

Topic BASIC Programming Programming Unit

Sub-Topics Operators, Program Statements, 3 major sub-topics


Built-in Functions

Duration 80 Minutes (Double Period) 2 × 40 min

Term Second Term Week 6–7

Previous Algorithm, Flowchart, Number Prerequisite topics


Knowledge Systems

Behavioural Objectives
By the end of this lesson, students should be able to:
1. Define programming and explain what a computer program is
2. List and explain at least five characteristics of a good program
3. State and use arithmetic, relational, and logical operators in BASIC
4. Write and explain the four types of BASIC program statements
5. Identify and use built-in mathematical and string functions in BASIC
6. Write short, complete BASIC programs to solve simple problems
7. Detect and correct common errors in BASIC programs

SECTION 1: INTRODUCTION TO PROGRAMMING

Computer Studies | SS2 | BASIC Programming Page 1


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

Opening Scenario
Imagine you ask a friend to fetch water for you. If your instructions are: "Go outside, pick up
the bucket, walk to the tap, open the tap, fill the bucket, close the tap, and bring the water
back" — your friend will succeed. But if you give random instructions, they will fail. A
computer program is exactly like those instructions — clear, ordered, and precise steps that
tell the computer exactly what to do.

1.1 Meaning of Programming


Programming (also called Computer Programming or Coding) is the process of writing a set of
instructions that tells a computer how to perform a specific task. These instructions are written in a
language the computer can understand.
Just as humans use English, Yoruba, or Hausa to communicate with each other, programmers use
special languages like BASIC, Python, or Java to communicate with computers.

Simple Definition:
Programming is the art and science of creating instructions (called code) that a
computer can read and execute to solve a problem.

1.2 Definition of a Program


A computer program is a set of coded instructions written in a programming language that directs a
computer to perform specific operations or tasks.
Think of a program as a recipe: the recipe tells you step by step how to cook a meal, and the program
tells the computer step by step how to complete a task.

Real-Life Examples of Programs:


• The calculator app on your phone — a program that performs calculations
• WhatsApp — a program that sends and receives messages
• Your school management system — a program that stores student results
• ATM software — a program that processes bank transactions
• Traffic light control system — a program that manages traffic flow

1.3 Characteristics of a Good Program


Not every piece of code qualifies as a good program. A good program must have the following
characteristics:

Characteristic Explanation

Correctness The program must produce the right output for every valid input. It
must solve the problem it was designed for.

Reliability The program must work consistently under all conditions — not crash
unexpectedly.

Computer Studies | SS2 | BASIC Programming Page 2


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

Readability The code must be easy to read and understand by other


programmers (use good variable names, comments, etc.).

Efficiency The program must use computer resources (memory, time) wisely. It
should run fast without wasting space.

Maintainability The program should be easy to update, fix, or improve in the future.

Portability A good program should be able to run on different computers or


operating systems with minimal changes.

User-Friendliness The program should be easy for users to operate, with clear
instructions and helpful messages.

Documentation The program should include comments and explanations so that


others can understand what each part does.

1.4 Importance of Programming


• Allows us to solve complex problems using computers
• Drives modern technology: phones, websites, games, hospitals, banks all rely on programs
• Creates employment — programmers are among the highest-paid professionals in the world
• Develops logical and analytical thinking skills
• Enables automation — repetitive tasks can be performed by computers without human effort
• Supports national development — e-government, agriculture monitoring, health systems
• Forms the foundation for Artificial Intelligence (AI), Robotics, and Data Science

1.5 Examples of Programming Languages


There are many programming languages in the world. They are generally grouped into three levels:

Category Examples Common Use

High-Level BASIC, Python, Java, C++, General programming, education, web,


Languages Pascal, Visual Basic apps

Middle-Level C Language, FORTRAN Systems programming, scientific computing


Languages

Low-Level Assembly Language, Machine Hardware control, device drivers


Languages Language

Focus Language for This Lesson: BASIC


What is BASIC?
BASIC stands for Beginner's All-purpose Symbolic Instruction Code. It was created in 1964
by John Kemeny and Thomas Kurtz at Dartmouth College, USA. It is the most beginner-
friendly programming language and is widely used in Nigerian SS2 Computer Studies
curriculum.

Computer Studies | SS2 | BASIC Programming Page 3


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

1.6 Real-Life Applications of Programming


Field Application Examples

Education Student result management, e-learning platforms, digital libraries

Banking & Finance ATM operations, internet banking, fraud detection systems

Healthcare Patient record systems, drug dispensing machines, hospital


management

Agriculture Weather forecast apps, crop monitoring, soil analysis systems

Transport Traffic control systems, airline booking, GPS navigation

Entertainment Video games, streaming services (Netflix, YouTube), animation

Government Tax collection, voter registration, national identity systems

Communication WhatsApp, email systems, video conferencing apps

KEY POINTS

SECTION 1 SUMMARY
1. Programming is the process of writing instructions for a computer to execute.
2. A program is a set of coded instructions that solves a specific problem.
3. Good programs are correct, reliable, readable, efficient, and maintainable.
4. BASIC (Beginner's All-purpose Symbolic Instruction Code) is our focus language.

SECTION 2: OPERATORS IN BASIC

What is an Operator?
An operator is a special symbol or keyword that tells the computer to perform a specific
operation on values or variables. Just like in Mathematics where + means "add", BASIC
uses operators to perform different kinds of operations.

2.1 Arithmetic Operators


Arithmetic operators are used to perform mathematical calculations such as addition, subtraction,
multiplication, and division. They work on numbers (integers and decimals).

Opera Symbol Meaning Example in BASIC


tor

Additi + Adds two values A+B → 5+3=8

Computer Studies | SS2 | BASIC Programming Page 4


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

on

Subtra - Subtracts one value from A-B → 9-4=5


ction another

Multipl * Multiplies two values A * B → 6 * 4 = 24


ication

Divisio / Divides one value by A / B → 10 / 2 = 5


n another

Intege \ Divides and returns only 10 \ 3 = 3 (no remainder)


r the whole number part
Divisio
n

MOD MOD Returns the remainder 10 MOD 3 = 1


(Modu after division
lus)

Expon ^ Raises a number to a 2 ^ 3 = 8 (i.e. 2³)


entiati power
on

Worked Examples — Arithmetic Operators

Example 1: Basic Arithmetic

10 LET A = 20
20 LET B = 6
30 LET SUM = A + B
40 LET DIFF = A - B
50 LET PROD = A * B
60 LET QUOT = A / B
70 LET REM = A MOD B
80 LET PWR = B ^ 2
90 PRINT "Sum = "; SUM
100 PRINT "Difference = "; DIFF
110 PRINT "Product = "; PROD
120 PRINT "Quotient = "; QUOT
130 PRINT "Remainder = "; REM
140 PRINT "6 Squared = "; PWR
150 END

OUTPUT:
Sum = 26 | Difference = 14 | Product = 120 | Quotient = 3.333... |
Remainder = 2 | 6 Squared = 36

Example 2: Calculating a Student's Total and Average Score

10 LET MATHS = 75
20 LET ENGLISH = 68

Computer Studies | SS2 | BASIC Programming Page 5


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

30 LET SCIENCE = 82
40 LET TOTAL = MATHS + ENGLISH + SCIENCE
50 LET AVERAGE = TOTAL / 3
60 PRINT "Total Score = "; TOTAL
70 PRINT "Average Score = "; AVERAGE
80 END

OUTPUT: Total Score = 225 | Average Score = 75

Example 3: MOD and Integer Division in Real Life


Problem: 25 students are to be shared into groups of 4. How many complete groups are
there, and how many students are left over?

10 LET STUDENTS = 25
20 LET GROUP_SIZE = 4
30 LET GROUPS = STUDENTS \ GROUP_SIZE
40 LET LEFTOVER = STUDENTS MOD GROUP_SIZE
50 PRINT "Complete Groups = "; GROUPS
60 PRINT "Students Left Over = "; LEFTOVER
70 END

OUTPUT: Complete Groups = 6 | Students Left Over = 1

CLASS EXERCISE

CLASS EXERCISE 2.1 — Arithmetic Operators


Evaluate the following BASIC expressions. Write your answers.
1. 15 + 7 * 2 = ____ (Hint: * is done before +)
2. 20 MOD 6 = ____
3. 17 \ 5 = ____
4. 3 ^ 4 = ____
5. (8 + 2) * (10 - 4) = ____
Answers: 1) 29 2) 2 3) 3 4) 81 5) 60

2.2 Relational Operators (Comparison Operators)


Relational operators are used to COMPARE two values. The result of a relational operation is always
either TRUE (1) or FALSE (0). These operators are very important for making decisions in programs.

Operator Symbol Meaning Example & Result

Equal to = Checks if two values are A = B → 5 = 5 is TRUE


the same

Greater > Checks if left value is A > B → 8 > 3 is TRUE


than bigger

Less than < Checks if left value is A < B → 2 < 7 is TRUE

Computer Studies | SS2 | BASIC Programming Page 6


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

smaller

Greater or >= Left is bigger than or A >= B → 5 >= 5 is TRUE


equal equal to right

Less or <= Left is smaller than or A <= B → 4 <= 4 is TRUE


equal equal to right

Not equal <> Checks if two values are A <> B → 5 <> 3 is TRUE
to different

Worked Examples — Relational Operators

Relational operators are commonly used with IF…THEN statements. Here are standalone examples to
understand their results:

Example 1: Comparing Student Scores

10 LET SCORE = 65
20 LET PASS_MARK = 50
30 IF SCORE >= PASS_MARK THEN PRINT "STUDENT PASSED"
40 IF SCORE < PASS_MARK THEN PRINT "STUDENT FAILED"
50 END

OUTPUT: STUDENT PASSED

Example 2: Age Verification

10 LET AGE = 17
20 IF AGE >= 18 THEN PRINT "You can vote"
30 IF AGE < 18 THEN PRINT "Too young to vote"
40 END

OUTPUT: Too young to vote

Example 3: Checking if Two Numbers are Different

10 LET X = 10
20 LET Y = 15
30 IF X <> Y THEN PRINT "X and Y are different"
40 IF X = Y THEN PRINT "X and Y are equal"
50 END

OUTPUT: X and Y are different

Computer Studies | SS2 | BASIC Programming Page 7


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

2.3 Logical Operators


Logical operators are used to combine two or more conditions together. They help us make more
complex decisions. There are three logical operators in BASIC:

Operator How It Works

AND Returns TRUE only when BOTH conditions are TRUE. If even one is FALSE, the
whole expression is FALSE.

OR Returns TRUE when AT LEAST ONE condition is TRUE. Returns FALSE only when
BOTH are FALSE.

NOT Reverses the result of a condition. If a condition is TRUE, NOT makes it FALSE, and
vice versa.

Truth Table for AND and OR:


Condition A Condition B A AND B A OR B

TRUE TRUE TRUE TRUE

TRUE FALSE FALSE TRUE

FALSE TRUE FALSE TRUE

FALSE FALSE FALSE FALSE

Worked Examples — Logical Operators

Example 1: Using AND — Check if a student qualifies for scholarship


Condition: Score must be >= 80 AND Attendance must be >= 75%

10 LET SCORE = 85
20 LET ATTENDANCE = 80
30 IF SCORE >= 80 AND ATTENDANCE >= 75 THEN PRINT "Qualifies for
Scholarship"
40 IF SCORE < 80 OR ATTENDANCE < 75 THEN PRINT "Does Not Qualify"
50 END

OUTPUT: Qualifies for Scholarship

Example 2: Using OR — Classify a number as small

10 LET N = 3
20 IF N = 1 OR N = 2 OR N = 3 THEN PRINT "N is a small number"
30 END

OUTPUT: N is a small number

Computer Studies | SS2 | BASIC Programming Page 8


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

Example 3: Using NOT — Reverse a condition

10 LET RAINING = 0
' 0 means FALSE (not raining)
20 IF NOT RAINING THEN PRINT "Go outside and play!"
30 IF RAINING THEN PRINT "Stay indoors"
40 END

OUTPUT: Go outside and play!

2.4 Order of Precedence (Priority of Operators)


When multiple operators appear in one expression, BASIC follows a strict order called the Order of
Precedence (just like BODMAS in Mathematics):

Priority (High to Low) Operator(s)

1st (Highest) ^ (Exponentiation)

2nd - (Unary minus — making a number negative)

3rd *, /, \ (Multiplication, Division, Integer Division)

4th MOD (Modulus)

5th + and - (Addition and Subtraction)

6th =, <>, <, >, <=, >= (Relational Operators)

7th NOT (Logical NOT)

8th AND (Logical AND)

9th (Lowest) OR (Logical OR)

Important Rule: Expressions inside brackets ( ) are always evaluated FIRST, before all
other operators!

Precedence Example:
Expression: 2 + 3 * 4 ^ 2 - 1

Step 1: Exponentiation first: 4 ^ 2 = 16


Step 2: Multiplication: 3 * 16 = 48
Step 3: Addition: 2 + 48 = 50
Step 4: Subtraction: 50 - 1 = 49

Result = 49

Computer Studies | SS2 | BASIC Programming Page 9


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

KEY POINTS

SECTION 2 SUMMARY
1. Arithmetic operators (+, -, *, /, \, MOD, ^) perform mathematical calculations.
2. Relational operators (=, <>, <, >, <=, >=) compare two values and return TRUE or
FALSE.
3. Logical operators (AND, OR, NOT) combine or reverse conditions.
4. BASIC follows a strict order of precedence — brackets override everything.

SECTION 3: PROGRAM STATEMENTS IN BASIC

What is a Program Statement?


A program statement is a single instruction in a BASIC program. Each statement occupies
one line and tells the computer to perform exactly one specific action. In BASIC, every
statement is assigned a line number (e.g., 10, 20, 30...) and is executed in order from the
smallest to the largest number.

3.1 Input Statements


Input statements are used to receive data from the user during program execution. They pause the
program and wait for the user to type in a value.

Statement Purpose

INPUT Displays a prompt (?) and waits for the user to enter a value. Stores the
value in a variable.

INPUT with Displays a custom message before asking for input.


prompt

READ…DATA Reads data that is stored inside the program itself (in DATA statements).

Syntax:
INPUT variable_name
INPUT "Your message here"; variable_name
READ variable1, variable2
DATA value1, value2

Worked Examples — Input Statements

Example 1: Simple INPUT

Computer Studies | SS2 | BASIC Programming Page 10


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

10 PRINT "Enter your name: "


20 INPUT NAME$
30 PRINT "Hello, "; NAME$
40 END

User types: Amara OUTPUT: Hello, Amara

Example 2: INPUT with custom prompt (inline message)

10 INPUT "Enter your age: "; AGE


20 INPUT "Enter your score: "; SCORE
30 PRINT "Age = "; AGE
40 PRINT "Score = "; SCORE
50 END

Example 3: READ and DATA (data embedded in program)

10 READ NAME$, SCORE


20 DATA "Chukwuemeka", 88
30 PRINT "Student: "; NAME$
40 PRINT "Score: "; SCORE
50 END

OUTPUT: Student: Chukwuemeka | Score: 88

3.2 Output Statements


Output statements are used to display results, messages, or values on the screen. They allow the
program to communicate information back to the user.

Statement Purpose

PRINT Displays text or the value of a variable on the screen

PRINT TAB Moves the cursor to a specific column position before printing

PRINT USING Prints values in a formatted way (e.g., with decimal places)

LPRINT Sends output to a printer instead of the screen

Syntax:
PRINT "text message"
PRINT variable_name
PRINT "label"; variable_name
PRINT TAB(column_number); "text"

Computer Studies | SS2 | BASIC Programming Page 11


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming
Worked Examples — Output Statements

Example 1: Different ways to use PRINT

10 PRINT "Welcome to Computer Studies!"


20 LET MARKS = 95
30 PRINT MARKS
40 PRINT "Your marks are: "; MARKS
50 PRINT "Name:"; TAB(15); "Score:"
60 PRINT "Fatima"; TAB(15); MARKS
70 END

OUTPUT:
Welcome to Computer Studies!
95
Your marks are: 95
Name: Score:
Fatima 95

Example 2: Printing a formatted result

10 INPUT "Enter principal amount: "; P


20 INPUT "Enter rate (%): "; R
30 INPUT "Enter time (years): "; T
40 LET INTEREST = P * R * T / 100
50 PRINT "Simple Interest = N"; INTEREST
60 END

3.3 Assignment Statements


An assignment statement is used to store a value into a variable. It tells the computer: 'Put this value
into this container (variable).' The LET keyword is used in BASIC for assignments.

Syntax: LET variable_name = expression


Note: In some versions of BASIC, the LET keyword is optional. You can write just:
variable_name = expression

Key Rules for Variables in BASIC:


• Variable names must begin with a letter (e.g., A, NAME, SCORE)
• String variables (holding text) must end with a $ sign (e.g., NAME$, CITY$)
• Numeric variables hold numbers only (e.g., AGE, TOTAL, PRICE)
• Variable names should be meaningful (e.g., use SCORE instead of X)
• BASIC is not case-sensitive: AGE, age, and Age all refer to the same variable

Worked Examples — Assignment Statements

Example 1: Numeric and String Assignments

Computer Studies | SS2 | BASIC Programming Page 12


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

10 LET AGE = 16
20 LET PRICE = 1500.50
30 LET NAME$ = "Bello"
40 LET CITY$ = "Lagos"
50 LET TOTAL = AGE * 2
60 PRINT NAME$; " lives in "; CITY$
70 PRINT "Age: "; AGE; " Double Age: "; TOTAL
80 END

OUTPUT: Bello lives in Lagos | Age: 16 Double Age: 32

Example 2: Updating a variable (counter/accumulator)

10 LET COUNT = 0
20 LET COUNT = COUNT + 1 ' Add 1 to COUNT
30 LET COUNT = COUNT + 1
40 LET COUNT = COUNT + 1
50 PRINT "Count = "; COUNT
60 END

OUTPUT: Count = 3

3.4 Control Statements (Decision Making)


Control statements allow a program to make decisions and change its flow of execution based on
conditions. They are the most important statements in programming because they give programs the
ability to THINK and CHOOSE.

A. The IF…THEN Statement


This is the simplest decision-making statement. It tests a condition and executes a statement ONLY if
the condition is TRUE. If the condition is FALSE, the statement is skipped.

Syntax:
IF condition THEN statement

Example 1: Simple IF…THEN

10 INPUT "Enter your score: "; SCORE


20 IF SCORE >= 50 THEN PRINT "Congratulations! You passed!"
30 PRINT "Program complete."
40 END

If user enters 72: OUTPUT: Congratulations! You passed! | Program


complete.
If user enters 35: OUTPUT: Program complete. (the IF line is skipped)

Computer Studies | SS2 | BASIC Programming Page 13


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

Example 2: IF…THEN with GOTO (jump to another line)

10 INPUT "Enter a number: "; N


20 IF N > 0 THEN GOTO 50
30 PRINT "The number is zero or negative"
40 GOTO 60
50 PRINT "The number is positive"
60 END

B. The IF…THEN…ELSE Statement


This is more powerful than IF…THEN. It executes one statement when the condition is TRUE, and a
DIFFERENT statement when the condition is FALSE. It always handles both possibilities.

Syntax:
IF condition THEN statement1 ELSE statement2

Example 1: Pass or Fail decision

10 INPUT "Enter student score: "; SCORE


20 IF SCORE >= 50 THEN PRINT "PASS" ELSE PRINT "FAIL"
30 END

Score = 65: OUTPUT: PASS


Score = 45: OUTPUT: FAIL

Example 2: Odd or Even — complete program

10 PRINT "--- ODD OR EVEN CHECKER ---"


20 INPUT "Enter a whole number: "; N
30 IF N MOD 2 = 0 THEN PRINT N; " is Even" ELSE PRINT N; " is Odd"
40 END

Example 3: Grade Classification — Nested IF (Multi-level decision)

10 PRINT "=== GRADE CALCULATOR ==="


20 INPUT "Enter your exam score (0-100): "; SCORE
30 IF SCORE >= 75 THEN PRINT "Grade: A (Distinction)"
40 IF SCORE >= 60 AND SCORE < 75 THEN PRINT "Grade: B (Credit)"
50 IF SCORE >= 50 AND SCORE < 60 THEN PRINT "Grade: C (Merit)"
60 IF SCORE >= 40 AND SCORE < 50 THEN PRINT "Grade: D (Pass)"
70 IF SCORE < 40 THEN PRINT "Grade: F (Fail)"
80 END

Score = 82: Grade: A (Distinction)

Computer Studies | SS2 | BASIC Programming Page 14


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

3.5 Complete Sample Programs

Sample Program 1: Simple Interest Calculator


Problem: Write a BASIC program to calculate and display the Simple Interest on a loan, given the
Principal, Rate, and Time.

10 REM SIMPLE INTEREST CALCULATOR


20 REM Formula: Interest = Principal * Rate * Time / 100
30 PRINT "========= SIMPLE INTEREST CALCULATOR ========="
40 INPUT "Enter Principal Amount (N): "; P
50 INPUT "Enter Rate of Interest (%): "; R
60 INPUT "Enter Time (in years): "; T
70 LET INTEREST = P * R * T / 100
80 LET TOTAL = P + INTEREST
90 PRINT "-----------------------------------------"
100 PRINT "Principal: N"; P
110 PRINT "Simple Interest: N"; INTEREST
120 PRINT "Total Amount: N"; TOTAL
130 PRINT "========================================="
140 END

Step-by-Step Explanation:
1. Lines 10-20: REM statements are REMARKS (comments) — they explain the
program but are NOT executed.
2. Line 30: PRINT displays a heading/title for the program.
3. Lines 40-60: INPUT statements pause the program and wait for the user to enter P,
R, and T.
4. Line 70: LET calculates the simple interest using the formula.
5. Line 80: LET calculates the total amount (Principal + Interest).
6. Lines 100-120: PRINT statements display the results clearly.
7. Line 140: END marks the end of the program.

Sample Program 2: Student Result Checker


Problem: Write a BASIC program that accepts a student's name and score, then classifies the result as
A, B, C, D, or F and prints PASSED or FAILED.

10 REM STUDENT RESULT CHECKER


20 PRINT "******* STUDENT RESULT SYSTEM *******"
30 INPUT "Enter student name: "; NAME$
40 INPUT "Enter score (0-100): "; SCORE
50 IF SCORE >= 70 THEN LET GRADE$ = "A"
60 IF SCORE >= 60 AND SCORE < 70 THEN LET GRADE$ = "B"
70 IF SCORE >= 50 AND SCORE < 60 THEN LET GRADE$ = "C"
80 IF SCORE >= 40 AND SCORE < 50 THEN LET GRADE$ = "D"
90 IF SCORE < 40 THEN LET GRADE$ = "F"
100 IF SCORE >= 40 THEN LET STATUS$ = "PASSED" ELSE LET STATUS$ = "FAILED"
110 PRINT "--------------------------------------"

Computer Studies | SS2 | BASIC Programming Page 15


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

120 PRINT "Student Name: "; NAME$


130 PRINT "Score: "; SCORE
140 PRINT "Grade: "; GRADE$
150 PRINT "Result: "; STATUS$
160 PRINT "--------------------------------------"
170 END

Sample Run — User enters: Ngozi Okafor, Score: 73


Student Name: Ngozi Okafor
Score: 73
Grade: A
Result: PASSED

KEY POINTS

SECTION 3 SUMMARY
1. INPUT/READ statements receive data from the user or program data.
2. PRINT statements display output (text, numbers, results) on the screen.
3. LET (assignment) stores a value or calculation result into a variable.
4. IF…THEN executes a statement only when a condition is TRUE.
5. IF…THEN…ELSE handles both TRUE and FALSE outcomes of a condition.

SECTION 4: BUILT-IN FUNCTIONS IN BASIC

What is a Built-in Function?


A built-in function is a ready-made instruction that is already programmed into BASIC.
Instead of writing many lines of code to perform common tasks (like finding a square root or
measuring a string), you simply call the function by its name and it does the work for you
automatically.

4.1 Mathematical Functions


Mathematical functions perform numerical calculations. They accept a number as input and return a
processed result.

A. ABS( ) — Absolute Value


ABS(x) returns the absolute value of x — the positive version of any number, regardless of its sign. It
removes the negative sign if present.
Syntax: ABS(number)

PRINT ABS(-15) ' Output: 15


PRINT ABS(7) ' Output: 7
PRINT ABS(-3.75) ' Output: 3.75

Computer Studies | SS2 | BASIC Programming Page 16


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

Example Use: Finding the difference between two temperatures:


LET DIFF = ABS(TEMP1 - TEMP2) ' Always gives positive difference

B. SQR( ) — Square Root


SQR(x) returns the square root of x. The value of x must be a positive number (zero or greater).
Syntax: SQR(number)

PRINT SQR(25) ' Output: 5


PRINT SQR(144) ' Output: 12
PRINT SQR(2) ' Output: 1.41421356...

Example Use: Finding hypotenuse of a right-angle triangle (Pythagoras):


LET HYP = SQR(A^2 + B^2)

C. INT( ) — Integer (Round Down)


INT(x) returns the largest integer that is less than or equal to x. In simple terms, it chops off the decimal
part and rounds DOWN to the nearest whole number.
Syntax: INT(number)

PRINT INT(7.9) ' Output: 7 (not 8 — it rounds DOWN)


PRINT INT(3.2) ' Output: 3
PRINT INT(-4.5) ' Output: -5 (rounds DOWN on negatives)
PRINT INT(100) ' Output: 100 (already a whole number)

Example Use: How many complete weeks in 45 days?


LET WEEKS = INT(45/7) ' Output: 6 complete weeks

4.2 String Functions


String functions work on text (strings). In BASIC, string variables end with $ (e.g., NAME$). String
functions can measure, extract, or manipulate text.

A. LEN( ) — Length of a String


LEN(x$) returns the total number of characters in a string, including spaces and punctuation.
Syntax: LEN(string$)

PRINT LEN("Computer") ' Output: 8


PRINT LEN("BASIC") ' Output: 5
PRINT LEN("Hello World") ' Output: 11 (space is counted!)

LET NAME$ = "Chidubem"


PRINT "Length of name: "; LEN(NAME$) ' Output: 8

B. LEFT$( ) — Extract from the Left

Computer Studies | SS2 | BASIC Programming Page 17


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming
LEFT$(x$, n) extracts the first n characters from the LEFT side of a string.
Syntax: LEFT$(string$, number_of_characters)

PRINT LEFT$("COMPUTER", 4) ' Output: COMP


PRINT LEFT$("Nigeria", 3) ' Output: Nig
PRINT LEFT$("12345", 2) ' Output: 12

Example Use: Extract the first 3 letters of a student's name for ID


LET ID$ = LEFT$(NAME$, 3) ' "Fatima" becomes "Fat"

C. RIGHT$( ) — Extract from the Right


RIGHT$(x$, n) extracts the last n characters from the RIGHT side of a string.
Syntax: RIGHT$(string$, number_of_characters)

PRINT RIGHT$("COMPUTER", 4) ' Output: UTER


PRINT RIGHT$("Nigeria", 3) ' Output: ria
PRINT RIGHT$("SS2-2025", 4) ' Output: 2025

Example Use: Extract year from an admission number


LET ADMNO$ = "ADM-2024"
LET YEAR$ = RIGHT$(ADMNO$, 4) ' Output: 2024

D. MID$( ) — Extract from the Middle


MID$(x$, start, length) extracts a specific number of characters from ANYWHERE inside a string,
starting at a given position. Position counting starts at 1.
Syntax: MID$(string$, start_position, length)

PRINT MID$("COMPUTER", 3, 4) ' Output: MPUT (start at 3, take 4)


PRINT MID$("ABCDEFGH", 2, 3) ' Output: BCD (start at 2, take 3)
PRINT MID$("Nigeria", 4, 3) ' Output: eri (start at 4, take 3)

Explanation of COMPUTER example:


C=1 O=2 M=3 P=4 U=5 T=6 E=7 R=8
Start at position 3 (M), take 4 characters: M-P-U-T = MPUT

4.3 Other Useful Functions

A. RND( ) — Random Number


RND returns a random decimal number between 0 and 1 (e.g., 0.734521...). To generate a random
whole number in a range, multiply and use INT.
Syntax: RND or RND(1)

PRINT RND ' Output: e.g. 0.741832 (random)

' Generate random integer from 1 to 6 (like a dice):


LET DICE = INT(RND * 6) + 1

Computer Studies | SS2 | BASIC Programming Page 18


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

PRINT "Dice roll: "; DICE

' Generate random integer from 1 to 100:


LET LUCKY = INT(RND * 100) + 1

B. VAL( ) — Convert String to Number


VAL(x$) converts a string that contains a number into an actual numeric value so that arithmetic can be
performed on it.
Syntax: VAL(string$)

PRINT VAL("45") ' Output: 45 (as a number)


PRINT VAL("3.14") ' Output: 3.14
PRINT VAL("99 bottles")' Output: 99 (reads up to first non-numeric char)

Example Use: Calculate using a number that was entered as text


LET AMOUNT$ = "5000"
LET TAX = VAL(AMOUNT$) * 0.075
PRINT "Tax = N"; TAX ' Output: Tax = N375

C. STR$( ) — Convert Number to String


STR$(x) converts a numeric value into a string (text). This is useful when you want to join (concatenate)
a number with other text, or format output in special ways.
Syntax: STR$(number)

PRINT STR$(100) ' Output: " 100" (note leading space for
positive)
PRINT STR$(3.14) ' Output: " 3.14"

Example Use: Build a student admission number


LET YEAR = 2025
LET SERIAL = 47
LET ADMNO$ = "STU-" + STR$(YEAR) + "-" + STR$(SERIAL)
PRINT ADMNO$ ' Output: STU- 2025- 47

4.4 Complete Program Using Built-in Functions

Sample Program: Name Analyser + Math Solver


10 REM NAME ANALYSER AND MATH SOLVER
20 PRINT "===== NAME AND MATH ANALYSER ====="
30 INPUT "Enter your full name: "; FULLNAME$
40 INPUT "Enter a number: "; NUM
50 PRINT "------- Name Analysis -------"
60 PRINT "Full Name: "; FULLNAME$
70 PRINT "Length of name: "; LEN(FULLNAME$); " characters"
80 PRINT "First 4 letters: "; LEFT$(FULLNAME$, 4)
90 PRINT "Last 3 letters: "; RIGHT$(FULLNAME$, 3)
100 PRINT "Letters 2 to 5: "; MID$(FULLNAME$, 2, 4)

Computer Studies | SS2 | BASIC Programming Page 19


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

110 PRINT "------ Number Analysis ------"


120 PRINT "Number: "; NUM
130 PRINT "Absolute value: "; ABS(NUM)
140 IF NUM >= 0 THEN PRINT "Square Root: "; SQR(NUM)
150 PRINT "Integer part: "; INT(NUM)
160 PRINT "====================================="
170 END

Sample Run — User enters: "Adaeze Okonkwo", Number: -7.5


Full Name: Adaeze Okonkwo
Length of name: 14 characters
First 4 letters: Adae
Last 3 letters: two
Absolute value: 7.5
Integer part: -8

SECTION 4 SUMMARY — QUICK REFERENCE

Functi Type What It Does Example


on

ABS(n) Math Returns positive value of n ABS(-8) = 8

SQR(n) Math Returns square root of n SQR(49) = 7

INT(n) Math Returns integer (rounds INT(5.9) = 5


down)

LEN(s$ String Returns length of string LEN("Hello") = 5


)

LEFT$ String First n characters from left LEFT$("Basic",2) = "Ba"


(s$,n)

RIGHT String Last n characters from RIGHT$("Basic",2) = "ic"


$(s$,n) right

MID$ String n chars from position p MID$("Basic",2,3) = "asi"


(s$,p,n)

RND Other Random number 0–1 INT(RND*6)+1 = dice

VAL(s$ Other String to number VAL("50") = 50


)

STR$ Other Number to string STR$(75) = " 75"


(n)

COMMON MISTAKES TO AVOID IN BASIC PROGRAMMING

Computer Studies | SS2 | BASIC Programming Page 20


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

Common Mistake Correct Approach / Explanation

Forgetting the $ sign for string Always add $ for text variables: NAME$ = "Tunde" (not
variables (using NAME instead of NAME = "Tunde")
NAME$)

Using = instead of <> to check 'not Use <> for not equal: IF A <> B THEN... (not IF A = B as a
equal' 'not equal' check)

Confusing INT and SQR — using SQR only works on non-negative numbers. Always check:
SQR on a negative number IF N >= 0 THEN PRINT SQR(N)

Forgetting END at the end of every Every BASIC program must end with END on the last
program executable line.

Mixing up INPUT and PRINT — INPUT is for RECEIVING data. PRINT is for DISPLAYING
using INPUT where PRINT is data. They are not interchangeable.
needed

Skipping line numbers or using the Each line in BASIC must have a unique, increasing number.
same line number twice Use 10, 20, 30... (spacing allows for insertions).

Using wrong operator: * for power Power/exponentiation uses ^. Write 2^3 (not 2*3) to mean 2
instead of ^ cubed.

Not enclosing text messages in Always use quotes for text: PRINT "Hello" not PRINT Hello
quotation marks in PRINT

Forgetting both YES and NO Every decision should handle both outcomes using IF…
branches in a decision THEN…ELSE for completeness.

Using LEN on a number instead of LEN only works on strings: LEN(NAME$) is correct.
a string LEN(42) will cause an error.

EXAMINATION QUESTIONS AND ANSWERS

PART A: OBJECTIVE QUESTIONS (Multiple Choice)


Choose the correct answer from the options A–D for each question.

Question 1
Which of the following is the correct BASIC operator for modulus (remainder after division)?
(A) MOD
(B) REM
(C) DIV
(D) INT

Computer Studies | SS2 | BASIC Programming Page 21


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

ANSWER: (A) MOD — e.g., 10 MOD 3 = 1 (the remainder when 10 is divided by 3)

Question 2
What is the output of the following BASIC statement? PRINT LEFT$("COMPUTER", 3)
(A) COM
(B) PUT
(C) TER
(D) MPU

ANSWER: (A) COM — LEFT$ takes the first 3 characters from the LEFT of the string
"COMPUTER" → C, O, M = COM

Question 3
Which BASIC statement is used to RECEIVE data entered by the user from the keyboard?
(A) PRINT
(B) INPUT
(C) LET
(D) DATA

ANSWER: (B) INPUT — The INPUT statement pauses the program and waits for the user to
type in a value.

Question 4
What is the result of: 5 + 2 * 3 ^ 2 in BASIC?
(A) 63
(B) 23
(C) 81
(D) 45

ANSWER: (B) 23
Step 1: 3^2 = 9 (exponentiation first) Step 2: 2*9 = 18 (multiplication) Step 3: 5+18 = 23
(addition last)

Question 5
Which BASIC function returns the number of characters in a text string?
(A) STR$( )
(B) VAL( )
(C) LEN( )
(D) MID$( )

ANSWER: (C) LEN( ) — LEN("BASIC") returns 5 because there are 5 characters in the

Computer Studies | SS2 | BASIC Programming Page 22


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

string.

Question 6
In BASIC, what symbol is used to mark a string variable?
(E) #
(F) @
(G) $ (dollar sign)
(H) &

ANSWER: (C) $ — String variables in BASIC must end with a dollar sign, e.g., NAME$,
CITY$, GRADE$

Question 7
Which logical operator returns TRUE only when BOTH conditions are TRUE?
(E) OR
(F) NOT
(G) AND
(H) XOR

ANSWER: (C) AND — AND requires both conditions to be TRUE. If even one is FALSE, the
result is FALSE.

PART B: THEORY QUESTIONS

Theory Question 1
(a) Define programming. (b) State FIVE characteristics of a good computer program.

MODEL ANSWER:
(a) Programming is the process of writing a set of instructions in a computer language that
directs a computer to perform a specific task or solve a problem.
(b) Five characteristics of a good program:
1. Correctness — It must produce the right result for all valid inputs.
2. Efficiency — It must use computer memory and time economically.
3. Readability — It must be easy to read and understand by other programmers.
4. Maintainability — It must be easy to update and modify in the future.
5. Reliability — It must work correctly under all conditions without unexpected crashes.

Theory Question 2
Explain THREE types of operators in BASIC and give TWO examples of each.

Computer Studies | SS2 | BASIC Programming Page 23


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

MODEL ANSWER:
1. Arithmetic Operators: Used for mathematical calculations.
Examples: + (addition: 5+3=8), * (multiplication: 4*6=24)
2. Relational Operators: Used to compare two values. Result is TRUE or FALSE.
Examples: > (greater than: 8>3 is TRUE), <> (not equal: 5<>3 is TRUE)
3. Logical Operators: Used to combine or reverse conditions.
Examples: AND (both must be TRUE), OR (at least one must be TRUE)

Theory Question 3
Differentiate between the IF…THEN and IF…THEN…ELSE statements in BASIC, using examples.

MODEL ANSWER:
IF…THEN:
Executes a statement ONLY when the condition is TRUE. If the condition is FALSE, nothing
happens — the statement is simply skipped.
Example: IF SCORE >= 50 THEN PRINT "Passed"
IF…THEN…ELSE:
Handles BOTH outcomes — executes one statement when TRUE and a DIFFERENT
statement when FALSE. No outcome is left unhandled.
Example: IF SCORE >= 50 THEN PRINT "Passed" ELSE PRINT "Failed"
Key Difference: IF…THEN only acts when the condition is TRUE. IF…THEN…ELSE
always acts — on TRUE and on FALSE.

Theory Question 4
(a) What is a built-in function in BASIC? (b) State the purpose of each of the following functions: ABS,
SQR, LEN, MID$, and VAL.

MODEL ANSWER:
(a) A built-in function is a pre-defined instruction in BASIC that performs a specific,
commonly needed task automatically, without the programmer writing the logic from scratch.
(b) Functions:
1. ABS(n) — Returns the absolute (positive) value of a number. ABS(-6) = 6.
2. SQR(n) — Returns the square root of a non-negative number. SQR(36) = 6.
3. LEN(s$) — Returns the number of characters in a string. LEN("Hello") = 5.
4. MID$(s$,p,n) — Extracts n characters from string s$ starting at position p.
5. VAL(s$) — Converts a string containing digits into a numeric value for arithmetic.

Theory Question 5
Explain the difference between the INPUT and READ…DATA statements in BASIC. When would you
prefer to use READ…DATA over INPUT?

MODEL ANSWER:
INPUT Statement:
Pauses program execution and waits for the user to type in a value at runtime (while the

Computer Studies | SS2 | BASIC Programming Page 24


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

program is running). The data comes from outside the program (the keyboard).
READ…DATA Statement:
Reads data that is already written INSIDE the program in a DATA statement. The program
does not need to pause for user input — it uses its own embedded data.
Prefer READ…DATA when: (1) the data is fixed and known in advance, (2) the same
data needs to be tested repeatedly, (3) there is a large list of values to process.

PART C: PRACTICAL QUESTIONS WITH SOLUTIONS

Practical Question 1
Write a BASIC program to accept two numbers from the user and display their sum, difference, product,
and quotient.

SOLUTION:

10 REM BASIC ARITHMETIC OPERATIONS


20 PRINT "=== ARITHMETIC CALCULATOR ==="
30 INPUT "Enter first number: "; A
40 INPUT "Enter second number: "; B
50 LET SUM = A + B
60 LET DIFF = A - B
70 LET PROD = A * B
80 LET QUOT = A / B
90 PRINT "Sum: "; SUM
100 PRINT "Difference: "; DIFF
110 PRINT "Product: "; PROD
120 PRINT "Quotient: "; QUOT
130 END

Practical Question 2
Write a BASIC program that accepts a student's score and prints the appropriate grade: A (70–100), B
(60–69), C (50–59), D (40–49), F (0–39).

SOLUTION:

10 REM GRADE CLASSIFICATION PROGRAM


20 PRINT "=== GRADE CLASSIFIER ==="
30 INPUT "Enter your score: "; SCORE
40 IF SCORE >= 70 THEN PRINT "Grade: A (Excellent)"
50 IF SCORE >= 60 AND SCORE < 70 THEN PRINT "Grade: B (Very Good)"
60 IF SCORE >= 50 AND SCORE < 60 THEN PRINT "Grade: C (Good)"
70 IF SCORE >= 40 AND SCORE < 50 THEN PRINT "Grade: D (Pass)"
80 IF SCORE < 40 THEN PRINT "Grade: F (Fail — Please repeat)"
90 END

Practical Question 3
Write a BASIC program to find the largest of THREE numbers entered by the user.

Computer Studies | SS2 | BASIC Programming Page 25


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

SOLUTION:

10 REM FIND THE LARGEST OF THREE NUMBERS


20 PRINT "=== LARGEST NUMBER FINDER ==="
30 INPUT "Enter first number (A): "; A
40 INPUT "Enter second number (B): "; B
50 INPUT "Enter third number (C): "; C
60 LET LARGEST = A
70 IF B > LARGEST THEN LET LARGEST = B
80 IF C > LARGEST THEN LET LARGEST = C
90 PRINT "The largest number is: "; LARGEST
100 END

Explanation:
Line 60 sets LARGEST to A as an initial guess. Line 70 checks if B is bigger — if so,
updates LARGEST to B. Line 80 checks if C is bigger — if so, updates LARGEST to C. After
all comparisons, LARGEST holds the greatest value.

Practical Question 4
Write a BASIC program that accepts a person's name and uses string functions to: (a) display the
name in full, (b) show the number of characters, (c) display the first 5 characters, (d) display the last 4
characters.

SOLUTION:

10 REM STRING FUNCTIONS PROGRAM


20 PRINT "=== NAME ANALYSER ==="
30 INPUT "Enter your full name: "; NAME$
40 PRINT "Full name: "; NAME$
50 PRINT "Number of characters: "; LEN(NAME$)
60 PRINT "First 5 characters: "; LEFT$(NAME$, 5)
70 PRINT "Last 4 characters: "; RIGHT$(NAME$, 4)
80 END

Practical Question 5
Write a BASIC program to calculate the area and perimeter of a rectangle. The program should accept
the length and width, perform the calculations, and display the results with appropriate labels.

SOLUTION:

10 REM RECTANGLE CALCULATOR


20 REM Area = Length x Width
30 REM Perimeter = 2 x (Length + Width)
40 PRINT "===== RECTANGLE CALCULATOR ====="
50 INPUT "Enter the Length: "; L
60 INPUT "Enter the Width: "; W
70 LET AREA = L * W
80 LET PERIM = 2 * (L + W)

Computer Studies | SS2 | BASIC Programming Page 26


COMPUTER STUDIES | SS2 LESSON NOTE BASIC Programming

90 PRINT "---------------------------------"
100 PRINT "Length: "; L; " units"
110 PRINT "Width: "; W; " units"
120 PRINT "Area: "; AREA; " sq. units"
130 PRINT "Perimeter: "; PERIM; " units"
140 PRINT "================================="
150 END

Sample Run — Length=8, Width=5:


Area: 40 sq. units | Perimeter: 26 units

FINAL LESSON SUMMARY

COMPLETE REVIEW — BASIC PROGRAMMING (SS2)


SECTION 1: Introduction
1. Programming is writing instructions for a computer to solve a problem.
2. A good program is correct, efficient, readable, reliable, and maintainable.
3. BASIC (Beginner's All-purpose Symbolic Instruction Code) is a beginner-friendly
language.
SECTION 2: Operators
1. Arithmetic: + - * / \ MOD ^ (for calculations)
2. Relational: = <> < > <= >= (for comparisons, return TRUE/FALSE)
3. Logical: AND OR NOT (for combining or reversing conditions)
SECTION 3: Program Statements
1. INPUT / READ…DATA — receives data from user or program
2. PRINT — displays output on screen
3. LET — assigns a value to a variable
4. IF…THEN and IF…THEN…ELSE — for decision making
SECTION 4: Built-in Functions
1. Math: ABS( ) SQR( ) INT( )
2. String: LEN( ) LEFT$( ) RIGHT$( ) MID$( )
3. Other: RND VAL( ) STR$( )

Teacher's Signature: Head of Department: Date:


_________________________ _________________________ _________________________
__ __ __

Computer Studies | SS2 | BASIC Programming Page 27

You might also like