Python practice-5

 

 

 

Class XII Python Programming Test (Paper 5)

Time Allowed: 3 hours

Maximum Marks: 70

Section A (1 mark each)

Question 1: What is the output of the following code?

print(['a', 'b', 'c'] + [1, 2, 3])

a) [‘a’, ‘b’, ‘c’, 1, 2, 3]

b) [‘a’, ‘b’, ‘c’, ‘1’, ‘2’, ‘3’]

c) [‘a1’, ‘b2’, ‘c3’]

d) Error

Question 2: How do you create a tuple with just one element?

a) t = (1)

b) t = 1

c) t = (1,)

d) t = 1,

Question 3: What will the following code print?

dictionary = {"A": 1, "B": 2}
print(dictionary.get("C", 3))

a) 1

b) 2

c) 3

d) Error

Question 4: What is the output of `type(range(5))` in Python?

a) <class ‘list’>

b) <class ‘range’>

c) <class ‘tuple’>

d) <class ‘dict’>

Question 5: How do you access the last element of a list in Python?

a) list[-1]

b) list[len(list)]

c) list[end]

d) list[last]

Section B (2 marks each)

Question 6: Write a Python program to find the sum of all elements in a list using a for loop.

Question 7: Write a Python program to find the common elements between two lists.

Question 8: Explain the use of the `pass` statement in Python with an example.

Question 9: Write a Python program that reverses a string without using the `reverse()` function or slicing.

Question 10: Explain the concept of mutability and how it applies to lists and tuples in Python.

Section C (3 marks each)

Question 11: Write a Python program to count the number of vowels in a given string.

Question 12: Write a Python function that accepts a dictionary as input and returns the sum of all the values in the dictionary.

Question 13: Explain the concept of list comprehension in Python with an example.

Question 14: Write a Python program to remove all occurrences of a specific value from a list.

Question 15: Write a Python function that takes a number and returns True if it is a prime number, otherwise False.

Section D (5 marks each)

Question 16: Write a Python program to keep track of the number of occurrences of each character in a string using dictionaries.

Question 17: Write a Python program to implement a stack using lists. Implement push, pop, and display functions.

Question 18: Write a Python program that uses a dictionary to store student names and marks. The program should be able to add, delete, and display data.

Question 19: Write a Python program that reads a CSV file and stores the data in a list of dictionaries.

Question 20: Write a Python program to implement a simple phone book application where you can add, view, and delete contacts.

Section E (10 marks)

Question 21: Write a Python program to implement a simple bank account class with methods to deposit, withdraw, and display the balance.

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top