IGCSE U8-PROGRAMMING 23-24
Theory & PSEUDOCODE
Sequence A set of logical steps executed in a sequence
variable – a named data store that contains a value that
may change during the execution of a program
constant – a named data store that contains a value that
does not change during the execution of a program
Selection It is used to select part of a program to be executed based on
condition.
Example:
if - used only for true condition
if-else – used for both true and false condition
elif ladder - used for multiple conditions
nested if and multiple if - used to define a condition within
an another condition
slab based if : used in If statements when different slabs are
given
Iteration Iteration is the process of repeating steps
Example:
for - number of iterations are known.(Entry controlled
loop/precondition loop)
While - number of iterations are unknown(Entry controlled
loop/ precondition loop)
Repeat until - it prints the statement then checks the
condition/post condition loop)
Note:
counting – keeping track of the number of times an action
is performed
totalling – keeping a total that values are added to
Page 1 of 47
IGCSE U8-PROGRAMMING 23-24
operator – a special character or word in a programming
language that identifies an action to be performed
1-D array A One-Dimensional Array is a group of elements having the
same data type which are stored under a single variable
name.
Example:
Arr = [2,4,5,6,11]
2d array The Two-Dimensional array is organized as matrices which
can be represented as the collection of rows and columns
Example:
An array of 2 rows and 3 columns
Rows : number of sets in the given array
Columns: number of elements in each set
Arr=[[1,2,3],[4,5,6]]
Function procedure – a set of programming statements grouped
together under a single name that can be called to perform
a task in a program.(No return statement)
function – a set of programming statements grouped
together under a single name which can be called to
perform a task in a program, rather than including a copy of
the code every time;
Note: function will return a value back to the main program
parameters – the variables in a procedure or function
declaration that store the values of the arguments passed
from the main program to a procedure or function
Library routines: (built-in functions)
MOD – an arithmetic operator that returns the remainder
of a division; different languages use different symbols for
this operation
DIV – an arithmetic operator that returns the quotient
(whole number part) of a division; different languages use
different symbols for this operation
ROUND – a library routine that rounds a value to a given
Page 2 of 47
IGCSE U8-PROGRAMMING 23-24
number of decimal places
RANDOM – a library routine that generates a random
number
Local and global variables
A global variable can be used by any part of a program – its
scope covers the whole program.
A local variable can only be used by the part of the program it
has been declared in – its scope is restricted to that part of
the program.
Example : (Procedure)
def add():
a=int(input(“Enter a number:”))
b= int(input(“Enter a number:”))
sum=a+b
print(“Result:”,sum)
Example : (Function)
def add():
a=int(input(“Enter a number:”))
b= int(input(“Enter a number:”))
sum=a+b
return sum
Page 3 of 47
IGCSE U8-PROGRAMMING 23-24
String It is a group of characters.
Strings are used to store text. Every string contains a number
of characters.
The characters in a string can be labelled by position number.
The first character in a string can be in position zero or
position one, depending on the language.
File Handling file – a collection of data stored by a computer program to
be used again
While any data stored in RAM will be lost when the computer
is switched off, when data is saved to a file it is stored
permanently. Data stored in a file can thus be accessed by
the same program at a later date or accessed by another
program. Data stored in a file can also be sent to be used on
other computer.
Page 4 of 47
IGCSE U8-PROGRAMMING 23-24
Every file is identified by its filename.
Page 5 of 47
IGCSE U8-PROGRAMMING 23-24
PSEUDOCODE
Pseudo code is a simple method of showing an algorithm. It describes what the algorithm
does by using English key words that are very similar to those used in a high-level
programming language.
Declaration
of
Variables
Input and
output
statements
Page 6 of 47
IGCSE U8-PROGRAMMING 23-24
Conditional
statements
Iteration
statements
Page 7 of 47
IGCSE U8-PROGRAMMING 23-24
TOTALLING
COUNTING
Page 8 of 47
IGCSE U8-PROGRAMMING 23-24
ARRAYS
Note:
ONE-DIMENSIONAL ARRAY
TWO-DIMENSTIONAL ARRAY
Page 9 of 47
IGCSE U8-PROGRAMMING 23-24
PROCEDURES
Page 10 of 47
IGCSE U8-PROGRAMMING 23-24
FUNCTIONS
LOCAL AND GLOBAL VARIABES
Page 11 of 47
IGCSE U8-PROGRAMMING 23-24
String Handling
Page 12 of 47
IGCSE U8-PROGRAMMING 23-24
FIE HANDLING
DECLARE TextLine : STRING // variables are declared as normal
DECLARE MyFile : STRING
MyFile ← "MyText.txt"
// writing the line of text to the file
OPEN MyFile FOR WRITE // opens file for writing
OUTPUT "Please enter a line of text"
INPUT TextLine
WRITEFILE, TextLine // writes a line of text to the file
CLOSEFILE(MyFile) // closes the file
// reading the line of text from the file
OUTPUT "The file contains this line of text:"
OPEN MyFile FOR READ // opens file for reading
READFILE, TextLine // reads a line of text from the file
OUTPUT TextLine
CLOSEFILE(MyFile) // closes the file
Page 13 of 47
IGCSE U8-PROGRAMMING 23-24
EXAMPLES: Codes
Sequential programs: It is a set of logical steps executed in a sequence.(Without a
condition)
1. WAP to accept the radius of a circle. Calculate and display the area of a circle
Program
Output:
2. WAP to accept the Principal, time and rate of interest. Calculate and display the simple interest
Program
Output:
Page 14 of 47
IGCSE U8-PROGRAMMING 23-24
3. WAP to accept the First name and the Last name. Concatenate the First name and the Last name.
Display the full name
Program
Output:
SELECTION
4. WAP to accept a number. Check and display whether the number is positive (one condition)
Program
Output:
Page 15 of 47
IGCSE U8-PROGRAMMING 23-24
5. WAP to accept a number. Check and display whether the number is positive or negative (two
conditions)
Program
Output:
6. WAP to accept a number. Check and display whether the number is positive or negative or
zero(three conditions)
Program
Output:
Page 16 of 47
IGCSE U8-PROGRAMMING 23-24
7. WAP to accept a number and check whether the number is even or odd
Program
Output:
% - modulus operator – to find the remainder
/- division operator – to find the quotient(Float division)
// - division operator – to find the quotient(integer division(ignores the fractional part)
Examples:
5%2 Ans=1
5/2 Ans=2.5
5//2 Ans=2
Page 17 of 47
IGCSE U8-PROGRAMMING 23-24
8. A cloth showroom has announced festival discounts and the gifts on the purchase of
items, based on the total cost as given below:
Total Cost Discount
Up to ₹ 2,000 5%
₹ 2,001 to ₹ 5,000 10%
₹ 5,001 to ₹ 10,000 15%
Above ₹ 10,000 20%
Write a program to input the total cost. Compute and display the discount amount to be
paid by the customer.
**MULTIPLE CONDITIONS (Else if)
Program
Output:
Page 18 of 47
IGCSE U8-PROGRAMMING 23-24
9. WAP to create a very simple pizza-ordering menu. At this pizzeria, there’s only one
kind of pizza you can order: cheese pizza with 4 toppings. Your choices for toppings can
be one or more. Accept the cost of the pizza and calculate the total amount of the pizza
with the toppings. Refer price menu below for the toppings.
Toppings cost
Tomato ₹60
Capsicum ₹70
Mushroom ₹80
Sweetcorn ₹85
**MULTIPLE CONDITIONS (multiple if)
Program
Output:
Page 19 of 47
IGCSE U8-PROGRAMMING 23-24
10. MakeMyTour taxi charges from the passenger as per the tariff given below:
Distance Rate
Up to 5 km ₹ 100
For the next 10 km ₹ 10/km
For the next 10 km ₹ 8/km
More than 25 km ₹ 5/km
Write a program to input the distance covered and calculate and display the amount
paid by the passenger.
Example 1 :: distance covered = 16
Split 16
5(Slab1) + 10(slab2) + 1 (slab3)
Add fare
100 + (10*10)+ (distancecovered-15)*8
100+100+(16-15)*8
100+100+8
208
Example 2 :: distance covered = 29
Split 29
5(Slab1) + 10(slab2) + 10 (slab3) + 4(Sab4)
Add fare
100 + (10*10)+ (10*8)+(distancecovered-25)*5
100+100+80+(29-25)*5
100+100+80+20
300
Note:;
Slab 1 : 100
Slab2 : 10X10
Slab3 : 10 X 8
Slab4 : 25 * 5
Page 20 of 47
IGCSE U8-PROGRAMMING 23-24
Multiple conditions(Slab based)
Program
Output:
Page 21 of 47
IGCSE U8-PROGRAMMING 23-24
Iteration: Looping (for, while)
11. WAP to print your school name 10 times
Program
Output
12. WAP to print numbers from 1 to 10
Program
Output
Page 22 of 47
IGCSE U8-PROGRAMMING 23-24
13. WAP to print numbers from 10 to 1
Program
Output
14. WAP to print EVEN numbers from 1 to 10
Program
Output
Page 23 of 47
IGCSE U8-PROGRAMMING 23-24
15. WAP to print ODD numbers from 1 to 10
Program
Output
16. WAP to find sum of all the numbers from 1 to 10
Program
Output
Page 24 of 47
IGCSE U8-PROGRAMMING 23-24
17. WAP to find sum of all the EVEN numbers from 1 to 10
Program
Output
18. WAP to find sum of all the ODD numbers from 1 to 10
Program
Output
Page 25 of 47
IGCSE U8-PROGRAMMING 23-24
19. WAP to find product of all the numbers from 1 to 5.(Factorial of a number)
Program
Output
20. WAP to accept a number and print all the factors of the number
Program
Output
Page 26 of 47
IGCSE U8-PROGRAMMING 23-24
21. WAP to accept a number .Count and display the number of factors
Program
Output
22. WAP to accept a number and check whether the number is a prime number or not
Program
Output
Page 27 of 47
IGCSE U8-PROGRAMMING 23-24
WHILE LOOP
23. WAP to accept a number. SPLIT and display the digits in a new line.(for loop)
Program and output : (to split three digit number : for range is from (1,4)
Program and output : (to split four digit number : for range is from (1,5)
Program and output : (to split five digit number : for range is from (1,6)
NOTE:
In the above 3 programs, for loop modified according to the number of digits in an input. Loop runs
for 3 times for 3 digit number, 4 times for 4 digits number and 5 times for 5 digit number. Hence
the need of while loop.(number of iterations are unknown)
Page 28 of 47
IGCSE U8-PROGRAMMING 23-24
24. WAP to accept a number. SPLIT and display the digits in a new line.(WHILE loop)
Program and output : (to split three digit number :
Program and output : (to split four digit number : (SAME CODE)
Program and output : (to split five digit number : (SAME code)
NOTE:
While loop is not modified in any of the above programs but splits 3,4 or any number of digits.
Page 29 of 47
IGCSE U8-PROGRAMMING 23-24
25. WAP to accept a number .SPLIT and display the sum of all the digits.
26. WAP to accept a number .SPLIT and display the product of all the digits.
Page 30 of 47
IGCSE U8-PROGRAMMING 23-24
24. WAP to accept a number. SPLIT and display the sum of squares of all the digits.
Example : 123 12+22+32 =1+4+9 = 14
25. WAP to accept a number. SPLIT and display the sum of cubes of all the digits.
Example : 123 13+23+33 =1+8+27 = 36
26. WAP to accept a number. Check and display whether the number is Armstrong or not
Example : 153 13+53+33 =1+125+27 = 153
Variable “orig” is used to store the value of “num” as the value of “num” reaches to 0 inside the loop. So it
cannot be compared with “sum” as original number
Page 31 of 47
IGCSE U8-PROGRAMMING 23-24
27. WAP to accept a sequence of numbers and terminates the program when zero entered.
28. WAP to ask a question “who invented Java” and terminates the program when the user gives
the correct answer
Inventor: James Gosling
29. WAP to display the menu to order a pizza until the user enters a valid choice and terminates
when the valid choice is selected.
Page 32 of 47
IGCSE U8-PROGRAMMING 23-24
ARRAY – one dimensional
30. WAP to initialize an array of 5 elements and display them
31. WAP to declare an array of size 5 and accept user input elements into an array
Page 33 of 47
IGCSE U8-PROGRAMMING 23-24
32. WAP to accept 5 elements. Find and display their sum
33. WAP to accept 5 elements. Find and display the count of even numbers and odd numbers
34. WAP to accept 5 elements. Find and display the sum of even numbers and odd numbers
Page 34 of 47
IGCSE U8-PROGRAMMING 23-24
35. WAP to accept 5 elements. Find and display the count and sum of all the prime numbers
Output:
Page 35 of 47
IGCSE U8-PROGRAMMING 23-24
36. WAP to accept 5 elements. Search an element in an array and display the message found or
not with an index of the search element
37. WAP to accept 5 names into an array. Search the name and display whether the name is
found or not
Page 36 of 47
IGCSE U8-PROGRAMMING 23-24
38. WAP to accept 5 elements. Find and display the maximum and minimum element in an array
Page 37 of 47
IGCSE U8-PROGRAMMING 23-24
38. WAP to accept 5 elements. Arrange the elements in an ascending order and display the result
Page 38 of 47
IGCSE U8-PROGRAMMING 23-24
38. WAP to accept 5 elements. Arrange the elements in an ascending order and display the result
Page 39 of 47
IGCSE U8-PROGRAMMING 23-24
TWO DIMENSTIONAL ARRAY
Two-dimensional arrays can be defined as arrays within an array. 2D arrays erected as
metrics, which is a collection of rows and columns
A class consists of 5 students, and the class has to publish the result of all those students. You
need a table to store all those five students' names, subjects' names, and marks. For that, it
requires storing all information in a tabular form comprising rows and columns. A row
contains the name of subjects, and columns contain the name of the students. That class
consists of four subjects, namely English, Science, Mathematics, and Hindi, and the names of
the students are first, second, third, fourth, and fifth.
Page 40 of 47
IGCSE U8-PROGRAMMING 23-24
39. WAP to initialize an array of 2X3 elements and display them
40. WAP to declare an array of size 2X3 and accept user input elements into an array and display them
41. WAP to declare an array of size 2X3 and accept user input elements into an array. Find and display
sum of all the elements in an array
Page 41 of 47
IGCSE U8-PROGRAMMING 23-24
42. WAP to declare an array of size 2X3 and accept user input elements into an array. Find and display
sum of all the elements in each ROW
43. WAP to declare an array of size 2X3 and accept user input elements into an array. Find and display
sum of all the elements in each COLUMN
Note: Write the column for loop then the row for loop to calculate the column sum
Page 42 of 47
IGCSE U8-PROGRAMMING 23-24
44. WAP to declare an array of size 2X3 and accept user input elements into an array. Count and
display the number of even numbers and odd numbers
45. WAP to declare an array of size 2X3 and accept user input elements into an array. display the sum
of even numbers and odd numbers
Page 43 of 47
IGCSE U8-PROGRAMMING 23-24
46. WAP to declare an array of size 2X3 and accept user input elements into an array. Count and
display the number of even numbers and odd numbers in each ROW
47. WAP to declare an array of size 2X3 and accept user input elements into an array. Count and
display the number of even numbers and odd numbers in each COLUMN
Page 44 of 47
IGCSE U8-PROGRAMMING 23-24
44. WAP to declare an array of size 2X3 and accept user input elements into an array. Find the
maximum and minimum element in an array
Page 45 of 47
IGCSE U8-PROGRAMMING 23-24
45. WAP to declare an array of size 4X2 and accept the first name and the last name in each for 4
people.
TASK 1 : Accept the first name and display the corresponding last name
TASK 2: Accept the last name and display the corresponding first name
Page 46 of 47
IGCSE U8-PROGRAMMING 23-24
OUTPUT:
Page 47 of 47