Important Questions & Viva
Python & functions
Q1. Differentiate between a parameter and an argument.
A parameter is the variable in the function header (def area(r)); an argument is the actual value passed in the call (area(5)).
Q2. What are default and keyword arguments?
A default argument has a value in the header (def f(a, b=5)) and is used when no value is passed. Keyword arguments are passed by name (f(b=2, a=1)) so order does not matter. Default parameters must come after non-default ones.
Q3. Differentiate between local and global variables.
A local variable is created inside a function and exists only there. A global variable is created outside all functions and can be read anywhere; to change it inside a function, declare it with global.
Q4. Is a list passed by value or reference?
Python passes references. Changes made to a mutable object (list, dict) inside the function are visible outside; re-assigning the parameter is not.
Q5. What is the use of the finally block?
Code in finally always runs whether an exception occurs or not – used to close files or connections.
Output-based questions
def change(a, b=5):
a = a + b
b = a - b
return a, b
x, y = change(10)
print(x, y)
print(change(3, 4))total = 0
def add(n):
global total
total += n
return total
add(5); add(7)
print(total)s = 'BoardExam2025'
print(s[2:7], s[-4:], s[::3])
print(s.upper().count('A'), s.find('Exam'))L = [10, 20, 30]
try:
print(L[3])
except IndexError:
print('Index error')
else:
print('No error')
finally:
print('Done')d = {'a': 1, 'b': 2}
d['c'] = d.get('a') + d.get('z', 10)
print(d, len(d))File handling
Q6. Differentiate between text and binary files.
Text files store characters readable in any editor and each line ends with EOL. Binary files store data in the same form as memory (pickle) and are not human-readable; no EOL translation.
Q7. What is the difference between 'w' and 'a' mode?
'w' creates a new file or erases an existing one. 'a' adds data at the end, keeping old content.
Q8. Differentiate read(), readline() and readlines().
read() returns the whole file (or n characters) as a string, readline() returns one line, readlines() returns a list of all lines.
Q9. What are dump() and load()?
Functions of the pickle module: dump(obj, file) writes (serialises) an object to a binary file, load(file) reads it back. load raises EOFError at the end of the file.
Q10. Why use newline="" with CSV files?
It prevents an extra blank line between rows on Windows because the csv module writes its own line endings.
with open('t.txt', 'w') as f:
f.write('ABCDEFGH')
with open('t.txt') as f:
print(f.read(3))
print(f.tell())
f.seek(5)
print(f.read())Stack
Q11. What is a stack? Give two applications.
A LIFO linear data structure with insertion and deletion at the top. Applications: undo in editors, reversing a string, balancing brackets, evaluating postfix expressions, function calls.
Q12. Convert A + B * C - D / E to postfix.
A B C * + D E / -
Q13. Evaluate the postfix expression 6 2 / 3 - 4 2 * +.
6/2 = 3 → 3−3 = 0 → 4×2 = 8 → 0+8 = 8.
Computer networks
Q14. Differentiate between a hub and a switch.
A hub broadcasts data to all ports; a switch sends it only to the destination port using MAC addresses, so it is faster and more secure.
Q15. Expand: HTTP, FTP, SMTP, POP, VoIP, TCP/IP, URL, DNS.
HyperText Transfer Protocol, File Transfer Protocol, Simple Mail Transfer Protocol, Post Office Protocol, Voice over Internet Protocol, Transmission Control Protocol/Internet Protocol, Uniform Resource Locator, Domain Name System.
Q16. Which medium would you use to connect two buildings 2 km apart?
Optical fibre – high speed over long distance and immune to interference. Repeaters are needed for long copper runs.
Q17. Differentiate between a virus and a worm.
A virus needs a host file and user action to spread; a worm is standalone and spreads itself across the network.
Q18. What is the difference between a web page and a website?
A web page is a single HTML document; a website is a collection of related web pages under one domain.
Database & SQL
Q19. Define degree and cardinality.
Degree = number of attributes (columns); cardinality = number of tuples (rows).
Q20. Differentiate primary key and candidate key.
Candidate keys are all attributes that can uniquely identify rows; the primary key is the one chosen among them. The others are alternate keys.
Q21. Differentiate DELETE and DROP.
DELETE is DML and removes rows (table remains); DROP is DDL and removes the table structure along with data.
Q22. Differentiate WHERE and HAVING.
WHERE filters rows before grouping; HAVING filters groups after GROUP BY and can use aggregate functions.
Q23. What is the output of SELECT COUNT(*), COUNT(col) on a column with 2 NULLs in 10 rows?
COUNT(*) = 10, COUNT(col) = 8.
Q24. Differentiate equi-join and natural join.
Equi-join uses = on the common column and keeps both copies of it; natural join joins on same-named columns and shows the column once.
Python–MySQL
Q25. Name the steps to connect Python with MySQL.
import mysql.connector → connect() → cursor() → execute() → fetchall()/commit() → close().
Q26. What is the use of commit()?
It permanently saves the changes made by INSERT, UPDATE or DELETE.
Q27. What does cursor.rowcount return?
Number of rows fetched by SELECT so far, or rows affected by INSERT/UPDATE/DELETE.
Viva questions
What is a module? Name two modules you used.
A .py file containing functions and variables that can be imported; e.g. math, random, pickle, csv, mysql.connector.
What is the use of the seek() function?
It moves the file pointer to a given byte position; tell() returns the current position.
What is an exception?
A runtime error such as ZeroDivisionError or ValueError, handled with try–except.
What is a foreign key?
An attribute in one table that refers to the primary key of another table, keeping data consistent.
What is an IP address?
A unique logical address for every device on a network, e.g. 192.168.1.10.
Exam tips
- 1Write function headers exactly as asked (name and parameters)
- 2In file programs, always close the file or use with
- 3Show the trace table for output questions
- 4In SQL, end each query with ; and use quotes for text
- 5Network case study: give a reason with every answer
