10th Class Computer Science Notes 2026 — Chapter 3

Download PDF
 

Class 10 Computer Science Notes – Chapter 3: Introduction to Python Programming

Punjab Board | 2026

EXERCISE SOLUTIONS

Multiple Choice Questions (MCQs)

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

Correct Answer: (d) Ignore Errors

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

Correct Answer: (c) Check “Add Python to PATH”

3. What will be the output of print(10 // 3)?

(a) 3.333
(b) 3
(c) 1
(d) 4

Correct Answer: (b) 3

4. What does the input() function return?

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

Correct Answer: (c) String

5. Which operator has the highest precedence in Python?

(a) Addition (+)
(b) Multiplication (*)
(c) Exponentiation (**)
(d) Parentheses (())

Correct Answer: (d) Parentheses (())

6. What is the result of 5 > 3 and 2 < 1?

(a) True
(b) False
(c) Error
(d) None

Correct Answer: (b) False

7. What does the += operator do?

(a) Adds two numbers
(b) Compares values
(c) Adds and assigns
(d) Multiplies values

Correct Answer: (c) Adds and assigns

8. Which function converts a string to an integer?

(a) str()
(b) int()
(c) float()
(d) input()

Correct Answer: (b) int()

9. What is the output of the following code?

age = 25print("Age : ", age)
 

(a) Age: 25
(b) 25
(c) Age
(d) age

Correct Answer: (a) Age : 25

10. Which symbol is used for comments in Python?

(a) //
(b) /*
(c) #
(d) --

Correct Answer: (c) #

Short Answer Questions

Question 1: Why are comments important in programming?

Answer:

Comments are non-executable notes added to source code. They are important because:

  • They explain the purpose and logic of the code, making it readable and understandable for developers.

  • They help in debugging and maintaining code in collaborative projects.

  • They allow programmers to temporarily disable specific lines of code during testing without deleting them.

Question 2: Discuss three basic data types in Python.

Answer:

  1. Integer (int): Represents whole numbers without a fractional part, such as 10 and -5.

  2. Float (float): Represents real numbers that contain decimal points, such as 3.14 and -0.5.

  3. String (str): Represents sequences of characters enclosed within single or double quotes, such as "Hello" and 'Python'.

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

Answer:

  • Integer (int): Used to store whole numerical values without decimal points. Example: x = 20.

  • Float (float): Used to store numerical values containing a decimal point or fractional component. Example: x = 20.5. Floats represent real numbers and require dynamic precision handling.

Question 4: How does the if statement differ from the if-else statement?

Answer:

  • if statement: Executes a block of code only if the given condition evaluates to True. If the condition is False, the block is skipped.

  • if-else statement: Provides two execution paths. If the condition is True, the if block executes; if the condition is False, the alternative else block executes.

Question 5: What are logical operators? Name all three.

Answer:

Logical operators are used to combine multiple conditional statements or invert Boolean values. The three logical operators in Python are:

  1. and: Returns True only if both operands or conditions are True.

  2. or: Returns True if at least one operand or condition is True.

  3. not: Reverses the logical state; returns False if the condition is True, and vice versa.

Question 6: How do you get user input in Python?

Answer:

User input in Python is retrieved using the built-in input() function. By default, it takes user input as a string.

Example:

name = input("Enter your name: ")
 

Question 7: What is the purpose of the print() statement in Python?

Answer:

The print() statement is used to display output, text messages, variable values, or calculation results directly onto the standard output screen (console).

Question 8: What is operator precedence? Give an example.

Answer:

Operator precedence determines the evaluation order of operations in an expression containing multiple operators. Operators with higher precedence are evaluated before operators with lower precedence.

Example:

In the expression:

result = 5 + 3 * 2
 

Multiplication (*) has higher precedence than addition (+), so 3 * 2 is evaluated first to give 6. Then 5 + 6 results in 11.

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

Answer:

  1. Variable names must start with a letter (a–z, A–Z) or an underscore (_), but cannot start with a digit.

  2. Variable names can contain alphanumeric characters and underscores (A–Z, a–z, 0–9, and _).

  3. Variable names are case-sensitive (age, Age, and AGE are different variables) and cannot be Python keywords, such as if, for, and class.

Long Answer Questions

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

Answer:

Data types define the type of value a variable can store. Python automatically detects the variable’s data type upon assignment.

1. Integer (int)

Represents positive or negative whole numbers without decimals.

Example:

age = 16count = -10
 

2. Float (float)

Represents real numbers with fractional parts or decimal points.

Example:

price = 99.99pi = 3.14159
 

3. String (str)

Represents textual data enclosed in single ('), double ("), or triple quotes.

Example:

name = "Ali"greeting = "Hello, World!"
 

4. Boolean (bool)

Represents logical truth values and can only take one of two values: True or False.

Example:

is_passed = Trueis_logged_in = False
 

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

Answer:

Arithmetic operators are used to perform mathematical calculations.

1. Addition (+)

Adds two numeric values.

Example:

total = 10 + 5
 

Result: 15

Usage: Calculating a total bill or combined scores.

2. Subtraction (-)

Subtracts the right operand from the left operand.

Example:

difference = 10 - 5
 

Result: 5

Usage: Finding a remaining balance or age difference.

3. Multiplication (*)

Multiplies two numbers.

Example:

product = 4 * 5
 

Result: 20

Usage: Calculating the total cost of multiple items.

4. Division (/)

Divides the left operand by the right operand and returns a float.

Example:

result = 10 / 2
 

Result: 5.0

Usage: Finding average values.

5. Floor Division (//)

Divides the left operand by the right operand and rounds the result down to the nearest whole number.

Example:

result = 10 // 3
 

Result: 3

Usage: Determining complete whole batches or grouping without fractional parts.

6. Modulus (%)

Returns the remainder of division.

Example:

remainder = 10 % 3
 

Result: 1

Usage: Checking whether a number is even or odd.

num % 2 == 0
 

7. Exponentiation (**)

Raises a base to the power of an exponent.

Example:

power = 2 ** 3
 

Result: 8

Usage: Calculating powers, compound interest, or geometrical areas such as \(r^2\).

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

Answer:

1. input() Function

The input() function pauses program execution to accept data entered by the user via the keyboard. It returns all entered input as a string (str). If numeric values are required, type-casting functions such as int() or float() must be used.

Example:

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

2. print() Function

The print() function outputs data, formatted text strings, variables, or expressions to the console window. Multiple arguments can be separated by commas.

Example:

name = "Ahmad"print("Hello", name, "Welcome to Python!")
 

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

Answer:

Comparison operators, such as ==, !=, >, <, >=, and <=, evaluate relationships between values and return a Boolean result (True or False).

Logical operators (and, or, not) combine multiple comparison expressions to form complex conditions in decision-making structures such as if-else.

Practical Example:

Checking whether a student qualifies for a scholarship based on GPA and attendance:

gpa = 3.8attendance = 92# Using comparison operators with logical 'and'if gpa >= 3.5 and attendance >= 90:    print("Scholarship Granted!")else:    print("Not eligible for scholarship.")
 

Explanation: The program compares gpa >= 3.5 and attendance >= 90. Both conditions are True. The and operator checks both conditions, so the scholarship is granted.

Question 5: Write a Python program that takes a name from the user and displays a greeting message.

Answer:

# Program to display greeting messageuser_name = input("Enter your name: ")print("Hello " + user_name + "! Welcome to Python Programming.")
 

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

Answer:

# Program to calculate sum of two numbersnum1 = float(input("Enter first number: "))num2 = float(input("Enter second number: "))total_sum = num1 + num2print("The sum of", num1, "and", num2, "is:", total_sum)
 

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

Answer:

# Program to calculate average of five numbersnum1 = float(input("Enter number 1: "))num2 = float(input("Enter number 2: "))num3 = float(input("Enter number 3: "))num4 = float(input("Enter number 4: "))num5 = float(input("Enter number 5: "))average = (num1 + num2 + num3 + num4 + num5) / 5print("The average of the 5 numbers is:", average)
 

Question 8: Solve the following expressions.

(a) \(8+3\times4-2^2\)

Step 1: Exponentiation

\[ 2^2=4 \]

The expression becomes:

\[ 8+3\times4-4 \]

Step 2: Multiplication

\[ 3\times4=12 \]

The expression becomes:

\[ 8+12-4 \]

Step 3: Addition

\[ 8+12=20 \]

Step 4: Subtraction

\[ 20-4=\boxed{16} \]

Final Result: 16

(b) \(20\%7\times3+10//3\)

Step 1: Modulus

\[ 20\%7=6 \]

The expression becomes:

\[ 6\times3+10//3 \]

Step 2: Multiplication

\[ 6\times3=18 \]

The expression becomes:

\[ 18+10//3 \]

Step 3: Floor Division

\[ 10//3=3 \]

The expression becomes:

\[ 18+3 \]

Step 4: Addition

\[ 18+3=\boxed{21} \]

Final Result: 21

(c) \(2\times3^2\%4+10-6/2\)

Step 1: Exponentiation

\[ 3^2=9 \]

The expression becomes:

\[ 2\times9\%4+10-6/2 \]

Step 2: Multiplication

\[ 2\times9=18 \]

The expression becomes:

\[ 18\%4+10-6/2 \]

Step 3: Modulus

\[ 18\%4=2 \]

The expression becomes:

\[ 2+10-6/2 \]

Step 4: Division

\[ 6/2=3.0 \]

The expression becomes:

\[ 2+10-3.0 \]

Step 5: Addition and Subtraction

\[ 2+10=12 \]
\[ 12-3.0=\boxed{9.0} \]

Final Result: 9.0

 

Notes by Sir Dilawar

For more notes, visit QuranEducationPoint.com