Class12 CS Questions With Answers
Class12 CS Questions With Answers
1. Flow of Control
Q: What is the difference between 'if', 'if-else' and 'if-elif-else' statements?
A: 'if' is used for a single condition.
'if-else' is used when there are two options.
'if-elif-else' is used for multiple conditions.
Q: Predict output:
for i in range(3):
if i == 1:
continue
print(i)
A: Output:
0
2
2. String Manipulation
Q: What is the output of: 'Python'.upper()?
A: 'PYTHON'
3. List Manipulation
Q: Write a program to reverse a list without using reverse() function.
A: lst = [1, 2, 3, 4]
lst = lst[::-1]
print(lst)
Q: Predict output:
list1 = [10, 20]
list1.append([30, 40])
print(list1)
A: Output:
[10, 20, [30, 40]]
Q: Predict output:
t = (1, 2, 3, 2)
print(t.count(2))
A: Output:
2
Q: Predict output:
d = {'a':1, 'b':2}; d['c']=3; print(d)
A: Output:
{'a':1, 'b':2, 'c':3}
Q: Predict output:
def add(a,b): return a+b
print(add(2,3))
A: Output:
5
7. Exception Handling
Q: Write a short code to handle division by zero error.
A: try:
x = 1/0
except ZeroDivisionError:
print("Division by zero error")
Q: Predict output:
f = open('data.txt', 'w')
f.write('Hello')
f.close()
A: Output: File 'data.txt' is created and 'Hello' is written to it.