Skip to content
πŸ“š Free notes, MCQ tests & past papers β€” FBISE & BISE Rawalpindi
πŸ“’ Latest Updates

10th Class Computer Science Unit 3 Introduction to Python Programming: Exercise Solutions 2027 (Punjab Board / BISE Rawalpindi)

Reviewed by Sadia Shahid, Senior Science teacher (Maths, Physics, Chemistry, Biology, Computer Science)

These are the solved end-of-unit exercises for Unit 3, Introduction to Python Programming, from the new PECTAA Computer Science and Entrepreneurship-10 textbook used by BISE Rawalpindi, Lahore and the other Punjab boards. Every answer is written from the text of the unit, for the 10th Class (SSC Part II) Annual Examination 2027.

This unit covers basic programming concepts, setting up Python, comments, variables and their types, input and output, and the arithmetic, comparison, assignment and logical operators with operator precedence. Every program below was run and the output shown is the real output.

Unit 3: Introduction to Python Programming
Class 10th Class (SSC Part II), Punjab boards
MCQs answered 10
Other questions solved 17

Exercise questions deleted in the ALP Smart Syllabus 2027

Nothing in Unit 3 is deleted in the ALP Smart Syllabus 2027. The whole unit and all of its exercise questions are in the exam.

Multiple Choice Questions

MCQ 1. Which of the following steps is NOT part of the basic programming process?
(a) Write Code (b) Compile/Interpret (c) Execute (d) Ignore Errors

Ans: (d) Ignore Errors β€” a programmer writes code, has it interpreted or compiled and executes it. Errors must be found and fixed, never ignored.

MCQ 2. What should you do when installing Python to run it from the command line more easily?
(a) Uncheck “Add Python to PATH” (b) Choose a different IDE (c) Check “Add Python to PATH” (d) Install only the IDE

Ans: (c) Check “Add Python to PATH” β€” the book’s tool tip says to tick the box “Add Python to PATH” during installation.

MCQ 3. What will be the output of: print(10 // 3)?
(a) 3.333 (b) 3 (c) 1 (d) 4

Ans: (b) 3 β€” // is floor division and gives the whole-number part of the quotient: 10 // 3 = 3.

MCQ 4. What does the input() function return?
(a) Integer (b) Float (c) String (d) Boolean

Ans: (c) String β€” the text typed by the user is stored as a string. int() or float() is used to convert it into a number.

MCQ 5. Which operator has the highest precedence in Python?
(a) Addition (+) (b) Multiplication (*) (c) Exponentiation (**) (d) Parentheses ()

Ans: (d) Parentheses () β€” the book places parentheses first, so the operations inside them are done before everything else.

MCQ 6. What is the result of 5 > 3 and 2 < 1?
(a) True (b) False (c) Error (d) None

Ans: (b) False β€” 5 > 3 is True but 2 < 1 is False. The and operator gives True only when both sides are True, so the result is False.

MCQ 7. What does the += operator do?
(a) Adds two numbers (b) Compares values (c) Adds and assigns (d) Multiplies values

Ans: (c) Adds and assigns β€” it is a compound assignment operator: a += b means a = a + b.

MCQ 8. Which function converts a string to an integer?
(a) str() (b) int() (c) float() (d) input()

Ans: (b) int() β€” int() converts the input string into an integer, for example int(input(“Enter your age: “)).

MCQ 9. What is the output of the below code? age = 25; print(" Age: ", age)
(a) Age: 25 (b) 25 (c) Age (d) age

Ans: (a) Age: 25 β€” print() displays the text and then the value of age. (Python also puts one space between the two items, so there is an extra space after the colon on screen.)

MCQ 10. Which symbol is used for comments in Python?
(a) // (b) /* (c) # (d) —

Ans: (c) # β€” a single-line comment starts with #. The interpreter does not execute it.

Short Answer Questions

Short 1. Why are comments important in programming?

Ans: Comments are lines that the Python interpreter does not run. They give explanations or notes to the programmer, so the code is easier to read and understand later. A single-line comment starts with #.

# This is a single-line comment
print("K2 is the second-highest mountain in the world")

Short 2. Discuss three basic data types in Python.

Data type Stores Example
Integer (int) Whole numbers age = 17
Floating-point (float) Decimal numbers price = 19.99
String (str) Text name = “Ali”

The book also lists the Boolean type (bool), which stores True or False, for example is_student = True.

Short 3. Describe the difference between integer and float data types in Python.

Integer (int) Float (float)
Whole numbers with no decimal point, e.g. 17. Numbers with a decimal point, e.g. 19.99.
Input is converted with int(input(…)). Input is converted with float(input(…)).

Short 4. How does the if statement differ from the if-else statement?

if statement if-else statement
Runs a block of code only when the condition is true. Nothing happens if it is false. Runs one block when the condition is true and a different block when it is false.
Syntax: if condition: followed by the indented code. Syntax: if condition: … else: followed by the indented code of each part.
temperature = 35
if temperature > 30:
    print("It's a hot day")

temperature = 15
if temperature > 30:
    print("It's a hot day")
else:
    print("It's not a hot day")

Output:

It's a hot day
It's not a hot day

Note: this question is answered from Section 4.1 of the next unit, because the if statement is taught there.

Short 5. What are logical operators? Name all three.

Ans: Logical operators combine two or more conditions or expressions and return a Boolean value (True or False). The three logical operators are and, or and not. With x = True and y = False: x and y is False, x or y is True and not x is False.

Short 6. How do you get user input in Python?

Ans: With the input() function. It shows a message, waits for the user to type and press Enter, and stores the typed text in a variable. For numbers, the text is converted with int() or float().

name = input("Enter your name: ")
user_age = int(input("Enter your age: "))

Short 7. What is the purpose of the print() statement in Python?

Ans: The print() function displays information on the screen. It can take one or more arguments, such as text and variables, and show them together, for example print("Hello, " + name + "!").

Short 8. What is operator precedence? Give an example.

Ans: Operator precedence is the order in which Python performs the operations of an expression. From highest to lowest: parentheses, exponentiation (**), then *, / and %, then + and -.

print(3 + 2 * 5)
print((3 + 2) * 5)

Output:

13
25

In the first line multiplication is done before addition (2 Γ— 5 = 10, then 3 + 10 = 13). In the second line the parentheses force the addition first (3 + 2 = 5, then 5 Γ— 5 = 25).

Short 9. Write any three main rules for naming variables in Python.

  • The name must begin with a letter (a–z, A–Z) or an underscore (_).
  • The remaining characters can be letters, digits (0–9) or underscores.
  • Names are case-sensitive, so age and Age are two different variables.
  • Reserved keywords such as for, while and if cannot be used as variable names.

Long Answer Questions

Long 1. What are the basic data types in Python? Explain integers, floats, strings and Booleans with examples.

Type Meaning Example
Integer (int) Whole numbers, positive or negative, without a decimal point. age = 17
Float (float) Numbers with a decimal point. price = 19.99
String (str) Text, written inside single or double quotation marks. name = "Ali"
Boolean (bool) Only two values: True or False. is_student = True
age = 17
price = 19.99
name = "Ali"
is_student = True
print(age, type(age))
print(price, type(price))
print(name, type(name))
print(is_student, type(is_student))

Output:

17 <class 'int'>
19.99 <class 'float'>
Ali <class 'str'>
True <class 'bool'>

A variable is a storage container in the computer’s memory. Its value can change while the program runs, and Python decides the type from the value stored in it.

Long 2. What are arithmetic operators in Python? Provide examples of each operator and explain when you would use them.

Arithmetic operators perform mathematical operations on numbers. The book uses a = 10 and b = 3.

Operator Name Example Result Use it to
+ Addition a + b 13 add values, such as totals
– Subtraction a – b 7 find a difference
* Multiplication a * b 30 find a product, such as price Γ— quantity
/ Division a / b 3.3333333333333335 divide and keep the decimal part
// Floor division a // b 3 get only the whole-number part of a division
% Modulus a % b 1 get the remainder, e.g. to test even or odd
** Exponentiation a ** b 1000 raise to a power
a = 10
b = 3
print(a, "+", b, "=", a + b)
print(a, "-", b, "=", a - b)
print(a, "*", b, "=", a * b)
print(a, "/", b, "=", a / b)
print(a, "//", b, "=", a // b)
print(a, "%", b, "=", a % b)
print(a, "**", b, "=", a ** b)

Output:

10 + 3 = 13
10 - 3 = 7
10 * 3 = 30
10 / 3 = 3.3333333333333335
10 // 3 = 3
10 % 3 = 1
10 ** 3 = 1000

Long 3. Explain the input() and print() functions with examples.

input() shows a message on the screen, waits for the user to type something and press Enter, and returns the typed text as a string. The text is stored in a variable. To use it as a number, convert it with int() or float().

print() displays one or more values on the screen. Items are separated by commas inside the brackets, and a newline is added at the end by default.

name = input("Enter your name: ")
print("Hello, " + name + "!")
user_age = int(input("Enter your age: "))
print("Your age is:", user_age)
user_height = float(input("Enter your height in meters: "))
print("Your height is", user_height, "meters")

Output:

Enter your name: Maryam Ashraf
Hello, Maryam Ashraf!
Enter your age: 16
Your age is: 16
Enter your height in meters: 1.5
Your height is 1.5 meters

The first two lines show text input and the greeting. The next lines show integer and float input after conversion.

Long 4. Explain how comparison and logical operators work together in conditional statements. Provide a practical example.

Comparison operators (>, <, ==, !=, >=, <=) compare two values and return True or False. Logical operators (and, or, not) join these True/False results into one condition. A conditional (if) statement uses the final result to decide which block of code runs.

Practical example: a student passes the term if the marks are at least 40 and the attendance is at least 75.

marks = 52
attendance = 80

if marks >= 40 and attendance >= 75:
    print("Pass")
else:
    print("Fail")

Output:

Pass

Here marks >= 40 is True and attendance >= 75 is True. Both are joined by and, so the whole condition is True and “Pass” is printed. If either comparison were False, the else block would print “Fail”.

Long 5. Write a program in Python that will take a name from the user and display a greeting message to the given name.

name = input("Enter your name: ")
print("Hello, " + name + "! Welcome to Python.")

Output:

Enter your name: Ayesha
Hello, Ayesha! Welcome to Python.

Long 6. Write a program in Python that takes two numbers from the user and displays their sum.

num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
total = num1 + num2
print("The sum is:", total)

Output:

Enter the first number: 12.5
Enter the second number: 7.5
The sum is: 20.0

float() is used so that numbers with a decimal point are also accepted. Use int() if only whole numbers are needed.

Long 7. Write a program in Python that takes five numbers from the user and displays their average.

n1 = float(input("Enter number 1: "))
n2 = float(input("Enter number 2: "))
n3 = float(input("Enter number 3: "))
n4 = float(input("Enter number 4: "))
n5 = float(input("Enter number 5: "))

average = (n1 + n2 + n3 + n4 + n5) / 5
print("The average is:", average)

Output:

Enter number 1: 10
Enter number 2: 20
Enter number 3: 30
Enter number 4: 40
Enter number 5: 50
The average is: 30.0

The brackets make Python add the five numbers first and then divide by 5. Without brackets, only n5 would be divided.

Long 8. Solve the following expressions: (a) 8 + 3 * 4 – 2 ** 2   (b) 20 % 7 * 3 + 10 // 3   (c) 2 * 3 ** 2 % 4 + 10 – 6 / 2

Expression Working (highest precedence first) Answer
8 + 3 * 4 – 2 ** 2 2 ** 2 = 4; 3 * 4 = 12; 8 + 12 = 20; 20 – 4 = 16 16
20 % 7 * 3 + 10 // 3 20 % 7 = 6; 6 * 3 = 18 (same level, left to right); 10 // 3 = 3; 18 + 3 = 21 21
2 * 3 ** 2 % 4 + 10 – 6 / 2 3 ** 2 = 9; 2 * 9 = 18; 18 % 4 = 2; 6 / 2 = 3.0; 2 + 10 = 12; 12 – 3.0 = 9.0 9.0
print(8 + 3 * 4 - 2 ** 2)
print(20 % 7 * 3 + 10 // 3)
print(2 * 3 ** 2 % 4 + 10 - 6 / 2)

Output:

16
21
9.0

The answer of (c) is 9.0 and not 9 because the division operator / always gives a float.

More for 10th Class Computer Science

The exercise questions are from the PECTAA Computer Science and Entrepreneurship-10 textbook. The deleted list follows the PECTAA ALP Smart Syllabus 2027. Please confirm all dates and figures on the official website: pectaa.edu.pk

Need help with 10th Class Computer Science? Join our live online classes for Matric (Punjab and Federal Board). Book a free demo class.

All chapters of this subject

πŸ“Œ Struggling with this chapter? Join our live online tuition β€” one-to-one or small group classes with experienced teachers. Book a free demo class β†’

Ask a question about this topic

Your email address will not be published. Required fields are marked *