CBSE Coding Class 8 Solution Student Handbook Chapter 4 Programming With Arrays
CBSE Coding Class 8 Solution Student Handbook Chapter 4 Programming With Arrays
LEARN MORE
https://www.netexplanations.com/cbse-coding-class-8-solution-student-handbook-chapter-4-programming-with-arrays/ 1/6
2/19/25, 8:26 PM CBSE Coding Class 8 Solution Student Handbook Chapter 4 Programming with Arrays
Reason: you can make an Array of Integers as well as another Array of Strings. However, you cannot make an Array having
Integer and Strings in same Collection.
Answer: There are chances of wastage of memory space if elements inserted in an array are lesser than the allocated size
Reason: Index value of an array can’t be negative neither we have to sequentially access elements in arrays.
Standard Questions
Answer: Arrays are collection of similar data type variables. Array can store multiples values which can be referenced by single
name. Arrays are always stores in specific memory location. Arrays do not support different data types in same collection. Arrays
improve readability of code by using a single variable for a large set of data.
For Example: you can make an Array of Integers as well as another Array of Strings. You cannot make an Array having Integer
and Strings in same Collection.
Answer: The variables in an Array are always ordered sequentially with index starting with 0.
https://www.netexplanations.com/cbse-coding-class-8-solution-student-handbook-chapter-4-programming-with-arrays/ 2/6
2/19/25, 8:26 PM CBSE Coding Class 8 Solution Student Handbook Chapter 4 Programming with Arrays
10 20 30 40 50 60
0 1 2 3 4 5
First Index = 0
Last Index = 5
(3) Explain how you can sort an array {67, 23, 98, 19} using Python?
Answer: Python has inbuilt sort function to order an array. The sort() method sorts the list ascending by default.
Numbers.Sort()
Print (Numbers)
Answer: Python uses index method to search for an element in an array. For Example –
X = [34,45,3,23,22,78,65]
Print(X.index(23))
If you run the above code, you would get 3 as output. As 23 is located on index 3.
(1) Make an array of animals (10 animals in the array) and use for loop which runs as many times as the length of the array to
drop horses from the sky.
Answer:
https://www.netexplanations.com/cbse-coding-class-8-solution-student-handbook-chapter-4-programming-with-arrays/ 3/6
2/19/25, 8:26 PM CBSE Coding Class 8 Solution Student Handbook Chapter 4 Programming with Arrays
(2) Make an array of animals (10 animals in the array) and use for loop which runs as many times as the length of the array to
drop animal present on the 4th position (Tip: The 4th position will be indexed as 3) from the sky
Answer:
Applied Project
https://www.netexplanations.com/cbse-coding-class-8-solution-student-handbook-chapter-4-programming-with-arrays/ 4/6
2/19/25, 8:26 PM CBSE Coding Class 8 Solution Student Handbook Chapter 4 Programming with Arrays
(1) Problem Statement: There is a robot which can read the numbers written on the cards only when kept close to its eyes. It
can pick only one card containing numbers in its left hand and another in its right hand. Can you help it to arrange the cards in
ascending order using bubble sort? Let’s try it on the numbers 1, 5, 4, 3, 2.
Step 2) Create a function to sort the array and pass the list as argument. And declare and initialize variable Flag to 0 to check if
the statement becomes false.
Step 3) Calculate the number of list and run the outer loop till length of list minus one.
Step 4) Perform inner passes n-1 times for outer pass. Get the first element value and compare it with the second value. If the
second value is less than the first value, then swap the positions.
Step 5) Repeat step 3 passes until you reach the outer pass (n – 1). Get the next element in the list then repeat the process that
was performed in step 3 until all the values have been placed in their correct ascending order. And change the value of flag to
1.
Step 6) Check the value of Flag if changed, if so then break the loop .
Step 7) Return the result when all passes have been done. Return the results of the sorted list.
defbubbleSort(array):
n = len(array)
for i in range( n – 1 ) :
flag = 0
for j in range(n – 1) :
tmp = array[j]
array [j + 1] = tmp
flag = 1
if flag == 0:
break
return array
https://www.netexplanations.com/cbse-coding-class-8-solution-student-handbook-chapter-4-programming-with-arrays/ 5/6
2/19/25, 8:26 PM CBSE Coding Class 8 Solution Student Handbook Chapter 4 Programming with Arrays
Number= [1, 5, 4, 3, 2]
result = bubbleSort(Number)
print (result)
https://www.netexplanations.com/cbse-coding-class-8-solution-student-handbook-chapter-4-programming-with-arrays/ 6/6