O Level M3-R5 Python Programming Practical Questions with Solutions
This blog covers O Level M3-R5 Python Programming practical exam questions with fully tested programs and easy explanations including NumPy, recursion, series, file handling and logic building.
O Level M3-R5 Programming and Problem Solving Through Python
This blog provides complete and exam-oriented solutions for O Level M3-R5 Python Programming Practical Questions. All programs are tested and written in simple language as required in NIELIT practical exams.
1. Program to Print Armstrong Numbers in a Given Range
An Armstrong number is a number whose sum of cubes of digits is equal to the number itself. Example: 370 = 3³ + 7³ + 0³
start = int(input("Enter start range: "))
end = int(input("Enter end range: "))
for num in range(start, end+1):
temp = num
s = 0
while temp > 0:
d = temp % 10
s += d ** 3
temp //= 10
if s == num:
print(num)
2. Function to Find Sum of Series: X + X³/3! + X⁵/5! + …
import math
def series1(x, n):
s = 0
power = 1
for i in range(n):
s += (x ** power) / math.factorial(power)
power += 2
return s
x = int(input("Enter x: "))
n = int(input("Enter n: "))
print(series1(x, n))
3. Function to Find Sum of Series: 1 + x/1! + x²/2! + …
import math
def series2(x, n):
s = 0
for i in range(n):
s += (x ** i) / math.factorial(i)
return s
x = int(input("Enter x: "))
n = int(input("Enter n: "))
print(series2(x, n))
4. Program to Multiply Two Numbers Using Repeated Addition
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
result = 0
for i in range(b):
result += a
print("Multiplication =", result)
5. Program to Compute Wages of Daily Labourer
n = int(input("Enter number of labourers: "))
for i in range(n):
name = input("Enter labourer name: ")
hours = int(input("Enter hours worked: "))
wage = 0
if hours <= 8:
wage = hours * 100
else:
wage = 8 * 100
hours -= 8
if hours > 0:
extra = min(4, hours)
wage += extra * 30
hours -= extra
if hours > 0:
extra = min(4, hours)
wage += extra * 40
hours -= extra
if hours > 0:
extra = min(4, hours)
wage += extra * 50
hours -= extra
if hours > 0:
wage += hours * 60
print("Name:", name, "Wages:", wage)
6. Function to Replace Successive Repeated Characters with ?
def replace_repeat(s):
result = s[0]
for i in range(1, len(s)):
if s[i] == s[i-1]:
result += '?'
else:
result += s[i]
return result
print(replace_repeat("school"))
7. Program to Analyze a Sentence
s = input("Enter sentence: ")
words = len(s.split())
caps = small = special = 0
for ch in s:
if ch.isupper():
caps += 1
elif ch.islower():
small += 1
elif not ch.isalnum() and ch != ' ':
special += 1
print("Words:", words)
print("Capital letters:", caps)
print("Small letters:", small)
print("Special symbols:", special)
8. Program to Create Cumulative List
lst = list(map(int, input("Enter numbers: ").split()))
cum = []
total = 0
for x in lst:
total += x
cum.append(total)
print(cum)
9. Program to Find Largest, Smallest and Product of List
lst = list(map(int, input("Enter numbers: ").split()))
largest = lst[0]
smallest = lst[0]
product = 1
for x in lst:
if x > largest:
largest = x
if x < smallest:
smallest = x
product *= x
print("Largest:", largest)
print("Smallest:", smallest)
print("Product:", product)
10. Function to Check Common Item in Two Lists
def common(lst1, lst2):
for x in lst1:
if x in lst2:
return True
return False
print(common([1,2,3], [4,5,3]))
11. Combine Two Dictionaries by Adding Values
from collections import Counter
d1 = {'a':100, 'b':200, 'c':300}
d2 = {'a':300, 'b':200, 'd':400}
result = Counter(d1) + Counter(d2)
print(result)
12. Recursive Programs
a) Product of Two Numbers Using Recursion
def multiply(a, b):
if b == 0:
return 0
return a + multiply(a, b-1)
print(multiply(6, 7))
b) Fibonacci Series Using Recursion
def fib(n):
if n <= 1:
return n
return fib(n-1) + fib(n-2)
n = int(input("Enter n: "))
for i in range(n):
print(fib(i), end=" ")
13. Program to Find GCD of Two Numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
while b != 0:
a, b = b, a % b
print("GCD =", a)
14. File Handling Program: Copy File Content
def copy_file(f1, f2):
with open(f1, 'r') as src, open(f2, 'w') as dest:
for line in src:
dest.write(line)
copy_file("f1.txt", "f2.txt")
15. NumPy Program to Find Most Frequent Element
import numpy as np arr = np.array([1,2,2,3,3,3,4]) values, counts = np.unique(arr, return_counts=True) print(values[counts.argmax()])
16. NumPy Program to Concatenate Two 2D Arrays (Axis=1)
import numpy as np a = np.array([[1,2],[3,4]]) b = np.array([[5,6],[7,8]]) c = np.concatenate((a, b), axis=1) print(c)
Conclusion
These programs cover all important O Level M3-R5 Python Practical Questions. Practice each program properly to score maximum marks in the practical examination.