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
Answer:
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
Answer:
Explanation: The + operator concatenates strings. The * operator repeats a string. The len() function returns the number of characters.
Question 3
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
Answer:
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
Answer:
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
Answer:
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
Error: input() returns a string. You cannot add an integer (1) to a string. This causes a TypeError.
Corrected code:
Error Question 2
Error: Variable names cannot start with a digit. This causes a SyntaxError.
Corrected code:
Error Question 3
Error: Tuples are immutable. You cannot change an item in a tuple. This causes a TypeError.
Corrected code (use a list instead):
Error Question 4
Error: You cannot concatenate a string with a float using +. The variable percentage is a float (90.0), not a string.
Corrected code:
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
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.
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
Program 4: Swap Two Numbers
Write a program that swaps the values of two variables without using a third variable.
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.
Alternative approach using max(): Python has a built-in max() function that makes this even simpler.
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.
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.
- 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)
- Write a program that takes a number and checks whether it is positive, negative, or zero.
- 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.
- Create a dictionary with details of your 3 favourite books (title, author, year). Print each book's details on a separate line.
- 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!