Class XII Python Programming Test (Paper 7)
Time Allowed: 3 hours
Maximum Marks: 70
Section A (1 mark each)
Question 1: Which method is used to remove an element from a set in Python?
a) pop()
b) discard()
c) remove()
d) delete()
Question 2: What is the output of `2**3` in Python?
a) 6
b) 8
c) 2
d) 5
Question 3: What is the data type of `True` in Python?
a) int
b) bool
c) str
d) float
Question 4: What is the purpose of the `break` statement in Python?
a) To exit the entire program
b) To exit the current loop
c) To skip the current iteration of a loop
d) None of the above
Question 5: What does the following code output? `print(list(‘hello’))`
a) [‘hello’]
b) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
c) hello
d) [‘h’, ‘e’, ‘l’, ‘o’]
Section B (2 marks each)
Question 6: Write a Python program that prints all the numbers from 1 to 50 that are not divisible by 3.
Question 7: Write a Python program that takes a string as input and converts all the vowels into uppercase.
Question 8: Write a Python program to calculate the sum of the squares of n natural numbers.
Question 9: Explain the difference between the ‘==’ operator and the ‘is’ keyword in Python.
Question 10: Write a Python program that reverses the words in a string.
Section C (3 marks each)
Question 11: Write a Python function named `is_palindrome` that takes a string as an argument and returns True if the string is a palindrome, otherwise False.
Question 12: Write a Python program that takes a list of numbers as input and returns the second largest number in the list.
Question 13: Explain the use of the `global` keyword in Python with an example.
Question 14: Write a Python program to find all the prime numbers within a given range.
Question 15: Write a Python function to find the GCD (Greatest Common Divisor) of two numbers.
Section D (5 marks each)
Question 16: Write a Python program to simulate a basic ATM machine. Allow users to check their balance, deposit money, and withdraw money.
Question 17: Write a Python class to represent a 2D point in space. Include methods for setting the coordinates, moving the point by a given distance, and calculating the distance between two points.
Question 18: Write a Python program that takes a string as input and prints the frequency of each character in the string using a dictionary.
Question 19: Write a Python program to sort a list of tuples based on the second element of each tuple.
Question 20: Write a Python program that reads the contents of a CSV file and stores them in a list of dictionaries. Each dictionary should represent a row of the CSV file.
Section E (10 marks)
Question 21: Write a Python program to implement a simple text-based game. The game should have different characters, enemies, and a simple combat system.