
🎓 हर हाथ कंप्यूटर, हर हाथ रोज़गार
30 real O Level PR-3 Python practical questions from Practical Sets 1 to 10 — each with a complete solution, sample input, the real output and an exam tip — plus the mistakes that cost marks, viva questions with answers, and a free online PR-3 practical test.
Zed-King Group of Institute
Zed-King Group of Institute

Most students who fail O Level M3-R5.1 do not fail the theory paper. They fail the Python practical — because they read programs in a notebook and never typed them, and on exam day the code on the screen does not run.
💻 Run every program below for free, right in your browser: copy it into our online Python compiler (real Python with NumPy — no install), then test yourself with Python practice questions that are checked instantly.
This guide fixes that. Below are 30 real Python practical questions from the ten O Level PR-3 Practical Question Sets, each with a complete solution, the sample input, the exact output, and one exam tip that saves marks. They are grouped by topic, so you can practise one kind of program at a time.
Every solution on this page was run in real Python 3 before it was published, and the output you see is the output the program actually prints — not something typed by hand. If your program prints the same thing for the same input, your logic is right.
Zed-King Group of Institute, Kaithal is a NIELIT Study Centre (ACCR-O3292) under the Ministry of Electronics & IT, Government of India. When you finish reading, you can take a free PR-3 mock test that runs your Python code in the browser — the link is at the end of the program list.
What This Guide Covers
Item | Detail |
|---|---|
Module | M3-R5.1 — Programming and Problem Solving through Python |
Practical paper | PR-3 |
Questions solved | 30, from Practical Question Sets 1 to 10 |
Topics | Loops and conditions · formulas · strings · lists and dictionaries · file handling · NumPy |
Each question has | Solution code · sample input · real output · exam tip |
Also inside | Mistakes that cost marks · viva questions with answers · free practice tests |
How the PR-3 Practical Is Judged
The practical is not a formality. Like every O Level module, it has to be cleared on its own at 50% — a good theory score does not carry a weak practical.
In the practical, the examiner is looking for four things, roughly in this order:
The program runs. A program with a syntax error usually scores very little, however good the idea was.
The output is correct for the input given in the question.
The logic is your own and readable — sensible variable names, correct indentation, the loop or condition the question asks for.
You can explain it in the viva. Expect to be asked why you used a particular loop, what a function returns, or what happens if the input changes.
The NIELIT practical gives you a small set of questions and asks you to attempt only some of them. Our free PR-3 practice tests follow that pattern: 3 questions, attempt any 2, 40 marks each, 50 minutes.
Topic Map — Where the 30 Questions Come From
Look at how the questions spread across the syllabus. This is the order to practise in:
Topic | Programs | M3 syllabus chapter |
|---|---|---|
Numbers, Conditions and Loops | 11 | Chapter 4: Operators, Expressions and Python Statements |
Formula Programs | 5 | Chapter 4: Operators, Expressions and Python Statements |
Strings | 3 | Chapter 5: Sequence Data Types |
Lists and Dictionaries | 4 | Chapter 5: Sequence Data Types |
File Handling | 4 | Chapter 7: File Processing |
NumPy | 3 | Chapter 9: NumPy Basics |
More than a third of the questions are numbers, conditions and loops, and the formula programs use the same skills. If you can write Prime, Factorial, Fibonacci, Armstrong, reverse and sum of digits without looking, you have already covered the biggest block. File handling and NumPy are fewer questions, but students skip them — so they are where marks are easiest to gain over others.
Numbers, Conditions and Loops (11 programs)
Syllabus link: Chapter 4: Operators, Expressions and Python Statements
1. Check whether a number is Prime
Question: Write a program to check whether a given number is Prime or not. (Practical Set 1)
Solution:
n = int(input())
if n < 2:
print("Not Prime")
else:
is_prime = True
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
is_prime = False
break
if is_prime:
print("Prime")
else:
print("Not Prime")Sample input: 29 → Output:
Prime💡 Exam tip: Test divisors only up to the square root of the number — it is enough, and it is faster. Remember that 0 and 1 are not prime.
2. Check whether a number is even or odd
Question: Write a program to check whether a number is even or odd. (Practical Set 7)
Solution:
n = int(input())
if n % 2 == 0:
print("Even")
else:
print("Odd")Sample input: 17 → Output:
Odd💡 Exam tip: The easiest marks in the paper. Write it neatly and print exactly what was asked.
3. Check whether a candidate is eligible to vote
Question: Write a program to check whether a candidate is eligible to vote. (Practical Set 8)
Solution:
age = int(input())
if age >= 18:
print("Eligible for vote")
else:
print("Not Eligible for vote")Sample input: 20 → Output:
Eligible for vote💡 Exam tip: The condition is >= 18, not > 18. An 18-year-old can vote.
4. Sum of even numbers between 1 and 50
Question: Write a program to display the sum of the even numbers between 1 and 50. (Practical Set 8)
Solution:
total = 0
for i in range(1, 51):
if i % 2 == 0:
total = total + i
print("Sum of even numbers:", total)Output:
Sum of even numbers: 650💡 Exam tip: range(1, 51) includes 50. range(1, 50) stops at 49 and gives the wrong total.
5. Factorial of a given number
Question: Write a program to find the Factorial of a given number. (Practical Set 2)
Solution:
n = int(input())
fact = 1
for i in range(1, n + 1):
fact = fact * i
print("Factorial:", fact)Sample input: 6 → Output:
Factorial: 720💡 Exam tip: Start fact at 1, not 0. Starting at 0 makes every answer 0.
6. Fibonacci series up to N terms
Question: Write a program to generate the Fibonacci series up to N terms. (Practical Set 3)
Solution:
n = int(input())
a, b = 0, 1
for i in range(n):
print(a, end=" ")
a, b = b, a + b
print()Sample input: 10 → Output:
0 1 1 2 3 5 8 13 21 34💡 Exam tip: a, b = b, a + b updates both numbers in one line without a temporary variable — examiners like to see it.
7. Armstrong number
Question: Write a program to check whether a number is an Armstrong number (for example 153 = 1³ + 5³ + 3³). (Practical Set 3)
Solution:
n = int(input())
temp = n
total = 0
digits = len(str(n))
while temp > 0:
d = temp % 10
total = total + d ** digits
temp = temp // 10
if total == n:
print("Armstrong")
else:
print("Not Armstrong")Sample input: 153 → Output:
Armstrong💡 Exam tip: Use len(str(n)) for the power, so the same program works for 3-digit and 4-digit numbers like 1634.
8. Reverse the digits of a number
Question: Write a program to reverse the digits of a number. (Practical Set 4)
Solution:
n = int(input())
rev = 0
while n > 0:
rev = rev * 10 + n % 10
n = n // 10
print("Reverse:", rev)Sample input: 12345 → Output:
Reverse: 54321💡 Exam tip: Use integer division //. With / the number becomes a float and the loop never behaves.
9. Sum of digits of a number
Question: Write a program to find the sum of digits of a number. (Practical Set 5)
Solution:
n = int(input())
total = 0
while n > 0:
total = total + n % 10
n = n // 10
print("Sum of digits:", total)Sample input: 9875 → Output:
Sum of digits: 29💡 Exam tip: n % 10 gives the last digit and n // 10 removes it. The same two lines solve reverse, sum and count of digits.
10. Count the number of digits in a number
Question: Write a program to count the number of digits in a number. (Practical Set 6)
Solution:
n = int(input())
count = 0
while n > 0:
count = count + 1
n = n // 10
print("Number of digits:", count)Sample input: 845721 → Output:
Number of digits: 6💡 Exam tip: len(str(n)) is also a correct one-line answer. The loop version shows the logic, which is useful in the viva.
11. Display all Prime numbers between two given numbers
Question: Write a program to display all Prime numbers between two given numbers. (Practical Set 5)
Solution:
start = int(input())
end = int(input())
for n in range(start, end + 1):
if n < 2:
continue
is_prime = True
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
is_prime = False
break
if is_prime:
print(n, end=" ")
print()Sample input: 10, 30 → Output:
11 13 17 19 23 29💡 Exam tip: This is the Prime program inside a loop. Use break as soon as a divisor is found.
Formula Programs (5 programs)
Syllabus link: Chapter 4: Operators, Expressions and Python Statements
12. Total, Percentage and Grade of a student
Question: Write a program to calculate the Total, Percentage and Grade of a student from the marks of 5 subjects (each out of 100). (Practical Set 1)
Solution:
m1 = int(input())
m2 = int(input())
m3 = int(input())
m4 = int(input())
m5 = int(input())
total = m1 + m2 + m3 + m4 + m5
percentage = total / 5
if percentage >= 85:
grade = "S"
elif percentage >= 75:
grade = "A"
elif percentage >= 65:
grade = "B"
elif percentage >= 55:
grade = "C"
elif percentage >= 50:
grade = "D"
else:
grade = "F"
print("Total:", total)
print("Percentage:", percentage)
print("Grade:", grade)Sample input: 78, 85, 69, 90, 72 → Output:
Total: 394
Percentage: 78.8
Grade: A💡 Exam tip: Check the highest grade first. If you test percentage >= 50 before percentage >= 85, every student gets a D.
13. Simple Interest
Question: Write a program to find the Simple Interest, where SI = (P × R × T) / 100. (Practical Set 1)
Solution:
p = float(input())
r = float(input())
t = float(input())
si = (p * r * t) / 100
print("Simple Interest:", si)Sample input: 5000, 5, 2 → Output:
Simple Interest: 500.0💡 Exam tip: Read the values with float(), not int(), so a rate like 7.5 does not crash the program.
14. Compound Interest
Question: Write a program to find the Compound Interest, where CI = P × (1 + R/100)^T − P. (Practical Set 3)
Solution:
p = float(input())
r = float(input())
t = float(input())
amount = p * ((1 + r / 100) ** t)
ci = amount - p
print("Compound Interest:", ci)Sample input: 10000, 5, 2 → Output:
Compound Interest: 1025.0💡 Exam tip: The power operator in Python is **, not ^. In Python ^ is bitwise XOR and gives a wrong answer silently.
15. Net Salary of an employee
Question: Write a program to calculate the Gross and Net Salary of an employee from basic salary, HRA %, DA % and total deduction. (Practical Set 4)
Solution:
basic = float(input())
hra_percent = float(input())
da_percent = float(input())
deduction = float(input())
hra = basic * hra_percent / 100
da = basic * da_percent / 100
gross = basic + hra + da
net = gross - deduction
print("Gross Salary:", gross)
print("Net Salary:", net)Sample input: 20000, 10, 20, 1500 → Output:
Gross Salary: 26000.0
Net Salary: 24500.0💡 Exam tip: HRA and DA are percentages of the basic salary — calculate them first, then add. Label every line of output.
16. Area of a circle
Question: Write a program to find the area of a circle, rounded to 2 decimal places. (Practical Set 6)
Solution:
import math
r = float(input())
area = math.pi * r * r
print("Area of circle:", round(area, 2))Sample input: 7 → Output:
Area of circle: 153.94💡 Exam tip: Use math.pi instead of typing 3.14 — it is more accurate and shows you know the math module.
Strings (3 programs)
Syllabus link: Chapter 5: Sequence Data Types
17. Count vowels, consonants, digits and special characters
Question: Write a program to count the vowels, consonants, digits and special characters in a string (spaces count as special characters). (Practical Set 2)
Solution:
text = input()
vowels = consonants = digits = special = 0
for ch in text:
if ch.isalpha():
if ch.lower() in "aeiou":
vowels += 1
else:
consonants += 1
elif ch.isdigit():
digits += 1
else:
special += 1
print("Vowels:", vowels)
print("Consonants:", consonants)
print("Digits:", digits)
print("Special:", special)Sample input: Hello World 123! → Output:
Vowels: 3
Consonants: 7
Digits: 3
Special: 3💡 Exam tip: isalpha() and isdigit() do most of the work. Whatever is neither is a special character.
18. Check whether a string is a Palindrome
Question: Write a program to check whether a string is a Palindrome. (Practical Set 4)
Solution:
s = input().strip()
if s == s[::-1]:
print("Palindrome")
else:
print("Not Palindrome")Sample input: madam → Output:
Palindrome💡 Exam tip: s[::-1] reverses a string. It is the shortest correct answer and is enough in the exam.
19. Check whether a string starts or ends with a given word
Question: Write a program to check whether a string starts or ends with a given word. (Practical Set 9)
Solution:
text = input()
word = input().strip()
print("Starts with:", text.startswith(word))
print("Ends with:", text.endswith(word))Sample input: ZedKing Institute Kaithal, Zed → Output:
Starts with: True
Ends with: False💡 Exam tip: startswith() and endswith() return True or False, so they can be printed directly.
Lists and Dictionaries (4 programs)
Syllabus link: Chapter 5: Sequence Data Types
20. Third smallest distinct number in a list
Question: Write a program to find the third smallest distinct number in a list of integers. If there are fewer than 3 distinct numbers, print -1. (Practical Set 7)
Solution:
nums = list(map(int, input().split()))
distinct = sorted(set(nums))
if len(distinct) < 3:
print(-1)
else:
print(distinct[2])Sample input: 5 4 3 2 1 → Output:
3💡 Exam tip: set() removes duplicates and sorted() orders them, so the answer is simply index 2.
21. Count the frequency of a given element
Question: Write a program to count the frequency of a given element in a list. (Practical Set 9)
Solution:
nums = input().split()
key = input().strip()
print("Frequency:", nums.count(key))Sample input: 4 7 2 7 9 7 1, 7 → Output:
Frequency: 3💡 Exam tip: The list method count() gives the answer directly.
22. Separate even and odd numbers into two lists
Question: Write a program to separate the even and odd numbers of a list into two different lists. (Practical Set 10)
Solution:
nums = list(map(int, input().split()))
even = []
odd = []
for n in nums:
if n % 2 == 0:
even.append(n)
else:
odd.append(n)
print("Even:", even)
print("Odd:", odd)Sample input: 1 2 3 4 5 6 7 8 9 10 → Output:
Even: [2, 4, 6, 8, 10]
Odd: [1, 3, 5, 7, 9]💡 Exam tip: Create both empty lists before the loop and use append() inside it.
23. Dictionary of employees with add, update, delete and search
Question: Create a dictionary of employees (ID and Name) and perform add, update, delete and search operations. (Practical Set 9)
Solution:
employees = {101: "Amit", 102: "Neha", 103: "Rahul"}
print("Employees:", employees)
employees[104] = "Priya"
print("After add:", employees)
employees[102] = "Neha Sharma"
print("After update:", employees)
del employees[103]
print("After delete:", employees)
if 101 in employees:
print("Search 101:", employees[101])
else:
print("Search 101: Not found")Output:
Employees: {101: 'Amit', 102: 'Neha', 103: 'Rahul'}
After add: {101: 'Amit', 102: 'Neha', 103: 'Rahul', 104: 'Priya'}
After update: {101: 'Amit', 102: 'Neha Sharma', 103: 'Rahul', 104: 'Priya'}
After delete: {101: 'Amit', 102: 'Neha Sharma', 104: 'Priya'}
Search 101: Amit💡 Exam tip: Adding and updating use the same syntax — employees[key] = value. Use in before searching so a missing ID does not crash the program.
File Handling (4 programs)
Syllabus link: Chapter 7: File Processing
24. Create a text file, write into it and display it
Question: Write a program to create a text file, write data into it, and then display its contents. (Practical Set 2)
Solution:
f = open("data.txt", "w")
f.write("ZedKing Institute Kaithal")
f.close()
f = open("data.txt", "r")
print(f.read())
f.close()Output:
ZedKing Institute Kaithal💡 Exam tip: Call close() after writing. If you read the file back before closing it, the data may not be saved yet.
25. Copy the contents of one text file into another
Question: Write a program to copy the contents of one text file into another file. (Practical Set 6)
Solution:
f = open("source.txt", "w")
f.write("ZedKing Institute Kaithal")
f.close()
f1 = open("source.txt", "r")
data = f1.read()
f1.close()
f2 = open("target.txt", "w")
f2.write(data)
f2.close()
f3 = open("target.txt", "r")
print(f3.read())
f3.close()Output:
ZedKing Institute Kaithal💡 Exam tip: Open the source in "r" mode and the target in "w" mode. Print the target at the end so the examiner can see the copy worked.
26. Count lines, words and characters in a text file
Question: Write a program to count the lines, words and characters in a text file. (Practical Set 5)
Solution:
text = "ZedKing Institute Kaithal\nNIELIT O Level Course\nPython Programming"
f = open("story.txt", "w")
f.write(text)
f.close()
f = open("story.txt", "r")
data = f.read()
f.close()
lines = data.split("\n")
words = data.split()
print("Lines:", len(lines))
print("Words:", len(words))
print("Characters:", len(data))Output:
Lines: 3
Words: 9
Characters: 66💡 Exam tip: split() with no argument splits on any whitespace, which is exactly what "words" means.
27. Count digits, uppercase letters and punctuation in a file
Question: Write a program to create a file and count the digits, uppercase letters and punctuation marks in it, then display all the lines in the file. (Practical Set 8)
Solution:
import string
text = "ZedKing Institute, Kaithal.\nO Level Batch 2026!"
f = open("data.txt", "w")
f.write(text)
f.close()
f = open("data.txt", "r")
data = f.read()
f.close()
digits = 0
upper = 0
punct = 0
for ch in data:
if ch.isdigit():
digits = digits + 1
if ch.isupper():
upper = upper + 1
if ch in string.punctuation:
punct = punct + 1
print("Digits:", digits)
print("Uppercase:", upper)
print("Punctuation:", punct)
print("Lines in the file:")
for line in data.split("\n"):
print(line)Output:
Digits: 4
Uppercase: 7
Punctuation: 3
Lines in the file:
ZedKing Institute, Kaithal.
O Level Batch 2026!💡 Exam tip: string.punctuation holds every punctuation character, so you do not have to type the list yourself.
NumPy (3 programs)
Syllabus link: Chapter 9: NumPy Basics
28. Shape, size and dimensions of an array
Question: Using NumPy, display the shape, size and number of dimensions of an array. (Practical Set 10)
Solution:
import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])
print("Array:")
print(a)
print("Shape:", a.shape)
print("Size:", a.size)
print("Dimensions:", a.ndim)Output:
Array:
[[1 2 3]
[4 5 6]]
Shape: (2, 3)
Size: 6
Dimensions: 2💡 Exam tip: shape, size and ndim are attributes, not methods — no brackets after them.
29. Addition, subtraction, multiplication and division of two arrays
Question: Using NumPy, perform addition, subtraction, multiplication and division of two arrays. (Practical Set 10)
Solution:
import numpy as np
a = np.array([10, 20, 30])
b = np.array([2, 4, 5])
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)Output:
Addition: [12 24 35]
Subtraction: [ 8 16 25]
Multiplication: [ 20 80 150]
Division: [5. 5. 6.]💡 Exam tip: NumPy works element by element — no loop needed. Division always gives floats, which is why the output shows 5..
30. Stack two arrays vertically and horizontally
Question: Using NumPy, stack two arrays horizontally and vertically. (Practical Set 7)
Solution:
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6, 7, 8, 9])
print("Horizontal stack:")
print(np.hstack((a, b)))
print("Vertical stack:")
print(np.vstack((a, b.reshape(2, 3))))Output:
Horizontal stack:
[1 2 3 4 5 6 7 8 9]
Vertical stack:
[[1 2 3]
[4 5 6]
[7 8 9]]💡 Exam tip: vstack needs rows of equal length, which is why b is reshaped to 2×3 first.
8 Mistakes That Cost Marks in the Python Practical
Forgetting to convert input. input() always returns text. "5" + "3" is "53", not 8. Wrap it: int(input()) or float(input()).
Using ^ for power. In Python the power operator is **. ^ runs without an error and gives a wrong answer.
Wrong range limit. range(1, 50) stops at 49. If the question says "1 to 50", write range(1, 51).
Mixed tabs and spaces. Python treats indentation as syntax. Use 4 spaces everywhere, and never copy code from a PDF straight into the editor.
Printing something different from what was asked. If the question says print Prime or Not Prime, do not print "The number is a prime number". Match the wording.
Not closing files. Call close() after writing, or use with open("file.txt", "w") as f:, which closes the file for you.
Forgetting the import. NumPy programs need import numpy as np on the first line. Without it, the whole program fails at line one.
Running the program only once. Try at least two inputs — including an edge case such as 0, 1 or a negative number — before you call the examiner.
Python Viva Questions With Short Answers
The viva is short, but it decides your marks when two programs look alike. These come up again and again:
What is Python? A high-level, interpreted, general-purpose programming language that supports procedural and object-oriented programming.
Who developed Python? Guido van Rossum. It was first released in 1991.
Why is indentation important in Python? Python uses indentation, not braces, to mark a block of code. Wrong indentation is an error.
What is the difference between a list and a tuple? A list is mutable — it can be changed. A tuple is immutable — it cannot be changed after it is created.
What is a dictionary? A collection of key–value pairs, where every key is unique. Example: {101: "Amit"}.
What is the difference between / and //? / always gives a float (7 / 2 = 3.5). // is floor division (7 // 2 = 3).
What is the difference between == and is? == compares values. is checks whether two names refer to the same object.
What is the difference between break and continue? break leaves the loop. continue skips the rest of the current pass and moves to the next one.
What does return do? It ends the function and sends a value back to the place the function was called from.
What is a local and a global variable? A local variable exists only inside the function where it is created. A global variable is created outside all functions and can be read anywhere in the program.
What is the difference between read() and readline()? read() reads the whole file. readline() reads one line at a time.
What is NumPy used for? Fast numerical work on arrays — arithmetic on whole arrays at once, without writing loops.
Practise PR-3 for Free — Real Python in Your Browser
Reading these 30 programs is step one. Writing them against a clock is what actually prepares you. Everything below is free, with no login and no fee:
Free PR-3 Python practical test — 10 practical papers. You write the code, it runs in real Python inside the browser (NumPy included), and it is marked out of 40 per question.
PR-3 previous year practical question sets — all 10 practical sets as PDFs.
M3-R5.1 viva questions with answers — a revision sheet for the viva.
Python practical video classes — step-by-step videos for the practical chapters.
Preparing for the M3 theory paper as well?
M3-R5.1 notes, chapter-wise MCQ and model papers — all 9 chapters.
Free M3 theory online test — 10 sets of 50 questions in 45 minutes, graded on the NIELIT S–F scale with an explanation for every answer.
Start the Free PR-3 Python Practical Test
A Simple 3-Week Plan for the Python Practical
Week 1 — Numbers, conditions and loops. Programs 1 to 11 above. Type each one from memory, then compare with the solution.
Week 2 — Formulas, strings, lists and dictionaries. Programs 12 to 23. Change the sample input and predict the output before you run it.
Week 3 — File handling, NumPy and full papers. Programs 24 to 30, then one timed PR-3 practice paper every day.
Every day: five viva questions out loud. Explaining code in words is a separate skill, and the viva tests it.
The students who score well in PR-3 are not the ones who read the most programs. They are the ones who typed the most.
Learn O Level and Python at Zed-King Institute, Kaithal
Zed-King Group of Institute is a NIELIT Study Centre — ACCR-O3292 — Ministry of Electronics & IT, Government of India, running in Kaithal since 2006. In our lab, every student writes and runs Python on a real computer, practical by practical, with a teacher to fix the error on the screen.
Course | Fee | Duration |
|---|---|---|
NIELIT O Level (M1–M4 with all practicals) | ₹20,000 | 1 Year |
Python Programming | ₹7,000 | 3 Months |
Visit us at: Kaithal - Pundri - Karnal Rd, near New Bus Stand, opp. Hanuman Vatika, Friends Colony, Kaithal, Haryana 136027. Call +91-9416111612.
Join O Level Course — NIELIT Study Centre, Kaithal
Related Reading
Tags
Free for every student
O Level mock tests (M1–M4 theory and PR-1–PR-4 practical) with instant grading, plus free notes, PDFs and video classes for CCC, O Level and ECC. No fees, no registration.
FAQ
Share this Article
ZedKing Courses
NIELIT & Indian Govt. certified programmes, expert faculty, aur guaranteed career support.
More Like This