Computer Science Viva Questions for Class 12: A Comprehensive Guide

Congratulations on reaching the viva voce stage of your Class 12 computer science journey! As you prepare for this important examination, it’s essential to be well-versed in various aspects of computer science, including Python projects, database management systems, computer networks, and file handling in Python. In this guide, we present a detailed set of questions to help you thoroughly prepare for your viva.

Computer Science Viva Questions for Class 12

Python Project Based Questions

Here are some potential questions that an examiner might ask during your viva voce for a Python project with MySQL connection:

Project Overview:

1. Explain the purpose of your project and its main features.

Purpose of the Project:- The project aims to create a simple inventory management system using Python and MySQL. It allows users to add, update, and retrieve product information from a centralized database.


2. How did you decide on using Python for this project? What advantages does Python offer in this context?

Choosing Python:- Python was chosen for its readability, extensive libraries, and ease of integration with MySQL. The simplicity of Python makes it ideal for rapid development, and its support for MySQL connectors simplifies database interactions.

3. Describe the database schema you designed for your project.

Database Schema:- The database schema includes tables for products, categories, and suppliers. Each product entry contains details such as ID, name, quantity, price, category, and supplier information.

4. Explain the process of establishing a connection between your Python code and MySQL database.

Database Connection:- I used the `mysql-connector-python` library to establish a connection. The connection details, including host, username, password, and database name, are configured in the script. The `connect()` function initiates the connection.

5. How did you handle error handling and exception handling in your project?

Error Handling:- I implemented try-except blocks to handle potential errors during database operations. This ensures that if there’s a connection error or a query fails, the program gracefully handles the situation and provides appropriate feedback.

6. Discuss the security measures you implemented to protect the database connection and data.

Security Measures:-To enhance security, I stored database credentials in a separate configuration file with restricted access. Additionally, input validation and parameterized queries were used to prevent SQL injection attacks.

7. Can you explain the significance of SQL injection and how your project guards against it?

SQL Injection Prevention:-SQL injection was mitigated by using parameterized queries. This ensures that user inputs are treated as data rather than executable code, preventing malicious SQL injection attempts.

8. Walk through the steps involved in retrieving data from the database using Python.

Retrieving Data:-Data retrieval involves executing SELECT queries based on user input. The results are fetched and displayed in the user interface or used for further processing within the program.

9. Discuss the role of libraries or modules you used in your project, especially those related to database connectivity.

Library Usage:-The `mysql-connector-python` library facilitated database interactions, while other standard libraries like `tkinter` were used for the graphical user interface. The combination of these libraries streamlined development.

10. How did you handle data validation and sanitation to ensure the integrity of the data in the database?

Data Validation:- Input data is validated to ensure it meets predefined criteria. For example, when adding a new product, the quantity and price must be numeric, and the product name should not be empty.

11. Explain the techniques you employed for optimizing database queries in your project.

Optimizing Database Queries:- Optimization involved indexing frequently queried columns and using efficient JOIN operations. Additionally, I avoided SELECT * and retrieved only the necessary columns to minimize data transfer.

12. Describe any challenges you faced during the development of the project and how you overcame them.

Challenges Faced:-One challenge was handling concurrent database access. I addressed this by implementing locks during critical sections of code to prevent data inconsistency. Additionally, debugging complex SQL queries posed challenges, which were overcome by using print statements and step-by-step analysis.

13. Discuss the testing process for your project. How did you ensure the reliability of the code?

Testing Process:-The testing process involved unit tests for individual functions and integration tests for the entire system. I created mock databases to simulate various scenarios, ensuring the robustness and reliability of the code.

14. Elaborate on any future enhancements or features you would consider adding to your project.

Future Enhancements:-Future enhancements could include implementing user authentication, refining the user interface for a more intuitive experience, and incorporating data analytics features for better decision-making.


These are concise examples to get you started. When answering these questions, ensure you provide enough detail to demonstrate your understanding of the concepts and your project’s implementation.

Providing specific examples and details from your project will enhance the authenticity of your answers during the viva voce.

Be prepared to explain your thought process, coding decisions, and the overall architecture of your project. Good luck with your practical exam!

Computer Science Viva Questions for Class 12

In this article you will find some of the best viva questions form Python Programming that may be possible to be asked by the examiner in your practical examination. Here we collect more than 50 viva questions in python for the students of Computer Science and I.P. Students are advised to make a quick overview  Computer Science Viva Questions for Class 12 before attending the CBSE Practical Examination which is scheduled in December-January in this session. Hope you will find this content helpful in getting maximum marks. 


1- What is Python?

Ans. Python is a high-level, interpreted, dynamic, Object-Oriented Programming Language that supports GUI programming.


2- Why is Python interpreted?

Ans. Python is interpreted because the program is processed at runtime by the interpreter and you do not need to compile your program before executing it.


3- Who developed Python?

Ans. Python was developed by Guido van Rossum in the early nineties at the National Research Institute for Mathematics in the Netherlands.


4- Why is Python easy to learn?

Ans. Python has relatively few keywords, simple structure and a clearly defined syntax. This allows the student to understand and work easily in a relatively short period of time.


5-Write any one feature of Python library.

Ans. Python library is very portable and cross-platform compatible with UNIX, Windows and Macintosh.


6- Is Python a compiler language or an interpreter language?

Ans. The normal execution of Python program is interpreted. However, subsets of the language can be compiled.


7- Python is a free and open-source language. What do you understand by this feature?

Ans. That Python is a free and open-source language signifies that we do not ave to pay anything to download it. Also, being an open-source language, its source code is also available if we wish to modify it.

8- State some distinguishable features of Python

Ans. Python is a modern, powerful, interpreted language with objects, modules, exceptions (or interrupts) and automatic memory management. It was introduced to the world by Guido van Rossum in the year 1991.

Salient Features of Python are:

(i) Simple and Easy: Python is a simple language that is easy to learn.

(ii) Free/Open source: Anybody can use Python without the need to purchase a licence. High-level Language: Being a high-level language, it can be easily understood by the user without the need to be concerned with low-level details.

(iii)Portable: Python codes are machine and platform-independent.

(iv) Extensible and Embeddable: Python programs support usage of C/C++ codes. pre-written tools for programming,

(v) Standard Library: Python standard library contains


9- What are the two modes to work with python.

Ans: (i) Interactive mode  (ii)Script mode


10- What is an expression?

Ans: An expression is legal combination of symbols that represents a value.

11- What is string?

Ans: String is a sequence of characters.


12- What is the use of ‘+’ operator in string?

Ans: ‘+’ operator joins or concatenates the strings on both sides of the operator.


13-What is the use of ‘*’ operator in string?

Ans: ‘*’ operator creates a new string concatenating multiple copies of the same string.


14- How many types of strings are supported in Python?

Ans: Python allows two string types:

i) Single line String- String that terminated in a single line.

ii) Multiline String-String storing multiple lines of text


15- What is a tuple?

Ans: A tuple is an immutable sequence of values which can be of any type and are indexed by an integer.


16- Differentiate between list and tuples.

Ans: Tuples cannot be changed unlike lists, tuples use parentheses, whereas list use square brackets.


You Should also check:


17- What is an argument? Give an example.

Ans: An argument is data passed to a function through function call statement. For example, in the statement print (math.sqrt(25)) the integer 25 is an argument.


18- Python has certain functions that you can readily use without having to write any special code. What types of functions are these?

Ans: The pre-defined functions that are always available for use are known as Python’s built-in functions.

Examples of some built-in functions are: input(), type(), int(), eval(), etc.


19- What is Python module? What is its significance?

Ans: A “module” is a chunk of Python code that exists in its own (.py) file and is intended to be used by Python code outside itself.

Modules allow one to bundle together code in a form in which it can easily be used later. The Modules can be “imported” in other programs so the functions and other definitions in imported modules become available to code that imports them.


20- What is the utility of the built-in function help()?

Ans: Python’s built-in function help() is very useful. When it is provided with a program name or a module-name or a function-name as an argument, it displays the documentation of the argument as help. It also displays the string within its passed-argument’s definition. For example,

>>>help (math)

21- What is the difference between local variable and global variable?

Local Variable

1- It is a variable which is declared within Function or within a block.

2- It is accessible only within the function /block program.

Global Variable

1- It is a variable which is declared outside all the functions.

2- It is accessible throughout the program in which it is declared.


22- Is return statement optional? Compare and comment on the following two return statements:


return val

The return statement is optional only when the function is void or we can say that when the function does not return a value. A function that returns a value must have at least one return statement. From the given two return statements, the statement:


is not returning any value. Rather, it returns the control to caller along with empty value None. And the statement:

return val

is returning the control to caller along with the value contained in variable val.


23- Distinguish between Java and Python.

Ans: Java and Python can be distinguished on the following bases:

(i) Python programs run slower than the Java codes, but Python saves much time and space. Python programs are 3 to 5 times smaller than Java programs.

(ii)Python is a loosely-typed dynamic language as no time gets wasted in declaring variable types as in Java.

(iii) Python is easier to learn than Java.


24- What is the difference between a keyword and a variable?

Ans. Keyword is a special word that has a special meaning and purpose. For example, int, float, for, if, elif, else, etc., are keywords. Keywords are reserved and are few.

Variable is the user-defined name given to a value. Variables are not fixed/reserved. These are defined by the user but they can have letters, digits and a symbol underscore. They must begin with either a letter or underscore. For example, _age, name, result_1, etc., are the variable names in Python.


25- What is a function? How is it useful?

Ans. A function in Python is a named block of statements within a program.


26- What is the difference between an expression and a statement in Python?


S. No. Expression Statement
1 An expression is a combination of symbols, operators and operands. Statement is defined as any programming instruction given in Python as per the syntax.
2 An expression represents some value. Statement is given to execute a task.
3 The outcome of an expression is always a value. Statement may or may not return a value as the result.
4 For example, 3*7 + 10 is an expression print (“Hello”) is a statement.


27- How many kinds of statements are there?

Ans. Statements are categorized into three types:

I) Empty statements,

II) Simple statements, and

III) Compound statements.


28- What is the significance of an empty statement?

Ans. An empty statement does nothing. In Python, an empty statement is a pass statement.


29- Describe flow charts, decision tree and pseudo-code.

Ans. Flow charts are diagrams that show the step-by-step solution to a given problem. A decision tree is a diagrammatic representation of possible outcomes of certain conditions. Pseudo-code is a simple and informal way of writing programming code in English. There are no standard rules to write Pseudo-code.


30- What is the difference between break and continue statements?

Ans. Break and continue are the jump statements, and can be used to alter the flow of loop. Break statement terminates the loop and resumes execution in the statement. Continue statement skips the rest of the code inside a loop for the current iteration.


31- What is the purpose of ‘else’ in a loop?

Ans. Looping statements can have an optional else block as well. The else part is executed if the items in the sequence do not match or when loop gets over.


32. What is namespace in Python?

Ans: A namespace is a naming system used to make sure that names are unique to avoid naming conflicts.


33. What is PYTHONPATH?

Ans: It is an environment variable which is used when a module is imported. Whenever a module is imported, PYTHONPATH is also looked up to check for the presence of the imported modules in various directories. The interpreter uses it to determine which module to load.


34. What are python modules? Name some commonly used built-in modules in Python?

Ans: Python modules are files containing Python code. This code can either be functions classes or variables. A Python module is a .py file containing executable code.

Some of the commonly used built-in modules are:

  • os
  • sys
  • math
  • random
  • data time
  • JSON


35. Is python case sensitive?

Ans: Yes. Python is a case sensitive language.

36. Is indentation required in python?

Ans: Indentation is necessary for Python. It specifies a block of code. All code within loops, classes, functions, etc is specified within an indented block. It is usually done using four space characters. If your code is not indented necessarily, it will not execute accurately and will throw errors as well.



37. What is the difference between Python Arrays and lists?

Ans: Arrays and lists, in Python, have the same way of storing data. But, arrays can hold only a single data type elements whereas lists can hold any data type elements.


38. What are functions in Python?

Ans: A function is a block of code which is executed only when it is called. To define a Python function, the def keyword is used.


39. How does break, continue and pass work?

Break: Allows loop termination when some condition is met and the control is transferred to the next statement.

Continue: Allows skipping some part of a loop when some specific condition is met and the control is transferred to the beginning of the loop

Pass: Used when you need some block of code syntactically, but you want to skip its execution. This is basically a null operation. Nothing happens when this is executed.



40. How do you write comments in python?

Ans: Comments in Python start with a # character. However, alternatively at times, commenting is done using docstrings(strings enclosed within triple quotes).


41. What is pickling and unpickling?

Ans: Pickle module accepts any Python object and converts it into a string representation and dumps it into a file by using dump function, this process is called pickling. While the process of retrieving original Python objects from the stored string representation is called unpickling.


42. How will you capitalize the first letter of string?

Ans: In Python, the capitalize() method capitalizes the first letter of a string. If the string already consists of a capital letter at the beginning, then, it returns the original string.


43. How will you convert a string to all lowercase?

Ans: To convert a string to lowercase, lower() function can be used.


44. What is the purpose of ‘is’, ‘not’ and ‘in’ operators?

Ans: Operators are special functions. They take one or more values and produce a corresponding result.

is: returns true when 2 operands are true  (Example: “a” is ‘a’)

not: returns the inverse of the boolean value

in: checks if some element is present in some sequence


45. What is a dictionary in Python?

Ans: The built-in datatypes in Python is called dictionary. It defines one-to-one relationship between keys and values. Dictionaries contain pair of keys and their corresponding values. Dictionaries are indexed by keys.


46. What are Python packages?

Ans: Python packages are namespaces containing multiple modules.


47. How can files be deleted in Python?

Ans: To delete a file in Python, you need to import the OS Module. After that, you need to use the os.remove() function.


48. What are the built-in types of python?

Ans: Built-in types in Python are as follows –

  • Integers
  • Floating-point
  • Complex numbers
  • Strings
  • Boolean
  • Built-in functions


49. How to add values to a python array?

Ans: Elements can be added to an array using the append(), extend() and the insert (i,x) functions.


50. How to remove values to a python array?

Ans: Array elements can be removed using pop() or remove() method. The difference between these two functions is that the former returns the deleted value whereas the latter does not.

51. What are Python libraries? Name a few of them.

Ans:Python libraries are a collection of Python packages. Some of the majorly used python libraries are – Numpy, Pandas, Matplotlib, Scikit-learn and many more.


52. What is split used for?

Ans:The split() method is used to separate a given string in Python.


53. What is the maximum possible length of an identifier?

Ans: Identifiers can be of any length.


54. What are the common built-in data types in Python?

Ans: The common built in data types in python are-

Numbers– They include integers, floating point numbers, and complex numbers. eg. 1, 7.9,3+4i

List– An ordered sequence of items is called a list. The elements of a list may belong to different data types. Eg. [5,’market’,2.4]

Tuple– It is also an ordered sequence of elements. Unlike lists , tuples are immutable, which means they can’t be changed. Eg. (3,’tool’,1)

String– A sequence of characters is called a string. They are declared within single or double quotes. Eg. “Sana”, ‘She is going to the market’, etc.

Set– Sets are a collection of unique items that are not in order. Eg. {7,6,8}

Dictionary– A dictionary stores values in key and value pairs where each value can be accessed through its key. The order of items is not important. Eg. {1:’apple’,2:’mango}

Boolean– There are 2 boolean values- True and False.


55. What is type conversion in Python?

Ans: Type conversion refers to the conversion of one data type iinto another.

int() – converts any data type into integer type

float() – converts any data type into float type

ord() – converts characters into integer

hex() – converts integers to hexadecimal

oct() – converts integer to octal

tuple() – This function is used to convert to a tuple.

set() – This function returns the type after converting to set.

list() – This function is used to convert any data type to a list type.

dict() – This function is used to convert a tuple of order (key,value) into a dictionary.

str() – Used to convert integer into a string.

complex(real,imag) – This function converts real numbers to complex(real,imag) number.


56. What are Literals in Python and explain about different Literals

Ans: A literal in python source code represents a fixed value for primitive data types. There are 5 types of literals in python-

i) String literals– A string literal is created by assigning some text enclosed in single or double quotes to a variable. To create multiline literals, assign the multiline text enclosed in triple quotes.”Tanya”

ii) A character literal– It is created by assigning a single character enclosed in double quotes. Eg. a=’t’

iii) Numeric literals– They include numeric values that can be either integer, floating point value, or a complex number. Eg. a=50

iv) Boolean literals– These can be 2 values- either True or False.


57. What are negative indexes and why are they used?

Ans: The sequences in Python are indexed and it consists of the positive as well as negative numbers. The numbers that are positive uses ‘0’ that is uses as first index and ‘1’ as the second index and the process goes on like that.

The index for the negative number starts from ‘-1’ that represents the last index in the sequence and ‘-2’ as the penultimate index and the sequence carries forward like the positive number.

The negative index is used to remove any new-line spaces from the string and allow the string to except the last character that is given as S[:-1]. The negative index is also used to show the index to represent the string in correct order.

I hope you go through the article named Computer Science Viva Questions for Class 12 and revise your preparation for  viva.  

Copywrite © 2020-2024, CBSE Python,
All Rights Reserved
error: Content is protected !!