Teachers and Examiners (CBSESkillEduction) collaborated to create the Python Revision Tour 1 Class 12 Questions with Answers. All the important Information are taken from the NCERT Textbook Computer Science (083) class 12.
Python Revision Tour 1 Class 12 Questions with Answers
1. What do you mean by Python shell’s “Interactive Mode”? Answer – You can enter one-line Python commands at the Python IDLE Shell’s prompt to have them instantly executed.
2. What do you mean by Python Shell’s “Script Mode”? Answer – You can add numerous lines of code while using Python’s Script Mode. In script mode, a Python programme is written to a file and executed by the interpreter. Beginners and testing little portions of code benefit from working in interactive mode because it enables immediate testing. However, whenever we create code that has more than a few lines, we should always save it so that we can edit and reuse it in the future.
Python Revision Tour 1 Class 12 Questions with Answers
3. What is a python Statement? Answer – A Python interpreter can run code in the form of statements. A statement is whatever you type in Python, to put it another way. The Python programming language supports a wide variety of statements, such as assignment statements, conditional statements, looping statements, and others.
4. What are Keywords? Answer – Key words in Python are reserved words that assist the interpreter in understanding the organisation of the programme. In Python, specified concepts with distinct meanings are known as keywords. It is not permitted to use the keyword as a variable, function, or identifier. All Python keywords are lowercase, with the exception of True and False.
5. What are Identifiers? Answer – An identifier, often known as a name, is provided to a variable, function, class, module, or other object. The identifier is a series of numbers and underscores. The identifier should have a letter or underline at the beginning and a number at the end. A-Z or a-z, an underscore (_), and a number make up the letters (0-9). Special characters (#, @, $,%,!) should be avoided in identifiers.
Python Revision Tour 1 Class 12 Questions with Answers
6. What is Variable? Answer -A variable is a location in memory where a value is stored in a computer language. In Python, a variable is formed when a value is put into it. Declaring a variable in Python doesn’t require any further
7. What other guidelines are there for declaring the variable? Answer – The rules for declaring variable are – 1. A number cannot be used as the first character in the variable name. Only a character or an underscore can be used as the first character. 2. Python variables are case sensitive. 3. Only alpha-numeric characters and underscores are allowed. 4. There are no special characters permitted.
8. What do you mean by Constant? Answer – A constant is a variable with a fixed value. Similar to containers that store data that cannot be modified later, constants hold unchangeable data.
9. What is Data Type in Python? Answer – Python values each have a datatype. Data types are essentially classes in the Python programming language, and variables are instances (or objects) of these classes. Python can handle a wide range of data types. Here is a list of some of the most popular data types.
1. Numbers 2. Sequences 3. Sets 4. Maps
Python Revision Tour 1 Class 12 Questions with Answers
10. What is the purpose of Dictionaries in Python? Answer – In Python, dictionaries are frequently used when working with huge volumes of data. Like any other collection array, a dictionary is a collection array. A dictionary is a set of freely alterable strings or integers that are not arranged in any particular hierarchy. To access dictionary items, use the keys. You declare a dictionary using curly brackets.
11. What is Implicit Type Conversion? Answer – Python uses implicit type conversion to convert data types automatically. Users are not required to take part in this procedure. Example : x = 5 y=2.5 z = x / z
12. What is Explicit Type Conversion? Answer – Using explicit type conversion, users change an object’s data type to the desired data type. We make use of established functions like int(), float(), str(), and others to do explicit type conversion. This type of conversion is also referred to as typecasting because the user
Teachers and Examiners (CBSESkillEduction) collaborated to create the Python Revision Tour Class 12 MCQ. All the important Information are taken from the NCERT Textbook Computer Science (083) class 12.
Python Revision Tour Class 12 MCQ
1. A ___________ is an organised series of instructions that a computer is supposed to follow in order to complete a particular task. a. Program b. Code c. Instruction d. None of the above
Show Answer ⟶Hide Answer ⟵
a. Program
2. Computers may communicate using a language made up of 0s and 1s known as ____________. a. Low level language b. Machine language c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
c. Both a) and b)
3. A high-level language programme is referred to as _________. a. Machine code b. Source code c. Language d. None of the above
Show Answer ⟶Hide Answer ⟵
b. Source code
4. The programme statements were interpreted by a _____________. a. All the source at a time b. One by one c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
b. One by one
5. Python is a __________. a. Machine level language b. High level language c. Low level language d. All of the above
Show Answer ⟶Hide Answer ⟵
b. High level language
6. Python is __________. a. Free language b. Open source language c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
c. Both a) and b)
7. Python support __________. a. Assembler b. Interpreter c. Compiler d. None of the above
Show Answer ⟶Hide Answer ⟵
b. Interpreter
8. Python programs are ___________. a. Easy to understand b. Relatively simple structure c. Clearly defined syntax d. All of the above
Show Answer ⟶Hide Answer ⟵
d. All of the above
9. Python is _________. a. Non case – sensitive b. Case – sensitive c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
a. Case – sensitive
10. Python is platform independent, it means that ___________. a. It can run various hardware platforms b. It can run various operating systems c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
c. Both a) and b)
11. What is the purpose of indentation in python __________. a. Nested Blocks b. Blocks c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
c. Both a) and b)
12. In order to develop and execute a Python programme, we ____________. a. We can use any online python interpreter b. Python interpreter installed on the computer c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
c. Both a) and b)
13. The interpreter is also known as _______. a. Shell b. Program c. Cell d. None of the above
Show Answer ⟶Hide Answer ⟵
a. Shell
14. The python application must be run __________. a. Script mode b. Interactive mode c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
c. Both a) and b)
15. The instantaneous execution of each statement is possible using _____________. a. Script mode b. Interactive mode c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
a. Interactive mode
16. We can write several instructions in a file called Python source code using _____________ . a. Script mode b. Interactive mode c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
b. Script mode
17. We can just type a Python statement on the _____________ prompt to operate in interactive mode. a. >>> b. >> c. > d. None of the above
Show Answer ⟶Hide Answer ⟵
a. >>>
18. A Python programme can be written in the script mode, saved, and then run using the ___________. a. Folder b. File c. Prompt d. All of the above
Show Answer ⟶Hide Answer ⟵
b. File
19. What is the extension of python __________. a. .py b. .pp c. .ppy d. .pyy
Show Answer ⟶Hide Answer ⟵
a. .py
20. Which one is the reserve word in python. a. Keyword b. Program c. Interpreter d. None of the aboveShow Answer ⟶Hide Answer ⟵
a. Keyword
21. Python has Specific rules for naming identifiers. a. It can be of any length b. Name should begin with an uppercase, lowercase or underscore c. It should not be a keyword d. All of the above
Show Answer ⟶Hide Answer ⟵
d. All of the above
22. Python does not permit the use of _________ special symbols when defining variables. a. @ b. # and ! c. $ and % d. All of the above
Show Answer ⟶Hide Answer ⟵
d. All of the above
23. __________ uniquely identified in the program. a. Identifier b. Keyword c. Code d. None of the above
Show Answer ⟶Hide Answer ⟵
a. Identifier
24. Variable in python refers to an ________. a. Keyword b. Object c. Alphabets d. None of the above
Show Answer ⟶Hide Answer ⟵
b. Object
25. If you want to declare string in the program, which option is used to hold the string. a. Double quotes “” b. Single quotes ” c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
c. Both a) and b)
26. Before being used in expressions, ____________ must always have a value assigned to it. a. Keyword b. Variable c. Code d. None of the above
Show Answer ⟶Hide Answer ⟵
b. Variable
27. ___________ are used to give remark note in the source code. a. Keyword b. Source c. Comment d. None of the above
Show Answer ⟶Hide Answer ⟵
c. Comment
28. __________ are ignored by the python interpreter. a. Keyword b. Source c. Comment d. None of the above
Show Answer ⟶Hide Answer ⟵
c. Comment
29. ________ helps to start python comment in program. a. # b. @ c. % d. $
Show Answer ⟶Hide Answer ⟵
a. #
30. Python treats each value or piece of data, whether it be a string, a number, or another kind (described in the following section), as a ___________. a. Object b. Variable c. Keyword d. None of the above
Show Answer ⟶Hide Answer ⟵
a. Object
31. A variable’s ___________ specifies the kinds of data values it may store and the operations that can be carried out on those values. a. Data type b. Data base c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
a. Data type
32. In python Number data type is defined as ________. a. int b. float c. complex d. All of the above
Show Answer ⟶Hide Answer ⟵
d. All of the above
33. ________ subtype of integer data type. a. Boolean b. string c. list d. None of the above
Show Answer ⟶Hide Answer ⟵
a. Boolean
34. An ordered group of elements is referred to as a Python sequence. a. Number b. Sequence c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
b. Sequence
35. Sequence data types fall under the _________ category. a. Strings b. Lists c. Tuples d. All of the above
Show Answer ⟶Hide Answer ⟵
d. All of the above
36. Python has a group of characters known as ____________. a. Number b. String c. Boolean d. All of the above
Show Answer ⟶Hide Answer ⟵
b. String
37. You can store the ___________ data in a string. a. Alphabets b. Digits c. Special character including space d. All of the above
Show Answer ⟶Hide Answer ⟵
d. All of the above
38. __________ is a list of items that are enclosed in square brackets [ ] and are separated by commas. a. List b. Tuple c. String d. None of the above
Show Answer ⟶Hide Answer ⟵
a. List
39. __________ is a list of items enclosed in parenthesis and separated by commas ( ). a. List b. Tuple c. String d. None of the above
Show Answer ⟶Hide Answer ⟵
b. Tuple
40. _________ is a list of items that are not in any particular order and are enclosed in curly brackets { }. a. List b. Set c. String d. None of the above
Show Answer ⟶Hide Answer ⟵
b. Set
41. ________ data type cannot support duplicate entries. a. List b. Set c. String d. None of the above
Show Answer ⟶Hide Answer ⟵
b. Set
42. A unique data type called _________ has only one value. a. List b. Set c. String d. None
Show Answer ⟶Hide Answer ⟵
d. None
43. ___________ In Python, data elements are stored as key-value pairs.. a. Dictionary b. Set c. String d. None
Show Answer ⟶Hide Answer ⟵
a. Dictionary
44. Items in a dictionary are enclosed in __________. a. Parenthesis () b. Brackets [] c. Curly brackets {} d. All of the above
Show Answer ⟶Hide Answer ⟵
c. Curly brackets {}
45. Every key and value in the dictionary are separated from one another by a __________. a. Colon (:) b. Semicolon (;) c. Comma (,) d. All of the above
Show Answer ⟶Hide Answer ⟵
a. Colon (:)
46. It is known as ________, to refer to variables whose values can be modified after they have been created and assigned. a. Immutable b. Mutable c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
b. Mutable
47. The term _________ refers to variables whose values cannot be modified once they have been created and assigned. a. Immutable b. Mutable c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
a. Immutable
48. It is recommended to use _____________ when we need uniqueness of elements and to prevent duplication. a. List b. Set c. Tuple d. All of the above
Show Answer ⟶Hide Answer ⟵
b. Set
49.The values that are used by the operators are referred to as __________. a. Operands b. Assignment c. Mathematical Operator d. All of the above
Show Answer ⟶Hide Answer ⟵
a. Operands
50. Which include the four fundamental arithmetic operations, modular division, floor division, and exponentiation. a. Arithmetic Operator b. Logical Operator c. Relational Operator d. All of the above
Show Answer ⟶Hide Answer ⟵
a. Arithmetic Operator
51. Operand-based computation is used. Raising the operand on the left to the power of the operand on the right is what this means. a. Floor Division (//) b. Exponent (**) c. Modulus (%) d. None of the above
Show Answer ⟶Hide Answer ⟵
b. Exponent (**)
52. ___________by comparing the operand values on each side, We can ascertain their relationship. a. Arithmetic Operator b. Logical Operator c. Relational Operator d. All of the above
Show Answer ⟶Hide Answer ⟵
c. Relational Operator
53. The variable on its left has its value either assigned or modified by ___________ operator. a. Relational Operator b. Assignment Operator c. Logical Operator d. All of the above
Show Answer ⟶Hide Answer ⟵
b. Assignment Operator
54. Which of the logical operators listed below is supported by Python. a. and b. or c. not d. All of the above
Show Answer ⟶Hide Answer ⟵
d. All of the above
55. Use the ___________ operator to verify that both operands are true. a. and b. or c. not d. All of the above
Show Answer ⟶Hide Answer ⟵
a. and
56. To determine whether a variable’s value belongs to a specific type or not, __________ are used. a. Relational Operator b. Logical Operator c. Identity Operator d. All of the above
Show Answer ⟶Hide Answer ⟵
c. Identity Operator
57. It is also possible to use ___________ to assess whether or not two variables are referring to the same thing. a. Relational Operator b. Logical Operator c. Identity Operator d. All of the above
Show Answer ⟶Hide Answer ⟵
c. Identity Operator
58. To determine if a value is a member of the given sequence or not, membership operators are used _________. a. Identity Operator b. Membership Operators c. Relational Operators d. All of the above
Show Answer ⟶Hide Answer ⟵
b. Membership Operators
59. A combination of constants, variables, and operators is known as a ____________. a. Expressions b. Precedence c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
a. Expressions
60. The expression is evaluated using a ____________ operators. a. Expressions b. Precedence c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
b. Precedence
61. Which of the following belongs to membership operators. a. in b. not c. in d. All of the above
Show Answer ⟶Hide Answer ⟵
d. All of the above
62. Which of the following belong to identity operators. a. is b. is not c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
c. Both a) and b)
63. The _____________ function in Python is available for accepting user input. a. prompt() b. input() c. in() d. None of the above
Show Answer ⟶Hide Answer ⟵
b. input()
64. The ____________ function in Python is available for showing the output. a. prompt() b. output() c. print() d. None of the above
Show Answer ⟶Hide Answer ⟵
c. print()
65. When data type conversion occurs because the programmer compelled it in the programme, _________ is also known as type casting. a. Explicit conversion b. Implicit conversion c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
a. Explicit conversion
66. When Python converts data types automatically without the programmer’s instruction, this is referred to as ______________, or coercion. a. Explicit conversion b. Implicit conversion c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
b. Implicit conversion
67. A programmer’s errors can prevent a programme from running properly or from producing the intended results. The method for locating and fixing such errors is known as ____________. a. Bugs b. Errors c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
c. Both a) and b)
68. Another name for finding and fixing programme bugs or problems is ___________. a. Debugging b. Mistakes c. Error d. None of the above
Show Answer ⟶Hide Answer ⟵
a. Debugging
69. Which of the subsequent errors can be found in Python scripts. a. Syntax error b. Logical error c. Runtime error d. All of the above
Show Answer ⟶Hide Answer ⟵
d. All of the above
70. A _________ produces an undesired output but without abrupt termination of the execution of the program. a. Syntax error b. Logical error c. Runtime error d. All of the above
Show Answer ⟶Hide Answer ⟵
b. Logical error
71. The programme is abnormally terminated while it is running due to a _________. a. Syntax error b. Logical error c. Runtime error d. All of the above
Show Answer ⟶Hide Answer ⟵
c. Runtime error
72. Python is a ______________ language that may be utilised for a variety of computing needs, both scientific and non-scientific. a. Open – source b. High level c. Interpreter – based d. All of the above
Show Answer ⟶Hide Answer ⟵
d. All of the above
73. In a programme, comments are ________ statements. a. Non – executable b. Executable c. Both a) and b) d. None of the above
Show Answer ⟶Hide Answer ⟵
a. Non – executable
74. A user-defined name for a variable or constant in a programme is ___________. a. Keyword b. Identifier c. Data type d. All of the above
Show Answer ⟶Hide Answer ⟵
b. Identifier
75. A computer program’s mistakes are found and fixed by a procedure known as _____________. a. Debugging b. Mistakes c. Error d. None of the above
Teachers and Examiners (CBSESkillEduction) collaborated to create the MySql Class 12 Notes. All the important Information are taken from the NCERT Textbook Information Technology (802) class 12.
MySql Class 12 Notes
What is Database?
A database is an organized collection of data that has been arranged and is typically kept electronically in a computer system. A database management system often oversees a database (DBMS).
A database has the following properties: 1) A database is a representation of some aspect of the real world also called miniworld. Whenever there are changes in this miniworld they are also reflected in the database. 2) It is designed, built and populated with data for specific purpose. 3) It can be of any size and complexity. 4) It can be maintained manually or it may be computerized.
Need for a Database
Database management systems enable users to securely, efficiently, and quickly share data throughout an organization. A data management system offers quicker access to more accurate data by quickly responding to database requests.
Database approach –
Data Redundancy – Data redundancy is the storing of the same data across many files. Space would be wasted as a result of this.
Data Inconsistency – If a file is modified, all the files that contain comparable information must also be updated, or the data will become inconsistent.
Lack of Data Integration – Because data files are unique, it is very challenging to obtain information from various files.
Database Management System (DBMS)
Data is stored, retrieved, and analyzed using software called database management systems (DBMS). Users can create, read, update, and remove data in databases using a DBMS, which acts as an interface between them and the databases.
The various operations that need to be performed on a database are as follows –
1. Defining the Database – It involves specifying the data type of data that will be stored in the database and also any constraints on that data.
2. Populating the Database – It involves storing the data on some storage medium that is controlled by DBMS.
3. Manipulating the Database – It involves modifying the database, retrieving data or querying the database, generating reports from the database etc.
4. Sharing the Database – Allow multiple users to access the database at the same time.
5. Protecting the Database – It enables protection of the database from software/ hardware failures and unauthorized access.
6. Maintaining the Database – It is easy to adapt to the changing requirements. Some examples of DBMS are – MySQL, Oracle, DB2, IMS, IDS etc.
Characteristics of Database Management Systems
Self-describing Nature of a Database System – A database system is said to as self-describing if it has metadata that defines and explains the data and relationships between tables in the database in addition to the database itself.
Insulation Between Programs and Data – Programs that access this data don’t need to be changed because the description of the data is stored separately in the database management system (DBMS) and any changes to the data’s structure are made in the catalogue.
Sharing of Data – Multiple users can access the database. Therefore, a DBMS must have concurrency control software to provide concurrent access to the database’s data without encountering any consistency issues.
Types of Users of DBMS
Depending on their needs and how they interact with the DBMS, different types of users use the DBMS. Four main categories of users exist –
End Users – those who use the database to perform queries, make changes, and produce reports based on their requirements is a end users.
Database Administrator (DBA) – The DBA is incharge of authorising access, keeping an eye on how it’s being used, offering technical support, and acquiring hardware and software resources.
Application Programmers – To communicate with the database, application developers create application programmes. To communicate with the database, these programmes are created using high level languages like SQL.
System Analyst – A system analyst is important to the feasibility, technical, and economic elements of database architecture.
Advantages of using DBMS Approach
Following are the advantages of using a DBMS –
Reduction in Redundancy – All the data is stored at one place. There is no repetition of the same data. This also reduces the cost of storing data on hard disks or other memory devices.
Improved Consistency – The chances of data inconsistencies in a database are also reduced as there is a single copy of data that is accessed or updated by all the users.
Improved Availability – Same information is made available to different users. This helps sharing of information by various users of the database.
Improved Security – The DBA can protect the database by using passwords and restricting users’ database access rights.
User Friendly – Because of its user-friendly interface, it reduces users’ dependence on computer specialists to carry out various data-related actions in a DBMS.
Limitations of using DBMS Approach
High Cost – The cost of implementing a DBMS system is very high. It is also a very time consuming process.
Security and Recovery Overheads – Depending on the data stored, unauthorised access to a database can result in a threat to the individual or business. Additionally, regular data backups are necessary to guard against disasters like fires and earthquakes.
Relational Database
A collection of data elements with pre-established relationships between them make up a relational database. These things are arranged in a series of tables with rows and columns. To store data about the things that will be represented in the database, tables are utilised.
In relational model,
A row is called a Tuple.
A column is called an Attribute.
A table is called as a Relation.
The data type of values in each column is called the Domain.
The number of attributes in a relation is called the Degree of a relation.
The number of rows in a relation is called the Cardinality of a relation.
Relational Model Constraints
Constraints are limitations on the values that are stored in a database according to the specifications.
We describe below various types of constraints in Relational model –
Domain Constraint – User-defined columns called domain constraints allow users to enter values in accordance with the data type. Additionally, if it receives an incorrect input, it alerts the user that the column needs to be filled out correctly.
Key Constraint – A primary key constraint is a column or group of columns that shares the same characteristics as a unique constraint. Relationships between tables can be specified using a primary key and foreign key constraints.
Null Value Constraint – A column may by default contain NULL values. A column must not accept NULL values according to the NOT NULL constraint. This forces a field to always have a value, thus you cannot add a value to this field while adding a new record or updating an existing record.
Entity Integrity Constraint – The primary key cannot be null due to the Entity Integrity Constraint. Individual records in a table are identified by a primary key, and if the primary key is null, we are unable to do so. Except for the main key column, any place in the table can have null values.
Referential Integrity Constraint – Foreign key constraints or referential integrity constraints. A logical rule governing the values in one or more columns in one or more tables is known as a foreign key constraint, also known as a referential constraint or a referential integrity constraint. For instance, a group of tables presents details about the suppliers to a company.
Data types commonly used
Data type
Meaning
Example
CHAR (n)
Fixed length character string. ‘n’ is the number of characters.
CHAR(5):“Ashok” “Vijay”
VARCHAR(n)
Variable length character string. ‘n’ is the maximum number of characters in the string.
VARCHAR(15): “Vijay Kumar” “Ashok Sen”
DATE
Date in the form of YYYY-MM-DD
DATE: ‘2014-03-20’
INTEGER
Integer number
23 56789
DECIMAL (m, d)
Fixed point number m represents the number of significant digits that are stored for values and d represents the number of digits that can be stored following the decimal point. If d is zero or not specified then the value does not contains any decimal part.
RDBMS data management is done using the SQL language. It is made up of two languages: Data Definition Language (DDL) and Data Manipulation Language (DML), where DDL is a language used to specify the structure and restrictions of data and DML is used to add, alter, and delete data in a database.
Create a Table using KEY CONSTRAINT – Primary Key of a table can be specified in two ways. If the primary key of the table consist of a single attribute, then the corresponding attribute can be declared primary key along with its description.
In the Create Table command, constraints can be named. The benefit is that using the Alter Table command, specified restrictions can be quickly altered or deleted. When naming a constraint, use the keyword CONSTRAINT followed by the constraint’s name and its specification.
For example consider the following Create Table command –
CREATE TABLE Teacher ( Teacher_ID INTEGER, First_Name VARCHAR(20) NOT NULL, Last_Name VARCHAR(20), Gender CHAR(1), Salary DECIMAL(10,2) DEFAULT 40000, Date_of_Birth DATE, Dept_No INTEGER, CONSTRAINT TEACHER_PK PRIMARY KEY (Teacher_ID), CONSTRAINT TEACHER_FK FOREIGN KEY (Dept_No) REFERENCES Department(Dept_ID) ON DELETE SET NULL ON UPDATE SET NULL );
In the above table, the primary key constraint is named as TEACHER_PK and the foreign key constraint is named as TEACHER_FK.
Drop Table Command
This command is used to delete tables. For example, suppose you want to drop the Teacher table then the command would be:
DROP TABLE Teacher CASCADE;
Thus Teacher table would be dropped and with the CASCADE option, i.e. all the constraints that refer this table would also be automatically dropped.
However if the requirement is that the table should not be dropped if it is being referenced in some other table then RESTRICT option can be used as shown below:
DROP TABLE Teacher RESTRICT;
Alter Table Command
Adding a column – Suppose we want to add a column Age in the Teacher table. Following command is used to add the column –
ALTER TABLE Teacher ADD Age INTEGER;
Dropping a column – A column can be dropped using this command but one must specify the options (RESTRICT or CASCADE) for the drop behavior. RESTRICT would not let the column be dropped if it is being referenced in other tables and CASCADE would drop the constraint associated with this column in this relation as well as all the constraints that refer this column.
ALTER TABLE Teacher DROP Dept_No CASCADE;
Dropping keys – A foreign key/primary key/key can be dropped by using ALTER TABLE command.
ALTER TABLE Teacher DROP FOREIGN KEY TEACHER_FK;
Adding a Constraint – If you want to add the foreign key constraint TEACHER_FK back, then the command would be –
ALTER TABLE Teacher ADD CONSTRAINT TEACHER_FK FOREIGN KEY (Dept_No) REFERENCES Department(Dept_ID) ON DELETE SET NULL ON UPDATE SET NULL;
Insert Command
This command is used to insert a tuple in a relation. We must specify the name of the relation in which tuple is to be inserted and the values. The values must be in the same order as specified during the Create Table command. For example, consider the following table Teacher: CREATE TABLE Teacher ( Teacher_ID INTEGER, First_Name VARCHAR(20) NOT NULL, Last_Name VARCHAR(20), Gender CHAR(1), Salary DECIMAL(10,2) DEFAULT 40000, Date_of_Birth DATE, Dept_No INTEGER, CONSTRAINT TEACHER_PK PRIMARY KEY (Teacher_ID), );
To insert a tuple in the Teacher table INSERT command can be used as shown below: INSERT INTO Teacher VALUES (101,”Shanaya”, “Batra”, ‘F’, 50000, ‘1984-08-11’, 1);
Update Command
This command is used to update the attribute values of one or more tuples in a table.
UPDATE Teacher SET Salary=55000 WHERE Teacher_ID=101;
Delete Command
In order to delete one or more tuples, DELETE command is used.
DELETE FROM Teacher WHERE Teacher_ID=101;
Select Command
The SELECT Command is used to retrieve information from a database.
SELECT <attribute list> FROM <table list> WHERE <condition>
1. Query – To retrieve all the information about Teacher with ID=101. In this query we have to specify all the attributes in the SELECT clause. An easier way to do this is to use asterisk (*), which means all the attributes.
SELECT * FROM Teacher WHERE Teacher_ID=101;
Output –
2. Query – To find the names of all teachers earning more than 50000.
SELECT First_Name,Last_Name FROM Teacher WHERE salary > 50000;
Output –
3. Query – To display Teacher_ID,First_Name,Last_Name and Dept_No of teachers who belongs to department number 4 or 7.
SELECT Teacher_ID,First_Name,Last_Name, Dept_No FROM Teacher WHERE Dept_No = 4 OR Dept_No = 7;
Output –
4. Query – To retrieve names of all the teachers and the names and numbers of their respective departments. Note that the above query requires two tables – Teacher and Department. Consider the following query:
SELECT First_Name, Last_Name, Dept_ID, Dept_Name FROM Teacher, Department;
5. Query – To retrieve names of all the teachers who belong to Hindi department.
SELECT First_Name, Last_Name FROM Teacher, Department WHERE Department. Dept_ID=Teacher. Dept_ID AND Dept_Name=”Hindi”;
6. Query – To retrieve names of all the teachers starting from letter ‘S’.
SELECT First_Name FROM Teacher WHERE First_Name LIKE “S%”;
Output –
7. Query – To retrieve names of all the teachers having 6 characters in the first name and starting with ‘S’
SELECT First_Name FROM Teacher WHERE First_Name LIKE “S_ _ _ _ _”;
Output –
8. Query – To retrieve names of all the teachers having at least 6 characters in the first name.
SELECT First_Name FROM Teacher WHERE First_Name LIKE “_ _ _ _ _ _%”;
Output –
9. Query – To list the names of teachers in alphabetical order.
SELECT First_Name, Last_Name FROM Teacher ORDER BY First_Name, Last_Name;
Output –
10. Query – To list the names of all the Departments in the descending order of their names.
SELECT Dept_Name FROM Department ORDER BY Dept_Name DESC;
Output –
11. Query – To retrieve the names and department numbers of all the teachers ordered by the Department number and within each department ordered by the names of the teachers in descending order.
SELECT First_Name, Last_Name, Dept_No FROM Teacher ORDER BY Dept_No ASC, First_Name DESC, Last_Name DESC;
Output –
12. Query – To retrieve all the details of those employees whose last name is not specified.
SELECT * FROM Teacher WHERE Last_Name IS NULL;
Output –
13. Query – To find total salary of all the teachers .
SELECT SUM(Salary) AS Total_Salary FROM Teacher;
Output –
13. Query – To find the maximum and minimum salary.
SELECT MAX(Salary) AS Max_Salary, MIN(Salary) AS Min_Salary FROM Teacher;
Output –
14. Query – To count the number of teachers earning more than Rs 40000.
SELECT COUNT(Salary) FROM Teacher WHERE Salary > 40000;
Output –
15. Query – To retrieve the number of teachers in “Computer Science” Department.
SELECT COUNT(*) AS No_of_Computer_Science_Teachers FROM Department, Teacher WHERE Dept_Name = “Computer Science”AND Dept_No=Dept_ID;
Teachers and Examiners (CBSESkillEduction) collaborated to create the Computer Network Class 12 Notes. All the important Information are taken from the NCERT Textbook Computer Science (083) class 12.
Computer Network Class 12 Notes
What is a Computer Network?
A computer network is an interconnection of two or more computers that exchange information or communicate with one another wirelessly or over wired cables. The goal of a computer network is to allow different devices to share resources.
Advantages of Computer Network
1. Data centralization – In an organisation, files can be shared and made accessible to all users on a central node. 2. Exchange of information – Users in a network can quickly communicate using text, video, audio, data, and information with other users. 3. Sharing of peripheral/Hardware device – A network of computers can share peripheral devices, such as a printer or scanner that can be utilised by all of the computers.
Computer Network Class 12 Notes
Evolution of Computer Network
a) 1969 ARPANET – The ARPANET was the first network to ever exist. This was the initial concept that gave rise to the Internet. b) 1980 NSFNET – A more powerful network than ARPANET, its primary intention was to be used for academic research. c) 1990 INTERNET – When ARPANET and NSFNET were joined to one another and other private networks also, This network is known as Internet.
Data communication terminologies
a) Sender – It is just a machine that transmits data messages. It could be a workstation, desktop computer, laptop, mobile phone, or another device. b) Receiver – Device that receives messages is referred to as a receiver. It could be a workstation, a mobile phone, a computer, etc. c) Communication Media – The means, channels, or methods used to transport messages from the sender to the receiver are referred to as communication medium. d) Protocols – A protocol is a set of rules for exchanging data. Each step and process of communication between two or more computers has a set of rules that apply to it. For networks to transport data successfully, they must abide by certain guidelines. e) Bandwidth – The data transfer rate of a computer network, measured in bits per second, is called bandwidth (Bps). f) Data Transfer Rate (DTR) – The amount of digital data transferred from one location to another in a predetermined amount of time is known as the data transfer rate (DTR). The speed at which a certain amount of data moves from one location to another is referred to as the data transfer rate. g) IP address – A device on the internet or a local network can be identified by its IP address, which is a special address. The rules defining the format of data delivered over the internet or a local network are known as Internet Protocol.
Computer Network Class 12 Notes
Switching Techniques
Multiple routes from the sender to the receiver are possible in big networks. The best path for data transfer will be selected by the switching technique. The systems are connected using a switching mechanism to provide one-to-one communication.
There are basically two types of switching 1. Circuit Switching – Two telephones linked via a circuit switched method. Circuit Switching Long-distance communication has long been accomplished using the circuit switching approach. 2. Packet Switching – Small data packets are sent between different networks using packet switching. These data “packets” or “chunks” enable quicker, more effective data transport. When a user transfers a file over a network, it frequently travels in smaller data packets rather than all at once.
Transmission media
A route that may transport data from a sender to a receiver is referred to as the transmission medium. There are two types of transmission media.
1. Guided Media
The signals are transferred using guided media, which is similar to a physical medium. Data is transmitted using guided media through a fixed-path network of cables.
a) Twisted pair cable – Two insulated copper wires are wrapped around one another to form the Twisted Pairs cable. Twisted pair cable is also known as Ethernet cable. Advantages of Ethernet Cable – Cost – Effective – Easy to install and Maintain
Disadvantages of Ethernet Cable – Installation is expensive – Very difficult to manage for long distance
Computer Network Class 12 Notes
b) Co-axial cable – Coaxial cable is a form of copper cable that is specifically designed with a metal shield and other signal-blocking components. It is largely utilised by cable TV providers. Advantages of Co-axial cable – Co-axial cable has greater data transmission quality than twisted pair cable. – Easy to install and very durable
Disadvantages of Co-axial cable – Coaxial cables are expensive – If single cable failure then all the network can take down
c) Fiber – optical cable – Large volumes of data are transmitted quickly and efficiently over fibre optic lines. Fiber optic cables are less clumsy, lighter, more flexible, and able to carry more data than conventional copper wires. Advantages of Fiber – optical cable – High speed data transmission – Data are more secure in fiber optical cable
Disadvantages of Fiber – optical cable – The cost of fiber optical cable is higher than the copper wire – Installation is also more expensive as compare to other wire
Computer Network Class 12 Notes
2. Unguided Media
The electromagnetic waves are transmitted via an unguided transmission without the help of any physical medium.
a) Radio waves – In the electromagnetic spectrum, radio waves have the longest wavelengths. These waves, which fall under the category of electromagnetic radiation, range in frequency from 300 GHz to 3 kHz, Advantages of Radio waves – Radio waves are transmitted easily through air. – Radio waves can be reflect and change their direction but data will not distroy
Disadvantage of Radio waves – Radio waves have low frequency so it can’t transmit a lot of data at one time – Rain, thunderstorms, and other meteorological factors can affect these signals.
b) Micro waves – Microwaves signal are used in satellite communication. This signal can transmit the data for long distance. A high frequency radio signal can be sent over the air in a straight line using a microwave. Advantages of Microwaves – Microwaves signal can receive any where – Higher data transfer rates and bandwidth is more as compare to other medium
Disadvantages of Microwaves – Rain, thunderstorms, and other meteorological factors can affect these signals. – It is not a secure method of communication
c) Infrared waves – A method of sending a signal over a distance with light is infrared. Infrared uses a light frequency that is higher than visible light in the red end of the light spectrum. Advantages of Infrared waves
Computer Network Class 12 Notes
Network Types
On the basis of geographical span, the network can be broadly categorized as PAN, LAN, MAN, and WAN.
Personal Area Network – A personal area network (PAN) is a form of computer network made to link computers and other devices that are close to a single user. Personal area networks, for instance, include personal computers, printers, fax machines, telephones, PDAs, and scanners.
Local Area Network – A local network is one that has been built inside a specific geographic region. Private networks with a 1 kilometre maximum radius. Usually, they are located in a building or on a campus. LANs operate at rates of 10 Mbps to 1 Gbps.
Metropolitan Area Network – A metropolitan area network may be owned by a single company, a sizable group of people, or numerous separate individuals or businesses (MAN). These networks, which have a 50 km radius, are employed to link up urban areas.
Wide Area Network – A wide area network, or WAN, has a radius of around 1000 km. They help connect remote areas and facilitate long-distance communication. Within a country or continent, they forge ties.
Computer Network Class 12 Notes
Network Topologies
The configuration of a network’s notes is referred to as its topology. The two main topologies are broadcast and point-to-point, respectively.
Broadcast Topology – Sending information to many recipients is referred to as broadcasting. A TV provider distributes a signal to digital TV subscribers similarly to how a radio station sends a signal to its numerous listeners.
Point – to – point Topology – The simplest topology is point to point, which connects two nodes directly using a shared link. Transmission between these two nodes is only capable of utilising the full capacity of the shared link.
Bus Topology
Bus topology, often called line topology, is a type of network topology in which each device is connected to the network by a single coaxial or RJ-45 network wire.
Ring Topology
In a ring topology, every device is connected via a wire that forms a ring. The intended recipient of the message is reached by way of a one-way transmission of the intended message. Device addition and deletion, as well as fault isolation and detection, are simple processes.
Star Topology
All of the devices in a star topology are linked to a central controller called a hub since communication between any two devices occurs through the hub. Installation and configuration of the Star network are simple. Furthermore, fault isolation and detection are simple.
Mesh Topology
Every node in the network is connected to every other node thanks to mesh topology. The topology offers secure data transport without any triffic issues because to dedicated point-to-point connections between every feasible pair of nodes.
Tree Topology
A hybrid topology that combines bus and star topologies is called tree topology. In a bus topology, backbone cable functions as the tree’s stem, while star networks (and even individual nodes) are connected to the primary tree by star cables.
Computer Network Class 12 Notes
Network Protocols
Transmission Control Protocol (TCP) – For communication via a network, TCP is a well-known communication protocol. Any communication is split up into a number of packets that are transferred from the source to the destination, where they are reassembled.
Internet Protocol (IP) – Internet Protocol is the procedure or method used to transport data from one computer to another over the internet (IP). A host, or a computer connected to the internet, is identified by at least one IP address that sets it apart from all other computers there.
Point-to-Point Protocol – The TCP/IP protocol, also known as the Point-to-Point Protocol, is used to connect one computer system to another (PPP). Computers utilise the PPP protocol to communicate across landlines and the Internet. A PPP connection is established when two systems are physically connected by a phone line.
HyperText Transfer Protocol (HTTP) – The HTTP protocol is used for internet-based resource transfers between client devices and servers. The resources needed to load a web page are requested by client devices, and in response, the servers provide the requested resources to the client devices.
File Transfer Protocol (FTP) – A method for downloading, uploading, and transferring files between computers and over the internet is the file transfer protocol. FTP enables the transfer of files between computers or via a cloud.
Simple mail transport Protocol (SMTP) – SMTP can be used to send and distribute outgoing email. It’s easy to set up and reliable to use the SMTP protocol. Either communications arrive at their intended recipients or an error notice alerts them to the problem.
Computer Network Class 12 Notes
Post office Protocol (POP) – POP3 is a method for receiving incoming emails. Post Office Protocol 3 is a common method of acquiring email that receives and holds email for a person until they pick it up (POP3).
Telnet – Telnet is the main internet protocol used to connect to remote machines. It makes it possible to link TCP/IP networks to distant machines.
Internet Relay Chat (IRC) – For conversing, IRC protocol is employed. The IRC server is used to transmit the message
Voice over Internet Protocol (VoIP) – It enables voice to be transported over a packet switched network as opposed to a public switched telephone network. VOIP software enables making phone calls over a standard internet connection. Today, ATA, IP phones, and computer-to-computer VoIP services are the three main categories that are regularly used.
Teachers and Examiners (CBSESkillEduction) collaborated to create the Data Structures Class 12 Notes. All the important Information are taken from the NCERT Textbook Computer Science (083) class 12.
Data Structures Class 12 Notes
Introduction to Data Structure
A data structure is a specific type of structure used to arrange, process, retrieve, and store data. There are a number of fundamental and specialized forms of data structures, all of which are made to organise data for a particular use. Users may easily get the data using data structure and they use it in the proper ways.
For example – Let’s say I want to gather certain information from the user and keep it for a long period. Then you can use data structures, which make it easier to store, retrieve and manage data easily.
Element of Data Representation
There are two different type of representation of data – a) Raw data – Raw data are raw facts. These are simply values or set of values. b) Data item – Data item represents single unit of value of certain type.
Data Structures Class 12 Notes
Difference between Data type vs Data Structure
A data type is one of the variations of a variable that can only have values of the same type allocated to them. A data type specifies a group of values in addition to well specified operations that describe the input-output behaviour. A data structre, on the other hand, is a physical implementation that explicitly defines a method of storing, reading, and altering data stored in a data structre.
Types of Data Structure
There are two different types of Data Structure.
a) Simple Data Structure – These data structures are normally built form primitive data types like integers, reals, characters, Boolean.
b) Compound Data Structure – Simple data structure can be combined in various ways to form more complex structures called compound data structures. Compound data structures are classified into following two types –
Linear data structures – If its elements are stored in sequence is known as linear data structure. example Array.
Non-linear Data structures – These are multilevel data structures. Example is Tree.
Linear List Arrays
A list with limited number of elements stored in memory is referred to as a linear array. Only homogenous data elements can be stored in a linear array. The array’s components are organised into a linear list or sequence that can contain the same kind of data. Each element of the array has an associated index number.
Array can be one dimensional, two dimensional or multi dimensional in Python.
Data Structures Class 12 Notes
Stacks
A stack is an arranged group of objects where new objects are always added and old objects are always removed from the same end. Stack is also known as LIFO (Last in, first out) for example If several plates are kept one after another, this indicates that a stack of plates is being maintained. Only one plate can be taken off the top of the stack and one plate can be put on top of the stack.
Queues
First In First Out (FIFO) order is used for performing operations on a queue, which is described as a linear data structure with open ends. In our definition of a queue, a list is one in which all additions are made at one end and all deletions are made at the other.
Linked Lists
A linked list is a type of linear data structure used to hold a set of elements. The linked list can also be used to contain a variety of objects that are similar in type. The list’s components are each denoted by a node. Each node has its own data as well as the following node’s address.
Tree
A tree is a non-linear, hierarchical data structure made up of a number of nodes, where each node holds a value as well as a list of pointers to other nodes. Topmost node is called the root of the tree and bottommost nodes are called leaves of the tree.
Data Structures Class 12 Notes
Operations on Data Structures
The basic operations that are performed on data structures are as follows –
1. Insertion – Insertion in a data structure refers to the adding of a new data element.
2. Deletion – A data element is deleted when it is taken out of a data structure. Before removing the data element, a search is conducted.
3. Searching – Searching involves searching for the specified data element in a data structure.
4. Traversal – A data structure must be traversed in order to process each data element individually.
5. Sorting – Sorting is the process of arranging data items in a data structure in a predetermined order.
6. Merging – Combining is the process of combining components from two comparable data structures to create a brand-new data structure of the same type.
Data Structures Class 12 Notes
Linear Search or Sequential Search
Algorithm
Step 1 : Set ctr = L Step 2 : Repeat steps 3 through 4 until ctr > U Step 3 : IF AR[ctr] == ITEM then { print(“Search Successful”) print(ctr, “is the location of”, ITEM) break } Step 4 : ctr = ctr + 1 Step 5 : IF ctr > U then print(“Search Unsuccessful!”) Step 6 : END
Program
def Lsearch(AR, ITEM) : i = 0 while i < len(AR) and AR[i] != ITEM : i = i + 1 if i < len(AR) : return i else : return False N = int(input(“Enter desired linear list size(max.50)…”)) print(“\n Enter elements for Linear List \n”) AR = [0] * N for i in range(N) : AR[i] = int(input(“Element” + str(i) + “:”)) ITEM = int(input(“\n Enter to be searched for …”)) index = Lsearch(AR, ITEM)
if index : print(“\nElement forund at index : “, index, “, Position :”,(index + 1)) else : print(“\nSorry!! Given element could not be found. \n”)
Data Structures Class 12 Notes
Binary Search
Step 1: Set BEG=LB, END=UB LOC = -1 Step 2: While(BEG <= END) MID = (BEG+END)/2 if ( ELE = A [ MID ] ) then LOC = MID Goto Step 3 else if( ELE < A[MID]) END=MID-1; else BEG=MID+1; [End if] [End if] [End of While loop] Step 3: if ( LOC >= 0 ) then Print Element, “Found in Location”, LOC else Print Element, “Search is Unsuccessful” Step 4: Exit
Teachers and Examiners (CBSESkillEduction) collaborated to create the Data Visualization Class 12 Notes. All the important Information are taken from the NCERT Textbook Computer Science (083) class 12.
Data Visualization Class 12 Notes
What is Data Visualization
The process of displaying data in the form of graphs or charts is known as data visualisation. It makes it incredibly simple to understand big and complex volumes of data. It makes decision-making very efficient and makes it simple for decision-makers to spot emerging trends and patterns. We can utilise a variety of Python data visualisation libraries, like Matplotlib, Seaborn, Plotly, etc.
Using Pylot of Matplotlib Library
The Python low-level package Matplotlib is used for data visualisation. It is simple to use and replicates the graphs and visualisation found in MATLAB. This library is composed of numerous plots, including line charts, bar charts, histograms, etc.
An interface similar to MATLAB is offered by the Matplotlib package Pyplot. Because it supports Python and is free and open-source, Matplotlib is intended to be just as functional as MATLAB. Each Pyplot function modifies a figure in some way, such as by creating a figure, a plotting region within the figure, some lines within the plot area, labelling the plot, etc.
Data Visualization Class 12 Notes
Installing and Importing matplotlib
Your machines already have the matplotlib library loaded if you installed Python using Anaconda. By launching Anaconda Navigator, you may verify it for yourself. Click Environments in the Navigator box, then scroll down then you can find list of installed software on your machine.
Data Visualization Class 12 Notes
Using NumPy Array
NumPy (‘Numerical Python’ or ‘Numeric Python’, pronounced as Num Pie) is an open source module of Python that offers functions and routines for fast mathmaatical computation on arrays and matrices. In order to use NumPy, you must import in your module by using a statemnt like –
import numpy as np
Code import numpy as np list = [1, 2, 3, 4] a1 = np.array(list) print(a1)
Data Visualization Class 12 Notes
Ways to create NumPy arrarys
a) Creating a One-dimensional Array To create a One dimensional Array the arange function is frequently used to quickly build an arrary. The arange method generates an array with values from 0 to 9 when given a value of 10.
Example import Numpy as np array = np.arange(20) array
b) Creating a Two-dimensional Array Let’s discuss how to make a two-dimensional array. The output of the arange function, when used alone, is a one-dimensional array. Combine its output with the reshape function to convert it to a two-dimensional array.
Creating Charts with Matplotlib Library’s Pyplot interface
You know that graphs and charts play a big and an important role in data visualization and decision making. Every chart type has a different utility and serves a different purpose. a) Line Chart – A line chart or line graph is a type of chart which displays information as a series of data points called ‘Markers’ connected by straight line segments. The PyPlot interface offers plot() function for creating line graph.
Example import matplotlib.pyplot as plt x = [5, 10, 20, 30] y = [10, 15, 25, 35] plt.plot(x, y) plt.title(“Line Chart”) plt.ylabel(‘Y-Axis’) plt.xlabel(‘X-Axis’) plt.show()
b) Bar Chart – A bar Graph or a Bar Chart is a graphical display of data using bars of different heights. A bar chart can be drawn vertically or horizontally using rectangles or bars of different heights/ widths PyPlot offer bar() function to create a bar chart.
Example import matplotlib.pyplot as plt x = [5, 10, 20, 30] y = [10, 15, 25, 35] plt.plot(x, y) plt.title(“Line Chart”) plt.ylabel(‘Y-Axis’) plt.xlabel(‘X-Axis’) plt.show()
Data Visualization Class 12 Notes
c) The Pie Chart – Recall that a pie chart is a circular statistical graphic, which is divided into slices to illustrate numerical proportion. Typically, a Pie Chart is used to show parts to the whole, and often a % share. The PyPlot interface offers pie() function for creating a pie chart.
Example import matplotlib.pyplot as plt x = [5, 10, 20, 30] y = [10, 15, 25, 35] plt.plot(x, y) plt.title(“Line Chart”) plt.ylabel(‘Y-Axis’) plt.xlabel(‘X-Axis’) plt.show()
Teachers and Examiners (CBSESkillEduction) collaborated to create the Idea of Efficiency in Python Class 12. All the important Information are taken from the NCERT Textbook Computer Science (083) class 12.
Idea of Efficiency in Python Class 12
Idea of Algorithmic Efficiency
A sufficiently accurate method or process that can be programmed into a computer and is used to carry out a given task is known as an algorithm. Numerous internal and external elements affect an algorithm’s performance, or should we say quality.
Internal Factors a) Time required to run b) Space required to run
External Factors a) Size of the input to the algorithm b) Speed of the computer on which it is run c) Quality of the compiler
Idea of Efficiency in Python Class 12
What is computational complexity
When analysing algorithms, computational complexity is a important factor. The words “compulation” and “complexity” are combined to form the term “compulation complxity.” The computation includes the issues that need to be resolved and the algorithms used to do so. In order to understand how much resource is required or adequate for this algorithm to operate effectively, complexity theory is used.
The resource generally include a) The time to run the algorithm b) The space needed to run the algorithm
Estimating Complexity of Algorithms Algorithmic complexity considers how quickly or slowly a specific algorithm operates. The mathematical function T(n) – time versus the input size n is how we define complexity. Without relying on implementation specifics, we wish to specify how long an algorithm takes.
Big-O Natation
Big O Notation is a technique for expressing how time-consuming an algorithm is. As the input increases, it calculates how long it will take to perform an algorithm. In other words, it determines an algorithm’s worst-case time complexity. The maximum runtime of an algorithm is expressed using the Big O Notation in data structures.
Idea of Efficiency in Python Class 12
Dominant Term
The growth rate is shown using the Big-O notation. By going inside the algorithm, one can find the category of mathematical formulas that most accurately captures the behaviour of an algorithm. The term that grows the quickest is the dominating term.
Common Growth Rates
Some growth rates of algorithms are as shown in following table – a) O(1) – Constant b) O(log N) – Log c) O(N) – Linear d) O(N log N) – n Log n e) O(N2) – Quadratic f) O(N3) – Cubic g) O(2N) – Exponential
Idea of Efficiency in Python Class 12
Guidelines for Computing Complexity
The five guidelines for finding out the time complexity of a piece of code are – a) Loops – The running time of a loop is , at most, equal to the running time of the stateemnts inside the loop multiplied by the number of iteration.
b) Nested Loops – To compute complexity of nested loops, analyze inside out. For nested loops, total running time is the product of the sizes of the loops.
c) Consecutive Statement – To compute the complexity of consecutive statement, simply add the time complexities of each statement.
d) If-then-else Statements – To compute time complexity of it-then-else statement, we consider worst-case running time, Which means, we consider the time taken by the test, plus taken by either the then part or the else part.
e) Logarithmic Complexity – The logarithmic complexity means that an algorithms performance time has logarithmic factor e.g. an algorithm is O(log N) if it takes a constant time to cut the problem size by a fraction.
Idea of Efficiency in Python Class 12
Best, Average and Worst case complexity
1) Best case – quickest turnaround time with optimal inputs. For instance, data that has already been sorted would be the best case scenario for a sorting algorithm. 2) Worst case – is the slowest completion speed, with pessimistic inputs. 3) Average case – mean equals average scenario.
Teachers and Examiners (CBSESkillEduction) collaborated to create the Recursion in Python Class 12. All the important Information are taken from the NCERT Textbook Computer Science (083) class 12.
Recursion in Python Class 12
Recursion in Python
Python allows for the recursion of functions, which allows a defined function to call itself. A popular idea in mathematics and computer programming is recursion.
There are two types of Recursion in Python. Function calls itself directly form within its body is an example of direct recursion. However, if a function calls another function which calls its caller function from within its body is known as indirect recursion.
Example Direct recursion def a() : a()
Indirect recursion def a() : b()
Recursion in Python Class 12
The Two Laws of Recursion
Must have a base case – At least one basic requirement or condition must be met before the function can stop calling itself.
Must move toward the base case – The recursive calls should progress so that each time they get closer to the initial requirements.
Advantages of using Recursion
1. Recursion can be used to break a complex function into smaller problems. 2. Recursion is more efficient at creating sequences than any nested iteration. 3. Recursive functions make the code appear straightforward and efficient.
Disadvantages of using Recursion
1. Recursive consume a lot of memory and time. 2. Debugging recursive functions can be difficult.
Recursion in Python Class 12
How recursion works in python
The function is called repeatedly through recursion from within the function. The repeated calls to the function are carried out by the recursive condition up until the base case is satisfied.
Factorial of a Number Using Recursion
def factorial(x): if x==1: return 1 else: return x*factorial(x-1) f=factorial(5) print (“factorial of 5 is “,f)
Output factorial of 5 is 120
Fibonacci numbers Using Recursion
def fibonacci(n): if n <= 1: return n else: return(fibonacci(n-1) + fibonacci(n-2)) n = int(input(“enter a number”)) if n <= 0: print(“Enter a positive Number”) else: print(“Fibonacci sequence:”) for i in range(n): print(fibonacci(i))
Output enter a number10 Fibonacci sequence: 0 1 1 2 3 5 8 13 21 34
Recursion in Python Class 12
Binary Search Using Recursion
def b_Search (arr, first, last, x): if last >= first: mid =int( first + (last – first)/2) if arr[mid] == x: return mid elif arr[mid] > x: return b_Search(arr, first, mid-1, x) else: return b_Search(arr, mid+1, last, x) else: return -1 arr = [ 1,3,5,6,7,8,10,13,14 ] x = 10 result = b_Search(arr, 0, len(arr)-1, x) if result != -1: print (“Position of the Element is %d” % result) else: print (“Element not found”)
Teachers and Examiners (CBSESkillEduction) collaborated to create the File Handling in Python Class 12 Notes. All the important Information are taken from the NCERT Textbook Computer Science (083) class 12.
File Handling in Python Class 12 Notes
File Handling in Python
File handling is the process of saving data in a Python programme in the form of outputs or inputs, The python file can be store in the form of binary file or a text file. There are six different types of modes are available in Python programming language.
1. r – read an existing file by opening it. 2. w – initiate a write operation by opening an existing file. If the file already has some data in it, it will be overwritten; if it doesn’t exist, it will be created. 3. a – Open a current file to do an add operation. Existing data won’t be replaced by it. 4. r+ – Read and write data to and from the file. It will replace any prior data in the file. 5. w+ – To write and read data, use w+. It will replace current data. 6. a+ – Read and add data to and from the file. Existing data won’t be replaced by it.
File Handling in Python Class 12 Notes
In Python, File Handling consists of following three steps
Open the file
Read and Write operation
Close the file
Opening and Closing file in Python
The file must first be opened before any reading, writing, or editing operations may be carried out. It must first be opened in order to create any new files. The file needs to be closed after we are finished using it. If we forgot to close the File, Python automatically closes files when a programme finishes or a file object is no longer referenced in a programme.
Example open() close()
File Handling in Python Class 12 Notes
Create a file using write() mode in Python
The write() mode is used to creating or manipulating file in Python.
Example # Create a file in python file = open(‘example.txt’,’w’) file.write(“I am Python learner”) file.write(“Welcome to my School”) file.close()
Read a file using read() mode in Python
You can read the data from binary or text file in Python using read() mode.
Example file = open(‘example.txt’, ‘r’) print (file.read())
Write a file using append() mode in Python
You can add multiple line of data in the file using append() mode in Python.
Example file = open(‘example.txt’, ‘a’) file.write(“The text will added in exicesiting file”) file.close()
File Handling in Python Class 12 Notes
Write a file using with() function mode in Python
You can also write the file using the with() mode in Python.
Example with open(“example.txt”, “w”) as f: f.write(“Welcome to my School”)
Split lines in a file using split() mode in Python
You can also split lines using file handling in Python.
Example with open(“example.text”, “r”) as file: data = file.readlines() for line in data: word = line.split() print (word)
File Handling in Python Class 12 Notes
Flush() function in File
When you write onto a file using any of the write functions, Python holds everthing to write in the file in buffer and pushes it onto actual file on storage device a leter time. If however, you want ot foce Python to write the contents of buffer onto storage, you can use flush() function. Python automatically flushes the files when closing them.
Example f = open(‘example.text’, ‘w+’) f.write(‘Welcome to my School’) f.flush()
File Handling in Python Class 12 Notes
Difference between Text file and Binary file
Text File – A text file is one whose contents may be examined using a text editor. Simply put, a text file is a collection of ASCII or Unicode characters. Text files include things like Python programmes and content created in text editors.
Binary File – A binary file is one whose content is stored in the form of binary, which consists of a series of bytes, each of which is eight bits long. Word documents, MP3 files, picture files, and .exe files are a few example of binary files.
Teachers and Examiners (CBSESkillEduction) collaborated to create the Using Python Libraries Class 12 Notes. All the important Information are taken from the NCERT Textbook Computer Science (083) class 12.
Using Python Libraries Class 12 Notes
Python Library
Python library is a collection of codes or modules of codes that may be used by a programme to do particular activities. We use libraries to avoid having to rewrite code that is already present in our programme.
Python standard library
Pandas
Numpy
SciPy
Scrapy
Matplotlib
TensorFlow
Example # Importing math library import math
num = 32 print(math.sqrt(num))
Using Python Libraries Class 12 Notes
Python Modules
A file containing definitions and statements in Python is known as a module. Functions, classes, and variables can all be defined using modules. Runnable code might also be a part of a module. The code is simpler to comprehend and utilise when similar code is gathered into a module. It also organises the code logically.
Example # Creating simple code of Module in python def addition(a, b): return (a+b)
def subtraction(a, b): return (a-b)
Importing Module in Python
Example import calc
print(calc.add(22, 2))
Advantage of module
It reduces the complexity of the program
You can create well defined program in python
You can use same program many times
Using Python Libraries Class 12 Notes
Importing Modules
A programme can import modules using the import statement in Python. There are two ways to use the import statement.
Use the import <module> command is used to import a full module.
The from “module” import “object” command can be used to import specific objects from a module.
Importing Entire Module in Python
The appropriate module name must be used along with the import keyword. The import statement causes the interpreter to add the module to the current programme when it encounters one. By adding the dot (.) operator to the module name, you can call the functions contained within a module.
Example import math n = 25 print(math.sqrt(n))
Importing Selected Objects in Python
You can also import single or multiple objects in python using the following syntax –
from <module name> import <object name1>, <object name2>, <object name3>
Using Python Libraries Class 12 Notes
Mathematical and String Function
1. oct(<integer>) – Returns octal string for given number.
Example x = oct(32) print(x)
Output 0o40
2. hex(<integer>) – Returns hex string for given number.
Example x = hex(32) print(x)
Output 0x20
3. int(<number) – Truncates the fractional part of given number and returns only the integer or whole part.
Example x = int(32.6) print(x)
Output 32
4. round(<number>, [<ndigits>]) – Returns number rounded to ndigits after the decimal points. If ndigits is not given, it returns nearest integer to its input.
Example x = round(7.3554, 2) print(x)
Output 7.36
5. <Str>.join(<String iterable>) – Joins a string or character after each memeber of the string iterator.
Example myTuple = (“Amit”, “Rakesh”, “Rajesh”) x = “#”.join(myTuple) print(x)
Output Amit#Rakesh#Rajesh
6. <Str>.split(<string / char>) – Splits a string based on given string or character and returns a list containing split strings are members.
Example str = “welcome to my School” x = str.split() print(x)
Output [‘welcome’, ‘to’, ‘my’, ‘School’]
Using Python Libraries Class 12 Notes
7. <Str>.replace(<word to be replaced>, <replace word>) – Replaces a word or part of the string with another in the given string <str>.
Example str = “welcome to my School” x = str.replace(“School”, “Home”) print(x)
Output welcome to my Home
8. random() – It returns a random floating point number N in the range [0.0, 1.0]
Example import random myList = [1, 2, 3, 4, 5] print(random.choice(myList))
9. randint(a,b) – It returns a random integer N in the range (a,b).
Example import random print(random.randint(3, 9))
Disclaimer – 100% of the information are taken from the Computer Science textbook written by Sumita Arora, and our team has tried to collect all the correct Notes from the textbook. If you found any suggestion or any error please contact us anuraganand2017@gmail.com.