Here we are going to give you all the important questions and solutions of previous year’s practical question paper of O level module code M3 – R5 which is related Problem solving through Python.
Download O level M3 R5 practical question paper with solution
To download O level Python previous year question paper in PDF, You must open Below link and select year and Click on view button. After that , You will be redirected to another window. And your previous year paper of Python’s practical will be downloaded to your local storage.
Download O level M3 R5 Practical Previous Year Python paper
O level M3 R5 practical question paper with answer in PDF
If you want to read O level previous year question paper of Nielit with solution, then read this article completely. In this you will get all O Level Module Code M3 R5 Previous Year Questions and Solutions.
Question 1 :
Write a program to print all Armstrong numbers in a given range. Note: An Armstrong number is a number whose sum of cubes of digits is equal to the number itself. E.g. 370=33+73+03
Solution of Question 1 :
def is_armstrong(num):
"""
Function to check if a number is an Armstrong number or not.
"""
n = len(str(num))
temp = num
sum = 0
while temp > 0:
digit = temp % 10
sum += digit ** n
temp //= 10
return sum == num
def print_armstrong_numbers(lower, upper):
"""
Function to print all Armstrong numbers in a given range.
"""
for num in range(lower, upper + 1):
if is_armstrong(num):
print(num)
# Driver code
lower = int(input("Enter the lower range: "))
upper = int(input("Enter the upper range: "))
print_armstrong_numbers(lower, upper)
Explanation :
This program takes in a lower and upper range and prints all the Armstrong numbers in that range. The is_armstrong
function checks if a given number is an Armstrong number or not by computing the sum of cubes of its digits. The print_armstrong_numbers
function uses the is_armstrong
function to print all the Armstrong numbers in the given range.
Question 2 :
Write a function to obtain sum n terms of the following series for any positive integer value of X: X +X3 /3! +X5 /5! ! +X7 /7! + …
Solution of Question 2 :
def series_sum(x, n):
"""
Function to obtain the sum of n terms of the series for a given positive integer x.
"""
result = 0
for i in range(n):
result += x**(2*i + 1) / factorial(2*i + 1)
return result
def factorial(n):
"""
Function to calculate the factorial of a given number.
"""
if n == 0:
return 1
else:
return n * factorial(n-1)
# Driver code
x = int(input("Enter the value of x: "))
n = int(input("Enter the number of terms: "))
print("Sum of", n, "terms:", series_sum(x, n))
Explanation :
This program takes in x
and n
as input and calculates the sum of n
terms of the series using the series_sum
function. The factorial
function is used to calculate the factorial of a number, which is used in the computation of the series.
Question 3 :
Write a function to obtain sum n terms of the following series for any positive integer value of X 1+x/1!+x2/2!+x3/3!+…
Solution of Question 3 :
def series_sum(x, n):
"""
Function to obtain the sum of n terms of the series for a given positive integer x.
"""
result = 0
for i in range(n):
result += x**i / factorial(i)
return result
def factorial(n):
"""
Function to calculate the factorial of a given number.
"""
if n == 0:
return 1
else:
return n * factorial(n-1)
# Driver code
x = int(input("Enter the value of x: "))
n = int(input("Enter the number of terms: "))
print("Sum of", n, "terms:", series_sum(x, n))
Explanation :
This program takes in x
and n
as input and calculates the sum of n
terms of the series using the series_sum
function. The factorial
function is used to calculate the factorial of a number, which is used in the computation of the series.
Question 4 :
Write a program to multiply two numbers by repeated addition e.g. 6*7 = 6+6+6+6+6+6+6
Solution of Question 4 :
def multiply(a, b):
"""
Function to multiply two numbers using repeated addition.
"""
result = 0
for i in range(b):
result += a
return result
# Driver code
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
print("Product:", multiply(a, b))
Explanation :
This program takes in two numbers a
and b
as input and calculates their product using the multiply
function. The multiply
function uses a loop to add a
to itself b
times, which is equivalent to multiplying a
by b
.
Question 5 :
Write a program to compute the wages of a daily laborer as per the following rules :-
Hours Worked Rate Applicable Upto first 8 hrs Rs100/-
a) For next 4 hrs Rs30/- per hr extra
b) For next 4 hrs Rs40/- per hr extra
c) For next 4 hrs Rs50/- per hr extra
d) For rest Rs60/- per hr extra
Solution of Question 5 :
def calculate_wages(hours_worked):
wage = 0
if hours_worked <= 8:
wage = hours_worked * 100
elif hours_worked <= 12:
wage = 800 + (hours_worked - 8) * 30
elif hours_worked <= 16:
wage = 800 + 4 * 30 + (hours_worked - 12) * 40
elif hours_worked <= 20:
wage = 800 + 4 * 30 + 4 * 40 + (hours_worked - 16) * 50
else:
wage = 800 + 4 * 30 + 4 * 40 + 4 * 50 + (hours_worked - 20) * 60
return wage
hours_worked = float(input("Enter number of hours worked: "))
wage = calculate_wages(hours_worked)
print("Wage: Rs.", wage)
Explanation :
This program takes the number of hours worked as input and returns the calculated wage as output.
Question 6 :
Accept the name of the labourer and no. of hours worked. Calculate and display the wages. The program should run for N number of labourers as specified by the user.
Solution of Question 6 :
def calculate_wage(name, hours_worked):
wage_per_hour = 100
return name + " earned RS " + str(hours_worked * wage_per_hour)
def main():
num_labourers = int(input("Enter number of labourers: "))
for i in range(num_labourers):
name = input("Enter name of labourer: ")
hours_worked = int(input("Enter number of hours worked: "))
print(calculate_wage(name, hours_worked))
if __name__ == "__main__":
main()
Explanation :
This code uses two functions: calculate_wage
and main
. The calculate_wage
function takes the name of the labourer and the number of hours worked as inputs and returns a string indicating the wages earned. The main
function asks the user to input the number of labourers and then runs a loop that asks for the name of each labourer and the number of hours worked. It calls the calculate_wage
function for each labourer and prints the result.
Question 7 :
Write a program that takes in a sentence as input and displays the number of words, number of capital letters, no. of small letters and number of special symbols.
Solution of Question 7 :
def count_characters(sentence):
words = sentence.split()
num_words = len(words)
num_cap_letters = 0
num_small_letters = 0
num_special_symbols = 0
for char in sentence:
if char.isalpha() and char.isupper():
num_cap_letters += 1
elif char.isalpha() and char.islower():
num_small_letters += 1
elif not char.isalnum():
num_special_symbols += 1
print("Number of words:", num_words)
print("Number of capital letters:", num_cap_letters)
print("Number of small letters:", num_small_letters)
print("Number of special symbols:", num_special_symbols)
sentence = input("Enter a sentence: ")
count_characters(sentence)
Question 8:
Write a program to input two numbers as input and compute the greatest common divisor
Solution of Question 8:
def gcd(a, b):
while b:
a, b = b, a % b
return a
x = int(input("Enter first number: "))
y = int(input("Enter second number: "))
print("The GCD of", x, "and", y, "is", gcd(x, y))
Explanation :
The function gcd
takes two numbers a
and b
as input and uses an iterative implementation of the Euclidean algorithm to compute their GCD. The algorithm repeatedly modifies the values of a
and b
until b
is equal to 0, at which point a
will contain the GCD. The rest of the program prompts the user to input two numbers, passes those numbers to the gcd
function, and prints the result.
Question 9 :
Apply recursive call to do the following:
a) Product of two numbers using repetitive addition
b) Print Fibonacci series upto term n
Solution of Question 9:
def product_of_two_numbers(a, b):
if b == 0:
return 0
return a + product_of_two_numbers(a, b - 1)
def fibonacci(n):
if n <= 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)
def print_fibonacci_series(n):
for i in range(n):
print(fibonacci(i), end=', ')
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("The product of", a, "and", b, "is", product_of_two_numbers(a, b))
n = int(input("Enter the number of terms in the Fibonacci series: "))
print("The first", n, "terms of the Fibonacci series are:")
print_fibonacci_series(n)
Explanation :
The first function, product_of_two_numbers
, implements repetitive addition to find the product of two numbers. The second function, fibonacci
, is a recursive implementation of the Fibonacci sequence. The third function, print_fibonacci_series
, uses a for loop to call the fibonacci
function n
times and print each result, separated by a comma. Finally, the program prompts the user to input two numbers and the number of terms in the Fibonacci series, calls the respective functions, and prints the results.
Hi , मैं मोहिनी एक टेक लवर और Latest & Updated जानकारी सीखने और सिखाने में अच्छा लगता है । मैने DCA, ADCA किया हैं । अभी मैं स्नातक ( Computer Science ) पार्ट 1 में हूं ।