Advertisement

Class - XII Half Yearly computer Science Important Question

 Class - XII Half Yearly computer Science Important  Question 

1

Which of the following is a valid variable name in Python?
a) 2variable                                                   b) my_variable
c) my-variable                                              d) for

2

What will be the output of the following code:
print(5 // 2)
a) 2.5                                                            b) 2
c) 3                                                               d) 2.0

3

Which of the following is used to handle exceptions in Python?
a) try-except                                                b) catch
c) error                                                        d) raise-catch

4

What is the default mode of the open() function in Python?
a) 'w'                                                            b) 'a'
c) 'r'                                                             d) 'x'

5

Which keyword is used to define a function in Python?
a) def                                                           b) func
c) function                                                   d) define

6

What is the output of the following code?

 

x = [1, 2, 3]  

 

print(x[-1])  

 

a) 1                       b) 2                    c) 3                     d) -1

7

Which of the following is not a data type in Python?
a) list                   b) tuple              c) set                  d) array

8

What is the result of:
'5' + '5'
a) 10                   b) 55                   c) '10'                 d) Error

9

Which of the following can be used to connect to a MySQL database in Python?
a) mysqladmin                                            b) MySQLdb
c) sqlite3                                                     d) pySQL

10

Which command is used to create a table in SQL?
a) MAKE TABLE                                     b) ADD TABLE
c) CREATE TABLE                                 d) NEW TABLE

11

What is the purpose of the fetchall() method in Python’s MySQL connector?
a) Executes a query                                   b) Fetches all rows of a query result
c) Commits the transaction                       d) Creates a new table

12

Which of the following is an aggregate function in SQL?
a) WHERE                                                b) COUNT()
c) SELECT                                                d) ORDER BY

13

What is the output of bool("") in Python?
a) True                                                     b) False
c) 0                                                           d) 1

14

What will be the output?

 

print(type({}))  

 

a) list                                                     b) dict
c) set                                                     d) tuple

15

In Python, which statement is used to exit a loop prematurely?
a) exit                                                  b) return
c) break                                               d) stop

16

The SQL clause ORDER BY is used to:
a) filter records                                  b) group records
c) sort records                                   d) delete records

17

In Python, how do you open a file for writing in binary mode?
a) 'wb'                                                 b) 'rb'
c) 'bw'                                                 d) 'br'

18

Which method is used to remove an item from a list in Python by index?
a) delete()                                           b) remove()
c) pop()                                              d) discard()

19

Which command is used to delete all records from a table in SQL without deleting the table?
a) DROP                                              b) REMOVE
c) DELETE                                         d) TRUNCATE

20

Which of the following is a valid Python set declaration?
a) {}                                                     b) set([])
c) []                                                      d) dict()

21

What is the output of the following:

 

print("abc".upper()) 

 

a) abc                                                   b) ABC
c) Abc                                                  d) error

 


22

Differentiate between append() and extend() methods of a list in Python.

23

Write any two differences between tuple and list.


What is the difference between ‘/’ and ‘//’ ?

24

What is exception handling? Explain with one example in Python.

25

Write the output:

a = "CBSE Computer" 

print(a[5:13]) 

26

Write any two uses of MySQL in Database Management.

27

What will be the output of the following code?

def add(x, y=5): 

    return x + y 

print(add(3)) 

28

What is the purpose of using GROUP BY clause in SQL?

 


29

Write a Python program to read a file named data.txt and count how many times the word "Python" appears in it.

 

30

 Write an SQL query for the following table:

 

Table: STUDENT

 

| ID | Name | Marks |

| 1  | Aman  | 78    |

| 2  | Rita     | 91    |

| 3  | John   | 64    |

a) Display names of students scoring more than 70
b) Display total number of students
c) Display students in ascending order of Marks

31

Write a Python function that accepts a list and returns a dictionary with elements as keys and their frequency as values.

OR

How many times will Python execute the code inside the following while loop? You should answer the question without using the interpreter! Justify your answers.

i = 0

 while i < 0 and i > 2 :

 print “Hello ...”

 i = i+1

 


32

Write a Python program to create a binary file emp.dat with employee records (EmpID, Name, Salary). Insert at least two records.

33

Consider the following table TEACHER:

| TID | Name   | Subject | Salary |

| 1   | Mohan  | CS      | 75000  |

| 2   | Anjali | Maths   | 70000  |

| 3   | Ravi   | Physics | 80000  |

Write SQL queries for:
a) Display teachers whose salary is more than 72000
b) Display all teachers teaching 'Maths'
c) Increase salary of teachers by 5000
d) Show maximum salary

34

Write a Python class Rectangle with methods to calculate area and perimeter. Accept length and breadth during object creation.

35

Write Python code to demonstrate file handling:

  • Open a text file story.txt
  • Count number of vowels in the file content.

Differentiate between the round() and floor() functions with the help of suitable example.



36

Write a menu-driven program in Python to do the following:
a) Insert records into a MySQL table BOOKS (BookID, Title, Price)
b) Display all records
(Use MySQL connector)

37

A company stores data of its employees in a text file. Each line has data in format:
EmpID, Name, Department, Salary.
Write a Python program to:
a) Read the file
b) Display names of employees whose Salary is greater than 50000.

38

Write a program to convert binary to decimal