CBSE Class 12 Computer Science
Chapters: 3
1. Computational Thinking and Programming - 2
Revision of Python · Functions · Exception handling · File handling · Stack
- Python Revision for Class 12: Everything from Class 11 in One Place – Class 12 builds on Class 11 Python. You must know tokens (keywords, identifiers, literals, operators, punctuators), data types (int, float, bool, str, list, tuple, dict), which types are mutable (can change in place) and which are immutable, operator precedence, if-elif-else, for and while loops with break and continue, string slicing, and the main methods of lists, tuples and dictionaries.
- Functions in Python: Build Your Own Machines – A function is a named block of code that does one job. Python has built-in functions (print, len), functions inside modules (math.sqrt, random.randint) and user-defined functions you write with def. Values sent in a call are arguments; the names that receive them are parameters. Arguments can be positional, keyword or use default values. return sends a value back. Python runs code top to bottom, jumps into a function when it is called and comes back after it. Names made inside a function are local; names made outside are global.
- Exception Handling in Python: Catch the Error, Keep the Program Alive – A syntax error stops a program before it runs. An exception is an error that happens while it runs, such as dividing by zero or opening a missing file. Without handling, the program crashes. With try and except, Python catches the exception and runs your rescue code instead. else runs when no exception happened; finally runs every time, error or not. raise lets you throw an exception yourself.
- File Handling in Python: Save Data That Lasts – Variables vanish when a program ends; files keep data on the disk. A text file stores characters in lines, a binary file stores raw bytes (such as pickled Python objects), and a CSV file stores table rows with commas. You open a file with open(path, mode), using an absolute or relative path and a mode such as r, w, a, r+, rb or wb. The with statement closes the file for you. Text files use write, writelines, read, readline and readlines. seek moves the file pointer and tell reports where it is. pickle.dump and pickle.load save and load objects in binary files, letting you search, append and update records. The csv module's writer (writerow, writerows) and reader handle CSV files.
- Stack in Python: Last In, First Out – A stack is a data structure where items are added and removed from one end only, called the top. It follows LIFO: last in, first out. Adding is push; removing is pop; looking at the top without removing is peek. Popping an empty stack is underflow; pushing into a full fixed-size stack is overflow. In Python a list works as a stack: append() pushes onto the end (the top) and pop() removes from the end.
2. Computer Networks
Evolution and data communication · Transmission media and devices · Topologies, network types and protocols · Web services
- Computer Networks and How the Internet Works – A network is a group of devices linked to share data. Each device has an IP address. Data is cut into numbered packets. Routers pass each packet hop by hop towards its address, and TCP puts the packets back in order. DNS turns a website name into an IP address. Clients ask, servers answer. Firewalls, passwords, updates and encryption keep a network safe.
- How Networks Grew and How Data Travels – A computer network is a group of connected devices that share data. Networking began with ARPANET (1969), grew into NSFNET (1980s) for universities, and joined with other networks to become the Internet, a network of networks. Every data communication has five parts: sender, receiver, message, communication media and protocol. Bandwidth is the range of frequencies a channel can carry (in Hz); data rate is how many bits travel per second (bps). Every device on a network has an IP address. Data can move by circuit switching (a fixed path is booked first) or packet switching (data is cut into packets that travel on their own).
- Transmission Media and Network Devices: The Roads and the Traffic Police – Transmission media are the paths that carry signals. Wired (guided) media are twisted pair cable, coaxial cable and optical fibre. Wireless (unguided) media are radio waves, microwaves and infrared. Network devices connect and direct data: a modem changes digital data to analog and back; an Ethernet card (NIC) and RJ45 connector join a computer to a cable; a Wi-Fi card joins it without wires; a repeater boosts a weak signal; a hub sends data to every port; a switch sends it only to the right port; a router sends packets between different networks; a gateway joins networks that use different protocols.
- Network Types, Topologies and Protocols: Size, Shape and Rules – Networks are grouped by size: PAN (a few metres around one person), LAN (a room, building or campus), MAN (a city) and WAN (a country or the world). A topology is the layout of how nodes are wired: bus (all on one backbone cable), star (all to a central hub or switch) and tree (stars joined in levels). A protocol is a set of rules: TCP/IP breaks and routes data on the Internet, HTTP and HTTPS carry web pages, FTP moves files, SMTP sends email, POP3 downloads email, PPP links two devices directly, TELNET logs into a remote computer, and VoIP carries voice calls over the Internet.
- Web Services: What Happens When You Open a Website – The World Wide Web (WWW) is a system of linked web pages that live on the Internet and are reached with a browser. Web pages are written in HTML, which uses fixed tags to show content; XML uses tags you make yourself to store and carry data. Every website has a domain name, like example.org, which DNS turns into an IP address. A URL is the full address of one resource: protocol, domain and path. A website is a set of related web pages. A web browser asks for pages and shows them; a web server stores them and sends them; web hosting is renting space on such a server so your site is online all the time.
3. Database Management
Database concepts and relational model · SQL · Python-SQL interface
- Relational Databases: Tables, Rows, Columns and Keys – Keeping data in many separate files leads to repeated data, mismatched copies and hard searching, so we use a database managed by a DBMS. In the relational model data sits in tables called relations. A column is an attribute, a row is a tuple, and the set of allowed values for a column is its domain. The number of columns is the degree; the number of rows is the cardinality. A candidate key is any column (or set) that can identify every row uniquely; the one chosen is the primary key and the others are alternate keys. A foreign key is a column in one table that refers to the primary key of another table, linking them.
- SQL for Class 12: Build Tables, Ask Questions, Join Tables – SQL is the language used to create and query relational databases. DDL commands (CREATE, ALTER, DROP) build structure; DML commands (INSERT, UPDATE, DELETE) change rows; SELECT reads data. Columns get data types (CHAR, VARCHAR, INT, FLOAT, DATE) and constraints (NOT NULL, UNIQUE, PRIMARY KEY, DEFAULT, FOREIGN KEY). SELECT can use aliases, DISTINCT, WHERE with relational and logical operators, IN, BETWEEN, LIKE and IS NULL, and ORDER BY. Aggregate functions (MAX, MIN, AVG, SUM, COUNT) summarise many rows; GROUP BY makes groups and HAVING filters groups. A Cartesian product pairs every row of one table with every row of another; an equi-join keeps only pairs whose common column matches; a natural join does the same and shows the common column once.
- Connecting Python to MySQL: Send SQL, Get Rows Back – Python can talk to a MySQL database using the mysql.connector module. connect() opens a connection with host, user, password and database. cursor() makes a cursor, the object that carries SQL to the database and brings results back. execute() runs one SQL statement. For INSERT, UPDATE and DELETE you must call commit() on the connection to save changes. For SELECT, fetchone() gives the next row as a tuple, fetchall() gives all remaining rows as a list of tuples, and rowcount tells how many rows were fetched or changed. Values are put into queries with %s placeholders (passing a tuple to execute) or with format().