Halaman

DIT Part-I Introduction to Programming Solved Paper 2026 - Python MCQs Loops [1st Term]

DIT Part-I Introduction to Programming Solved Paper 2026 - Python MCQs Loops [1st Term]

Khyber Pakhtunkhwa Board of Technical & Commerce Education Peshawar - Diploma in Information Technology (Part-I) - 1st Term Examination 2026 - Paper: Introduction to Programming
Time Allowed: Part-A 20 Minutes + Part-B & C 02 Hrs & 40 Minutes | Marks: 75.

DIT Part-I Introduction to Programming Solved Paper 2026 - Python MCQs Loops [1st Term]
Part-A Q.1 - Choose / Encircle the Correct Answer (15)
i Which is a High-level programming language?

Ans: c) Python - Machine code and Binary Code are low-level, Assembly is middle-level. Python is high-level, user-friendly.

ii Valid variable name in Python?

Ans: b) length_2 - Variable cannot start with number (2length invalid), cannot contain hyphen or special char (#, -). length_2 is valid. Underscore allowed.

iii Value of Python expression 4+4%5?

Ans: b) 8 - % has higher precedence than +. 4%5 = 4, then 4+4 = 8.

iv Output of print(type(5))?

Ans: b) <class 'int'> - 5 is integer. type() returns class. float would be 5.0, str would be "5".

v How to write single-line comment in Python?

Ans: b) # - Example: # This is comment. // is comment in Java/C++, /* */ is multi-line in other languages.

vi Output of 4+6/2*2 in Python?

Ans: b) 10 - BODMAS: Division and Multiplication first left to right. 6/2=3.0, 3*2=6.0, 4+6=10.0

vii Used to take input from user?

Ans: a) input() - Example: name = input("Enter name: "). raw_input() was in Python 2.

viii Operator to concatenate two lists in Python?

Ans: b) + - Example: [1,2] + [3,4] = [1,2,3,4]

ix Result of 10//3 in Python?

Ans: c) 3 - // is floor division, gives integer part without remainder. 10/3=3.33, 10//3=3.

x Keyword to define a function in Python?

Ans: d) def - Syntax: def function_name():

xi Keyword to terminate execution of a loop?

Ans: c) break - break exits loop completely, continue skips current iteration.

xii Function to convert string into integer?

Ans: c) int() - Example: int("123") = 123. str() does opposite, float() converts to float.

xiii Result of 4%5*2+3?

Ans: 11 (If paper is 4+5%2+3 etc calculation varies). Standard: 4%5=4*2=8+3=11. Modulus first.

xiv What does % operator do?

Ans: c) Modulus - Returns remainder. Example: 10%3 = 1. / is division, ** is exponentiation, * is multiplication.

xv How to remove item from dictionary?

Ans: b) del dict[key] and c) dict.Pop(key) both correct - del dict["name"] removes, dict.pop("name") removes and returns value. Exam expects dict.Pop(key).

Part-B - Attempt any 06 (05 Marks Each)
i What is High Level Language?

High Level Language is a programming language that is close to human language and far from machine language. It is easy to read, write, and understand. It is machine-independent and needs translator (Compiler/Interpreter). Examples: Python, Java, C, C++, C#. Advantages: Easy to learn, less errors, portable. Disadvantages: Slower than low-level languages.

ii Define a variable in Python

A variable is a name given to a memory location where data is stored. In Python, you don't need to declare type, it is dynamically typed. Variable is created when you assign value to it. Rules: Must start with letter or underscore, cannot start with number, can contain letters, numbers, underscore, case-sensitive. Example: age = 20, name = "Ali", _marks = 85.5

iii Global and local variables in Python

Local Variable: Defined inside a function, accessible only inside that function, destroyed after function ends. Example: def func(): x=10 (x is local)
Global Variable: Defined outside all functions, accessible everywhere in program. Example: y=20 defined outside. If you want to modify global inside function, use global keyword: global y. Local has priority over global if same name.

iv General Syntax of If statement in Python

If statement is used for decision making. Syntax:

if condition:
    # code if condition True
elif condition2:
    # code
else:
    # code if all false

Example: if age >= 18: print("Adult") else: print("Child"). Note indentation is compulsory in Python.

v General syntax of For Loop in Python

For loop is used to iterate over a sequence (list, tuple, string, range). Syntax:

for variable in sequence:
    # body

Example: for i in range(5): print(i) prints 0-4. Example with list: for name in ["Ali","Ahmed"]: print(name)

vi Purpose of range() function

range() function generates a sequence of numbers. It is used with for loop to repeat code specific number of times. Syntax: range(start, stop, step). range(5) gives 0,1,2,3,4. range(1,10,2) gives 1,3,5,7,9. Purpose: To create number list quickly without manually typing, used for looping.

vii Define dictionary in Python

Dictionary is an unordered collection of key-value pairs. It is mutable, defined with curly braces {}. Keys must be unique and immutable. Example: student = {"name":"Ali", "age":20, "marks":85}. Access: student["name"] gives Ali. Methods: keys(), values(), get(), pop(), update(). Dictionary is fast for searching data using key.

viii Program to Print first 10 natural numbers using While Loop
i = 1
while i <= 10:
    print(i)
    i = i + 1

# Output: 1 2 3 4 5 6 7 8 9 10
Part-C - Attempt any 03 (10 Marks Each)
Q3 What is Operator? Different types with examples

Operator is a symbol that performs operation on values/variables (operands). Types:
1. Arithmetic Operators: + - * / // % **. Example: 10+3=13, 10%3=1, 2**3=8
2. Comparison Operators: ==!= > < >= <=. Example: 5==5 True
3. Logical Operators: and or not. Example: True and False = False
4. Assignment Operators: = += -= *= /=. Example: x+=5 means x=x+5
5. Membership Operators: in, not in. Example: 'a' in 'Ali' True
6. Identity Operators: is, is not

Q4 Break and Continue in for loop with examples

break: Terminates loop completely and comes out of loop.

for i in range(10):
    if i == 5:
        break
    print(i)
# Output: 0 1 2 3 4 (stops at 5)

continue: Skips current iteration and goes to next iteration.

for i in range(5):
    if i == 2:
        continue
    print(i)
# Output: 0 1 3 4 (skips 2)
Q5 What is functions and Python function to calculate square

Function: A function is a block of reusable code that performs specific task. It avoids repetition. Defined with def keyword, can take parameters and return value.
Types: Built-in (print(), len()) and User-defined.

def square(num):
    return num * num

# Calling
result = square(5)
print(result) # 25

# Another example with input
def square_of_number():
    n = int(input("Enter number: "))
    print("Square is", n*n)
square_of_number()
Q6 Short note on any two: replace() list while loop NumPy tool

a) replace(): String method that replaces a substring with another. Syntax: string.replace(old, new, count). Example: "hello world".replace("world","Ali") => "hello Ali". Original string unchanged.

b) list: List is ordered, mutable collection that can store multiple data types. Defined with []. Example: my_list = [1, "Ali", 3.5, True]. Features: Indexing (my_list[0]), Slicing, Methods: append(), insert(), remove(), pop(), sort(). List can contain duplicate values.

c) while loop: Loop that repeats as long as condition is True. Syntax: while condition: body. Used when number of iterations unknown. Example: while i<=10: print(i); i+=1. Need to update variable otherwise infinite loop. While loop is entry-controlled loop.

d) NumPy tool: NumPy stands for Numerical Python. It is a powerful library for numerical computing. Main feature is ndarray (n-dimensional array) which is faster than Python list. Provides functions for mathematical operations, matrix operations, statistics. Example: import numpy as np; arr = np.array([1,2,3]); print(arr*2). Used in Data Science, Machine Learning, AI.

Related Post

No comments