0% found this document useful (0 votes)
54 views

Computer Class 12th Half Yearly

Uploaded by

musicalduniya88
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Computer Class 12th Half Yearly

Uploaded by

musicalduniya88
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

JD EDUCATION CENTRE

Arra road , Naubasta , Kanpur Nagar


HALF YEARLY EXAMINATION 2024-25

CLASS : XII M.M. 70

SUBJECT : Computer Science (083) TIME : 03:00 hrs

Name…………………………………………......……………..……………….…….Section………..…….…RollNo…..…………..Invigilator Sign………………………..………...

General Instructions :

1. The question paper contains total 8 pages and divided into four sections: A , B , C and D.

2. All questions are compulsory.

3. There is no overall choice.

4. Marks for each question are indicated against it.

5. Write balanced and relevant answers as per the marks allocated.

Section - A (20 Marks)

Select the most appropriate answer for each of the following questions:

1. What will be the output of the following code snippet? (1 Mark)

x = [1, 2, 3]

y = [x] * 3

y[0][1] = 5

print(y)

a) [[1, 5, 3], [1, 2, 3], [1, 2, 3]]

b) [[1, 5, 3], [1, 5, 3], [1, 5, 3]]

c) [[1, 2, 3], [1, 2, 3], [1, 2, 3]]

d) [[1, 2, 3]]

2. Which of the following will produce a TypeError? (1 Mark)

a) '10' + 5

b) 10 + 5

c) '10' + '5'

d) 5 / 2

3. What is the output of the following code? (1 Mark)

a = [10, 20, 30, 40]

b = a

1
b[0] = 100

print(a)

a) [10, 20, 30, 40]

b) [100, 20, 30, 40]

c) []

d) None

4. Which of the following functions is used to create a copy of a dictionary? (1 Mark)

a) copy()

b) replicate()

c) duplicate()

d) clone()

5. What will be the output of the following code snippet? (1 Mark)

def foo(x, result=[]):

result.append(x)

return result

print(foo(5))

print(foo(10))

a) [5], [10]

b) [5], [5, 10]

c) [10], [5, 10]

d) [10], [10]

6. Which of the following methods is not a method of the str class in Python? (1 Mark)

a) startswith()

b) split()

c) title()

d) indexing()

7. Consider the following function definition. What will be the value of result when the function bar(4) is called? (1 Mark)

def bar(n):

if n == 1:

return 1

else:

return n * bar(n - 1)

result = bar(4)

2
a) 4

b) 6

c) 24

d) 120

8. Which of the following statements will delete the third element of a list named my_list? (1 Mark)

a) my_list.pop(3)

b) del my_list[2]

c) my_list.remove(2)

d) del my_list[3]

9. What will be the output of the following code? (1 Mark)

x = {'a': 1, 'b': 2, 'c': 3}

print(x['d'])

a) 1

b) 2

c) None

d) KeyError

10. What will be the output of the following Python code?

def manipulate_string(s):

s = s.replace("e", "3").replace("o", "0").upper()

words = s.split()

return " ".join(words[::-1])

text = "Hello, how are you doing today?"

result = manipulate_string(text)

print(result)

A) TODAY? DOING 0U 3AR H0W H3LL0,


B) TODAY? 0U 3AR H0W H3LL0, DOING
C) TODAY? 3AR H0W H3LL0, 0U DOING
D) TODAY? DOING 3AR H0W H3LL0, 0U

11. What is the difference between a mutable and an immutable object? (1 Mark)

a) Mutable objects can be changed, whereas immutable objects cannot

b) Immutable objects can be changed, whereas mutable objects cannot

c) Mutable objects are always integers, and immutable objects are always strings

d) There is no difference

3
12. What is the output of the following code? (1 Mark)

def test(a, b=[]):

b.append(a)

return b

print(test(1))

print(test(2))

a) [1], [2]

b) [1, 2], [2]

c) [1, 2]

d) [2, 1]

13. Given the following code, what is the correct way to initialize the class Sample? (1 Mark)

class Sample:

def _init_(self, val):

self.value = val

a) Sample = Sample(5)

b) sample = Sample(val=5)

c) sample = Sample(5)

d) sample = _init_(5)

14. Which of the following operations is not allowed on a set? (1 Mark)

a) add()

b) update()

c) index()

d) pop()

15. What is the output of the following code? (1 Mark)

def recursive_sum(n):

if n <= 1:

return n

else:

return n + recursive_sum(n - 1)

print(recursive_sum(5))

4
a) 5

b) 15

c) 10

d) 0

16. What will be the output of the following code snippet? (1 Mark)

def f(x, y=[]):

y.append(x)

return y

print(f(1, [2, 3]))

print(f(4))

a) [2, 3, 1], [4]

b) [2, 3, 1], [1, 4]

c) [2, 3, 1], [1]

d) [2, 3, 1], [4, 1]

17. Which of the following correctly merges two dictionaries, d1 = {'a': 1, 'b': 2} and d2 = {'b': 3, 'c': 4} in Python 3.9+? (1 Mark)

a) d1 + d2

b) {**d1, **d2}

c) d1 | d2

d) d1.merge(d2)

18. Consider the following snippet. What will be the value of total? (1 Mark)

def count(n):

total = 0

while n > 0:

if n % 2 == 0:

total += n

n -= 1

return total

total = count(6)

a) 6

b) 10

c) 12

d) 20

5
19. Assertion (A): The replace() method in Python strings creates a new string and does not modify the original string.

Reason (R): Strings in Python are immutable, meaning their contents cannot be changed after they are created.

 A) Both A and R are true, and R is the correct explanation for A.

 B) Both A and R are true, but R is not the correct explanation for A.

 C) A is true, but R is false.

 D) A is false, but R is true.

20. Assertion (A): The math.log() function can return results in different bases.

Reason (R): The first argument of math.log() specifies the number, and the second argument (optional) specifies the base.

 A) Both A and R are true, and R is the correct explanation for A.

 B) Both A and R are true, but R is not the correct explanation for A.

 C) A is true, but R is false.

 D) A is false, but R is true.

Section - B (2 x 5 = 10 Marks)

21. Write a Python function to find the GCD (Greatest Common Divisor) of two numbers using recursion. (2 Marks)

22. Predict the output of the given program : (2 Marks)

def outer_function(x):

def inner_function(y):

return y + x

return inner_function

def apply_function(func, value):

return func(value) * 2

closure = outer_function(10)

result = apply_function(closure, 5)

print(result)

23. Write a function called reverse_list () that takes a list as input and returns a new list with the elements in reverse order. (2
Marks)

24. Write a Python program that uses the random module to perform the following tasks:

1. Generate a random integer between 1 and 100 (inclusive).

2. Create a list of 10 random floating-point numbers between 0.0 and 1.0.

25. What will be the output of the following Python code? Explain your answer. (2 Marks)

my_tuple = (1, 2, 3, 4)

6
result = my_tuple[1:3] + (5, 6)

print(result)

Section - C (4 x 5 = 20 Marks)

26. Write a Python program that performs the following tasks with a CSV file containing employee data {fields: Name, Age, Department,
Salary} (4 Marks)

1. Create a function that reads the employee data from the CSV file and returns a list of dictionaries, where each dictionary
represents an employee.

2. Write a function that takes the list of employees and a minimum salary as input, and returns a list of employees who earn
above that salary.

3. Implement a function that calculates and returns the average age of employees in the list. Ensure to handle the case where the
list is empty.

4. Create a function that writes the filtered list of employees (those earning above the specified salary) to a new CSV file.

27. Write a Python program that reads a text file containing a list of words (one word per line) and performs the following operations: (4
Marks)

A. Count the total number of words in the file.


B. Identify and print the longest word and its length.
C. Create a new text file that contains only the words that start with a vowel.
D. Explain how you would handle potential errors, such as the file not being found or being empty

28. Discuss the concept of stack overflow and underflow in the context of stack operations. Address the following points : (4
Marks)

A. Define stack overflow and stack underflow, and explain the conditions under which each occurs.
B. Describe how stack overflow can be prevented in a programming context (e.g., dynamic resizing).
C. Provide examples of scenarios where stack underflow might occur, such as in function call management or expression
evaluation.
D. Explain how these conditions can be handled programmatically to ensure the robustness of stack-based implementations.

29. Write a Python function that takes a string as input and performs the following tasks: (4 Marks)

A. Count and return the number of vowels in the string.


B. Remove all whitespace from the string and return the modified string.
C. Check if the string is a palindrome (reads the same forwards and backwards) and return a boolean value indicating the result.
D. Reverse the string and return the reversed version.

30. Write a Python program that performs the following operations on a binary file : (4 Marks)

A. Write a function that takes a list of integers (e.g., [10, 20, 30, 40, 50]) and creates a binary file to store these integers. Each
integer should be written in binary format.
B. Write a function to read the integers back from the binary file and return them as a list. Ensure that the function handles the
case where the file does not exist.
C. Write a function that takes the list of integers read from the binary file and calculates their sum. If the list is empty, return 0.

Section - D (10 x 2 = 20 Marks)

31. Write a Python program that simulates a simple dice game using the random module. The program should include the following
features: (10 Marks)

7
A. Roll a Dice: Create a function called roll_dice() that simulates rolling a six-sided dice and returns the result (a random integer
between 1 and 6).
B. Game Loop: Implement a game loop that allows the player to roll the dice until they choose to stop. After each roll, display the
result and ask the player if they want to roll again or quit.
C. Score Tracking: Keep track of the total score, which is the sum of all rolls. When the player chooses to quit, print their total
score.
D. Bonus Feature: After quitting, randomly determine if the player receives a bonus based on their total score:

o If the score is 20 or more, award a bonus of 10 points.

o If the score is less than 20, no bonus is awarded.

Error Handling: Ensure that user input is properly handled, especially when asking if the player wants to continue rolling (e.g., handling
unexpected input).

32. Create a Python program to manage a list of students, allowing operations such as adding, removing, updating, and calculating
average grades also implement error handling for invalid inputs. (10 Marks)

Student Structure: Each student is a dictionary with:

o id: Unique identifier (integer).

o name: Student's name (string).

o age: Student's age (integer).

o grades: List of grades (integers).

Functions:

o add_student(students): Add a new student (ensure unique ID).

o remove_student(students, student_id): Remove a student by ID.

o update_student(students, student_id): Update student details.

o average_grade(students, student_id): Return average grade for a student.

o list_students(students): Display all students.

o find_student_by_name(students, name): Find students by name.

o sort_students_by_age(students): Sort students by age.

User Interface: Create a menu to allow users to:

o Add, remove, update students

o Calculate average grades

o List all students

o Find by name

o Sort by age

o Exit

You might also like