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.
Ans: c) Python - Machine code and Binary Code are low-level, Assembly is middle-level. Python is high-level, user-friendly.
Ans: b) length_2 - Variable cannot start with number (2length invalid), cannot contain hyphen or special char (#, -). length_2 is valid. Underscore allowed.
Ans: b) 8 - % has higher precedence than +. 4%5 = 4, then 4+4 = 8.
Ans: b) <class 'int'> - 5 is integer. type() returns class. float would be 5.0, str would be "5".
Ans: b) # - Example: # This is comment. // is comment in Java/C++, /* */ is multi-line in other languages.
Ans: b) 10 - BODMAS: Division and Multiplication first left to right. 6/2=3.0, 3*2=6.0, 4+6=10.0
Ans: a) input() - Example: name = input("Enter name: "). raw_input() was in Python 2.
Ans: b) + - Example: [1,2] + [3,4] = [1,2,3,4]
Ans: c) 3 - // is floor division, gives integer part without remainder. 10/3=3.33, 10//3=3.
Ans: d) def - Syntax: def function_name():
Ans: c) break - break exits loop completely, continue skips current iteration.
Ans: c) int() - Example: int("123") = 123. str() does opposite, float() converts to float.
Ans: 11 (If paper is 4+5%2+3 etc calculation varies). Standard: 4%5=4*2=8+3=11. Modulus first.
Ans: c) Modulus - Returns remainder. Example: 10%3 = 1. / is division, ** is exponentiation, * is multiplication.
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).
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.
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
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.
If statement is used for decision making. Syntax:
# 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.
For loop is used to iterate over a sequence (list, tuple, string, range). Syntax:
# body
Example: for i in range(5): print(i) prints 0-4. Example with list: for name in ["Ali","Ahmed"]: print(name)
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.
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.
while i <= 10:
print(i)
i = i + 1
# Output: 1 2 3 4 5 6 7 8 9 10
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
break: Terminates loop completely and comes out of loop.
if i == 5:
break
print(i)
# Output: 0 1 2 3 4 (stops at 5)
continue: Skips current iteration and goes to next iteration.
if i == 2:
continue
print(i)
# Output: 0 1 3 4 (skips 2)
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.
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()
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.
![DIT Part-I Introduction to Programming Solved Paper 2026 - Python MCQs Loops [1st Term]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7PoISdMhyAXeIneX3NDKbwsSLGS4J8khCXp5RMnl7t-2bE1UKrZEApnOMfFm-O1YYc9GTIAZhMB4BF4nMLCm6Mmhk1HpPmsIlbPIJ8DKHsDdzi2xSE0WTaglj9UJ0o_cDIr1N3vgzEZLyuHptuocnBejdusNCHmA_ht-lXXrfIG0-amPUhJ9pl_UmIwbL/s1600-rw/1000257484.webp)