By QB365 on 31 Dec, 2022
QB365 provides a detailed and simple solution for every Possible Questions in Class 12 Computer Science Subject - Important 3 Mark English Medium. It will help Students to get more practice questions, Students can Practice these question papers in addition to score best marks.
12th Standard
Computer Science
Answer all the following questions.
What is the side effect of impure function. Give example.
Identify Which of the following are List, Tuple and class ?
(a) arr [1, 2, 34]
(b) arr (1, 2, 34)
(c) student [rno, name, mark]
(d) day= (‘sun’, ‘mon’, ‘tue’, ‘wed’)
(e) x= [2, 5, 6.5, [5, 6], 8.2]
(f) employee [eno, ename, esal, eaddress]
Why access control is required?
What do you understand by Dynamic programming?
Explain Ternary operator with examples.
Write note on if..else structure.
Write the basic rules for global keyword in python.
What is composition in functions?
Write a Python program to display the given pattern
C O M P U T E R
C O M P U T E
C O M P U T
C O M P U
C O M P
C O M
C O
C
What is the use of format( )? Give an example.
What are the advantages of Tuples over a list?
Explain the difference between del and clear( ) in dictionary with an example.
What are class members? How do you define it?
What is the output of the following program?
class Greeting:
def __init__(self, name):
self.__name = name
def display(self):
print("Good Morning ", self.__name)
obj=Greeting ('Bindu Madhavan')
obj.display()
Explain Cartesian Product with a suitable example.
Write a note on different types of DBMS users.
Write a SQL statement to modify the student table structure by adding a new field.
Write the use of Savepoint command with an example.
Write a note on open() function of python. What is the difference between the two methods?
What is the difference between the write mode and append mode.
Differentiate PYTHON and C++.
Identify the module, operator, definition name for the following
welcome.display().
What is the use of Where Clause.Give a python statement Using the where clause.
Write any three uses of data visualization.
Write a short note an syntax for function types.
How will you access the list elements using multiple assignments?
How the variable scopes are prioritized?
Write a pseudo code for Binary search
Fill up the blanks to get the following output from Python code given.
Output:
Enter Number 1: 34
Enter Number 2: 70
The Sum = 104
Code:
X = \(\overset { (1) }{ \_ \_ \_ \_ \_ } \) (input ("Enter Number 1:"))
Y = \(\overset { (2) }{ \_ \_ \_ \_ \_ } \) (\(\overset { (3) }{ \_ \_ \_ \_ \_ } \) ("Enter Number 2 :"))
\(\overset { (4) }{ \_ \_ \_ \_ \_ } \) ("The sum =", \(\overset { (5) }{ \_ \_ \_ \_ \_ } \))
Write a Program to check the number is odd or even.
Answers
The variables used inside the function may cause side effects though the functions which are not passed with any arguments. In such cases the function is called impure function.
For example the mathematical function random() will give different outputs for the same function call.
let randomnumber :=
a := random()
if a > 10 then
return: a
else
return: 10
(a) List
(b) Tuple
(c) Class
(d) Tuple
(e) List
(f) Class
(i) Access control is a security technique that regulates who or what can view or use resources in a computing environment.
(ii) It is a fundamental concept in security that minimizes risk to the object.
(iii) In other words access control is a selective restriction of access to data.
(iv) In object oriented programming languages is implemented through access modifiers.
(i) Dynamic programming is an algorithmic design method that can be used when the solution to a problem can be viewed as the result of a sequence of decisions.
(ii) Dynamic programming approach is similar to divide and conquer. The given problem is divided into smaller and yet smaller possible sub-problems.
(iii) Dynamic programming is used whenever problems can be divided into similar sub-problems. So that their results can be re-used to complete the process.
(iv) Dynamic programming approaches are used to find the solution in optimized way. For every inner subproblem, dynamic algorithm will try to check the results of the previously solved sub-problems. The solutions of overlapped sub-problems are combined in order to get the better solution.
(i) Ternary operator is also known as conditional operator that evaluate something based on a condition being true or false.
(ii) It simply allows testing a condition in a single line replacing the multiline if-else making the code compact. The syntax for conditional operator is,
Variable Name = [on_true] if [Test expression]
else [on_false]
(iii) Example:
min = 50 if 49 < 50 else 70 # min = 50
min = 50 if 49 > 50 else 70 # min = 70
(i) The if.. else statement provides control to check the true block as well as the false block,
(ii) Syntax :
if
statemets-block 1
else :
statement-block 2
(iii) if..else statement thus provides possibilities and the condition determines which BLOCK is to be executed.
Rules of global Keyword: The basic rules for global keyword in Python are:
(i) When we define a variable outside a function, it's global by default. you don't have to use global keyword.
(ii) We use global keyword to modify the value of the global variable inside a function.
(iii) Use of global keyword outside a function has no effect.
(i) The value returned by a function may be used as an argument for another function in a nested manner.
(ii) This is called composition, For example, if we wish to take a numeric value or an expression as a input from the user, we take the input string from the user using the function input() and apply eval() function to evaluate its value.
Str 1 = "COMPUTER"
index = 0
for i in str 1:
print (str 1[:index -1])
index =1
(i) The format( ) function used with strings is very versatile and powerful function used for formatting strings.
(ii) The curly braces {} are used as placeholders or replacement fields which get replaced along with format( ) function.
Example:
num1 = int (input("Number 1:"))
num2 = int (input("Number 2:"))
print ("The, sum of {} and {} is {}". format (num1, num2, (num1 + num2)))
Output:
Number 1: 34
Number 2: 54
The sum of 34 and 54 is 88.
(i) The elements of a list are changeable (mutable) whereas the elements of a tuple are unchangeable (immutable), this is the key difference between tuples and list.
(ii) The elements of a list are enclosed within square brackets[ ]. But the elements of a tuple are enclosed by parenthesis().
(iii) Iterating tuples is faster than list.
del | Clear( ) | |
(i) | The del statements is used to delete elements whose index is known. | The function clear ( ) is used to delete all the elements in list. |
(ii) | The del statement can also be used to delete entire list. | It deletes only the elements and retains the list. |
(iii) | Example: del Dict ["MarkT"] | Example : Dict.clear( ) |
Variables defined inside a class are called as "Class Variable" and functions are called as "Methods. Class variable and methods are together known as members of the class. The class members should be accessed through objects or instance of class. A class can be defined anywhere in a Python program.
Defining classes: In Python, a class is defined by using the keyword class. Every class has a unique name followed by a colon (:).
Syntax for Defining a Class:
class class_name:
statement_1
statement_2
....................
....................
statement_n
Good Morning Bindu Madhavan.
(i) Cross product is a way of combining two relations. The resulting relation contains, both relations being combined.
(ii) A x B means A times B, where the relation A and B have different attributes.
(iii) This type of operation is helpful to merge columns from two relations
Database Administrators:
Database Administrator or DBA is the one who manages the complete database management system. DBA takes care of the security of the DBMS, managing the license keys, managing user accounts and access etc.
Application Programmers or software Developers:
This user group is involved in developing and designing the parts of DBMS.
End User:
All modern applications, web or mobile, store user data. Applications are programmed in such a way that they collect user data and store the data on DBMS systems running on their server. End users are the one who store, retrieve, update and delete data.
Database designers:
Database designers are responsible for identifying the data to be stored in the database for choosing appropriate structures to represent and store the data.
ALTER TABLE <table-name> ADD <column- name><data type><size>;
Example: ALTER TABLE Student MODIFY Address char (25)
(i) The SAVEPOINT command is used to temporarily save a transaction so that you can rollback to the point whenever required.
(ii) The different states of our table can be saved at any time using different names and the rollback to that state can be done using the ROLLBACK command.
(iii) SAVEPOINT savepoint_name:
UPDATE student SET Name = 'Mini' WHERE Admno=105;
SAVEPOINT A;
(i) Python has a built-in function open() to open a file. This function returns a file object also called a handle, as it is used to read or modify the file accordingly.
For Example:
>>>f = open ("sample.txt") #open file in current directory # f is file object
>>> f = open ('c:\\Pyprg\ch13 sample5.csv') # specifying full path
(ii) The default is reading in text mode. In this mode, while reading from the file the data would be in the format of strings.
(iii) On the other hand, binary mode returns bytes and this is the mode to be used when dealing with non-text files like image or exe files.
Write mode:
Open a file for writing. Creates a new file if it does not exist or truncates the file if it exists.
Append mode:
Open for appending at the end of the file without truncating it. Creates a new file if it does not exist.
S.No | PYTHON | C++ |
---|---|---|
(i) | Python is typically an "interpreted" language | C++ is typically a "compiled" language |
(il) | Python is a dynamic typed language | C++ is compiled statically typed language |
(iii) | Data type is not required while declaring variable | Data type is required while declaring variable |
(iv) | It can act both as scripting and general purpose language | It is a general purpose language |
welcome → module name
● → operator name
display() → definition name
The WHERE clause is used to extract only those records that fulfill a specified condition. In this example we are going to display the different grades scored by male students from "student table.
import sqlite3
connection = sqlite3.connect ("Academy.db")
cursor = connection.cursor()
cursor.execute ("SELECT DISTINCT (Grade) FROM student where gender = "M")
result = cursor.fetchall()
print(* result, sep ="\n")
Output:
('B,')
('A,')
('C,')
('D,')
(i) Data Visualization help users to analyze and interpret the data easily.
(ii) It makes complex data understandable and usable.
(iii) Various Charts in Data Visualization helps to show relationship in the data for one or more variables.
The syntax for function types
x\(\rightarrow \)y
x1 \(\rightarrow \)x2\(\rightarrow \)y
x1 \(\rightarrow \) .... \(\rightarrow \)x n\(\rightarrow \)y
The 'x' and 'y' are variables indicating types. The type x \(\rightarrow \) y is the type of a function that gets an input of type 'x' and returns an output of type 'y'. Where as x1\(\rightarrow \) x2 -\(\rightarrow \) y is a type of a function that takes two inputs, the first input is of type 'x1' and the second input of type 'x1', and returns an output of type 'y'. Likewise x1 \(\rightarrow \)...\(\rightarrow \)x n\(\rightarrow \)y has type 'x' as input of n arguments and 'y' type as output.
The elements of a list can be accessed in the method of multiple assignments, which unpacks a list into its elements and binds each element to a different name.
1st:=[10,20]
x,y:=1st
In the above example, x will become 10 and y will become 20. Mathematically we can represent list similar to a set.
Example:
lst [(0,10), (1,20)]
The LEGB rule is used to decide the order in which the scopes are to be searched for scope resolution. The scopes are listed below in terms of hierarchy.
Local (L) | Define inside functions/class |
Enclosed (E) | Defined inside enclosing functions |
Global (G) | Define at the upper most level |
Built-in (B) | Reserved names in built-in functions |
Start with the middle element:
(I) If the search element is equal to the middle element of the array i.e., the middle value = number of elements in array/2, then return the index of the middle element.
(ii) If not, then compare the middle element with the search value,
(iii) If the search element is greater than the number in the middle index, then select the elements to the right side of the middle index, and go to Step-1
(iv) If the search element is less than the number in the middle index, then select the elements to the left side of the middle index, and start with Step-1 ( When a match is found, display success message with the index of the element matched.
(vi) If no match is found for all comparisons, then display unsuccessful message
(1) int
(2) int
(3) input
(4) print
(5) x + y
# Program to check if the accepted number odd or even
a = int(input ("Enter any number:")
if a % 2 = = 0 :
print (a, "is an even number")
else:
print (a, "is an odd number")
Output 1:
Enter any number: 56
56 is an even number
Output 2:
Enter any number: 67
67 is an odd number.