TutorialsISCClass 11Python

Python Practice Questions and Solved Programs for ICSE and ISC Students

Test your Python skills with output prediction questions, error-finding exercises, solved programs, and MCQ-style questions designed for ICSE and ISC board examinations.

Updated 15 min read
Python Practice Questions and Solved Programs for ICSE and ISC Students

Welcome to Part 3 of our Python for ICSE and ISC Students series! In Part 1, you learned what Python is and wrote your first program. In Part 2, you mastered variables, data types, and operators. Now it is time to put all that knowledge to the test.

This tutorial contains the types of questions that frequently appear in ICSE and ISC board examinations. Practice each section carefully and try to solve the questions on your own before looking at the answers.

Section A: Predict the Output

Read each code snippet carefully and predict what it will print. These questions test your understanding of how Python evaluates expressions.

Question 1

x = 10
y = 3
print(x / y)
print(x // y)
print(x % y)

Answer:

3.3333333333333335
3
1

Explanation: The / operator performs regular division and always returns a float. The // operator performs floor division (removes the decimal). The % operator gives the remainder when 10 is divided by 3.

Question 2

a = "Python"
b = "Programming"
print(a + " " + b)
print(a * 2)
print(len(a))

Answer:

Python Programming
PythonPython
6

Explanation: The + operator concatenates strings. The * operator repeats a string. The len() function returns the number of characters.

Question 3

x = 5
x += 3
x *= 2
x -= 4
print(x)

Answer: 12

Explanation: Step by step: x = 5, then x = 5 + 3 = 8, then x = 8 * 2 = 16, then x = 16 - 4 = 12.

Question 4

a = True
b = False
print(a and b)
print(a or b)
print(not a)
print(a and not b)

Answer:

False
True
False
True

Explanation: The and operator returns True only when both values are True. The or operator returns True when at least one is True. The not operator reverses the Boolean value. In the last line, not b is True, so True and True gives True.

Question 5

fruits = ["apple", "banana", "cherry", "date"]
print(fruits[1])
print(fruits[-1])
fruits.append("elderberry")
print(len(fruits))
fruits[0] = "avocado"
print(fruits)

Answer:

banana
date
5
['avocado', 'banana', 'cherry', 'date', 'elderberry']

Explanation: Index 1 gives the second item. Index -1 gives the last item. append() adds to the end. Lists are mutable, so we can change fruits[0].

Question 6

student = {"name": "Aarav", "age": 16, "grade": "A"}
print(student["name"])
student["age"] = 17
student["city"] = "Delhi"
print(len(student))
print(student)

Answer:

Aarav
4
{'name': 'Aarav', 'age': 17, 'grade': 'A', 'city': 'Delhi'}

Section B: Find the Errors

Each of the following code snippets contains one or more errors. Identify the errors and write the corrected code. These questions test your ability to debug Python programs.

Error Question 1

age = input("Enter your age: ")
next_year = age + 1
print("Next year you will be", next_year)

Error: input() returns a string. You cannot add an integer (1) to a string. This causes a TypeError.

Corrected code:

age = int(input("Enter your age: "))
next_year = age + 1
print("Next year you will be", next_year)

Error Question 2

2name = "Rahul"
print(2name)

Error: Variable names cannot start with a digit. This causes a SyntaxError.

Corrected code:

name2 = "Rahul"
print(name2)

Error Question 3

marks = (85, 90, 78)
marks[0] = 95
print(marks)

Error: Tuples are immutable. You cannot change an item in a tuple. This causes a TypeError.

Corrected code (use a list instead):

marks = [85, 90, 78]
marks[0] = 95
print(marks)

Error Question 4

total = 450
percentage = total / 500 * 100
print("Your percentage is: " + percentage + "%")

Error: You cannot concatenate a string with a float using +. The variable percentage is a float (90.0), not a string.

Corrected code:

total = 450
percentage = total / 500 * 100
print("Your percentage is: " + str(percentage) + "%")

Section C: Write the Program

Try writing these programs on your own first, then compare with the solutions below.

Program 1: Temperature Converter

Write a program that takes temperature in Celsius from the user and converts it to Fahrenheit. Formula: F = (C x 9/5) + 32

# Temperature Converter: Celsius to Fahrenheit
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9 / 5) + 32
print(str(celsius) + " degrees Celsius = " + str(fahrenheit) + " degrees Fahrenheit")

Sample output: If user enters 37, it prints: 37.0 degrees Celsius = 98.6 degrees Fahrenheit

Program 2: Check Even or Odd

Write a program that takes a number from the user and checks whether it is even or odd.

# Even or Odd Checker
number = int(input("Enter a number: "))

if number % 2 == 0:
    print(str(number) + " is Even")
else:
    print(str(number) + " is Odd")

Key concept: A number is even if it leaves no remainder when divided by 2. We check this using the modulus operator (%).

Program 3: Simple Interest Calculator

Write a program that takes principal amount, rate of interest, and time in years from the user and calculates simple interest. Formula: SI = (P x R x T) / 100

# Simple Interest Calculator
print("=" * 35)
print("  SIMPLE INTEREST CALCULATOR")
print("=" * 35)

principal = float(input("Enter principal amount (Rs): "))
rate = float(input("Enter rate of interest (%): "))
time = float(input("Enter time period (years): "))

si = (principal * rate * time) / 100
total_amount = principal + si

print("\n--- Results ---")
print("Simple Interest: Rs", round(si, 2))
print("Total Amount:    Rs", round(total_amount, 2))

Program 4: Swap Two Numbers

Write a program that swaps the values of two variables without using a third variable.

# Swapping two numbers without a third variable
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

print("Before swapping: a =", a, ", b =", b)

# Python's elegant swap
a, b = b, a

print("After swapping:  a =", a, ", b =", b)

Note: Python allows swapping in a single line using a, b = b, a. This is a unique Python feature. In other languages, you would typically need a temporary third variable.

Program 5: Largest of Three Numbers

Write a program that takes three numbers from the user and finds the largest one.

# Finding the largest of three numbers
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))

if a >= b and a >= c:
    largest = a
elif b >= a and b >= c:
    largest = b
else:
    largest = c

print("The largest number is:", largest)

Alternative approach using max(): Python has a built-in max() function that makes this even simpler.

# Using the built-in max() function
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))
print("The largest number is:", max(a, b, c))

Program 6: Student Grade Calculator

Write a program that takes marks of 5 subjects, calculates the total and percentage, and assigns a grade based on the percentage.

# Student Grade Calculator
print("Enter marks for 5 subjects (out of 100 each):")

sub1 = float(input("Subject 1: "))
sub2 = float(input("Subject 2: "))
sub3 = float(input("Subject 3: "))
sub4 = float(input("Subject 4: "))
sub5 = float(input("Subject 5: "))

total = sub1 + sub2 + sub3 + sub4 + sub5
percentage = total / 5

if percentage >= 90:
    grade = "A+ (Outstanding)"
elif percentage >= 80:
    grade = "A (Excellent)"
elif percentage >= 70:
    grade = "B+ (Very Good)"
elif percentage >= 60:
    grade = "B (Good)"
elif percentage >= 50:
    grade = "C (Average)"
elif percentage >= 33:
    grade = "D (Below Average)"
else:
    grade = "F (Fail)"

print("\n--- Result ---")
print("Total Marks:", total, "/ 500")
print("Percentage: ", round(percentage, 2), "%")
print("Grade:      ", grade)

Section D: Multiple Choice Questions

Test your conceptual understanding with these MCQs. Try to answer each question before reading the answer.

Q1. Which of the following is NOT a valid variable name in Python?

(a) _count (b) my_var (c) 3total (d) Total_3

Answer: (c) 3total — Variable names cannot start with a digit.

Q2. What is the output of print(type(10.0))?

(a) <class 'int'> (b) <class 'float'> (c) <class 'str'> (d) <class 'number'>

Answer: (b) <class 'float'> — The decimal point makes it a float, even if the decimal part is zero.

Q3. What does the // operator do in Python?

(a) Regular division (b) Exponentiation (c) Floor division (d) Modulus

Answer: (c) Floor division — It divides and removes the decimal portion, returning only the integer part.

Q4. Which data type is immutable?

(a) List (b) Dictionary (c) Tuple (d) Set

Answer: (c) Tuple — Once created, items in a tuple cannot be changed, added, or removed.

Q5. What is the result of: 5 + 3 * 2?

(a) 16 (b) 11 (c) 13 (d) 10

Answer: (b) 11 — Python follows BODMAS/PEMDAS. Multiplication is done before addition: 3 * 2 = 6, then 5 + 6 = 11.

Q6. What does input() return in Python?

(a) Integer (b) Float (c) Boolean (d) String

Answer: (d) String — The input() function always returns a string, regardless of what the user types. You must convert it using int() or float() if you need a number.

Bonus Challenge Problems

Try these on your own. Write the complete program in Python IDLE and test it.

  1. Write a program that takes the radius of a circle and prints its area and circumference. (Hint: Area = 3.14159 * r * r, Circumference = 2 * 3.14159 * r)
  2. Write a program that takes a number and checks whether it is positive, negative, or zero.
  3. Write a program that takes marks of a student and checks if the student has passed or failed. The passing mark is 33 out of 100.
  4. Create a dictionary with details of your 3 favourite books (title, author, year). Print each book's details on a separate line.
  5. Write a program that takes a 4-digit number and prints the sum of its digits. (Hint: Use // and % operators)

Series Summary

Congratulations on completing the Python Fundamentals series! Here is what you have learned across all three parts:

  • Part 1: What Python is, how to install it, IDLE, print(), comments, and case sensitivity
  • Part 2: Variables, data types (int, float, str, bool, list, tuple, dict), type conversion, input(), and operators
  • Part 3: Output prediction, error finding, solved programs, and MCQ practice

These concepts form the foundation of Python programming. In upcoming tutorials, we will explore conditional statements (if-elif-else) in greater depth, loops (for and while), functions, and string manipulation. Keep practising, and you will be well-prepared for your board examinations!

Happy coding!