Here are the important short and long questions of Unit 3, Programming Fundamentals, from the Federal Board (FBISE) 1st Year Computer Science course (HSSC-I, Intermediate Part I), solved in full for the Annual Examination 2027.
| Unit | 3: Programming Fundamentals |
|---|---|
| Class | 1st Year (HSSC-I), Federal Board |
| Subject | Computer Science |
| Contents | Short and long questions with answers |
| Exam | FBISE Annual Examination 2027 |
Note for checking: the NBF book takes numeric input with eval(input()). int(input()) / float(input()) are equally correct and are used in some answers below.
3.2 Python: An Overview
Short Questions
Q1. How is indentation important in Python? Elaborate with an example. [3] (SA25 Q8-A)
Indentation means the spaces at the start of a line. In Python, indentation is compulsory β it shows which statements belong to a block (if, else, for, while, def). The “:” after a statement shows that the following lines are part of that block and must be indented.
β’ It gives better readability and shows the structure of the program.
β’ Wrong indentation causes an IndentationError or logical bugs (a statement may run outside the loop/condition).
marks = 45
if marks >= 40:
print(“Pass”) # indented: part of if-block
else:
print(“Fail”) # indented: part of else-block
print(“Result shown”) # not indented: runs always
3.4 Turtle Graphics
Short Questions
Q1. Write Python statements using turtle graphics to perform the given actions. [3] (FAM25 Q13-B; FAE25 Q13-B; SA25 Q10-B)
Version FAM25 β (a) pen colour blue, (b) move backward 150 pixels, (c) rotate 90Β° left:
import turtle
turtle.pencolor(“blue”)
turtle.back(150) # or turtle.backward(150)
turtle.left(90)
Version FAE25 β (a) rotate 45Β° right, (b) move forward 100 pixels, (c) pen colour red:
import turtle
turtle.right(45)
turtle.forward(100)
turtle.pencolor(“red”)
Version SA25 β (a) pen colour blue, (b) rotate 90Β° right, (c) move forward 50 pixels:
import turtle
turtle.pencolor(“blue”)
turtle.right(90)
turtle.forward(50)
3.5 Libraries
Short Questions
Q1. Why do programmers use libraries in Python instead of writing all code from scratch? / What is the importance of importing libraries in Python? Give example. [3 / 2 + 1] (SA25 Q5-A; FA26 P-3)
A library is a set of already written and tested code (functions) meant for a particular task. With a library we can produce a result with just one line of code rather than writing tens of lines of our own code.
β’ Saves time and effort: ready-made functions are used directly after importing the library.
β’ Reliable: library functions are already tested, so they have fewer errors.
β’ Extra features: libraries add facilities not built into Python (e.g. date/time, graphics, random numbers); any additional library can be installed with pip.
Example:
import datetime
x = datetime.datetime.now()
print(x.year) # prints the current year, e.g. 2026
(Other examples: import turtle β drawing; from random import randint; import math β math.sqrt(25).)
3.6 Python Variables
Short Questions
Q1. Compare / differentiate between local and global variables with example. [2 / 1.5 + 1.5] (MP25 Q5-A; FA26 P-3)
| Local Variable | Global Variable |
|---|---|
| Defined inside a function. | Defined in the main program (outside all functions). |
| Its scope is limited to that function; it does not exist outside it. | Its scope covers the whole program; can be used anywhere. |
| Created when the function is called and destroyed when it ends. | Exists till the program ends. |
total = 100 # global variable
def show():
bonus = 10 # local variable
print(total + bonus) # 110
show()
print(total) # 100
# print(bonus) here would give an error (bonus is local)
Q2. What will be displayed after executing the following statements? x = [“apple”,”banana”,”mango”]; print(type(x)) / x = “Hello World”; print(type(x)) / x = 20.5; print(type(x)) [3] (MP25 Q7-B)
| Python Statements | Output |
|---|---|
| x = [“apple”, “banana”, “mango”]; print(type(x)) | <class ‘list’> |
| x = “Hello World”; print(type(x)) | <class ‘str’> |
| x = 20.5; print(type(x)) | <class ‘float’> |
Q3. Determine whether these variable names are valid or invalid; give reasons for invalid names: (a) input (b) your age (c) marks1 [3] (FAM25 Q5-A)
| Variable name | Valid / Invalid | Reason |
|---|---|---|
| input | Should not be used (treat as invalid) | input is the name of Python’s built-in input() function; using it as a variable hides the function. (It is not a keyword, so Python itself does not give a syntax error.) |
| your age | Invalid | A variable name cannot contain spaces (use your_age). |
| marks1 | Valid | Alphanumeric, starts with a letter. |
Q4. Determine whether these variable names are valid or invalid; give reasons: (a) range (b) total marks (c) counter [3] (FAE25 Q5-A)
| Variable name | Valid / Invalid | Reason |
|---|---|---|
| range | Should not be used (treat as invalid) | range is a built-in function name; using it as a variable hides range(). (Not a keyword, so no syntax error.) |
| total marks | Invalid | Spaces are not allowed (use total_marks). |
| counter | Valid | Starts with a letter, contains only letters. |
3.7 Python Input/Output (I/O)
Short Questions
Q1. Write a Python program that takes an alphabet as input and prints whether it is a vowel or a consonant. [3] (MP25 Q10-B)
ch = input(“Enter an alphabet: “)
if ch.lower() in “aeiou”:
print(ch, “is a vowel”)
else:
print(ch, “is a consonant”)
Q2. Write a Python program that asks the user to input name and marks (or name and age), and displays them. [3] (FAM25 Q10-A; FAE25 Q10-A)
name = input(“Enter your name: “)
marks = eval(input(“Enter your marks: “)) # for age: age = eval(input(“Enter your age: “))
print(“Name:”, name)
print(“Marks:”, marks) # print(“Age:”, age)
Q3. Write a Python program that takes an alphabet as input and prints whether it is lower case or upper case. [3] (FA26 P-1)
ch = input(“Enter an alphabet: “)
if ch.isupper():
print(“Upper case letter”)
elif ch.islower():
print(“Lower case letter”)
else:
print(“Not an alphabet”)
(Comparison method also correct: if ch >= ‘A’ and ch <= ‘Z’: β¦ elif ch >= ‘a’ and ch <= ‘z’: β¦)
Q4. Write a Python program that takes three numbers as input and prints which one is largest. [3] (FA26 P-2)
a = eval(input(“Enter first number: “))
b = eval(input(“Enter second number: “))
c = eval(input(“Enter third number: “))
if a >= b and a >= c:
print(“Largest number is”, a)
elif b >= a and b >= c:
print(“Largest number is”, b)
else:
print(“Largest number is”, c)
Q5. Write a simple Python program to take a number as input and print its square. [3] (FA26 P-3)
num = eval(input(“Enter a number: “))
square = num * num # or num ** 2
print(“Square of”, num, “is”, square)
Q6. Write a Python program that reads two numbers and prints their product. [3] (FA26 P-3)
a = eval(input(“Enter first number: “))
b = eval(input(“Enter second number: “))
print(“Product =”, a * b)
Q7. Write a Python program that reads two numbers and prints the smaller number. [3] (FA26 P-3)
a = eval(input(“Enter first number: “))
b = eval(input(“Enter second number: “))
if a < b:
print(“Smaller number is”, a)
else:
print(“Smaller number is”, b)
3.8 Operators in Python
Order of precedence used below: ( ) β ** β *, /, //, % (left to right) β +, β (left to right). “/” always gives a float; “//” gives the integer (floor) part; “%” gives the remainder.
Short Questions
Q1. x = 4, y = 8, z = 2. What value will be stored after: (a) result1 = y // z (b) result2 = z ** 3 (c) result4 = x & z [4] (Set-1 Q6)
| Statement | Working | Value |
|---|---|---|
| result1 = y // z | 8 // 2 | 4 |
| result2 = z ** 3 | 2 Γ 2 Γ 2 | 8 |
| result4 = x & z | 4 = 100, 2 = 010 (bitwise AND) β 000 | 0 |
(result3 is missing in the printed question.)
Q2. x = 4, y = 10, z = 2. What value will be stored in result1, result2, result3: result1 = y β x; result2 = y // z; result3 = x % z [3] (FAM25 Q1-A)
| Statement | Working | Value |
|---|---|---|
| result1 = y β x | 10 β 4 | 6 |
| result2 = y // z | 10 // 2 | 5 |
| result3 = x % z | remainder of 4 Γ· 2 | 0 |
Q3. x = 4, y = 8, z = 2. What value will be stored: result1 = x + y; result2 = z ** 3 (or z ** 4); result3 = y / x [1Γ3] (FAE25 Q1-A; FA26 P-1)
| Statement | Working | Value |
|---|---|---|
| result1 = x + y | 4 + 8 | 12 |
| result2 = z ** 3 | 2Β³ | 8 |
| result2 = z ** 4 (FA26) | 2β΄ | 16 |
| result3 = y / x | 8 / 4 (true division) | 2.0 |
Q4. a = 6, b = 4, c = 2. What value will be stored in x, y, z: x = a + b; y = x β c; z = y * b [1Γ3] (FA26 P-2)
| Statement | Working | Value |
|---|---|---|
| x = a + b | 6 + 4 | 10 |
| y = x β c | 10 β 2 | 8 |
| z = y * b | 8 Γ 4 | 32 |
Q5. Evaluate using the correct order of operations: (2 + 3 ** 2 + 4 // 2 * 5 % 3 β 1) * 2 [3] (MP25 Q8-A)
β’ Brackets first; inside, 3 ** 2 = 9 β (2 + 9 + 4 // 2 * 5 % 3 β 1) * 2
β’ Left to right *, //, %: 4 // 2 = 2 β 2 * 5 = 10 β 10 % 3 = 1 β (2 + 9 + 1 β 1) * 2
β’ Addition/subtraction: 2 + 9 + 1 β 1 = 11 β 11 * 2
β’ Answer = 22
Q6. Evaluate: 2 + 2 ** 3 // 2 * 4 % 3 β 1 [3] (FAM25 Q8-A)
β’ 2 ** 3 = 8 β 2 + 8 // 2 * 4 % 3 β 1
β’ 8 // 2 = 4 β 4 * 4 = 16 β 16 % 3 = 1 β 2 + 1 β 1
β’ Answer = 2
Q7. Evaluate: 3 ** 2 β 8 % 4 + 10 / 5 * 3 [3] (FAE25 Q8-A)
β’ 3 ** 2 = 9 β 9 β 8 % 4 + 10 / 5 * 3
β’ 8 % 4 = 0; 10 / 5 = 2.0; 2.0 * 3 = 6.0 β 9 β 0 + 6.0
β’ Answer = 15.0
Q8. Evaluate: 4 ** 2 β 6 % 3 + 8 / 4 * 2 [3] (SA25 Q13-B)
β’ 4 ** 2 = 16 β 16 β 6 % 3 + 8 / 4 * 2
β’ 6 % 3 = 0; 8 / 4 = 2.0; 2.0 * 2 = 4.0 β 16 β 0 + 4.0
β’ Answer = 20.0
Q9. Evaluate: 10 / 2 * 3 + 4 % 3 β 2 ** 2 [3] (FA26 P-1)
β’ 2 ** 2 = 4 β 10 / 2 * 3 + 4 % 3 β 4
β’ 10 / 2 = 5.0 β 5.0 * 3 = 15.0; 4 % 3 = 1 β 15.0 + 1 β 4
β’ Answer = 12.0
Q10. Evaluate: 8 % 5 + 6 // 2 * 3 β 2 ** 3 [3] (FA26 P-2)
β’ 2 ** 3 = 8 β 8 % 5 + 6 // 2 * 3 β 8
β’ 8 % 5 = 3; 6 // 2 = 3 β 3 * 3 = 9 β 3 + 9 β 8
β’ Answer = 4
Q11. Solve using operator precedence: 5 / 2 + 8 * 2 % 4 β 3 // 2 [3] (FA26 P-3)
β’ 5 / 2 = 2.5
β’ 8 * 2 = 16 β 16 % 4 = 0
β’ 3 // 2 = 1 β 2.5 + 0 β 1
β’ Answer = 1.5
3.9 Iteration & Loop
Short Questions
Q1. Complete the Python code that exits when x is “Physics”: subjects = [“Computer”, “English”, “Physics”]; for x in ____: if x == ____: ____; print(x) [3] (MP25 Q13-A)
subjects = [“Computer”, “English”, “Physics”]
for x in subjects:
if x == “Physics”:
break
print(x)
Output: Computer, English (loop exits when x becomes “Physics”).
Q2. Write a Python program using a for loop to print numbers from 1 to 10. [3] (FA26 P-1)
for i in range(1, 11):
print(i)
Q3. Write a Python program using a while loop to print numbers from 1 to 10. [3] (FA26 P-2)
i = 1
while i <= 10:
print(i)
i = i + 1
Long Questions
Q4. Write a Python program to count even and odd numbers in a list by using a while loop. [6] (NMP26 / MP25 Q5-OR)
numbers = [12, 7, 9, 20, 33, 46, 51, 8]
even = 0
odd = 0
i = 0
while i < len(numbers):
if numbers[i] % 2 == 0:
even = even + 1
else:
odd = odd + 1
i = i + 1
print(“List:”, numbers)
print(“Even numbers:”, even)
print(“Odd numbers:”, odd)
Output: List: [12, 7, 9, 20, 33, 46, 51, 8] Even numbers: 4 Odd numbers: 4
Logic: index i starts at 0; each element is divided by 2 β remainder 0 means even, otherwise odd; loop stops when i reaches the length of the list.
Q5. Write a Python program that inputs a number and prints its multiplication table from 1 to 10 using a for loop. [5] (FAE25 P-2 Q5-OR; SA25)
num = eval(input(“Enter a number: “))
for i in range(1, 11):
print(num, “x”, i, “=”, num * i)
Output (num = 5): 5 x 1 = 5, 5 x 2 = 10, β¦ , 5 x 10 = 50
Q6. Write a Python program that takes a number and prints its factorial using a for loop. [5] (FAM25 P-2 Q5-OR)
num = eval(input(“Enter a number: “))
fact = 1
for i in range(1, num + 1):
fact = fact * i
print(“Factorial of”, num, “is”, fact)
Output (num = 5): Factorial of 5 is 120 (0! = 1 is also handled, because the loop does not run and fact stays 1.)
Q7. Develop a Python program that calculates the product of even numbers from 1 to 20 using a loop. [6] (FA26 P-1)
product = 1
for i in range(2, 21, 2): # 2, 4, 6, …, 20
product = product * i
print(“Product of even numbers from 1 to 20 =”, product)
Output: Product of even numbers from 1 to 20 = 3715891200
Q8. Write a Python program that calculates the sum of the series 1 + 3 + 5 + β¦ + 99 using repetition. [6] (FA26 P-2)
total = 0
for i in range(1, 100, 2): # 1, 3, 5, …, 99
total = total + i
print(“Sum of series =”, total)
Output: Sum of series = 2500
Q9. Write a Python program using repetition to print the sum of the series S = 1Β² + 3Β² + 5Β² + β¦ + 29Β² [5] (FA26 P-3)
s = 0
for i in range(1, 30, 2): # 1, 3, 5, …, 29
s = s + i ** 2
print(“S =”, s)
Output: S = 4495
3.10 List
Short Questions
Q1. What will be generated by: country = [“Pakistan”, “Iran”, “China”]; country[2] = “Turkey”; country.append(“Oman”); print(country) [3] (FAM25 Q12-B)
β’ country[2] = “Turkey” replaces “China” (index 2) with “Turkey”.
β’ append(“Oman”) adds “Oman” at the end.
Output: [‘Pakistan’, ‘Iran’, ‘Turkey’, ‘Oman’]
Q2. What will be generated by: list1 = [34, “abc”, 40, 89]; list1[2] = 67; list1.append(“xyz”); print(list1) [3] (FAE25 Q12-B)
β’ list1[2] = 67 replaces 40 with 67; append(“xyz”) adds “xyz” at the end.
Output: [34, ‘abc’, 67, 89, ‘xyz’]
Q3. Suppose list = [2, 4, 6, 8, 10]. Write a Python program to find the sum of all elements in the list. [3] (SA25 Q13-A)
nums = [2, 4, 6, 8, 10]
total = 0
for n in nums:
total = total + n
print(“Sum =”, total) # or simply: print(sum(nums))
Output: Sum = 30
3.11 Functions in Python
Short Questions
Q1. What is the difference between parameters and arguments in functions? [4] (Set-1 Q7-A)
| Parameters | Arguments |
|---|---|
| Variables written in the function definition (inside the brackets after def). | Actual values passed to the function when it is called. |
| Receive the values; act as local variables of the function. | Supply the values to the parameters. |
| Example: def add(a, b): β a and b are parameters. | Example: add(4, 6) β 4 and 6 are arguments. |
| Defined once. | Can be different in each function call. |
def add(a, b): # a, b β parameters
return a + b
print(add(4, 6)) # 4, 6 β arguments β output 10
Q2. Write a Python function find_max() that takes two numbers as input and returns the maximum number. [3] (MP25 Q13-B)
def find_max(a, b):
if a > b:
return a
else:
return b
x = eval(input(“Enter first number: “))
y = eval(input(“Enter second number: “))
print(“Maximum is”, find_max(x, y))
Q3. Write a Python function named welcome() that takes a user’s name “Ali” as a parameter and prints a welcome message. [3] (FA26 P-1)
def welcome(name):
print(“Welcome”, name, “to Python programming!”)
welcome(“Ali”)
Output: Welcome Ali to Python programming!
Q4. Write a Python function named add_numbers() that takes two numbers 4 and 6 as parameters and prints their sum. [3] (FA26 P-2)
def add_numbers(a, b):
print(“Sum =”, a + b)
add_numbers(4, 6)
Output: Sum = 10
Q5. Why is it better to use functions rather than writing one long program? Give three reasons. / A program to calculate total and average marks is written once as a single block and once using smaller functions β which approach is better and why? [1Γ3 / 1 + 2] (SA25 Q7-B; FA26 P-2)
The program divided into functions is better.
β’ Easy to understand and manage: a long code is divided into segments; each function does a separate task, so the logic is easy to keep track of.
β’ Reusability: a function is defined once and called many times (e.g. calculate_average() for every student) instead of writing the same code again and again.
β’ Easy testing and debugging: each function can be tested separately; errors are located quickly, and changes are made in one place only.
Q6. Two students solve the same problem: one uses global variables inside a function, the other passes values as parameters and returns the result. Which approach is better, and why? [1 + 2] (FA26 P-1)
Passing values as parameters and returning the result is better.
β’ The function becomes independent and reusable; it can work on different values each time it is called.
β’ Local variables are limited to the function, so there is no accidental change of global data; the function is easier to test and debug.
3.12 Debugging
Short Questions
Q1. Identify and correct the errors in the code: length = input(“Enter length”); width = input(Enter width”); area = length * width; print(“Area of rectangle is:”, area); if area > 0 print(“Valid area”) [4 / 3] (Set-1 Q1-B; FA26 P-2)
| Error | Correction |
|---|---|
| input() returns a string; length * width cannot multiply two strings. | length = eval(input(“Enter length”)) (or float/int) β same for width. |
| Missing opening quote in input(Enter width”). | input(“Enter width”) |
| Missing colon after if area > 0 | if area > 0: |
| print(“Valid area”) not indented under if. | Indent it by 4 spaces. |
| (FA26 version) print(“Area of rectangle is:” area β missing comma and closing bracket. | print(“Area of rectangle is:”, area) |
length = eval(input(“Enter length: “))
width = eval(input(“Enter width: “))
area = length * width
print(“Area of rectangle is:”, area)
if area > 0:
print(“Valid area”)
Q2. Identify and correct any three errors: num1 = input(“Enter first number”); num2 = input(“Enter second number); sum = num1 + num2; print(“Sum = ” sum [1Γ3] (FA26 P-1)
| Error | Correction |
|---|---|
| Missing closing quote in input(“Enter second number) | input(“Enter second number”) |
| input() gives strings, so + joins them (concatenation) instead of adding. | num1 = eval(input(…)), num2 = eval(input(…)) |
| print(“Sum = ” sum β missing comma and closing bracket. | print(“Sum = “, sum) |
num1 = eval(input(“Enter first number: “))
num2 = eval(input(“Enter second number: “))
sum = num1 + num2
print(“Sum = “, sum)
Q3. Correct the following Python code segments by removing errors (three segments). [3] (MP25 Q1-A)
| Incorrect code | Code without errors |
|---|---|
| num1 = 10; num2 = “5”; result = num1 + num2; print(result) (TypeError: int + str) | num1 = 10; num2 = 5 (or int(“5”)); result = num1 + num2; print(result) β 15 |
| fruits = [“Islamabad”, “Karachi”, “Lahore”]; print(fruits[3]) (IndexError: last index is 2) | print(fruits[2]) β Lahore |
| num1 = 10; num2 = 0; result = num1 / num2; print(result) (ZeroDivisionError) | num2 = 2 (any non-zero value) or: if num2 != 0: result = num1 / num2 β 5.0 |
Q4. Correct any three errors in the code: temperature = 5; / if temperature > 30: print(“It’s hot”) / elif temperature = 5: display(“It’s cold”) / else: print(“The weather is mild”) [3] (FAM25 Q7-B)
| Error | Correction |
|---|---|
| elif temperature = 5: (“=” is assignment) | elif temperature == 5: |
| display(“It’s cold”) (no display() function) | print(“It’s cold”) |
| temperature = 5; (semicolon not needed in Python) / print statements not indented | temperature = 5 and indent each print under its condition |
temperature = 5
if temperature > 30:
print(“It’s hot”)
elif temperature == 5:
print(“It’s cold”)
else:
print(“The weather is mild”)
Q5. Correct any three errors in the code: number = 0; / if number > 0: print(“Positive number”) / eliff number = 0: print(“Zero”) / else: print(“Negative number”) [3] (FAE25 Q7-B)
| Error | Correction |
|---|---|
| eliff β misspelt keyword | elif |
| number = 0 inside condition (“=” is assignment) | number == 0 |
| number = 0; (semicolon not needed) / missing indentation | number = 0 and indent the print statements |
number = 0
if number > 0:
print(“Positive number”)
elif number == 0:
print(“Zero”)
else:
print(“Negative number”)
Q6. How does a debugger help programmers? Justify. [3] (SA25 Q1-B)
A bug is an unanticipated error, generally logical in nature. For a large program, manual dry-run is tedious, so a debugger is used.
β’ Step-by-step execution: the Step button executes the code line by line, so the programmer sees exactly where the program goes wrong.
β’ Watching variables: the Debug Control window shows the values of global and local variables after each instruction.
β’ Breakpoints: the debugger stops at the marked line that needs close examination; Go, Over and Out buttons skip the parts already checked β the bug is located quickly.
Q7. Briefly explain any two methods used to debug Python code. [1.5 + 1.5] (FA26 P-3)
β’ Debugger in IDLE (or pdb): select Debug β Debugger, run the program, and use Step, Go, Over, Out buttons and breakpoints to execute line by line while watching variable values. (pdb: python -m pdb file.py with step, next, break, continue.)
β’ Debugging via print statements: place print() statements after important lines to display variable values; the output shows where the values become wrong. (Also: assert statement β raises AssertionError when an expected condition is false.)
Long Questions
Q8. A teacher wants to find the highest and lowest marks in a class. Write a Python function that takes marks of 10 students as input and returns both the maximum and minimum marks. [6] (NMP26 / MP25 Q9-OR)
def max_min(marks):
highest = marks[0]
lowest = marks[0]
for m in marks:
if m > highest:
highest = m
if m < lowest:
lowest = m
return highest, lowest
marks = []
for i in range(10):
m = eval(input(“Enter marks of student ” + str(i + 1) + “: “))
marks.append(m)
high, low = max_min(marks)
print(“Highest marks:”, high)
print(“Lowest marks:”, low)
Sample output (marks 45, 78, 66, 90, 34, 58, 72, 81, 49, 63): Highest marks: 90 Lowest marks: 34
(Using built-in functions inside the function is also correct: return max(marks), min(marks).)
Q9. Write a Python program to compute the area of a circle and a rectangle by using function(s). [6] (NMP26 / MP25 Q3-OR)
def circle_area(r):
return 3.14159 * r * r
def rectangle_area(length, width):
return length * width
r = eval(input(“Enter radius of circle: “))
l = eval(input(“Enter length of rectangle: “))
w = eval(input(“Enter width of rectangle: “))
print(“Area of circle =”, circle_area(r))
print(“Area of rectangle =”, rectangle_area(l, w))
Output (r = 7, l = 10, w = 5): Area of circle = 153.93791 Area of rectangle = 50
Q10. Write a Python program that reads two numbers and prints the minimum number by using a function. [5] (FAE25 P-2 Q4-OR)
def minimum(a, b):
if a < b:
return a
else:
return b
x = eval(input(“Enter first number: “))
y = eval(input(“Enter second number: “))
print(“Minimum number is”, minimum(x, y))
Q11. Write a Python program that reads three numbers and prints their product by using a function. [5] (FAM25 P-2 Q4-OR)
def product(a, b, c):
return a * b * c
x = eval(input(“Enter first number: “))
y = eval(input(“Enter second number: “))
z = eval(input(“Enter third number: “))
print(“Product =”, product(x, y, z))
Output (2, 3, 4): Product = 24
Q12. Write a Python program using function(s) to find the sum, product and difference of two numbers. [5] (SA25)
def calculate(a, b):
s = a + b
p = a * b
d = a – b
return s, p, d
x = eval(input(“Enter first number: “))
y = eval(input(“Enter second number: “))
s, p, d = calculate(x, y)
print(“Sum =”, s)
print(“Product =”, p)
print(“Difference =”, d)
Output (8, 3): Sum = 11 Product = 24 Difference = 5
Q13. Write a Python program to find the smallest of three numbers using function. [6] (FA26 P-1)
def smallest(a, b, c):
if a <= b and a <= c:
return a
elif b <= a and b <= c:
return b
else:
return c
x = eval(input(“Enter first number: “))
y = eval(input(“Enter second number: “))
z = eval(input(“Enter third number: “))
print(“Smallest number is”, smallest(x, y, z))
Q14. Write a Python program with a function to find the square and cube of a number. [6] (FA26 P-2)
def square_cube(n):
return n ** 2, n ** 3
num = eval(input(“Enter a number: “))
sq, cb = square_cube(num)
print(“Square of”, num, “=”, sq)
print(“Cube of”, num, “=”, cb)
Output (num = 4): Square of 4 = 16 Cube of 4 = 64
Q15. Write a Python program using function to read a number and print whether it is prime or composite. [5] (FA26 P-3)
def check_prime(n):
if n < 2:
return “neither prime nor composite”
for i in range(2, n):
if n % i == 0:
return “composite”
return “prime”
num = eval(input(“Enter a number: “))
print(num, “is”, check_prime(num))
Output: 7 is prime | 12 is composite | 1 is neither prime nor composite
You can find the other units of 1st Year Computer Science on the main page: FBISE 1st Year Computer Science short and long questions, all units.
Questions follow the FBISE HSSC-I Computer Science syllabus and paper pattern. Please confirm all dates and figures on the official website: www.fbise.edu.pk
Need help with 1st Year Computer Science? Join our live online classes for the Federal Board. Book a free demo class.

Ask a question about this topic