Class XII Python Programming Test (Paper 2)
Time Allowed: 3 hours
Maximum Marks: 70
Section A (1 mark each)
Question 1: What is the output of the following code snippet?
print(type([]) is list)
a) 1
b) True
c) False
d) Error
Question 2: What will the following code print?
for i in range(3):
print(i, end=' ')
a) 1 2 3
b) 0 1 2
c) 0 1
d) 1 2
Question 3: What does the `items()` method do in a dictionary?
a) It deletes all the items
b) It returns a list of tuples representing the dictionary’s items
c) It returns a view object displaying a list of the dictionary’s key-value tuples
d) None of the above
Question 4: What will be the output of the following code?
print('12'.isnumeric())
a) True
b) False
c) 12
d) Error
Question 5: What is the output of the following code?
t = (1, 2, 4, 8)
t.append(16)
print(len(t))
a) 4
b) 5
c) Error
d) 16
Section B (2 marks each)
Question 6: Write a program to check if a given string is a palindrome or not.
Question 7: Write a Python program to calculate the sum of all elements in a list using a loop.
Question 8: Write a program that uses a list comprehension to create a new list that contains only the even numbers from an existing list.
Question 9: Write a Python program to remove all elements from a dictionary.
Question 10: Explain the concept of unpacking in Python, with an example.
Section C (3 marks each)
Question 11: Write a program to find the largest number in a list of numbers entered by the user.
Question 12: Write a Python function that accepts a string and returns the reverse of the string.
Question 13: Explain the difference between a list and a tuple in Python.
Question 14: Write a Python program to find the common elements between two lists.
Question 15: Write a Python program that uses a dictionary to store and manipulate student grades (CRUD operations).
Section D (5 marks each)
Question 16: Write a Python program that takes a string input from the user and counts the frequency of each character in the string.
Question 17: Write a Python program to implement a stack (LIFO) using lists. Your program should include functions to add an item, remove an item, and view the stack.
Question 18: Write a Python program to find the second largest number in a list.
Question 19: Write a Python program to merge two dictionaries.
Question 20: Write a Python program that reads a file, counts the number of words in the file, and then writes the count to another file.
Section E (10 marks)
Question 21: Write a Python program to simulate a simple inventory management system for a retail store. The system should be able to add, view, update, and delete products (CRUD operations) and should also handle basic input validation.