Completed
Class 12 CS – CSV File Handling & Stack Live Challenge
Questions From This Challenge
Q1mcq1 mark
A CSV file contains the record: Ravi,85,12 When this record is read using csv.reader(), what are the data types of the three values returned in the row?
str, int, int
str, str, str ✓
int, int, int
str, float, int
Q2mcq1 mark
A program uses csv.writer and executes writer.writerow(["Amit", 85, "X"]). How many fields will the resulting CSV record contain?
1
2
3 ✓
4
Q3mcq1 mark
A CSV file is opened in write mode and three records are written using writerow(). What happens to any existing contents of that CSV file?
They are preserved and the new records are added at the beginning
They are preserved and the new records are added at the end
They are removed before the new records are written ✓
The file automatically becomes read-only
Q4mcq1 mark
Which statement correctly distinguishes writerow() from writerows()?
writerow() writes one row, while writerows() writes multiple rows ✓
writerow() reads one row, while writerows() reads multiple rows
writerow() writes columns, while writerows() writes rows
There is no difference between them
Q5mcq1 mark
A CSV file contains: Name,Marks A,80 B,65 C,90 A program reads the file using csv.reader(). Which condition is required if the program wants to calculate the total of the Marks column?
The values from the Marks column must be converted from strings to numbers ✓
csv.reader() automatically converts all numeric fields to integers
The entire CSV file must first be converted to binary
The header row must be deleted before reading
Q6output1 mark
What will be the output of the following Python code?
import csv
with open("data.csv", "w", newline="") as f:
w = csv.writer(f)
w.writerow(["A", 10])
w.writerow(["B", 20])
with open("data.csv", "r", newline="") as f:
r = csv.reader(f)
for row in r:
print(row[1], end=" ")
Correct output:
10 20Q7output1 mark
What will be the output of the following Python code?
import csv
with open("data.csv", "w", newline="") as f:
w = csv.writer(f)
w.writerows([["A", 10], ["B", 20], ["C", 30]])
with open("data.csv", "r", newline="") as f:
r = csv.reader(f)
total = 0
for row in r:
total += int(row[1])
print(total)
Correct output:
60Q8output1 mark
What will be the output of the following Python code?
import csv
with open("data.csv", "w", newline="") as f:
w = csv.writer(f)
w.writerows([["A", 10], ["B", 20]])
with open("data.csv", "a", newline="") as f:
w = csv.writer(f)
w.writerow(["C", 30])
with open("data.csv", "r", newline="") as f:
r = csv.reader(f)
for row in r:
print(row[0], end=" ")
Correct output:
A B CQ9mcq1 mark
A program reads a CSV file containing a header row followed by 5 student records. The program uses csv.reader() and processes every row without explicitly skipping the header. What is the main problem?
The reader cannot read more than five rows
The header will also be processed as a student record ✓
The CSV file will automatically be deleted
The reader will convert the header into integers
Q10mcq1 mark
Consider the following stack operations: Push(12) Push(25) Pop() Push(40) Push(55) Pop() Push(70) Pop() Which value remains at the top of the stack?
12
25
40 ✓
70
Q11mcq1 mark
Consider an initially empty stack. The following operations are performed: Push(5) Push(10) Push(15) Pop() Push(20) Pop() Pop() What is the final stack?
[5] ✓
[5, 10]
[10]
[5, 20]
Q12output1 mark
What will be the output of the following Python code?
stack = []
for x in [3, 6, 9, 12]:
stack.append(x)
a = stack.pop()
b = stack.pop()
stack.append(a + b)
print(stack)
Correct output:
[3, 6, 21]Q13output1 mark
What will be the output of the following Python code?
stack = [] stack.append(10) stack.append(20) stack.append(30) x = stack.pop() stack.append(x + 5) stack.append(40) print(stack.pop()) print(stack.pop())
Correct output:
40
35Q14mcq1 mark
A stack contains [10, 20, 30, 40], with 40 at the top. The following operations are performed: Pop() Pop() Push(50) Pop() Which element is at the top after these operations?
10
20 ✓
30
50
Q15output1 mark
What will be the output of the following Python code?
stack = []
for i in range(1, 6):
if i % 2 == 0:
stack.append(i * 10)
else:
stack.append(i)
print(stack.pop(), end=" ")
print(stack.pop(), end=" ")
print(stack)
Correct output:
5 40 [1, 20, 3]