Which of these is application software?
(a) Billing software Billing software is used by people for a particular job, so it is application software. The other options (operating system, device driver, utility) are system software.
Minimum Learning Support Material · CBSE 2026-27
Notes · Infographics · Labs · 1682 solved questions · Flashcards · Quiz · Practice Paper Maker
Theory 70 marks, 3 hours, 37 questions in five sections
| Section | Questions | Marks each | Total | What comes |
|---|---|---|---|---|
| A | Q1 to Q21 | 1 | 21 | MCQ and True/False on all units; Q20 and Q21 are Assertion-Reason |
| B | Q22 to Q28 | 2 | 14 | Computer system, emerging trends, Python, database, SQL |
| C | Q29 to Q32 | 3 | 12 | Python output and program, SQL commands, keys |
| D | Q33, Q34 | 4 | 8 | Computer system case, Python program |
| E | Q35 to Q37 | 5 | 15 | Long Python program, SQL outputs and SQL commands |
One common blueprint for all twenty practice papers. Each cell shows the number of questions, with their marks in brackets.
| Unit | Sec A1 mark each1 m | Sec B2 marks each2 m | Sec C3 marks each3 m | Sec D4 marks each4 m | Sec E5 marks each5 m | Totalmarks |
|---|---|---|---|---|---|---|
| Unit 1Introduction to Computer System | 4 (4) | 1 (2) | - | 1 (4) | - | 10 |
| Unit 2Introduction to Python | 6 (6) | 2 (4) | 2 (6) | 1 (4) | 1 (5) | 25 |
| Unit 3Database Concepts and SQL | 8 (8) | 3 (6) | 2 (6) | - | 2 (10) | 30 |
| Unit 4Introduction to Emerging Trends | 3 (3) | 1 (2) | - | - | - | 5 |
| Total | 21 (21) | 7 (14) | 4 (12) | 2 (8) | 3 (15) | 70 |
CBSE holds no board exam for Class XI and gives no Class XI sample paper. This design follows the CBSE Class XII Informatics Practices Sample Question Paper 2026-27 (37 questions, 70 marks, 3 hours), with the Class XI unit marks 10, 25, 30 and 5. Schools may set their own design.
Internal choice (OR) is given in Q24, Q25, Q26, Q28, Q29, Q30, Q32, Q34, Q35 and Q37.
Practical file: at least 14 Python programs and 14 SQL queries.
Where the 70 marks come from, easiest first
Unit 3 (database and SQL) carries 30 marks, the most of all. It is also the most scoring, because the questions follow a fixed pattern.
WHERE Phone = NULL is wrong; use IS NULL.input() gives a string: use int().L.sort() returns None.Evolution, parts, block diagram, input and output devices
A computer is an electronic device that takes data as input, processes it according to instructions, stores it and gives output.
In daily life: A school office: forms come in (input), the principal decides (CPU), files are kept in the almirah (memory), and the result is announced (output).
Tap each part.
Does: takes data and instructions from the user and converts them into a form the computer understands.
Devices: keyboard, mouse, scanner, microphone, webcam, OMR, MICR, barcode reader, biometric scanner.
Does: processes the data. It has the ALU, the control unit and registers.
Known as: the brain of the computer; a microprocessor is a CPU on one chip.
Does: arithmetic (+, -, ×, ÷) and logical work (comparisons).
Does: fetches, decodes and runs instructions; directs all the other units.
Does: holds the program and data being used; RAM, ROM, cache, registers.
Does: gives the result to the user.
Devices: monitor, printer, speaker, projector, plotter, 3D printer.
Data bus: carries data.
Address bus: carries memory addresses.
Control bus: carries control signals.
Input and output devices
| Input device | Use | Output device | Use |
|---|---|---|---|
| Keyboard | type text | Monitor | shows soft copy |
| Scanner | copies paper to image | Printer | gives hard copy |
| OMR | reads filled bubbles | Speaker | sound output |
| MICR | reads cheque numbers | Plotter | large drawings, maps |
| Barcode reader | reads product codes | Projector | shows on a big screen |
| Biometric scanner | fingerprint, face | 3D printer | makes solid objects |
Tap the right box.
Tap from the oldest to the newest.
Generations of computers
| Generation | Technology | Example | Feature |
|---|---|---|---|
| 1st (1940s-50s) | vacuum tubes | ENIAC, UNIVAC | huge, hot, costly |
| 2nd (1950s-60s) | transistors | IBM 1401 | smaller, faster |
| 3rd (1960s-70s) | integrated circuits | IBM 360 | keyboards and monitors |
| 4th (1970s-now) | microprocessors | PCs, laptops | small, cheap, personal |
| 5th (now) | AI, parallel processing | smart assistants | learning machines |
Input: water, milk, tea leaves, sugar · Processing: boiling on the stove (CPU) as per the recipe (program) · Memory: the recipe you remember · Output: a cup of tea.
Tap a device.
Reads: pencil or pen marks in bubbles.
Where: answer sheets of NEET, JEE, school tests.
Reads: numbers printed with magnetic ink.
Where: the bottom line of a bank cheque.
Reads: printed text from an image and makes it editable.
Where: scanning a book page into a Word file.
Reads: black-and-white bar or square codes.
Where: shop billing, UPI payments.
Reads: fingerprint, face or iris.
Where: Aadhaar, school attendance, phone unlock.
Remember the order: vacuum tube → transistor → IC → microprocessor. Each made computers smaller, faster and cheaper.
The CPU is not the cabinet (box). The CPU is the chip inside it.
Units, primary and secondary memory, deletion, recovery, security
Memory stores data and instructions. The smallest unit is a bit (0 or 1).
Type a value and choose units.
| Primary memory | Secondary memory | |
|---|---|---|
| Accessed by CPU | directly | through primary memory |
| Speed | fast | slower |
| Cost per GB | high | low |
| Size | small (GB) | large (TB) |
| Volatile? | RAM yes, ROM no | no |
Worked conversions
1) 5 GB to MB : 5 x 1024 = 5120 MB
2) 3072 KB to MB : 3072 / 1024 = 3 MB
3) 2 bytes to bits : 2 x 8 = 16 bits
4) 1 TB to KB : 1 x 1024 x 1024 x 1024 = 1073741824 KB
Rule: big unit to small unit -> multiply
small unit to big unit -> divide How big is it? Easy examples
| Size | About as much as |
|---|---|
| 1 byte | one letter, such as A |
| 1 KB | a short paragraph |
| 1 MB | a small book or a photo |
| 1 GB | a full-length movie (low quality) |
| 1 TB | about 2.5 lakh photos |
| HDD | SSD | Pen drive | |
|---|---|---|---|
| Works by | spinning magnetic disk | flash chips | flash chips |
| Speed | slower | very fast | medium |
| Moving parts | yes | no | no |
| Use | cheap large storage | fast laptops | carrying files |
Deleting a file is like tearing the index page of a notebook: the page with the writing is still there until someone writes over it.
Formatting or deleting is not enough before selling a phone. Use encryption and a secure wipe.
System and application, generic and specific, translators, OS
Software is a set of programs that tells the hardware what to do.
Language translators
| Assembler | Compiler | Interpreter | |
|---|---|---|---|
| From | assembly language | high-level, whole program | high-level, line by line |
| Errors | - | all listed together | stops at the first error |
| Example | NASM | C, C++ | Python |
Tap the type.
A mobile phone body, screen and battery are hardware. Android and the WhatsApp app are software. Without software, the hardware cannot do anything; without hardware, software has nothing to run on.
| Software | Type | Why |
|---|---|---|
| Windows 11 | System (OS) | runs the computer |
| Printer driver | System (driver) | lets the OS use the printer |
| Antivirus | System (utility) | protects the computer |
| Python interpreter | System (translator) | runs Python programs |
| LibreOffice Writer | Application, general purpose | anyone can type letters |
| School fee software | Application, specific purpose | made for one school |
Tap in order.
Modes, tokens, data types, operators, I/O, errors
Python is a free, open-source, high-level, interpreted language. It is easy to read, case sensitive and runs on all platforms.
>>>, see the result at once; not savedTokens: the smallest units
| Token | Meaning | Examples |
|---|---|---|
| Keyword | reserved word | if, else, for, while, True, False, None, and |
| Identifier | name given by the user | marks, total_1, Name |
| Literal | fixed value | 25, 3.5, 'KV', True, None |
| Operator | does an operation | + - * / // % ** == and in |
| Punctuator | separates parts | ( ) [ ] { } , : ' # |
| Mutable | Immutable | |
|---|---|---|
| Meaning | can be changed in place | cannot be changed; a change makes a new object |
| Types | list, dict | int, float, complex, bool, str |
Variables, l-value and r-value
x = 10 # x is the l-value, 10 is the r-value y = x * 2 + 1 # r-value is worked out first x, y = y, x # swap print(x, y)
Output
21 10
| Kind | Operators | Example | Result |
|---|---|---|---|
| Arithmetic | + - * / // % ** | 17 // 5, 17 % 5, 2 ** 3 | 3, 2, 8 |
| Relational | == != > < >= <= | 7 != 4 | True |
| Logical | and or not | 5 > 3 and 2 > 4 | False |
| Assignment | = | x = 5 | x gets 5 |
| Augmented | += -= *= /= //= %= **= | x += 2 | x = x + 2 |
| Identity | is, is not | a is b | same object? |
| Membership | in, not in | 3 in [1, 3] | True |
print(15 + 4 * 3 // 2 - 2 ** 3) print(7 / 2, 7 // 2, 7 % 2) print(10 > 5 and not 3 == 3)
Output
13 3.5 3 1 False
Input, output and type conversion
name = input('Name: ')
age = int(input('Age: '))
print('Hello', name)
print('Next year you will be', age + 1)
print('A', 'B', 'C', sep='-', end='.\n')Output
Name: Riya Age: 16 Hello Riya Next year you will be 17 A-B-C.
| Implicit conversion | Explicit conversion | |
|---|---|---|
| Done by | Python itself | the programmer |
| Example | 5 + 2.5 gives 7.5 (int to float) | int('25'), float(7), str(10) |
| Error | When | Example |
|---|---|---|
| Syntax error | grammar is wrong; found before running | if x > 5 print(x) (no colon) |
| Logical error | runs but gives a wrong answer | avg = a + b / 2 |
| Runtime error | while running | 10 / 0 (ZeroDivisionError), int("ten") (ValueError) |
Tap the box.
Easy example: a variable is a labelled box
The name is the label; the value is what is kept inside. marks = 78 puts 78 in the box named marks.
Worked example: precedence step by step
print(15 + 4 * 3 // 2 - 2 ** 3) Step 1: 2 ** 3 = 8 Step 2: 4 * 3 = 12 Step 3: 12 // 2 = 6 Step 4: 15 + 6 = 21 Step 5: 21 - 8 = 13 -> output 13
a = 7 b = 2 print(a + b, a - b, a * b) print(a / b, a // b, a % b, a ** b) print(a > b, a == b, a != b) print(a > 5 and b > 5, a > 5 or b > 5, not a > 5)
Output
9 5 14 3.5 3 1 49 True False True False True False
Identity and membership
L = [1, 2, 3] M = L N = [1, 2, 3] print(M is L, N is L, N == L) print(2 in L, 5 not in L)
Output
True False True True True
Comments
# This is a single-line comment marks = 78 # comment after a statement ''' A multi-line string is often used as a long comment '''
if, if-else, if-elif-else, for, range, while
Python runs statements one after another (sequence), chooses with if (selection) and repeats with for and while (iteration). Blocks are marked by indentation.
marks = 72
if marks >= 80:
print('A')
elif marks >= 60:
print('B')
else:
print('C')for i in range(1, 6):
print(i * i, end=' ')Change start, stop and step.
while loop: sum of digits of 4728
n = 4728
s = 0
while n > 0:
s = s + n % 10
n = n // 10
print(s)Output
21
| n | n % 10 | s | n // 10 |
|---|---|---|---|
| 4728 | 8 | 8 | 472 |
| 472 | 2 | 10 | 47 |
| 47 | 7 | 17 | 4 |
| 4 | 4 | 21 | 0 |
| for | while | |
|---|---|---|
| Use | number of rounds known | repeat while a condition is True |
| Example | for i in range(5): | while n > 0: |
| Risk | - | infinite loop if the condition never becomes False |
range(a, b) gives a, a+1, ... b-1. It runs b - a times.
Forgetting the colon or the indentation is the most common syntax error.
Easy examples
| Real life | Python idea |
|---|---|
| If it rains, take an umbrella, else wear sunglasses | if ... else |
| Do 10 push-ups | for i in range(10): |
| Keep filling the bottle until it is full | while not full: |
| Traffic light: red, yellow or green | if ... elif ... else |
Worked programs
total = 0
for i in range(1, 6):
total = total + i
print('i =', i, 'total =', total)Output
i = 1 total = 1 i = 2 total = 3 i = 3 total = 6 i = 4 total = 10 i = 5 total = 15
n = 5
fact = 1
while n > 1:
fact = fact * n
n = n - 1
print('5! =', fact)Output
5! = 120
Operations, traversing, methods, built-in functions
A list is an ordered, mutable collection in [ ]: L = [10, 'KV', 3.5].
L[0] is 10, L[-1] is 50, L[1:4] is [20, 30, 40].
| Operation | Example | Result |
|---|---|---|
| Concatenation | [1, 2] + [3] | [1, 2, 3] |
| Repetition | [0] * 3 | [0, 0, 0] |
| Membership | 3 in [1, 3] | True |
| Slicing | [5, 6, 7, 8][1:3] | [6, 7] |
| Traversing | for x in L: print(x) | each element |
Type a value, tap a method, watch the list change.
| Method / function | Does | Example (L = [30, 10, 20]) |
|---|---|---|
| len(L) | number of elements | 3 |
| list(x) | makes a list | list('ab') gives ['a', 'b'] |
| L.append(x) | adds x at the end | [30, 10, 20, 5] |
| L.insert(i, x) | adds x at index i | L.insert(1, 5) gives [30, 5, 10, 20] |
| L.extend(L2) | adds all of L2 | [30, 10, 20, 1, 2] |
| L.count(x) | how many times x occurs | L.count(10) gives 1 |
| L.index(x) | position of x | L.index(20) gives 2 |
| L.remove(x) | deletes the first x | [30, 20] |
| L.pop(i) | deletes and returns | L.pop() gives 20 |
| L.reverse() | reverses in place | [20, 10, 30] |
| L.sort() | sorts in place | [10, 20, 30] |
| sorted(L) | new sorted list | [10, 20, 30] |
| min, max, sum | smallest, largest, total | 10, 30, 60 |
Suggested practical: third largest and third smallest
L = [34, 7, 91, 15, 62, 48, 23]
L.sort()
print('Third smallest:', L[2])
print('Third largest:', L[-3])Output
Third smallest: 23 Third largest: 48
Easy example: a list is like a train
Each coach has a number starting from 0. You can add (append), insert, or remove coaches: a list is mutable.
Changing a list step by step
L = [30, 10, 20] L.append(40) print(L) L.insert(1, 15) print(L) L.remove(10) print(L) x = L.pop() print(x, L) L.sort() print(L) L.reverse() print(L)
Output
[30, 10, 20, 40] [30, 15, 10, 20, 40] [30, 15, 20, 40] 40 [30, 15, 20] [15, 20, 30] [30, 20, 15]
Traversal in two ways
marks = [56, 78, 91]
for m in marks:
print(m, end=' ')
print()
for i in range(len(marks)):
print(i, marks[i])Output
56 78 91 0 56 1 78 2 91
Key-value pairs, creating, traversing, updating, deleting, methods
A dictionary stores key: value pairs in { }. Keys are unique and immutable; values can be anything. It is mutable.
marks = {'Amit': 85, 'Bela': 92, 'Charu': 78}
key → value. Keys are unique; marks['Bela'] gives 92.
D = {'Amit': 85, 'Bela': 92}. Add, change, get or delete.
| Method / function | Does | Example (D = {"a": 1, "b": 2}) |
|---|---|---|
| dict() | makes a dictionary | dict(a=1) gives {"a": 1} |
| len(D) | number of pairs | 2 |
| D[k] = v | adds or updates | D["c"] = 3 |
| del D[k] | deletes a pair | del D["a"] |
| D.get(k) | value, or None if absent | D.get("z") gives None |
| D.keys() | all keys | dict_keys(["a", "b"]) |
| D.values() | all values | dict_values([1, 2]) |
| D.items() | all pairs | dict_items([("a", 1), ("b", 2)]) |
| D.update(E) | adds / changes pairs of E | D.update({"b": 5}) |
| D.clear() | removes all pairs | {} |
Traversing a dictionary
capitals = {'Kerala': 'Thiruvananthapuram', 'Bihar': 'Patna', 'Goa': 'Panaji'}
for state in capitals:
print(state, '->', capitals[state])
print(len(capitals))Output
Kerala -> Thiruvananthapuram Bihar -> Patna Goa -> Panaji 3
Highest and lowest value in a dictionary
marks = {'Anu': 78, 'Ben': 92, 'Charu': 64}
hi = max(marks, key=marks.get)
lo = min(marks, key=marks.get)
print(hi, marks[hi])
print(lo, marks[lo])Output
Ben 92 Charu 64
Easy example: a dictionary is like a phone book
You look up a name (key) to get the number (value). Two contacts cannot have the same name.
Changing a dictionary step by step
D = {'pen': 20, 'book': 120}
D['bag'] = 650 # add
print(D)
D['pen'] = 25 # update
print(D)
del D['book'] # delete
print(D, len(D))
print(D.get('book'), D.get('book', 0))Output
{'pen': 20, 'book': 120, 'bag': 650}
{'pen': 25, 'book': 120, 'bag': 650}
{'pen': 25, 'bag': 650} 2
None 0 Suggested practical: names and marks in five subjects
R = {'Asha': [78, 85, 90, 72, 88], 'Ravi': [65, 70, 58, 80, 75]}
for name in R:
print(name, 'Total:', sum(R[name]), 'Average:', sum(R[name]) / 5)Output
Asha Total: 413 Average: 82.6 Ravi Total: 348 Average: 69.6
Arrays from lists, ndim, shape, size, dtype
NumPy (Numerical Python) is a library for fast work with arrays. An array holds elements of one type.
import numpy as np a = np.array([12, 45, 7, 30]) # 1-D array from a list b = np.array([[1, 2, 3], [4, 5, 6]]) # 2-D array from a nested list
1-D array: np.array([12, 45, 7, 30])
ndim 1 · shape (4,) · size 4
2-D array: np.array([[1, 2, 3], [4, 5, 6]])
ndim 2 · shape (2, 3): 2 rows, 3 columns · size 6
import numpy as np a = np.array([12, 45, 7, 30]) b = np.array([[1, 2, 3], [4, 5, 6]]) print(a.ndim, a.shape, a.size, a.dtype) print(b.ndim, b.shape, b.size) print(a * 2) print(b[1][2], b[0, 1])
Output
1 (4,) 4 int64 2 (2, 3) 6 [24 90 14 60] 6 2
Type a list or a nested list (rows of equal length). See ndim, shape and size.
| Python list | NumPy array | |
|---|---|---|
| Types | mixed allowed | one type only |
| + | joins: [1, 2] + [3, 4] = [1, 2, 3, 4] | adds: [4 6] |
| * 2 | repeats the list | doubles each element |
| Speed and memory | slower, more memory | faster, less memory |
Remember: ndim = number of dimensions, shape = (rows, columns), size = total elements, dtype = type of the elements.
Print shows arrays without commas: [2 4 6], not [2, 4, 6].
Picture: element-by-element work
With lists, [10, 20, 30] + [1, 2, 3] would join them into 6 elements.
import numpy as np price = np.array([100, 250, 80]) qty = np.array([2, 1, 5]) print(price * qty) print((price * qty).sum())
Output
[200 250 400] 850
Easy example
A shopkeeper has prices and quantities of three items. With NumPy, one line price * qty gives the amount for every item at once, without a loop.
DBMS, relational model, degree, cardinality, keys
A database is an organised collection of related data. A DBMS (such as MySQL) is software to create and manage it.
| Term | Meaning | In the picture |
|---|---|---|
| Relation | a table | STUDENT |
| Attribute | a column | RollNo, Name, Section, Marks |
| Tuple | a row | (2, Bhavya, B, 92) |
| Degree | number of attributes | 4 |
| Cardinality | number of tuples | 3 |
| Domain | set of allowed values | Section: {A, B, C} |
| Key | Meaning | Example |
|---|---|---|
| Candidate key | can uniquely identify each row | RollNo, AdmNo |
| Primary key | the candidate key chosen; no NULL, no repeats | RollNo |
| Alternate key | candidate key not chosen | AdmNo |
Tap the term that changes.
In a school without a DBMS, the office, the library and the sports room each keep a separate register with the address of every student. When a student shifts house, one register is corrected and the others are not: this is redundancy causing inconsistency. A database keeps the address once and everyone uses it.
Find the keys yourself
| AdmNo | RollNo | Name | Aadhaar | City |
|---|---|---|---|---|
| 4501 | 1 | Aarav | 1111 2222 3333 | Delhi |
| 4512 | 2 | Bhavya | 4444 5555 6666 | Delhi |
| 4523 | 3 | Aarav | 7777 8888 9999 | Pune |
Candidate keys: AdmNo, RollNo, Aadhaar (all unique). Name and City repeat, so they cannot be keys. If AdmNo is the primary key, RollNo and Aadhaar are alternate keys. Degree 5, cardinality 3.
Data types, constraints, DDL, DML, SELECT with WHERE
SQL (Structured Query Language) is used to create and work with relational databases. MySQL is a free, open-source DBMS that uses SQL.
Data Definition Language
defines the structure
CREATE DATABASE / TABLEALTER TABLE (add, drop column / primary key)DROP TABLE / DATABASEData Manipulation Language
changes the data
INSERT INTO ... VALUESUPDATE ... SET ... WHEREDELETE FROM ... WHEREData Query Language
reads the data
SELECT ... FROM ... WHEREwith relational and logical operatorsBETWEEN, IS NULL, IS NOT NULLData types and constraints
| Data type | Stores | Example |
|---|---|---|
| INT | whole numbers | 45 |
| FLOAT / DECIMAL(8,2) | numbers with decimals | 45.75 |
| CHAR(n) | fixed-length text | CHAR(1): 'A' |
| VARCHAR(n) | variable-length text | VARCHAR(25): 'Bhavya' |
| DATE | date as 'YYYY-MM-DD' | '2009-11-30' |
| Constraint | Rule |
|---|---|
| NOT NULL | a value must be given |
| UNIQUE | no two rows have the same value |
| PRIMARY KEY | NOT NULL + UNIQUE; identifies each row |
DDL: creating and changing the structure
CREATE DATABASE SCHOOL;
SHOW DATABASES;
USE SCHOOL;
CREATE TABLE STUDENT (
RollNo INT PRIMARY KEY,
Name VARCHAR(25) NOT NULL,
Section CHAR(1),
DOB DATE,
Marks INT
);
SHOW TABLES;
DESCRIBE STUDENT;
ALTER TABLE STUDENT ADD Phone VARCHAR(10);
ALTER TABLE STUDENT DROP Phone;
ALTER TABLE STUDENT DROP PRIMARY KEY;
ALTER TABLE STUDENT ADD PRIMARY KEY (RollNo);
DROP TABLE STUDENT;
DROP DATABASE SCHOOL; DML: changing the data
INSERT INTO STUDENT VALUES (8, 'Harsh', 'B', '2009-05-14', 81); INSERT INTO STUDENT (RollNo, Name) VALUES (9, 'Isha'); UPDATE STUDENT SET Marks = Marks + 5 WHERE Section = 'C'; DELETE FROM STUDENT WHERE Marks < 33;
SELECT Name, Markswhich columnsFROM STUDENTwhich tableWHERE Marks BETWEEN 60 AND 80which rows; end of the statementTable: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name, Marks FROM STUDENT WHERE Marks > 70;
| Name | Marks |
|---|---|
| Aarav | 78 |
| Bhavya | 92 |
| Eshan | 88 |
Explanation: WHERE keeps only the rows where Marks is more than 70: 3 of the 7 rows match (Aarav, Bhavya, Eshan). SELECT then shows only the columns Name, Marks.
SELECT * FROM STUDENT WHERE Section = 'A' AND Gender = 'F';
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
Explanation: WHERE keeps only the rows where Section is 'A' and Gender is 'F': 1 of the 7 rows matches (Farah). SELECT then shows all the columns (*).
SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
| Name | DOB |
|---|---|
| Bhavya | 2009-11-30 |
| Divya | 2009-07-21 |
| Farah | 2009-09-09 |
Explanation: WHERE keeps only the rows where DOB is from '2009-06-01' to '2009-12-31' (both included): 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, DOB.
SELECT Name FROM STUDENT WHERE Phone IS NULL;
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Phone is empty (NULL): 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
SELECT Name, Marks, Marks + 5 FROM STUDENT WHERE Section <> 'A' OR Marks >= 85;
| Name | Marks | Marks + 5 |
|---|---|---|
| Bhavya | 92 | 97 |
| Divya | 66 | 71 |
| Eshan | 88 | 93 |
| Gaurav | 59 | 64 |
Explanation: WHERE keeps only the rows where Section is not 'A' or Marks is at least 85: 4 of the 7 rows match (Bhavya, Divya, Eshan, Gaurav). SELECT then shows only the columns Name, Marks, Marks + 5.
Build a query on the STUDENT table above and see its result at once.
Text and dates go in single quotes; numbers do not. BETWEEN a AND b includes both a and b.
= NULL never matches. Use IS NULL / IS NOT NULL.
Tap the family of the command.
UPDATE STUDENT SET Marks = Marks + 5 WHERE Section = 'A';
Before
| RollNo | Name | Section | Marks | Phone |
|---|---|---|---|---|
| 1 | Aarav | A | 78 | 98100 |
| 2 | Bhavya | B | 92 | NULL |
| 3 | Chirag | A | 45 | 98101 |
| 4 | Divya | C | 66 | 98102 |
After
| RollNo | Name | Section | Marks | Phone |
|---|---|---|---|---|
| 1 | Aarav | A | 83 | 98100 |
| 2 | Bhavya | B | 92 | NULL |
| 3 | Chirag | A | 50 | 98101 |
| 4 | Divya | C | 66 | 98102 |
DELETE FROM STUDENT WHERE Marks < 50;
Before
| RollNo | Name | Section | Marks | Phone |
|---|---|---|---|---|
| 1 | Aarav | A | 78 | 98100 |
| 2 | Bhavya | B | 92 | NULL |
| 3 | Chirag | A | 45 | 98101 |
| 4 | Divya | C | 66 | 98102 |
After
| RollNo | Name | Section | Marks | Phone |
|---|---|---|---|---|
| 1 | Aarav | A | 78 | 98100 |
| 2 | Bhavya | B | 92 | NULL |
| 4 | Divya | C | 66 | 98102 |
INSERT INTO STUDENT VALUES (5, 'Esha', 'B', 81, NULL);
Before
| RollNo | Name | Section | Marks | Phone |
|---|---|---|---|---|
| 1 | Aarav | A | 78 | 98100 |
| 2 | Bhavya | B | 92 | NULL |
| 3 | Chirag | A | 45 | 98101 |
| 4 | Divya | C | 66 | 98102 |
After
| RollNo | Name | Section | Marks | Phone |
|---|---|---|---|---|
| 1 | Aarav | A | 78 | 98100 |
| 2 | Bhavya | B | 92 | NULL |
| 3 | Chirag | A | 45 | 98101 |
| 4 | Divya | C | 66 | 98102 |
| 5 | Esha | B | 81 | NULL |
ALTER TABLE STUDENT ADD Grade CHAR(1);
Before
| RollNo | Name | Section | Marks | Phone |
|---|---|---|---|---|
| 1 | Aarav | A | 78 | 98100 |
| 2 | Bhavya | B | 92 | NULL |
| 3 | Chirag | A | 45 | 98101 |
| 4 | Divya | C | 66 | 98102 |
After
| RollNo | Name | Section | Marks | Phone | Grade |
|---|---|---|---|---|---|
| 1 | Aarav | A | 78 | 98100 | NULL |
| 2 | Bhavya | B | 92 | NULL | NULL |
| 3 | Chirag | A | 45 | 98101 | NULL |
| 4 | Divya | C | 66 | 98102 | NULL |
Easy example: SQL in daily life
| You want to | SQL |
|---|---|
| see the students of Section A | SELECT * FROM STUDENT WHERE Section = 'A'; |
| give 5 grace marks to Section A | UPDATE STUDENT SET Marks = Marks + 5 WHERE Section = 'A'; |
| find who has not given a phone number | SELECT Name FROM STUDENT WHERE Phone IS NULL; |
| remove a student who left | DELETE FROM STUDENT WHERE RollNo = 4; |
AI, ML, NLP, AR, VR, robotics, Big Data, IoT, cloud, grid, blockchain
New technologies that are changing how we live and work.
Cloud computing: three service models
Going up the stack, the provider manages more and the user manages less.
Big Data: the five Vs
How IoT works
Blockchain
| Cloud computing | Grid computing | |
|---|---|---|
| Idea | services from a provider over the Internet | many computers share work on one task |
| Example | Google Drive, Gmail | scientific research projects |
| AR | VR | |
|---|---|---|
| World | real world + digital layer | fully computer-made |
| Device | phone camera, AR glasses | VR headset |
| Example | Pokemon Go, IKEA Place | VR games, flight training |
Tap the technology.
| Technology | Easy example from your life |
|---|---|
| AI | Google Maps finds the fastest route |
| ML | YouTube suggests videos you may like |
| NLP | typing by speaking (voice typing) |
| AR | trying spectacles on your face in an app |
| VR | a virtual tour of the Taj Mahal with a headset |
| Robotics | a robot vacuum cleaner |
| Big Data | crores of UPI payments analysed every day |
| IoT | a smart bulb switched on from the phone |
| Cloud | class notes saved on Google Drive |
| Grid | many labs sharing computers for weather study |
| Blockchain | records of cryptocurrency transactions |
Sensors around you
| Sensor | Where |
|---|---|
| Temperature | AC, refrigerator |
| Motion (PIR) | automatic lights, alarms |
| Light | auto-brightness of phones, street lights |
| Fingerprint | phone unlock, attendance |
| GPS | maps, cab apps |
| Smoke | fire alarms |
1682 questions in 22 types, in the order of the paper
Tap a type to open it. In Section A, tap an option to check yourself. Every Python output and sample run was produced by running the code; every SQL output by running the query.
Which of these is application software?
(a) Billing software Billing software is used by people for a particular job, so it is application software. The other options (operating system, device driver, utility) are system software.
Which of these is an output device?
(b) Monitor A projector shows the computer's output on a big screen.
Which of these is an input device?
(d) MICR A barcode reader sends the product code into the computer, so it is an input device.
Software that manages the hardware and gives a platform to other programs is
(a) an operating system The operating system manages the hardware and runs all other programs, e.g. Windows, Linux.
State True or False: Python uses an interpreter.
(a) True Python code is run line by line by the Python interpreter.
Which of these is an output device?
(b) Monitor A projector shows the computer's output on a big screen.
Which of these is an output device?
(b) Plotter A projector shows the computer's output on a big screen.
Which of these is an output device?
(b) Headphones A projector shows the computer's output on a big screen.
Which of these is an input device?
(d) OMR A barcode reader sends the product code into the computer, so it is an input device.
How many bits are there in 15 bytes?
(d) 120 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
The part of the CPU that does calculations and comparisons is the
(c) ALU The Arithmetic Logic Unit does arithmetic (+, -, *, /) and logical comparisons (>, <, ==).
Antivirus and disk cleanup are examples of
(d) utility software Utilities maintain and protect the computer; they are a kind of system software.
Which of these is an input device?
(d) Microphone A barcode reader sends the product code into the computer, so it is an input device.
Which of these is application software?
(a) Photo editor Photo editor is used by people for a particular job, so it is application software. The other options (operating system, device driver, utility) are system software.
How many GB are there in 4 TB?
(d) 4096 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which invention replaced vacuum tubes and made computers smaller?
(c) Transistor The transistor (1947) is small, cheap and cool, so second-generation computers became smaller and faster.
Which of these is free and open source software?
(d) LibreOffice LibreOffice is free and its source code is open; the others are proprietary.
Which of these is an output device?
(b) 3D printer A projector shows the computer's output on a big screen.
Which of these is an output device?
(b) Monitor A projector shows the computer's output on a big screen.
Which of these is an output device?
(b) Plotter A projector shows the computer's output on a big screen.
1 GB is equal to
(a) 1024 MB Each bigger unit is 1024 times the smaller: 1 GB = 1024 MB.
Which of these is an example of specific purpose software?
(b) Railway reservation software Railway reservation software is made only for the railways' own work.
Which of these is an input device?
(d) Graphics tablet A barcode reader sends the product code into the computer, so it is an input device.
Which of these is an input device?
(d) Barcode reader A barcode reader sends the product code into the computer, so it is an input device.
Which of these is system software?
(a) Antivirus A device driver helps the operating system use a device, so it is system software.
A device that reads the answer sheets of competitive exams is
(b) OMR (Optical Mark Reader) OMR reads the marks (filled bubbles) on special sheets, as in competitive exams.
Which of these is system software?
(a) Python interpreter A device driver helps the operating system use a device, so it is system software.
How many TB are there in 12 PB?
(a) 12288 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which of these is system software?
(a) Compiler A device driver helps the operating system use a device, so it is system software.
How many bytes are there in 15 KB?
(b) 15360 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
How many KB are there in 16 MB?
(d) 16384 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
The part of the CPU that controls the order of operations is the
(d) control unit The control unit fetches and decodes instructions and directs the other parts, like a traffic police officer.
How many bits are there in 4 nibbles?
(b) 16 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
An assembler translates
(c) assembly language into machine language An assembler converts assembly language (mnemonics like ADD, MOV) into machine code.
How many bytes are there in 6 KB?
(c) 6144 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which of these is non-volatile?
(a) ROM ROM keeps its contents even without power; it stores the start-up program.
The idea of storing a program in memory along with data is called the
(d) stored program concept (von Neumann architecture) John von Neumann suggested that the program and the data both be kept in memory; all modern computers follow it.
Which of these is an output device?
(b) Monitor A projector shows the computer's output on a big screen.
Which of these is application software?
(a) Word processor Word processor is used by people for a particular job, so it is application software. The other options (operating system, device driver, utility) are system software.
How many bytes are there in 12 KB?
(a) 12288 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which of these is an input device?
(d) Microphone A barcode reader sends the product code into the computer, so it is an input device.
Which of these is an input device?
(d) Barcode reader A barcode reader sends the product code into the computer, so it is an input device.
Which of these is an input device?
(d) Graphics tablet A barcode reader sends the product code into the computer, so it is an input device.
Which of these is an input device?
(d) Biometric scanner A barcode reader sends the product code into the computer, so it is an input device.
Which memory holds the BIOS / start-up program?
(b) ROM The BIOS (start-up program) is kept in ROM because ROM does not lose data without power.
State True or False: A deleted file is always lost for ever.
(b) False It can often be recovered until it is overwritten.
Which of these is an output device?
(b) Monitor A projector shows the computer's output on a big screen.
Which of these is system software?
(d) Device driver A device driver helps the operating system use a device, so it is system software.
Which law says that the number of transistors on a chip doubles about every two years?
(c) Moore's law Gordon Moore observed that the number of transistors on a chip doubles about every two years.
How many bits are there in 7 bytes?
(b) 56 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which of these is system software?
(a) Compiler A device driver helps the operating system use a device, so it is system software.
ENIAC was built using
(a) vacuum tubes ENIAC (1946) used about 18,000 vacuum tubes, filled a large room and used a lot of power.
Which of these is application software?
(a) Railway reservation software Railway reservation software is used by people for a particular job, so it is application software. The other options (operating system, device driver, utility) are system software.
How many bits are there in 2 bytes?
(c) 16 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which of these is an input device?
(d) OMR A barcode reader sends the product code into the computer, so it is an input device.
Which of these is an output device?
(b) Printer A projector shows the computer's output on a big screen.
Which memory loses its contents when the power is switched off?
(c) RAM RAM is volatile: its contents are lost when the power is switched off.
Which of these is an output device?
(b) Projector A projector shows the computer's output on a big screen.
Which of these is system software?
(a) Disk cleanup A device driver helps the operating system use a device, so it is system software.
The abacus was used mainly for
(a) counting and simple calculation It has beads on rods that are moved to count, add and subtract; it is the oldest calculating device.
The wires that carry data between the parts of a computer are called
(c) buses Buses (data, address and control bus) connect the CPU, memory and devices.
Which of these is an output device?
(b) Projector A projector shows the computer's output on a big screen.
A 3D printer is an example of
(a) an output device It takes a design from the computer and makes a solid object, so it gives output.
1 nibble is equal to
(b) 4 bits A nibble is half a byte, that is 4 bits.
Which of these is an output device?
(b) Headphones A projector shows the computer's output on a big screen.
When a file is deleted, the operating system usually
(d) marks its space as free; the data stays until it is overwritten Only the file's entry is removed and its space is marked free; the bits remain until new data is written there.
Which of these is an output device?
(b) Printer A projector shows the computer's output on a big screen.
How many GB are there in 11 TB?
(d) 11264 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which of these is an output device?
(b) Speaker A projector shows the computer's output on a big screen.
How many GB are there in 6 TB?
(a) 6144 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which of these is application software?
(a) Railway reservation software Railway reservation software is used by people for a particular job, so it is application software. The other options (operating system, device driver, utility) are system software.
Which of these is an output device?
(b) Plotter A projector shows the computer's output on a big screen.
The Intel 4004 (1971) was the first
(a) microprocessor Intel 4004, made in 1971, was the first microprocessor (a 4-bit CPU on one chip).
The operating system of most smartphones is
(c) Android or iOS Android (Google) and iOS (Apple) are mobile operating systems.
How many TB are there in 2 PB?
(b) 2048 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Software used to bring back deleted files is called
(d) data recovery software Data recovery software scans the disk for data that is marked free but not yet overwritten.
How many MB are there in 5 GB?
(c) 5120 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
How many GB are there in 9 TB?
(c) 9216 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which of these is an input device?
(d) Mouse A barcode reader sends the product code into the computer, so it is an input device.
Registers are
(c) the fastest memory, inside the CPU Registers are tiny storage places inside the CPU; they are the fastest memory.
Which memory is between the CPU and RAM and is very fast?
(d) Cache memory Cache keeps the most-used data close to the CPU so the CPU does not wait for slower RAM.
The Pascaline, made by Blaise Pascal, could
(b) add and subtract Pascal's machine (1642) used gears and wheels and could only add and subtract numbers.
Which of these is an output device?
(a) Projector A projector shows the computer's output on a big screen.
A word processor used by everyone is an example of
(b) general purpose (generic) software It is made for many users and common tasks, so it is general purpose software.
Which of these is application software?
(a) Railway reservation software Railway reservation software is used by people for a particular job, so it is application software. The other options (operating system, device driver, utility) are system software.
1 byte is equal to
(b) 8 bits 8 bits make 1 byte; one byte can store one English character.
Many transistors on one silicon chip is called an
(c) integrated circuit (IC) An integrated circuit puts thousands of transistors on one chip; it started the third generation.
Software made for a particular user or organisation, such as a school's fee system, is
(b) specific purpose (customised) software It is made to order for one organisation, so it is specific purpose (customised) software.
Which of these is application software?
(a) Spreadsheet Spreadsheet is used by people for a particular job, so it is application software. The other options (operating system, device driver, utility) are system software.
State True or False: Cache memory is faster than RAM.
(a) True Cache is made of fast SRAM and sits close to the CPU, so it is faster than RAM.
Which of these is system software?
(a) Compiler A device driver helps the operating system use a device, so it is system software.
How many bits are there in 14 bytes?
(c) 112 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which of these is an input device?
(d) Barcode reader A barcode reader sends the product code into the computer, so it is an input device.
Which of these is secondary storage?
(d) Hard disk drive A hard disk stores data permanently; cache, registers and RAM are primary memory.
Which of these is an input device?
(d) OMR A barcode reader sends the product code into the computer, so it is an input device.
How many bytes are there in 10 KB?
(c) 10240 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which of these is an input device?
(d) Graphics tablet A barcode reader sends the product code into the computer, so it is an input device.
How many bits are there in 10 nibbles?
(d) 40 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which of these is system software?
(a) Disk cleanup A device driver helps the operating system use a device, so it is system software.
How many bits are there in 13 bytes?
(a) 104 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which device converts text on paper into editable text?
(c) Scanner with OCR The scanner makes an image of the page; OCR software then recognises the characters as text.
State True or False: The microprocessor was invented before the transistor.
(b) False Transistor (1947) came before the IC and the microprocessor (1971).
Which of these is an output device?
(b) Monitor A projector shows the computer's output on a big screen.
Which of these is application software?
(a) Photo editor Photo editor is used by people for a particular job, so it is application software. The other options (operating system, device driver, utility) are system software.
A complete CPU on a single chip is a
(d) microprocessor A microprocessor has the ALU, control unit and registers on one chip; it made personal computers possible.
Deleted files from the hard disk first go to the
(c) Recycle Bin (Trash) In Windows a deleted file first goes to the Recycle Bin, from where it can be restored.
The device used by banks to read the numbers printed on cheques is
(d) MICR MICR reads the numbers printed in magnetic ink at the bottom of a cheque.
An SSD stores data on
(a) flash memory chips An SSD uses flash memory chips and has no moving parts, so it is faster than a hard disk.
Which of these is an input device?
(d) OMR A barcode reader sends the product code into the computer, so it is an input device.
Which of these is an output device?
(b) Speaker A projector shows the computer's output on a big screen.
Herman Hollerith's tabulating machine used
(b) punched cards Hollerith used punched cards to read and count the census data of the USA (1890).
A program that translates the whole high-level program at once is a
(d) compiler A compiler translates the whole program at once and reports all errors together.
Who designed the Analytical Engine, the first idea of a general-purpose computer?
(d) Charles Babbage Charles Babbage's Analytical Engine had input, a mill (processor), a store (memory) and output, like a modern computer; so he is called the father of the computer.
How many TB are there in 13 PB?
(c) 13312 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which of these is an output device?
(b) Plotter A projector shows the computer's output on a big screen.
Which of these is system software?
(a) Compiler A device driver helps the operating system use a device, so it is system software.
How many KB are there in 12 MB?
(c) 12288 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which is the largest unit?
(d) Petabyte Order: MB < GB < TB < PB, so the petabyte is the largest of these.
The three main parts of a computer system are
(c) input unit, CPU and output unit Data enters through the input unit, is processed by the CPU, and results leave through the output unit.
Software owned by a company whose source code is not shared is
(c) proprietary software Proprietary software is owned by a company; the user buys a licence but cannot see or change the code.
How many bits are there in 11 bytes?
(c) 88 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which of these is an output device?
(b) 3D printer A projector shows the computer's output on a big screen.
Which device works both as input and output?
(c) Touch screen A touch screen shows output and also takes our touch as input.
Which of these is an output device?
(b) Plotter A projector shows the computer's output on a big screen.
How many bytes are there in 3 KB?
(d) 3072 1 byte = 8 bits; each larger unit is 1024 times the smaller one.
Which of these is system software?
(a) Compiler A device driver helps the operating system use a device, so it is system software.
The best way to prevent misuse of data on an old hard disk before selling it is to
(c) securely wipe (shred) the data or physically destroy the disk Simple deletion can be undone; secure wiping overwrites the data, and destroying the disk makes recovery impossible.
Recovering deleted files is possible because
(b) the data stays on the disk until it is overwritten Since the data is not erased at once, recovery software can read it back if it has not been overwritten.
State True or False: A compiler shows all the errors of a program together.
(a) True The compiler checks the whole program first and lists all the errors together.
Which of these is an input device?
(d) Keyboard A barcode reader sends the product code into the computer, so it is an input device.
Which of these is an output device?
(b) 3D printer A projector shows the computer's output on a big screen.
Which of these is an output device?
(b) Speaker A projector shows the computer's output on a big screen.
Which of these is an input device?
(d) MICR A barcode reader sends the product code into the computer, so it is an input device.
A program that translates a high-level program line by line is an
(d) interpreter An interpreter translates and runs one line at a time and stops at the first error.
Which of these is an input device?
(d) Scanner A barcode reader sends the product code into the computer, so it is an input device.
What is the result of 9 % 4 ** 2?
(c) 9 4 ** 2 = 16 first; 9 % 16 = 9.
All the elements of a NumPy array must be of
(b) the same data type An array stores elements of one type; mixed values are converted to one type.
The number of dimensions of a NumPy array is given by
(a) ndim ndim gives the number of dimensions: 1 for a simple list, 2 for rows and columns.
Which method returns all the key-value pairs of a dictionary?
(d) items() D.items() gives (key, value) pairs.
Which operator is used for exponent (power)?
(a) ** 2 ** 3 gives 8; ^ is not power in Python.
input() always returns a value of type
(c) str input() returns a string; use int() or float() to get a number.
The default value of end in print() is
(b) a new line (\n) After printing, print() goes to a new line unless end is changed.
The value of 5 > 3 and 3 > 1 is
(c) True Both conditions are True, so and gives True.
Which method returns the value of a key, and None if the key is not present?
(d) get() D.get('x') returns None instead of giving KeyError.
The default separator (sep) in print() is
(d) a space print(1, 2) prints 1 2 with a space between.
bool(0) and bool('') give
(d) False and False 0 and the empty string are treated as False.
The total number of elements of a NumPy array is given by
(b) size size gives the total number of elements: rows x columns for a 2-D array.
Which method makes a dictionary from a list of keys, with the same value for every key?
(c) dict.fromkeys() dict.fromkeys(['a', 'b'], 0) gives {'a': 0, 'b': 0}.
Which function makes a NumPy array from a list?
(a) np.array() np.array([1, 2, 3]) makes an array from the list.
The smallest individual unit of a Python program is a
(d) token Tokens: keywords, identifiers, literals, operators and punctuators.
For an array made from [[1, 2, 3], [4, 5, 6]], shape is
(d) (2, 3) 2 rows and 3 columns, so shape is (2, 3).
The correct way to import NumPy with its usual short name is
(d) import numpy as np np is the usual short name: import numpy as np.
The else part of a loop runs when
(d) the loop ends normally, without break The loop's else runs only if the loop was not stopped by break.
Which statement does nothing and is used as a placeholder?
(b) pass pass is used where a statement is needed but nothing is to be done.
The value None belongs to the data type
(d) NoneType None is the only value of the NoneType type.
Which of these names is NOT valid?
(c) my-name A hyphen is not allowed in a name; Python reads it as minus.
Which operator gives the remainder?
(d) % 17 % 5 gives 2, the remainder.
Which method adds one element at the end of a list?
(d) append() L.append(5) adds 5 as the last element.
In Python, complex numbers are written as
(d) 3 + 4j Python uses j for the imaginary part: 3 + 4j.
The output of print(10, 20, sep='-') is
(c) 10-20 sep='-' puts - between the values instead of a space.
In 5 + 2.0, Python converts 5 to a float on its own. This is
(c) implicit type conversion Python converts it automatically, so it is implicit conversion.
Which operator checks whether two names refer to the same object?
(a) is is checks identity (same object); == checks equal values.
An error in the grammar of the code, such as a missing colon, is a
(c) syntax error Wrong grammar (syntax) is caught before the program runs.
Which of these is a membership operator?
(a) in in checks whether a value is present: 3 in [1, 3] is True.
State True or False: Adding two NumPy arrays of the same size adds their elements one by one.
(a) True NumPy adds element by element: [1, 2] + [3, 4] gives [4 6].
Accessing a key that is not in the dictionary with d[key] gives
(a) KeyError D['x'] for a missing key gives KeyError.
Searching a list element by element from the start is called
(a) linear search Checking every element one after another is linear search.
Python program files are saved with the extension
(a) .py Python scripts are saved as name.py.
Which method removes the first occurrence of a given value?
(a) remove() L.remove(10) deletes the first 10 in the list.
Which loop is best when the number of repetitions is known?
(c) for for i in range(n) runs exactly n times.
Which statement deletes the elements from index 1 to 2 of L?
(b) del L[1:3] del L[1:3] deletes index 1 and 2 (the stop index 3 is not included).
np.array([1, 2.5, 3]) has the data type
(d) float64 One value is a float, so all elements become float64.
How many times does 'for i in range(3, 15, 4)' run?
(b) 3 i takes 3, 7 and 11.
NumPy is a Python library used mainly for
(b) working with arrays and numbers NumPy (Numerical Python) works with arrays of numbers quickly.
Dividing a number by zero while the program runs gives a
(c) runtime error (ZeroDivisionError) The program starts but stops with ZeroDivisionError while running.
State True or False: L[1] = 10 is allowed on a list L of 3 elements.
(a) True Lists are mutable and index 1 exists in a 3-element list.
Which method removes an element by index and returns it?
(c) pop() L.pop(2) removes and returns the element at index 2.
State True or False: A NumPy array can be made from a Python list.
(a) True np.array(list) does exactly this.
Which statement skips the rest of the current loop round and goes to the next round?
(d) continue continue jumps to the next round of the loop.
list('KV') gives
(c) ['K', 'V'] list() makes one element from each character.
A loop that never ends is called
(c) an infinite loop If the condition never becomes False, the loop runs for ever.
State True or False: Dictionary keys can be repeated.
(b) False A new value for an existing key replaces the old value.
range(5) gives the numbers
(c) 0, 1, 2, 3, 4 range(5) starts at 0 and stops before 5.
np.array([1, 2, 3]) * 2 gives
(d) [2 4 6] NumPy multiplies every element by 2; arrays print without commas.
Which mode of Python runs one statement at a time with the >>> prompt?
(b) Interactive mode Interactive mode shows the >>> prompt and gives the result of each statement at once.
A while loop is called
(b) entry-controlled The condition is checked before each round (at the entry).
Which statement is used to write an empty if block?
(d) pass An empty block gives an error, so pass is written inside it.
A comment in Python starts with
(a) # Everything after # on a line is ignored by Python.
Converting the type of a value by a function such as int() or float() is called
(c) explicit type conversion The programmer converts it on purpose, so it is explicit conversion.
Which attribute gives the data type of the elements of an array?
(d) dtype dtype tells the type, such as int64 or float64.
Which method adds all the elements of another list at the end?
(b) extend() L.extend([4, 5]) adds 4 and 5 one by one.
State True or False: A while loop may not run even once.
(a) True If the condition is False at the start, the body is skipped.
State True or False: The = operator compares two values.
(b) False = assigns; == compares.
Which statement ends the loop at once?
(a) break break stops the loop immediately.
Which of these can be a dictionary key?
(a) (1, 2) A key must be immutable: numbers, strings and tuples can be keys; lists and dictionaries cannot.
Which function gives the memory address (identity) of an object?
(b) id() id(x) gives the identity of the object x.
State True or False: In Python, a variable must be declared with its type before use.
(b) False Python finds the type from the value given.
d.update(e)
(b) adds the pairs of e to d, changing the values of common keys New keys are added and the values of existing keys are replaced.
What is the length of [1, [2, 3], 4]?
(d) 3 The inner list counts as one element: 1, [2, 3], 4.
A loop inside another loop is called
(c) a nested loop The inner loop runs fully for every round of the outer loop.
Which of these is a valid identifier?
(c) total_marks It has letters and an underscore; it does not start with a digit, has no hyphen and is not a keyword.
Which method removes all the elements of a list?
(b) clear() L.clear() leaves an empty list [].
len({'a': 1, 'b': 2}) is
(c) 2 There are two key-value pairs.
Python is a
(b) high-level, interpreted language Python is close to English (high level) and is run by an interpreter.
What is the output of the following code?
D = {'Dev': 65, 'Gita': 50, 'Bela': 41, 'Esha': 77}
D["Zoya"] = 99
print(len(D))(b) 5 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [25, 36, 6, 2, 27, 31] L.sort(reverse=True) print(L)
(c) [36, 31, 27, 25, 6, 2] sort(reverse=True) arranges the same list in descending order (largest first).
What is the output of the following code?
L = [23, 3, 17, 28, 9] L.insert(4, 60) print(L)
(c) [23, 3, 17, 28, 60, 9] insert(4, 60) puts 60 at index 4; the elements from index 4 onwards move one place to the right.
What is the output of the following code?
for i in range(6, -6, -1):
print(i, end=" ")(d) 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
import numpy as np a = np.array([5, 9, 22, 8]) b = np.array([16, 7, 4, 22]) print(a + b)
(a) [21 16 26 30] NumPy works element by element on arrays of one type.
What is the output of the following code?
print(-14 // 4, -14 % 4)
(d) -4 2 // rounds down towards minus infinity, so -14 // 4 is -4; the remainder takes the sign of the divisor.
What is the output of the following code?
for i in range(0, 4, 1):
print(i, end=" ")(d) 0 1 2 3 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
D = {'Esha': 48, 'Charu': 52, 'Gita': 76, 'Dev': 43}
print(D.get("Zoya"))(d) None A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [8, 9, 36, 6] L[0] = 44 print(L)
(a) [44, 9, 36, 6] Lists are mutable, so L[0] = 44 replaces the element at index 0 (8) with 44.
What is the output of the following code?
print(24 - 5 // 5 % 2)
(b) 23 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(-21 // 6, -21 % 6)
(d) -4 3 // rounds down towards minus infinity, so -21 // 6 is -4; the remainder takes the sign of the divisor.
What is the output of the following code?
L = [24, 36, 14, 17, 4] print(L[1:6])
(c) [36, 14, 17, 4] The slice L[1:6] takes index 1 up to index 5 (the stop index is not included). A slice never gives an error even if the stop is beyond the end.
What is the output of the following code?
for i in range(1, -6, -1):
print(i, end=" ")(a) 1 0 -1 -2 -3 -4 -5 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
print(8 - 3 % 5 * 2)
(a) 2 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
for i in range(0, -11, -2):
print(i, end=" ")(b) 0 -2 -4 -6 -8 -10 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
a = 4 b = a * 2 a = b - a b //= 3 print(a, b)
(d) 4 2 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
import numpy as np a = np.array([1.5, 2, 3]) print(a.dtype)
(b) float64 NumPy works element by element on arrays of one type.
What is the output of the following code?
D = {'Bela': 59, 'Dev': 68, 'Farid': 81, 'Charu': 60}
print(D.get("Zoya", 0))(a) 0 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
print(str(9) * 2)
(a) 99 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
n = 36
count = 0
while n > 5:
n = n - 5
count += 1
print(count, n)(b) 7 1 Trace the loop: the condition is checked before every round.
What is the output of the following code?
print(type('7' * 2))(a) <class 'str'> The type of the result decides the class.
What is the output of the following code?
D = {'Esha': 94, 'Charu': 80, 'Dev': 73, 'Amit': 48}
print(list(D.values())[1])(d) 80 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [32, 17, 25, 23] print(sorted(L)[1])
(b) 23 sorted(L) gives a new list in ascending order: [17, 23, 25, 32]. Its element at index 1 is 23.
What is the output of the following code?
marks = 14
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(d) Fail Only the first true condition of an if-elif chain runs.
What is the output of the following code?
n = 47
count = 0
while n > 3:
n = n - 9
count += 1
print(count, n)(c) 5 2 Trace the loop: the condition is checked before every round.
What is the output of the following code?
print(7 + 5 * 3 % 3)
(d) 7 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
D = {'Bela': 55, 'Dev': 67, 'Esha': 89, 'Charu': 56}
print(D.get("Zoya", 0))(b) 0 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
D = {'Amit': 42, 'Gita': 49, 'Dev': 92, 'Charu': 67}
print(list(D.keys()))(b) ['Amit', 'Gita', 'Dev', 'Charu'] A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [18, 12, 16, 2] print(L * 2)
(c) [18, 12, 16, 2, 18, 12, 16, 2] The * operator repeats the list, so the elements appear 2 times one after another.
What is the output of the following code?
import numpy as np a = np.array([19, 16, 29, 6]) print(a[2], a[-1], a[1:3])
(d) 29 6 [16 29] NumPy works element by element on arrays of one type.
What is the output of the following code?
L = [38, 8, 10, 15, 39, 31] L.append([60, 61]) print(L)
(d) [38, 8, 10, 15, 39, 31, [60, 61]] append() adds its argument as ONE element, so the whole list [60, 61] becomes the last element (a nested list).
What is the output of the following code?
for i in range(2, 12, 2):
print(i, end=" ")(c) 2 4 6 8 10 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
print(not 1)
(b) False not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
a = 9 b = 8 a += b b = a - b a = a - b print(a, b)
(c) 8 9 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
c = 0
for i in range(4):
for j in range(4):
c += 1
print(c)(d) 16 The inner loop runs fully for every round of the outer loop.
What is the output of the following code?
D = {'Gita': 46, 'Charu': 76, 'Bela': 52, 'Dev': 74}
print(sorted(D))(b) ['Bela', 'Charu', 'Dev', 'Gita'] A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
import numpy as np a = np.array([[7, 12, 8], [10, 12, 3]]) print(a.ndim, a.shape, a.size)
(d) 2 (2, 3) 6 NumPy works element by element on arrays of one type.
What is the output of the following code?
D = {'Charu': 80, 'Farid': 49, 'Bela': 62, 'Dev': 68}
print(max(D))(c) Farid A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
D = {'Gita': 85, 'Dev': 80, 'Amit': 53, 'Farid': 75}
print(D["Farid"])(c) 75 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [13, 1, 9, 29, 25] L.extend([46, 47]) print(L)
(b) [13, 1, 9, 29, 25, 46, 47] extend() adds each element of the given list separately at the end, so the length grows by 2.
What is the output of the following code?
L = [20, 6, 16, 10, 22] print(16 in L, 52 not in L)
(d) True True 16 is in the list, so "in" gives True; 52 is not in the list, so "not in" gives True.
What is the output of the following code?
for i in range(3, 12):
if i % 2 == 0:
continue
print(i, end=" ")(a) 3 5 7 9 11 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
for i in range(5, 12, 3):
print(i, end=" ")(d) 5 8 11 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
print(28 / 3, 28 // 3, 28 % 3)
(c) 9.333333333333334 9 1 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(type(7 // 2))
(b) <class 'int'> The type of the result decides the class.
What is the output of the following code?
print(57 / 9, 57 // 9, 57 % 9)
(c) 6.333333333333333 6 3 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
n = 34
count = 0
while n > 7:
n = n - 6
count += 1
print(count, n)(d) 5 4 Trace the loop: the condition is checked before every round.
What is the output of the following code?
D = {'Dev': 53, 'Charu': 90, 'Amit': 72, 'Farid': 97}
print(max(D.values()))(a) 97 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [27, 1, 35, 36] print(L.index(1))
(c) 1 index(1) returns the position of the first 1; counting from 0, it is at index 1.
What is the output of the following code?
L = [9, 34, 19, 7, 25] L.append(41) print(L)
(c) [9, 34, 19, 7, 25, 41] append(41) adds 41 as the last element.
What is the output of the following code?
for i in range(3, -8, -2):
print(i, end=" ")(b) 3 1 -1 -3 -5 -7 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
D = {'Esha': 88, 'Bela': 77, 'Charu': 89, 'Gita': 49}
print(D.get("Zoya"))(d) None A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
c = 0
for i in range(2):
for j in range(4):
c += 1
print(c)(b) 8 The inner loop runs fully for every round of the outer loop.
What is the output of the following code?
print(8 + 2 * 2 % 4)
(c) 8 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
L = [35, 19, 8, 24] L.insert(2, 51) print(L)
(a) [35, 19, 51, 8, 24] insert(2, 51) puts 51 at index 2; the elements from index 2 onwards move one place to the right.
What is the output of the following code?
for i in range(1, 14):
if i % 3 == 0:
continue
print(i, end=" ")(d) 1 2 4 5 7 8 10 11 13 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
L = [14, 38, 27, 19, 32] del L[1] print(L)
(a) [14, 27, 19, 32] del L[1] removes the element at index 1, which is 38.
What is the output of the following code?
L = [36, 25, 14, 27] L[0] = 52 print(L)
(b) [52, 25, 14, 27] Lists are mutable, so L[0] = 52 replaces the element at index 0 (36) with 52.
What is the output of the following code?
L = [38, 33, 27, 32] print(sum(L) // len(L))
(a) 32 sum(L) is 130 and len(L) is 4; // gives the floor quotient 130 // 4 = 32.
What is the output of the following code?
D = {'Farid': 83, 'Amit': 60, 'Dev': 91, 'Esha': 51}
print(max(D))(a) Farid A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
D = {'Charu': 84, 'Bela': 96, 'Esha': 88, 'Dev': 92}
print(D.get("Zoya"))(d) None A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
D = {'Esha': 41, 'Charu': 62, 'Bela': 79, 'Gita': 53}
print("Esha" in D, 41 in D)(d) True False A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [12, 20, 3, 10] print(max(L) - min(L))
(b) 17 max(L) is 20 and min(L) is 3, so 20 - 3 = 17.
What is the output of the following code?
for i in range(4, 13):
if i % 3 == 0:
continue
print(i, end=" ")(a) 4 5 7 8 10 11 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
D = {'Gita': 80, 'Charu': 60, 'Farid': 98, 'Esha': 55}
D["Charu"] = 99
print(D)(c) {'Gita': 80, 'Charu': 99, 'Farid': 98, 'Esha': 55} A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [30, 4, 31, 35, 23, 37] del L[3] print(L)
(d) [30, 4, 31, 23, 37] del L[3] removes the element at index 3, which is 35.
What is the output of the following code?
L = [8, 32, 2, 4, 16] print(L.pop(3), L)
(c) 4 [8, 32, 2, 16] pop(3) removes and returns the element at index 3 (4); then the changed list is printed.
What is the output of the following code?
a, b = 9, 6 a, b = b, a + b print(a, b)
(b) 6 15 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
L = [34, 36, 39, 1, 32] print(max(L) - min(L))
(a) 38 max(L) is 39 and min(L) is 1, so 39 - 1 = 38.
What is the output of the following code?
marks = 81
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(a) A Only the first true condition of an if-elif chain runs.
What is the output of the following code?
import numpy as np a = np.array([21, 7, 4, 25]) print(a.ndim, a.shape, a.size)
(b) 1 (4,) 4 NumPy works element by element on arrays of one type.
What is the output of the following code?
L = [18, 24, 33, 19, 7, 20] print(7 in L, 45 not in L)
(a) True True 7 is in the list, so "in" gives True; 45 is not in the list, so "not in" gives True.
What is the output of the following code?
L = [30, 39, 5, 33, 8] print(len(L + [53]))
(d) 6 L + [..] makes a new list with one more element: 5 + 1 = 6. L itself does not change.
What is the output of the following code?
print(type(float(7)))
(a) <class 'float'> The type of the result decides the class.
What is the output of the following code?
D = {'Esha': 76, 'Amit': 77, 'Bela': 71, 'Dev': 78}
print(sorted(D))(d) ['Amit', 'Bela', 'Dev', 'Esha'] A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
for i in range(2, 9, 2):
print(i, end=" ")(b) 2 4 6 8 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(2, 13):
if i % 8 == 0:
break
print(i, end=" ")(a) 2 3 4 5 6 7 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
x = 6 x -= 2 x **= 2 print(x)
(c) 16 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
print(13 + 6 * 2 ** 2)
(a) 37 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
for i in range(1, 7, 3):
print(i, end=" ")(b) 1 4 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(6, 10, 2):
print(i, end=" ")(a) 6 8 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
import numpy as np a = np.array([6, 10, 27, 7]) b = np.array([22, 23, 7, 27]) print(a + b)
(d) [28 33 34 34] NumPy works element by element on arrays of one type.
What is the output of the following code?
print(20 / 4, 20 // 4, 20 % 4)
(a) 5.0 5 0 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
D = {'Dev': 58, 'Farid': 96, 'Amit': 90, 'Gita': 77}
D["Gita"] = 99
print(D)(d) {'Dev': 58, 'Farid': 96, 'Amit': 90, 'Gita': 99} A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [4, 33, 11, 24, 25] print(L[::-2])
(c) [25, 11, 4] A step of -2 starts from the last element and moves left, taking every second element: [25, 11, 4].
What is the output of the following code?
L = [14, 5, 11, 2, 25] print(14 in L, 48 not in L)
(c) True True 14 is in the list, so "in" gives True; 48 is not in the list, so "not in" gives True.
What is the output of the following code?
n = 25
count = 0
while n > 6:
n = n - 3
count += 1
print(count, n)(c) 7 4 Trace the loop: the condition is checked before every round.
What is the output of the following code?
D = {'Esha': 97, 'Bela': 43, 'Dev': 54, 'Gita': 45}
D["Zoya"] = 99
print(len(D))(c) 5 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
print(13 - 3 // 3 % 4)
(c) 12 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
import numpy as np a = np.array([[7, 13, 5], [2, 1, 8]]) print(a[1][0], a[0, 0])
(d) 2 7 NumPy works element by element on arrays of one type.
What is the output of the following code?
marks = 42
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(a) C Only the first true condition of an if-elif chain runs.
What is the output of the following code?
n = 39
count = 0
while n > 7:
n = n - 4
count += 1
print(count, n)(a) 8 7 Trace the loop: the condition is checked before every round.
What is the output of the following code?
print(not 5 > 3 or 5 == 3 and 0)
(a) False not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
import numpy as np a = np.array([[9, 5, 16], [13, 18, 15]]) print(a[1][1], a[0, 2])
(d) 18 16 NumPy works element by element on arrays of one type.
What is the output of the following code?
print(21 + 4 * 3 * 2)
(a) 45 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
for i in range(6, 12, 1):
print(i, end=" ")(a) 6 7 8 9 10 11 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
print(29 / 8, 29 // 8, 29 % 8)
(a) 3.625 3 5 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
L = [7, 3, 22, 28, 29, 5] L.append([50, 51]) print(L)
(c) [7, 3, 22, 28, 29, 5, [50, 51]] append() adds its argument as ONE element, so the whole list [50, 51] becomes the last element (a nested list).
What is the output of the following code?
L = [32, 23, 15, 14] print(sorted(L)[1])
(a) 15 sorted(L) gives a new list in ascending order: [14, 15, 23, 32]. Its element at index 1 is 15.
What is the output of the following code?
import numpy as np a = np.array([[5, 13, 6], [10, 1, 8]]) print(a[1][1], a[0, 1])
(d) 1 13 NumPy works element by element on arrays of one type.
What is the output of the following code?
print(17 + 5 * 4 // 2)
(b) 27 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
D = {'Farid': 63, 'Amit': 66, 'Dev': 48, 'Gita': 90}
print(sorted(D))(b) ['Amit', 'Dev', 'Farid', 'Gita'] A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
D = {'Gita': 48, 'Amit': 74, 'Bela': 41, 'Esha': 68}
print(max(D))(c) Gita A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [6, 36, 38, 31, 33, 25] L.append(47) print(L)
(a) [6, 36, 38, 31, 33, 25, 47] append(47) adds 47 as the last element.
What is the output of the following code?
D = {'Farid': 86, 'Charu': 47, 'Esha': 50, 'Gita': 62}
print(D.pop("Esha"), len(D))(d) 50 3 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
print(30 + 4 // 2 ** 2)
(d) 31 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
marks = 15
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(d) Fail Only the first true condition of an if-elif chain runs.
What is the output of the following code?
D = {'Bela': 70, 'Gita': 64, 'Farid': 42, 'Charu': 67}
print(D.get("Zoya", 0))(c) 0 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
print(-13 // 6, -13 % 6)
(d) -3 5 // rounds down towards minus infinity, so -13 // 6 is -3; the remainder takes the sign of the divisor.
What is the output of the following code?
print(0 or 5)
(c) 5 not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
print(-23 // 4, -23 % 4)
(b) -6 1 // rounds down towards minus infinity, so -23 // 4 is -6; the remainder takes the sign of the divisor.
What is the output of the following code?
n = 27
count = 0
while n > 6:
n = n - 9
count += 1
print(count, n)(a) 3 0 Trace the loop: the condition is checked before every round.
What is the output of the following code?
print(float('8') * 2)(d) 16.0 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
x = 8 x -= 2 x **= 2 print(x)
(a) 36 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
L = [22, 20, 9, 35, 7, 34] print(L.pop(), L)
(d) 34 [22, 20, 9, 35, 7] pop() without an index removes and returns the last element (34); then the changed list is printed.
What is the output of the following code?
import numpy as np a = np.array([16, 18, 8, 27]) print(a[1], a[-1], a[1:3])
(b) 18 27 [18 8] NumPy works element by element on arrays of one type.
What is the output of the following code?
D = {'Esha': 82, 'Farid': 67, 'Bela': 94, 'Charu': 60}
D["Esha"] = 99
print(D)(d) {'Esha': 99, 'Farid': 67, 'Bela': 94, 'Charu': 60} A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [24, 16, 22, 5, 21] L.insert(0, 53) print(L)
(b) [53, 24, 16, 22, 5, 21] insert(0, 53) puts 53 at index 0; the elements from index 0 onwards move one place to the right.
What is the output of the following code?
import numpy as np a = np.array([[17, 19, 15], [8, 10, 1]]) print(a.ndim, a.shape, a.size)
(a) 2 (2, 3) 6 NumPy works element by element on arrays of one type.
What is the output of the following code?
marks = 49
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(b) C Only the first true condition of an if-elif chain runs.
What is the output of the following code?
print(str(3) * 2)
(d) 33 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
L = [5, 32, 16, 30] L[0] = 53 print(L)
(a) [53, 32, 16, 30] Lists are mutable, so L[0] = 53 replaces the element at index 0 (5) with 53.
What is the output of the following code?
print(32 / 3, 32 // 3, 32 % 3)
(b) 10.666666666666666 10 2 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(9 and 8)
(a) 8 not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
for i in range(3, 15):
if i % 7 == 0:
break
print(i, end=" ")(d) 3 4 5 6 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
print(type(2 ** 3))
(d) <class 'int'> The type of the result decides the class.
What is the output of the following code?
L = [23, 28, 15, 32] print(L.index(28))
(c) 1 index(28) returns the position of the first 28; counting from 0, it is at index 1.
What is the output of the following code?
print(30 + 5 * 4 // 4)
(a) 35 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
D = {'Charu': 78, 'Amit': 56, 'Gita': 45, 'Dev': 48}
print(D.get("Zoya"))(a) None A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [12, 1, 26, 6] print(L.pop(1), L)
(d) 1 [12, 26, 6] pop(1) removes and returns the element at index 1 (1); then the changed list is printed.
What is the output of the following code?
L = [27, 9, 7, 24, 1, 37] print(sorted(L)[1])
(c) 7 sorted(L) gives a new list in ascending order: [1, 7, 9, 24, 27, 37]. Its element at index 1 is 7.
What is the output of the following code?
for i in range(1, -8, -2):
print(i, end=" ")(d) 1 -1 -3 -5 -7 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(1, -6, -2):
print(i, end=" ")(c) 1 -1 -3 -5 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
x = 9 x *= 2 + 3 print(x)
(a) 45 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
D = {'Esha': 78, 'Dev': 53, 'Bela': 52, 'Gita': 70}
print(D.pop("Bela"), len(D))(c) 52 3 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
import numpy as np a = np.array([[18, 13, 19], [16, 13, 1]]) print(a[1][2], a[0, 2])
(a) 1 19 NumPy works element by element on arrays of one type.
What is the output of the following code?
L = [35, 27, 31, 2] print(L[1:4])
(a) [27, 31, 2] The slice L[1:4] takes index 1 up to index 3 (the stop index is not included). A slice never gives an error even if the stop is beyond the end.
What is the output of the following code?
c = 0
for i in range(1, 5):
for j in range(i):
c += j
print(c)(a) 10 The inner loop runs fully for every round of the outer loop.
What is the output of the following code?
print(42 / 3, 42 // 3, 42 % 3)
(c) 14.0 14 0 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(float('2') * 2)(d) 4.0 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
L = [31, 29, 18, 24, 6] print(L * 2)
(d) [31, 29, 18, 24, 6, 31, 29, 18, 24, 6] The * operator repeats the list, so the elements appear 2 times one after another.
What is the output of the following code?
for i in range(5, 12, 1):
print(i, end=" ")(b) 5 6 7 8 9 10 11 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
import numpy as np a = np.array([4, 12, 20, 24]) b = np.array([7, 2, 14, 9]) print(a + b)
(c) [11 14 34 33] NumPy works element by element on arrays of one type.
What is the output of the following code?
print(26 + 2 * 5 * 4)
(c) 66 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
n = 35
count = 0
while n > 6:
n = n - 5
count += 1
print(count, n)(c) 6 5 Trace the loop: the condition is checked before every round.
What is the output of the following code?
D = {'Charu': 86, 'Gita': 47, 'Bela': 84, 'Farid': 80}
print(sorted(D))(c) ['Bela', 'Charu', 'Farid', 'Gita'] A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
print(7 + 3 % 3 // 4)
(b) 7 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
import numpy as np a = np.array([2, 23, 10, 11]) print(a.sum(), a.max(), a.min())
(d) 46 23 2 NumPy works element by element on arrays of one type.
What is the output of the following code?
for i in range(1, 13, 1):
print(i, end=" ")(c) 1 2 3 4 5 6 7 8 9 10 11 12 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
print(28 - 5 // 2 % 2)
(b) 28 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
import numpy as np a = np.array([[4, 17, 13], [5, 9, 4]]) print(a[1][2], a[0, 0])
(d) 4 4 NumPy works element by element on arrays of one type.
What is the output of the following code?
for i in range(1, 11, 2):
print(i, end=" ")(a) 1 3 5 7 9 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(1, -11, -2):
print(i, end=" ")(a) 1 -1 -3 -5 -7 -9 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
import numpy as np a = np.array([18, 21, 23, 29]) print(a * 2)
(d) [36 42 46 58] NumPy works element by element on arrays of one type.
What is the output of the following code?
import numpy as np a = np.array([28, 17, 21, 29]) b = np.array([26, 4, 20, 5]) print(a + b)
(b) [54 21 41 34] NumPy works element by element on arrays of one type.
What is the output of the following code?
for i in range(2, -10, -2):
print(i, end=" ")(a) 2 0 -2 -4 -6 -8 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
D = {'Amit': 82, 'Esha': 62, 'Bela': 53, 'Dev': 42}
print(list(D.keys()))(b) ['Amit', 'Esha', 'Bela', 'Dev'] A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
print(16 / 5, 16 // 5, 16 % 5)
(d) 3.2 3 1 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
for i in range(3, 15):
if i % 6 == 0:
break
print(i, end=" ")(d) 3 4 5 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
import numpy as np a = np.array([8, 3, 25, 5]) b = np.array([10, 26, 20, 1]) print(a + b)
(d) [18 29 45 6] NumPy works element by element on arrays of one type.
What is the output of the following code?
for i in range(2, 7, 2):
print(i, end=" ")(c) 2 4 6 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
n = 34
count = 0
while n > 2:
n = n - 9
count += 1
print(count, n)(c) 4 -2 Trace the loop: the condition is checked before every round.
What is the output of the following code?
print(type(7 / 2))
(b) <class 'float'> The type of the result decides the class.
What is the output of the following code?
marks = 74
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(c) B Only the first true condition of an if-elif chain runs.
What is the output of the following code?
L = [1, 15, 11, 17, 24, 5] L.reverse() print(L)
(d) [5, 24, 17, 11, 15, 1] reverse() reverses the order of the elements in the same list (it does not sort).
What is the output of the following code?
print(6 and 9)
(a) 9 not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
print(type((7)))
(b) <class 'int'> The type of the result decides the class.
What is the output of the following code?
n = 38
count = 0
while n > 1:
n = n - 9
count += 1
print(count, n)(d) 5 -7 Trace the loop: the condition is checked before every round.
What is the output of the following code?
D = {'Esha': 77, 'Charu': 47, 'Amit': 84, 'Bela': 70}
print(sorted(D))(b) ['Amit', 'Bela', 'Charu', 'Esha'] A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
import numpy as np a = np.array([11, 15, 20, 29]) b = np.array([10, 7, 9, 13]) print(a + b)
(a) [21 22 29 42] NumPy works element by element on arrays of one type.
What is the output of the following code?
import numpy as np a = np.array([1, 18, 27, 9]) print(a * 2)
(c) [ 2 36 54 18] NumPy works element by element on arrays of one type.
What is the output of the following code?
D = {'Dev': 67, 'Esha': 69, 'Gita': 87, 'Farid': 88}
print(max(D))(d) Gita A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
n = 54
count = 0
while n > 7:
n = n - 6
count += 1
print(count, n)(b) 8 6 Trace the loop: the condition is checked before every round.
What is the output of the following code?
L = [30, 14, 36, 33, 13, 1] L.remove(14) print(L)
(a) [30, 36, 33, 13, 1] remove(14) deletes the first occurrence of the value 14 (not the index).
What is the output of the following code?
L = [15, 8, 22, 5] L.sort() print(L)
(a) [5, 8, 15, 22] sort() arranges the same list in ascending order (smallest first).
What is the output of the following code?
print(13 + 5 % 5 ** 2)
(c) 18 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
D = {'Farid': 83, 'Charu': 44, 'Esha': 94, 'Gita': 82}
print(D.get("Zoya", 0))(a) 0 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
print(-19 // 5, -19 % 5)
(a) -4 1 // rounds down towards minus infinity, so -19 // 5 is -4; the remainder takes the sign of the divisor.
What is the output of the following code?
print(56 / 9, 56 // 9, 56 % 9)
(d) 6.222222222222222 6 2 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(not 0)
(a) True not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
D = {'Charu': 89, 'Esha': 65, 'Farid': 94, 'Dev': 71}
print(len(D))(c) 4 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
D = {'Bela': 90, 'Gita': 54, 'Amit': 82, 'Dev': 76}
print("Gita" in D, 54 in D)(d) True False A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [19, 33, 5, 3, 15] print(max(L) - min(L))
(a) 30 max(L) is 33 and min(L) is 3, so 33 - 3 = 30.
What is the output of the following code?
print(7 > 5 and 12 < 10 or not 0)
(d) True not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
print(16 - 6 % 4 * 3)
(a) 10 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(-19 // 6, -19 % 6)
(a) -4 5 // rounds down towards minus infinity, so -19 // 6 is -4; the remainder takes the sign of the divisor.
What is the output of the following code?
L = [6, 7, 37, 29] L.insert(0, 44) print(L)
(a) [44, 6, 7, 37, 29] insert(0, 44) puts 44 at index 0; the elements from index 0 onwards move one place to the right.
What is the output of the following code?
print(27 - 6 * 2 ** 2)
(b) 3 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
import numpy as np a = np.array([20, 19, 9, 26]) print(a[0], a[-1], a[1:3])
(a) 20 26 [19 9] NumPy works element by element on arrays of one type.
What is the output of the following code?
D = {'Amit': 87, 'Bela': 49, 'Dev': 66, 'Gita': 63}
print(D["Amit"])(d) 87 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
import numpy as np a = np.array([11, 16, 6, 20]) print(a[2], a[-1], a[1:3])
(c) 6 20 [16 6] NumPy works element by element on arrays of one type.
What is the output of the following code?
L = [34, 14, 23, 24] print(L * 2)
(a) [34, 14, 23, 24, 34, 14, 23, 24] The * operator repeats the list, so the elements appear 2 times one after another.
What is the output of the following code?
n = 49
count = 0
while n > 7:
n = n - 4
count += 1
print(count, n)(a) 11 5 Trace the loop: the condition is checked before every round.
What is the output of the following code?
L = [18, 33, 28, 16, 25] L.extend([57, 58]) print(L)
(b) [18, 33, 28, 16, 25, 57, 58] extend() adds each element of the given list separately at the end, so the length grows by 2.
What is the output of the following code?
import numpy as np a = np.array([True, False]) print(a.dtype)
(b) bool NumPy works element by element on arrays of one type.
What is the output of the following code?
for i in range(2, 14):
if i % 3 == 0:
continue
print(i, end=" ")(d) 2 4 5 7 8 10 11 13 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
n = 52
count = 0
while n > 4:
n = n - 9
count += 1
print(count, n)(b) 6 -2 Trace the loop: the condition is checked before every round.
What is the output of the following code?
print(int(8.5), round(8.5))
(a) 8 8 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
marks = 55
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(b) C Only the first true condition of an if-elif chain runs.
What is the output of the following code?
D = {'Esha': 72, 'Bela': 80, 'Amit': 85, 'Farid': 74}
print(list(D.values())[1])(a) 80 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
D = {'Charu': 76, 'Dev': 53, 'Esha': 73, 'Bela': 93}
D.update({"Bela": 50, "Zoya": 60})
print(D)(d) {'Charu': 76, 'Dev': 53, 'Esha': 73, 'Bela': 50, 'Zoya': 60} A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
import numpy as np a = np.array([28, 21, 17, 16]) b = np.array([8, 3, 6, 12]) print(a + b)
(d) [36 24 23 28] NumPy works element by element on arrays of one type.
What is the output of the following code?
print(7 + 6 // 5 * 3)
(d) 10 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
import numpy as np a = np.array([[5, 11, 16], [8, 3, 4]]) print(a[1][0], a[0, 1])
(b) 8 11 NumPy works element by element on arrays of one type.
What is the output of the following code?
print(-22 // 4, -22 % 4)
(d) -6 2 // rounds down towards minus infinity, so -22 // 4 is -6; the remainder takes the sign of the divisor.
What is the output of the following code?
import numpy as np a = np.array([11, 13, 29, 14]) print(a.ndim, a.shape, a.size)
(b) 1 (4,) 4 NumPy works element by element on arrays of one type.
What is the output of the following code?
print(10 - 2 // 3 % 3)
(d) 10 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
L = [2, 27, 22, 7, 38] L.extend([43, 44]) print(L)
(c) [2, 27, 22, 7, 38, 43, 44] extend() adds each element of the given list separately at the end, so the length grows by 2.
What is the output of the following code?
a = 7 b = 6 a += b b = a - b a = a - b print(a, b)
(c) 6 7 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
import numpy as np a = np.array([5, 13, 20, 10]) print(a.sum(), a.max(), a.min())
(a) 48 20 5 NumPy works element by element on arrays of one type.
What is the output of the following code?
print(22 + 6 * 4 ** 2)
(d) 118 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
for i in range(0, 5, 1):
print(i, end=" ")(a) 0 1 2 3 4 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
L = [8, 37, 20, 36, 1] L.remove(20) print(L)
(c) [8, 37, 36, 1] remove(20) deletes the first occurrence of the value 20 (not the index).
What is the output of the following code?
L = [24, 17, 10, 11, 19] print(L[1:2])
(b) [17] The slice L[1:2] takes index 1 up to index 1 (the stop index is not included). A slice never gives an error even if the stop is beyond the end.
What is the output of the following code?
D = {'Dev': 50, 'Gita': 81, 'Bela': 82, 'Amit': 45}
print(len(D))(c) 4 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
c = 0
for i in range(2):
for j in range(3):
c += 1
print(c)(d) 6 The inner loop runs fully for every round of the outer loop.
What is the output of the following code?
D = {'Dev': 49, 'Charu': 81, 'Esha': 52, 'Farid': 67}
print(D.get("Zoya"))(a) None A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
print(int(7.5), round(7.5))
(b) 7 8 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
L = [8, 19, 20, 23, 16, 10] print(len(L + [51]))
(c) 7 L + [..] makes a new list with one more element: 6 + 1 = 7. L itself does not change.
What is the output of the following code?
D = {'Dev': 67, 'Farid': 83, 'Esha': 78, 'Charu': 48}
print(list(D.items())[0])(d) ('Dev', 67) A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
print(str(8) * 2)
(d) 88 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
for i in range(1, 16):
if i % 3 == 0:
continue
print(i, end=" ")(c) 1 2 4 5 7 8 10 11 13 14 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
print(int('7') + 7, '7' + '7')(c) 14 77 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
a = 10 b = 8 a += b b = a - b a = a - b print(a, b)
(c) 8 10 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
D = {'Dev': 88, 'Bela': 82, 'Esha': 44, 'Gita': 81}
print(D["Gita"])(d) 81 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [5, 12, 21, 39] print(L[1:4])
(d) [12, 21, 39] The slice L[1:4] takes index 1 up to index 3 (the stop index is not included). A slice never gives an error even if the stop is beyond the end.
What is the output of the following code?
D = {'Amit': 50, 'Dev': 42, 'Charu': 51, 'Esha': 47}
del D["Dev"]
print(D)(a) {'Amit': 50, 'Charu': 51, 'Esha': 47} A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [26, 1, 33, 6] print(sum(L) // len(L))
(c) 16 sum(L) is 66 and len(L) is 4; // gives the floor quotient 66 // 4 = 16.
What is the output of the following code?
print(9 < 6 < 15)
(a) False not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
L = [23, 39, 5, 4, 7] L.reverse() print(L)
(c) [7, 4, 5, 39, 23] reverse() reverses the order of the elements in the same list (it does not sort).
What is the output of the following code?
marks = 12
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(c) Fail Only the first true condition of an if-elif chain runs.
What is the output of the following code?
marks = 78
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(d) A Only the first true condition of an if-elif chain runs.
What is the output of the following code?
for i in range(1, 13, 2):
print(i, end=" ")(c) 1 3 5 7 9 11 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
print(float('9') * 2)(d) 18.0 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
x = 3 x -= 2 x **= 2 print(x)
(c) 1 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
for i in range(2, 12):
if i % 6 == 0:
break
print(i, end=" ")(a) 2 3 4 5 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
print(20 - 4 % 3 % 3)
(d) 19 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
import numpy as np a = np.array([14, 29, 11, 17]) print(a[1], a[-1], a[1:3])
(d) 29 17 [29 11] NumPy works element by element on arrays of one type.
What is the output of the following code?
print(20 / 8, 20 // 8, 20 % 8)
(b) 2.5 2 4 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(22 / 6, 22 // 6, 22 % 6)
(a) 3.6666666666666665 3 4 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
for i in range(0, -8, -1):
print(i, end=" ")(a) 0 -1 -2 -3 -4 -5 -6 -7 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
print(27 - 3 % 4 ** 3)
(b) 24 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
import numpy as np a = np.array([12, 4, 21, 9]) b = np.array([19, 8, 21, 20]) print(a + b)
(a) [31 12 42 29] NumPy works element by element on arrays of one type.
What is the output of the following code?
for i in range(0, 12, 3):
print(i, end=" ")(d) 0 3 6 9 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
D = {'Esha': 60, 'Bela': 69, 'Charu': 94, 'Amit': 42}
print(list(D.items())[0])(b) ('Esha', 60) A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
D = {'Dev': 78, 'Farid': 86, 'Amit': 74, 'Bela': 50}
D["Dev"] = 99
print(D)(a) {'Dev': 99, 'Farid': 86, 'Amit': 74, 'Bela': 50} A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
D = {'Amit': 45, 'Charu': 85, 'Gita': 52, 'Bela': 67}
print(max(D.values()))(a) 85 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
for i in range(5, -7, -2):
print(i, end=" ")(c) 5 3 1 -1 -3 -5 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
L = [10, 39, 12, 7] L[2] = 52 print(L)
(a) [10, 39, 52, 7] Lists are mutable, so L[2] = 52 replaces the element at index 2 (12) with 52.
What is the output of the following code?
print(type(2 ** -1))
(b) <class 'float'> The type of the result decides the class.
What is the output of the following code?
L = [34, 36, 14, 12, 11] print(L[::-2])
(b) [11, 14, 34] A step of -2 starts from the last element and moves left, taking every second element: [11, 14, 34].
What is the output of the following code?
import numpy as np a = np.array([[7, 3, 11], [11, 10, 1]]) print(a.ndim, a.shape, a.size)
(d) 2 (2, 3) 6 NumPy works element by element on arrays of one type.
What is the output of the following code?
for i in range(2, 12):
if i % 8 == 0:
break
print(i, end=" ")(b) 2 3 4 5 6 7 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
print(14 - 5 // 2 ** 3)
(c) 14 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
import numpy as np a = np.array([[5, 15, 13], [4, 14, 2]]) print(a[1][2], a[0, 1])
(b) 2 15 NumPy works element by element on arrays of one type.
What is the output of the following code?
D = {'Gita': 84, 'Farid': 47, 'Charu': 64, 'Dev': 78}
print(sorted(D))(d) ['Charu', 'Dev', 'Farid', 'Gita'] A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
print(0 or 9)
(a) 9 not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
import numpy as np a = np.array([18, 14, 25, 29]) print(a * 2)
(c) [36 28 50 58] NumPy works element by element on arrays of one type.
What is the output of the following code?
D = {'Esha': 83, 'Farid': 44, 'Bela': 86, 'Amit': 55}
D["Farid"] = 99
print(D)(b) {'Esha': 83, 'Farid': 99, 'Bela': 86, 'Amit': 55} A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
import numpy as np a = np.array([[7, 11, 18], [10, 7, 4]]) print(a[1][1], a[0, 0])
(a) 7 7 NumPy works element by element on arrays of one type.
What is the output of the following code?
D = {'Esha': 51, 'Dev': 54, 'Amit': 56, 'Charu': 64}
print(list(D.values())[1])(a) 54 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [24, 22, 9, 33, 30, 13] L.sort(reverse=True) print(L)
(c) [33, 30, 24, 22, 13, 9] sort(reverse=True) arranges the same list in descending order (largest first).
What is the output of the following code?
print(8 + 6 % 3 % 3)
(c) 8 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
for i in range(3, 12):
if i % 6 == 0:
break
print(i, end=" ")(c) 3 4 5 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
c = 0
for i in range(1, 6):
for j in range(i):
c += j
print(c)(c) 20 The inner loop runs fully for every round of the outer loop.
What is the output of the following code?
import numpy as np a = np.array([5, 18, 1, 7]) b = np.array([25, 18, 11, 6]) print(a + b)
(a) [30 36 12 13] NumPy works element by element on arrays of one type.
What is the output of the following code?
D = {'Bela': 74, 'Dev': 77, 'Charu': 94, 'Esha': 84}
print(D.pop("Esha"), len(D))(d) 84 3 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
for i in range(3, 10):
if i % 2 == 0:
continue
print(i, end=" ")(c) 3 5 7 9 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
x = 10 x *= 2 + 3 print(x)
(b) 50 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
a, b = 8, 10 a, b = b, a + b print(a, b)
(c) 10 18 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
D = {'Dev': 40, 'Charu': 70, 'Amit': 67, 'Farid': 60}
del D["Charu"]
print(D)(a) {'Dev': 40, 'Amit': 67, 'Farid': 60} A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
marks = 4
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(a) Fail Only the first true condition of an if-elif chain runs.
What is the output of the following code?
L = [9, 30, 37, 6, 34] print(max(L) - min(L))
(b) 31 max(L) is 37 and min(L) is 6, so 37 - 6 = 31.
What is the output of the following code?
print(34 / 6, 34 // 6, 34 % 6)
(d) 5.666666666666667 5 4 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(23 - 5 // 3 ** 2)
(d) 23 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
import numpy as np a = np.array([[2, 8, 18], [7, 5, 3]]) print(a[1][2], a[0, 0])
(d) 3 2 NumPy works element by element on arrays of one type.
What is the output of the following code?
L = [25, 32, 27, 22] L.append(46) print(L)
(b) [25, 32, 27, 22, 46] append(46) adds 46 as the last element.
What is the output of the following code?
L = [32, 11, 15, 1, 29] print(11 in L, 45 not in L)
(d) True True 11 is in the list, so "in" gives True; 45 is not in the list, so "not in" gives True.
What is the output of the following code?
print(47 / 7, 47 // 7, 47 % 7)
(c) 6.714285714285714 6 5 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(type('3' + '4'))(d) <class 'str'> The type of the result decides the class.
What is the output of the following code?
import numpy as np a = np.array([20, 24, 12, 5]) b = np.array([6, 29, 19, 23]) print(a + b)
(a) [26 53 31 28] NumPy works element by element on arrays of one type.
What is the output of the following code?
D = {'Esha': 66, 'Amit': 76, 'Dev': 61, 'Gita': 75}
print(D.pop("Esha"), len(D))(b) 66 3 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
import numpy as np a = np.array([25, 14, 1, 8]) b = np.array([15, 10, 21, 11]) print(a + b)
(a) [40 24 22 19] NumPy works element by element on arrays of one type.
What is the output of the following code?
D = {'Esha': 52, 'Amit': 84, 'Dev': 80, 'Charu': 48}
print(D.get("Zoya", 0))(a) 0 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
marks = 7
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(c) Fail Only the first true condition of an if-elif chain runs.
What is the output of the following code?
print(-25 // 4, -25 % 4)
(d) -7 3 // rounds down towards minus infinity, so -25 // 4 is -7; the remainder takes the sign of the divisor.
What is the output of the following code?
import numpy as np a = np.array([10, 11, 26, 9]) print(a.ndim, a.shape, a.size)
(a) 1 (4,) 4 NumPy works element by element on arrays of one type.
What is the output of the following code?
D = {'Dev': 73, 'Charu': 59, 'Gita': 45, 'Bela': 55}
print(sorted(D))(d) ['Bela', 'Charu', 'Dev', 'Gita'] A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
import numpy as np a = np.array([[10, 11, 13], [14, 15, 3]]) print(a[1][1], a[0, 0])
(d) 15 10 NumPy works element by element on arrays of one type.
What is the output of the following code?
import numpy as np a = np.array([1, 2, 3]) print(a.dtype)
(b) int64 NumPy works element by element on arrays of one type.
What is the output of the following code?
n = 43
count = 0
while n > 1:
n = n - 3
count += 1
print(count, n)(d) 14 1 Trace the loop: the condition is checked before every round.
What is the output of the following code?
D = {'Gita': 47, 'Esha': 74, 'Bela': 94, 'Amit': 88}
print(D.pop("Bela"), len(D))(c) 94 3 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
for i in range(6, -2, -1):
print(i, end=" ")(a) 6 5 4 3 2 1 0 -1 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
print(20 + 5 % 2 * 3)
(a) 23 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
a = 2 b = 5 a += b b = a - b a = a - b print(a, b)
(a) 5 2 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
D = {'Esha': 55, 'Gita': 96, 'Bela': 51, 'Farid': 56}
D["Bela"] = 99
print(D)(d) {'Esha': 55, 'Gita': 96, 'Bela': 99, 'Farid': 56} A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
print(type(7 % 2 == 1))
(c) <class 'bool'> The type of the result decides the class.
What is the output of the following code?
D = {'Esha': 40, 'Gita': 66, 'Bela': 75, 'Farid': 69}
D["Farid"] = 99
print(D)(a) {'Esha': 40, 'Gita': 66, 'Bela': 75, 'Farid': 99} A dictionary keeps key: value pairs; keys are unique.
Which column of the table PATIENT given below can be a candidate key?
Table: PATIENT
| PID | Aadhaar | Ward | Doctor | AdmitDate |
|---|---|---|---|---|
| 16 | 623462346234 | Maternity | Dr. Iyer | 2026-09-18 |
| 14 | 423442344234 | Maternity | Dr. Iyer | 2026-09-12 |
| 13 | 323432343234 | General | Dr. Rao | 2026-09-10 |
| 15 | 523452345234 | ICU | Dr. Sen | 2026-09-15 |
| 17 | 723472347234 | General | Dr. Rao | 2026-09-20 |
| 11 | 123412341234 | General | Dr. Rao | 2026-09-02 |
(c) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If BookID is the primary key of the table BOOK given below, which is its alternate key?
Table: BOOK
| BookID | ISBN | Title | Publisher | Price | Member |
|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | NCERT | 210 | Asha |
| 207 | 9789386551023 | Learn SQL | BPB | 400 | Karan |
| 203 | 9780143032311 | Wings of Fire | Universities | 299 | Ravi |
| 205 | 9789352925032 | Chemistry Part 1 | NCERT | 190 | Neha |
| 202 | 9789352920112 | Physics Part 1 | NCERT | 180 | NULL |
(c) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If PID is the primary key of the table PATIENT given below, which is its alternate key?
Table: PATIENT
| PID | Aadhaar | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|
| 15 | 523452345234 | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 14 | 423442344234 | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 16 | 623462346234 | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 13 | 323432343234 | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 17 | 723472347234 | General | Dr. Rao | 2026-09-20 | 900 | Star |
(a) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If PID is the primary key of the table PATIENT given below, which is its alternate key?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
(a) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table STUDENT given below can be a candidate key?
Table: STUDENT
| RollNo | AdmNo | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|
| 6 | 4556 | A | F | 2009-09-09 | 31 | 9810066666 |
| 4 | 4534 | C | F | 2009-07-21 | 66 | 9810044444 |
| 1 | 4501 | A | M | 2009-04-12 | 78 | 9810011111 |
(b) RollNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table BOOK given below can be a candidate key?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | Price | Member |
|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 210 | Asha |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 190 | Neha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 180 | NULL |
(b) BookID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If BookID is the primary key of the table BOOK given below, which is its alternate key?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher |
|---|---|---|---|---|
| 207 | 9789386551023 | Learn SQL | Computer | BPB |
| 204 | 9789386551009 | Python Basics | Computer | BPB |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT |
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT |
(c) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Member |
|---|---|---|---|---|---|---|
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | Ravi |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | Karan |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | Neha |
(c) 7 and 4 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which of these is NOT a relational DBMS?
(d) MS Paint MS Paint is a drawing program; MySQL, Oracle and PostgreSQL are relational DBMS.
What are the degree and cardinality of the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
(d) 8 and 5 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Data about data, kept in the data dictionary, is
(a) metadata Metadata describes data, such as column names and types.
The set {'M', 'F'} for the column Gender is its
(d) domain The set of allowed values of a column is its domain.
If PCode is the primary key of the table PRODUCT given below, which is its alternate key?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price |
|---|---|---|---|---|---|---|
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 |
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 |
(a) Barcode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which of these is a DBMS?
(c) MySQL MySQL is a relational DBMS; Python is a language, MS Paint and Windows are not DBMS.
Which column of the table EMPLOYEE given below can be a candidate key?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
(d) EmpID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table BOOK given below can be a candidate key?
Table: BOOK
| BookID | ISBN | Title | Subject | IssueDate | Price |
|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | 2026-07-03 | 210 |
| 204 | 9789386551009 | Python Basics | Computer | 2026-08-01 | 350 |
| 207 | 9789386551023 | Learn SQL | Computer | 2026-08-12 | 400 |
| 206 | 9780140449136 | The Story of My Experiments | Biography | 2026-05-30 | 250 |
| 203 | 9780143032311 | Wings of Fire | Biography | 2026-06-21 | 299 |
| 202 | 9789352920112 | Physics Part 1 | Science | 2026-07-10 | 180 |
(b) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If EmpID is the primary key of the table EMPLOYEE given below, which is its alternate key?
Table: EMPLOYEE
| EmpID | EName | DOJ | Salary | |
|---|---|---|---|---|
| E106 | wasim@co.in | Wasim | 2022-07-25 | 39000 |
| E107 | yamini@co.in | Yamini | 2017-12-12 | 81000 |
| E104 | usha@co.in | Usha | 2021-03-10 | 36000 |
| E103 | tarun@co.in | Tarun | 2016-09-20 | 75000 |
| E102 | seema@co.in | Seema | 2020-01-15 | 58000 |
| E101 | ravi@co.in | Ravi | 2018-06-01 | 42000 |
| E105 | vikas@co.in | Vikas | 2019-11-05 | 64000 |
(b) Email Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table PATIENT given below can be a candidate key?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee |
|---|---|---|---|---|---|---|
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 |
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 |
(c) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which of these is the best primary key for a table of bank accounts?
(a) Account number Every account has a different account number; names and cities can repeat.
If RollNo is the primary key of the table STUDENT given below, which is its alternate key?
Table: STUDENT
| RollNo | AdmNo | Name | Section | DOB | Marks | Phone |
|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | 2009-04-12 | 78 | 9810011111 |
| 7 | 4567 | Gaurav | C | 2010-02-28 | 59 | 9810077777 |
| 4 | 4534 | Divya | C | 2009-07-21 | 66 | 9810044444 |
| 6 | 4556 | Farah | A | 2009-09-09 | 31 | 9810066666 |
| 3 | 4523 | Chirag | A | 2010-01-05 | 45 | 9810033333 |
(a) AdmNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
When copies of the same data do not match, it is called
(a) data inconsistency If one copy is changed and another is not, the data becomes inconsistent.
Which column of the table EMPLOYEE given below can be a candidate key?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
(d) EmpID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table BOOK given below can be a candidate key?
Table: BOOK
| BookID | ISBN | Title | Publisher | IssueDate |
|---|---|---|---|---|
| 202 | 9789352920112 | Physics Part 1 | NCERT | 2026-07-10 |
| 204 | 9789386551009 | Python Basics | BPB | 2026-08-01 |
| 206 | 9780140449136 | The Story of My Experiments | Penguin | 2026-05-30 |
| 201 | 9789352921485 | Informatics Practices | NCERT | 2026-07-03 |
| 203 | 9780143032311 | Wings of Fire | Universities | 2026-06-21 |
(b) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
(c) 8 and 6 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
State True or False: A primary key can have NULL values.
(b) False No; a primary key must have a value in every row and no repeats.
Which column of the table STUDENT given below can be a candidate key?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
(b) RollNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | Insurance |
|---|---|---|---|---|---|
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | LIC |
| 11 | 123412341234 | Mohan | General | Dr. Rao | LIC |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | NULL |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | NULL |
(d) 6 and 4 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Keeping the same data at more than one place is called
(c) data redundancy Storing the same data many times is redundancy; it wastes space.
The number of tuples (rows) in a relation is its
(d) cardinality Cardinality counts the rows. (Degree counts the columns.)
A row of a relation is called a
(c) tuple Each row holds one record and is called a tuple.
What are the degree and cardinality of the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price |
|---|---|---|---|---|---|---|
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 |
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 |
(c) 7 and 4 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
(c) 8 and 4 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
(c) 8 and 5 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|
| E102 | seema@co.in | Seema | 2020-01-15 | 58000 | NULL |
| E107 | yamini@co.in | Yamini | 2017-12-12 | 81000 | NULL |
| E105 | vikas@co.in | Vikas | 2019-11-05 | 64000 | 4000 |
| E103 | tarun@co.in | Tarun | 2016-09-20 | 75000 | 5000 |
| E101 | ravi@co.in | Ravi | 2018-06-01 | 42000 | 3000 |
| E104 | usha@co.in | Usha | 2021-03-10 | 36000 | NULL |
(c) 6 and 6 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
A collection of related data stored in an organised way is a
(b) database A database stores related data, such as all student records, in an organised way.
The structure (design) of a database, such as table names and columns, is the
(a) schema The schema is the design: tables, columns and types.
The set of all possible values that an attribute can take is its
(d) domain The domain is the set of allowed values, such as {M, F} for Gender.
If EmpID is the primary key of the table EMPLOYEE given below, which is its alternate key?
Table: EMPLOYEE
| EmpID | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|
| E105 | vikas@co.in | Pune | 2019-11-05 | 64000 | 4000 |
| E101 | ravi@co.in | Delhi | 2018-06-01 | 42000 | 3000 |
| E103 | tarun@co.in | Delhi | 2016-09-20 | 75000 | 5000 |
| E107 | yamini@co.in | Mumbai | 2017-12-12 | 81000 | NULL |
| E102 | seema@co.in | Pune | 2020-01-15 | 58000 | NULL |
| E106 | wasim@co.in | Delhi | 2022-07-25 | 39000 | 2000 |
| E104 | usha@co.in | Mumbai | 2021-03-10 | 36000 | NULL |
(b) Email Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table STUDENT given below can be a candidate key?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Phone |
|---|---|---|---|---|
| 2 | 4512 | Bhavya | B | NULL |
| 4 | 4534 | Divya | C | 9810044444 |
| 5 | 4545 | Eshan | B | NULL |
| 3 | 4523 | Chirag | A | 9810033333 |
| 6 | 4556 | Farah | A | 9810066666 |
| 1 | 4501 | Aarav | A | 9810011111 |
| 7 | 4567 | Gaurav | C | 9810077777 |
(b) RollNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table PRODUCT given below can be a candidate key?
Table: PRODUCT
| PCode | Barcode | Category | MfgDate | Price |
|---|---|---|---|---|
| P04 | 89010044 | Electronics | 2026-02-20 | 650 |
| P02 | 89010022 | Electronics | 2025-08-15 | 450 |
| P05 | 89010055 | Home | 2025-05-30 | 320 |
| P07 | 89010077 | Home | 2025-12-18 | 275 |
| P06 | 89010066 | Electronics | 2026-03-05 | 899 |
(a) PCode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Gender | Phone |
|---|---|---|---|---|
| 7 | 4567 | Gaurav | M | 9810077777 |
| 3 | 4523 | Chirag | M | 9810033333 |
| 4 | 4534 | Divya | F | 9810044444 |
(c) 5 and 3 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
State True or False: A table can have more than one candidate key.
(a) True Yes; for example both RollNo and AdmNo can identify every student.
Candidate keys that are not chosen as the primary key are
(a) alternate keys The remaining candidate keys are called alternate keys.
If PID is the primary key of the table PATIENT given below, which is its alternate key?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
(a) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If PID is the primary key of the table PATIENT given below, which is its alternate key?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
(a) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
The number of attributes (columns) in a relation is its
(c) degree Degree counts the columns. (Cardinality counts the rows.)
What are the degree and cardinality of the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
(d) 8 and 6 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If PCode is the primary key of the table PRODUCT given below, which is its alternate key?
Table: PRODUCT
| PCode | Barcode | PName | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|
| P02 | 89010022 | Pen Drive | SanDisk | 2025-08-15 | 450 | NULL |
| P01 | 89010011 | Notebook | Classmate | 2026-01-10 | 60 | 5 |
| P07 | 89010077 | Lunch Box | Milton | 2025-12-18 | 275 | 8 |
| P06 | 89010066 | Earphones | Boat | 2026-03-05 | 899 | 20 |
| P04 | 89010044 | Mouse | Logitech | 2026-02-20 | 650 | 15 |
(a) Barcode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If RollNo is the primary key of the table STUDENT given below, which is its alternate key?
Table: STUDENT
| RollNo | AdmNo | Gender | Marks | Phone |
|---|---|---|---|---|
| 4 | 4534 | F | 66 | 9810044444 |
| 7 | 4567 | M | 59 | 9810077777 |
| 3 | 4523 | M | 45 | 9810033333 |
| 1 | 4501 | M | 78 | 9810011111 |
| 6 | 4556 | F | 31 | 9810066666 |
| 5 | 4545 | M | 88 | NULL |
| 2 | 4512 | F | 92 | NULL |
(a) AdmNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table EMPLOYEE given below can be a candidate key?
Table: EMPLOYEE
| EmpID | EName | Dept | DOJ | Salary | |
|---|---|---|---|---|---|
| E105 | vikas@co.in | Vikas | IT | 2019-11-05 | 64000 |
| E106 | wasim@co.in | Wasim | HR | 2022-07-25 | 39000 |
| E107 | yamini@co.in | Yamini | IT | 2017-12-12 | 81000 |
| E101 | ravi@co.in | Ravi | Sales | 2018-06-01 | 42000 |
| E102 | seema@co.in | Seema | HR | 2020-01-15 | 58000 |
| E103 | tarun@co.in | Tarun | IT | 2016-09-20 | 75000 |
(d) Email Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table BOOK given below can be a candidate key?
Table: BOOK
| BookID | ISBN | Title | IssueDate | Price | Member |
|---|---|---|---|---|---|
| 203 | 9780143032311 | Wings of Fire | 2026-06-21 | 299 | Ravi |
| 202 | 9789352920112 | Physics Part 1 | 2026-07-10 | 180 | NULL |
| 201 | 9789352921485 | Informatics Practices | 2026-07-03 | 210 | Asha |
| 207 | 9789386551023 | Learn SQL | 2026-08-12 | 400 | Karan |
(b) BookID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If BookID is the primary key of the table BOOK given below, which is its alternate key?
Table: BOOK
| BookID | ISBN | Title | IssueDate | Member |
|---|---|---|---|---|
| 205 | 9789352925032 | Chemistry Part 1 | 2026-07-15 | Neha |
| 202 | 9789352920112 | Physics Part 1 | 2026-07-10 | NULL |
| 207 | 9789386551023 | Learn SQL | 2026-08-12 | Karan |
| 203 | 9780143032311 | Wings of Fire | 2026-06-21 | Ravi |
| 206 | 9780140449136 | The Story of My Experiments | 2026-05-30 | NULL |
| 204 | 9789386551009 | Python Basics | 2026-08-01 | NULL |
(c) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
A table has 5 columns and 8 rows. Its degree and cardinality are
(a) 5 and 8 Degree = number of columns = 5; cardinality = number of rows = 8.
A table has 5 columns. A new column is added. The new degree is
(d) 6 Degree is the number of columns: 5 + 1 = 6.
If PCode is the primary key of the table PRODUCT given below, which is its alternate key?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
(a) Barcode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Software used to create and manage a database is a
(d) DBMS A DBMS (Database Management System) is the software; MySQL is an example.
Which column of the table EMPLOYEE given below can be a candidate key?
Table: EMPLOYEE
| EmpID | Dept | City | DOJ | Bonus | |
|---|---|---|---|---|---|
| E106 | wasim@co.in | HR | Delhi | 2022-07-25 | 2000 |
| E102 | seema@co.in | HR | Pune | 2020-01-15 | NULL |
| E103 | tarun@co.in | IT | Delhi | 2016-09-20 | 5000 |
| E105 | vikas@co.in | IT | Pune | 2019-11-05 | 4000 |
| E104 | usha@co.in | Sales | Mumbai | 2021-03-10 | NULL |
(d) Email Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table STUDENT given below can be a candidate key?
Table: STUDENT
| RollNo | AdmNo | Name | Gender | Marks |
|---|---|---|---|---|
| 5 | 4545 | Eshan | M | 88 |
| 7 | 4567 | Gaurav | M | 59 |
| 4 | 4534 | Divya | F | 66 |
| 6 | 4556 | Farah | F | 31 |
(b) RollNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table BOOK given below?
Table: BOOK
| BookID | ISBN | Subject | Publisher | Price |
|---|---|---|---|---|
| 201 | 9789352921485 | Computer | NCERT | 210 |
| 202 | 9789352920112 | Science | NCERT | 180 |
| 203 | 9780143032311 | Biography | Universities | 299 |
| 206 | 9780140449136 | Biography | Penguin | 250 |
| 207 | 9789386551023 | Computer | BPB | 400 |
| 204 | 9789386551009 | Computer | BPB | 350 |
| 205 | 9789352925032 | Science | NCERT | 190 |
(c) 5 and 7 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table PATIENT given below can be a candidate key?
Table: PATIENT
| PID | Aadhaar | PName | Ward | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|
| 16 | 623462346234 | Rekha | Maternity | 2026-09-18 | 4500 | NULL |
| 15 | 523452345234 | Qasim | ICU | 2026-09-15 | 9500 | NULL |
| 12 | 223422342234 | Nisha | ICU | 2026-09-05 | 8000 | NULL |
(c) PID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|
| E106 | wasim@co.in | Wasim | HR | 2022-07-25 | 39000 | 2000 |
| E102 | seema@co.in | Seema | HR | 2020-01-15 | 58000 | NULL |
| E107 | yamini@co.in | Yamini | IT | 2017-12-12 | 81000 | NULL |
(c) 7 and 3 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If BookID is the primary key of the table BOOK given below, which is its alternate key?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Member |
|---|---|---|---|---|---|---|
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | Neha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | Ravi |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | Karan |
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | Asha |
(c) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If BookID is the primary key of the table BOOK given below, which is its alternate key?
Table: BOOK
| BookID | ISBN | Title | IssueDate | Member |
|---|---|---|---|---|
| 207 | 9789386551023 | Learn SQL | 2026-08-12 | Karan |
| 203 | 9780143032311 | Wings of Fire | 2026-06-21 | Ravi |
| 206 | 9780140449136 | The Story of My Experiments | 2026-05-30 | NULL |
(c) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table PATIENT given below can be a candidate key?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee |
|---|---|---|---|---|---|---|
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 |
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 |
(c) PID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
(c) 8 and 3 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table PRODUCT given below can be a candidate key?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
(a) PCode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table PATIENT given below can be a candidate key?
Table: PATIENT
| PID | Aadhaar | Doctor | Fee | Insurance |
|---|---|---|---|---|
| 16 | 623462346234 | Dr. Iyer | 4500 | NULL |
| 13 | 323432343234 | Dr. Rao | 1200 | Star |
| 15 | 523452345234 | Dr. Sen | 9500 | NULL |
| 17 | 723472347234 | Dr. Rao | 900 | Star |
| 12 | 223422342234 | Dr. Sen | 8000 | NULL |
| 11 | 123412341234 | Dr. Rao | 1500 | LIC |
(c) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
An attribute (or set of attributes) that can uniquely identify each tuple is a
(c) candidate key Any column whose value is different in every row can be a candidate key.
If PCode is the primary key of the table PRODUCT given below, which is its alternate key?
Table: PRODUCT
| PCode | Barcode | PName | Category | MfgDate |
|---|---|---|---|---|
| P02 | 89010022 | Pen Drive | Electronics | 2025-08-15 |
| P03 | 89010033 | Geometry Box | Stationery | 2025-11-02 |
| P05 | 89010055 | Water Bottle | Home | 2025-05-30 |
| P04 | 89010044 | Mouse | Electronics | 2026-02-20 |
| P06 | 89010066 | Earphones | Electronics | 2026-03-05 |
| P01 | 89010011 | Notebook | Stationery | 2026-01-10 |
| P07 | 89010077 | Lunch Box | Home | 2025-12-18 |
(a) Barcode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If RollNo is the primary key of the table STUDENT given below, which is its alternate key?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
(a) AdmNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | MfgDate | Price | Discount |
|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | 2026-01-10 | 60 | 5 |
| P07 | 89010077 | Lunch Box | 2025-12-18 | 275 | 8 |
| P04 | 89010044 | Mouse | 2026-02-20 | 650 | 15 |
| P03 | 89010033 | Geometry Box | 2025-11-02 | 180 | 10 |
| P06 | 89010066 | Earphones | 2026-03-05 | 899 | 20 |
(c) 6 and 5 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
In a table EMP, every employee has a unique Email and a unique EmpID. These two columns are
(a) candidate keys Both columns are unique for every row, so both are candidate keys.
What are the degree and cardinality of the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Section | DOB | Phone |
|---|---|---|---|---|
| 6 | 4556 | A | 2009-09-09 | 9810066666 |
| 2 | 4512 | B | 2009-11-30 | NULL |
| 4 | 4534 | C | 2009-07-21 | 9810044444 |
| 5 | 4545 | B | 2010-03-17 | NULL |
| 3 | 4523 | A | 2010-01-05 | 9810033333 |
| 7 | 4567 | C | 2010-02-28 | 9810077777 |
| 1 | 4501 | A | 2009-04-12 | 9810011111 |
(c) 5 and 7 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table EMPLOYEE given below can be a candidate key?
Table: EMPLOYEE
| EmpID | EName | Salary | Bonus | |
|---|---|---|---|---|
| E104 | usha@co.in | Usha | 36000 | NULL |
| E102 | seema@co.in | Seema | 58000 | NULL |
| E103 | tarun@co.in | Tarun | 75000 | 5000 |
| E106 | wasim@co.in | Wasim | 39000 | 2000 |
| E105 | vikas@co.in | Vikas | 64000 | 4000 |
| E107 | yamini@co.in | Yamini | 81000 | NULL |
| E101 | ravi@co.in | Ravi | 42000 | 3000 |
(d) Email Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | Ward | Fee | Insurance |
|---|---|---|---|---|
| 11 | 123412341234 | General | 1500 | LIC |
| 17 | 723472347234 | General | 900 | Star |
| 15 | 523452345234 | ICU | 9500 | NULL |
(d) 5 and 3 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
(c) 8 and 4 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If BookID is the primary key of the table BOOK given below, which is its alternate key?
Table: BOOK
| BookID | ISBN | Title | IssueDate | Price | Member |
|---|---|---|---|---|---|
| 202 | 9789352920112 | Physics Part 1 | 2026-07-10 | 180 | NULL |
| 207 | 9789386551023 | Learn SQL | 2026-08-12 | 400 | Karan |
| 204 | 9789386551009 | Python Basics | 2026-08-01 | 350 | NULL |
| 203 | 9780143032311 | Wings of Fire | 2026-06-21 | 299 | Ravi |
| 205 | 9789352925032 | Chemistry Part 1 | 2026-07-15 | 190 | Neha |
(c) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If EmpID is the primary key of the table EMPLOYEE given below, which is its alternate key?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
(b) Email Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
A primary key column
(b) cannot have NULL or repeated values A primary key must identify every row, so it cannot be empty (NULL) or repeated.
If BookID is the primary key of the table BOOK given below, which is its alternate key?
Table: BOOK
| BookID | ISBN | Subject | IssueDate | Member |
|---|---|---|---|---|
| 204 | 9789386551009 | Computer | 2026-08-01 | NULL |
| 203 | 9780143032311 | Biography | 2026-06-21 | Ravi |
| 207 | 9789386551023 | Computer | 2026-08-12 | Karan |
| 202 | 9789352920112 | Science | 2026-07-10 | NULL |
| 201 | 9789352921485 | Computer | 2026-07-03 | Asha |
| 205 | 9789352925032 | Science | 2026-07-15 | Neha |
| 206 | 9780140449136 | Biography | 2026-05-30 | NULL |
(c) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table PATIENT given below can be a candidate key?
Table: PATIENT
| PID | Aadhaar | Ward | AdmitDate | Fee |
|---|---|---|---|---|
| 15 | 523452345234 | ICU | 2026-09-15 | 9500 |
| 11 | 123412341234 | General | 2026-09-02 | 1500 |
| 17 | 723472347234 | General | 2026-09-20 | 900 |
(c) PID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table BOOK given below?
Table: BOOK
| BookID | ISBN | Publisher | IssueDate | Member |
|---|---|---|---|---|
| 204 | 9789386551009 | BPB | 2026-08-01 | NULL |
| 205 | 9789352925032 | NCERT | 2026-07-15 | Neha |
| 202 | 9789352920112 | NCERT | 2026-07-10 | NULL |
(c) 5 and 3 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | Price | Discount |
|---|---|---|---|---|---|---|
| P05 | 89010055 | Water Bottle | Home | Milton | 320 | NULL |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 180 | 10 |
| P01 | 89010011 | Notebook | Stationery | Classmate | 60 | 5 |
| P07 | 89010077 | Lunch Box | Home | Milton | 275 | 8 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 650 | 15 |
| P06 | 89010066 | Earphones | Electronics | Boat | 899 | 20 |
(c) 7 and 7 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | DOJ | Salary | |
|---|---|---|---|---|---|
| E104 | usha@co.in | Usha | Sales | 2021-03-10 | 36000 |
| E101 | ravi@co.in | Ravi | Sales | 2018-06-01 | 42000 |
| E102 | seema@co.in | Seema | HR | 2020-01-15 | 58000 |
| E103 | tarun@co.in | Tarun | IT | 2016-09-20 | 75000 |
| E106 | wasim@co.in | Wasim | HR | 2022-07-25 | 39000 |
| E107 | yamini@co.in | Yamini | IT | 2017-12-12 | 81000 |
| E105 | vikas@co.in | Vikas | IT | 2019-11-05 | 64000 |
(c) 6 and 7 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which is NOT an advantage of a DBMS?
(d) More data redundancy A DBMS reduces redundancy; more redundancy is a problem, not an advantage.
The data stored in a database at a given moment is the
(d) instance (state) The instance is the actual data at a moment; it changes as rows are added or changed.
A table has 6 rows and 4 columns. Two rows are deleted. The new cardinality is
(b) 4 Cardinality is the number of rows: 6 - 2 = 4. The degree stays 4.
Which column of the table PRODUCT given below can be a candidate key?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | Price | Discount |
|---|---|---|---|---|---|---|
| P06 | 89010066 | Earphones | Electronics | Boat | 899 | 20 |
| P01 | 89010011 | Notebook | Stationery | Classmate | 60 | 5 |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 180 | 10 |
| P05 | 89010055 | Water Bottle | Home | Milton | 320 | NULL |
(a) Barcode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If PID is the primary key of the table PATIENT given below, which is its alternate key?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
(a) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table BOOK given below?
Table: BOOK
| BookID | ISBN | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|
| 202 | 9789352920112 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 207 | 9789386551023 | Computer | BPB | 2026-08-12 | 400 | Karan |
| 204 | 9789386551009 | Computer | BPB | 2026-08-01 | 350 | NULL |
| 206 | 9780140449136 | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 203 | 9780143032311 | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 201 | 9789352921485 | Computer | NCERT | 2026-07-03 | 210 | Asha |
(c) 7 and 6 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
The candidate key chosen to identify the rows of a table is the
(c) primary key Out of the candidate keys, the one we choose is the primary key.
If RollNo is the primary key of the table STUDENT given below, which is its alternate key?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
(a) AdmNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Brand | Discount |
|---|---|---|---|---|
| P05 | 89010055 | Water Bottle | Milton | NULL |
| P06 | 89010066 | Earphones | Boat | 20 |
| P01 | 89010011 | Notebook | Classmate | 5 |
| P02 | 89010022 | Pen Drive | SanDisk | NULL |
| P04 | 89010044 | Mouse | Logitech | 15 |
| P07 | 89010077 | Lunch Box | Milton | 8 |
| P03 | 89010033 | Geometry Box | Camlin | 10 |
(c) 5 and 7 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table PATIENT given below can be a candidate key?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
(c) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Publisher | IssueDate |
|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | NCERT | 2026-07-03 |
| 206 | 9780140449136 | The Story of My Experiments | Penguin | 2026-05-30 |
| 207 | 9789386551023 | Learn SQL | BPB | 2026-08-12 |
| 204 | 9789386551009 | Python Basics | BPB | 2026-08-01 |
| 205 | 9789352925032 | Chemistry Part 1 | NCERT | 2026-07-15 |
(c) 5 and 5 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
In the relational model, a table is called a
(a) relation In the relational model a table is called a relation.
If RollNo is the primary key of the table STUDENT given below, which is its alternate key?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
(a) AdmNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table EMPLOYEE given below can be a candidate key?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
(d) Email Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table STUDENT given below can be a candidate key?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
(b) AdmNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table PRODUCT given below can be a candidate key?
Table: PRODUCT
| PCode | Barcode | PName | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Classmate | 2026-01-10 | 60 | 5 |
| P06 | 89010066 | Earphones | Boat | 2026-03-05 | 899 | 20 |
| P03 | 89010033 | Geometry Box | Camlin | 2025-11-02 | 180 | 10 |
(a) PCode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If PID is the primary key of the table PATIENT given below, which is its alternate key?
Table: PATIENT
| PID | Aadhaar | Ward | Doctor | Insurance |
|---|---|---|---|---|
| 14 | 423442344234 | Maternity | Dr. Iyer | LIC |
| 13 | 323432343234 | General | Dr. Rao | Star |
| 15 | 523452345234 | ICU | Dr. Sen | NULL |
| 11 | 123412341234 | General | Dr. Rao | LIC |
| 17 | 723472347234 | General | Dr. Rao | Star |
| 12 | 223422342234 | ICU | Dr. Sen | NULL |
(a) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If PID is the primary key of the table PATIENT given below, which is its alternate key?
Table: PATIENT
| PID | Aadhaar | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|
| 13 | 323432343234 | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 12 | 223422342234 | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
(a) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
A column of a relation is called an
(a) attribute Each column is an attribute, such as Name or Marks.
Which column of the table BOOK given below can be a candidate key?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
(b) BookID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | Marks | Phone |
|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 78 | 9810011111 |
| 4 | 4534 | Divya | C | F | 66 | 9810044444 |
| 2 | 4512 | Bhavya | B | F | 92 | NULL |
(c) 7 and 3 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
Which column of the table BOOK given below can be a candidate key?
Table: BOOK
| BookID | ISBN | Title | Publisher | Price |
|---|---|---|---|---|
| 204 | 9789386551009 | Python Basics | BPB | 350 |
| 202 | 9789352920112 | Physics Part 1 | NCERT | 180 |
| 207 | 9789386551023 | Learn SQL | BPB | 400 |
| 201 | 9789352921485 | Informatics Practices | NCERT | 210 |
| 203 | 9780143032311 | Wings of Fire | Universities | 299 |
| 205 | 9789352925032 | Chemistry Part 1 | NCERT | 190 |
| 206 | 9780140449136 | The Story of My Experiments | Penguin | 250 |
(b) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
What are the degree and cardinality of the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | |
|---|---|---|---|---|---|---|
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 |
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 |
(c) 7 and 5 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
If RollNo is the primary key of the table STUDENT given below, which is its alternate key?
Table: STUDENT
| RollNo | AdmNo | Name | Gender | Marks |
|---|---|---|---|---|
| 4 | 4534 | Divya | F | 66 |
| 2 | 4512 | Bhavya | F | 92 |
| 6 | 4556 | Farah | F | 31 |
| 7 | 4567 | Gaurav | M | 59 |
| 3 | 4523 | Chirag | M | 45 |
(a) AdmNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.
SQL stands for
(a) Structured Query Language SQL is Structured Query Language, used to work with relational databases.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT * FROM BOOK WHERE Subject = 'Computer';
(c) 3 Rows that satisfy the condition: 3.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT Title, Member FROM BOOK WHERE Member IS NOT NULL;
(c) 4 Rows that satisfy the condition: 4.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 70000;
(c) 3 Rows that satisfy the condition: 3.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName, Dept FROM EMPLOYEE WHERE NOT Dept = 'IT';
(c) 4 Rows that satisfy the condition: 4.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name, Marks FROM STUDENT WHERE Marks > 70;
(d) 3 Rows that satisfy the condition: 3.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name, Section FROM STUDENT WHERE NOT Section = 'A';
(c) 4 Rows that satisfy the condition: 4.
Which command adds a new column to an existing table?
(a) ALTER TABLE ... ADD ALTER TABLE STUDENT ADD Phone VARCHAR(10); adds a column.
Which of these is a DML command?
(c) UPDATE UPDATE changes the data in rows, so it is DML; CREATE, DROP, ALTER are DDL.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 100 AND 500;
(c) 4 Rows that satisfy the condition: 4.
Which constraint stops a column from having empty values?
(c) NOT NULL NOT NULL forces a value to be given in every row.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT * FROM STUDENT WHERE Section = 'B';
(d) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT BookID, Title, Price FROM BOOK WHERE Price BETWEEN 250 AND 300;
(b) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PID, PName, Fee FROM PATIENT WHERE Fee BETWEEN 1000 AND 1500;
(d) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 50000 AND 70000;
(a) 2 Rows that satisfy the condition: 2.
Which logical operator returns rows only when both conditions are true?
(a) AND AND needs both conditions to be true; OR needs at least one.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName FROM EMPLOYEE WHERE Dept = 'HR' AND Salary >= 40000;
(a) 1 Rows that satisfy the condition: 1.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT BookID, Title, Price FROM BOOK WHERE Price BETWEEN 200 AND 350;
(a) 4 Rows that satisfy the condition: 4.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName, Salary FROM EMPLOYEE WHERE Salary < 40000 OR Bonus IS NULL;
(c) 4 Rows that satisfy the condition: 4.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName FROM PATIENT WHERE Insurance IS NULL;
(a) 3 Rows that satisfy the condition: 3.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PName, Price FROM PRODUCT WHERE Price > 100;
(b) 6 Rows that satisfy the condition: 6.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT Title FROM BOOK WHERE Subject = 'Science' AND Price >= 200;
(d) 0 Rows that satisfy the condition: 0.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name FROM STUDENT WHERE Gender = 'F' AND Phone IS NOT NULL;
(c) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'IT' OR Dept = 'HR';
(b) 5 Rows that satisfy the condition: 5.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT Title FROM BOOK WHERE Subject = 'Biography' AND Price >= 250;
(b) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PName FROM PRODUCT WHERE Category = 'Home' AND Price >= 100;
(b) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName FROM EMPLOYEE WHERE Bonus IS NULL;
(d) 3 Rows that satisfy the condition: 3.
Which command lists all the tables of the current database?
(b) SHOW TABLES; SHOW TABLES; lists the tables of the database in use.
State True or False: SQL keywords are not case sensitive.
(a) True SELECT, select and Select all work the same.
State True or False: DELETE FROM T; removes the table T from the database.
(b) False It removes all rows; DROP TABLE removes the table.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName FROM PATIENT WHERE Ward = 'General' AND Fee >= 1000;
(d) 2 Rows that satisfy the condition: 2.
Which query shows the students with marks from 60 to 80?
(a) SELECT * FROM STUDENT WHERE Marks BETWEEN 60 AND 80; BETWEEN 60 AND 80 includes both ends, so this is the correct way.
Which command removes rows but keeps the structure of the table?
(d) DELETE DELETE FROM removes rows; the empty table remains.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 50 AND 60;
(a) 1 Rows that satisfy the condition: 1.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
(d) 5 Rows that satisfy the condition: 5.
Which command deletes a whole database?
(c) DROP DATABASE DROP DATABASE SCHOOL; removes the database with all its tables.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT Title, Price FROM BOOK WHERE Price > 350;
(b) 1 Rows that satisfy the condition: 1.
State True or False: BETWEEN 10 AND 20 includes 10 and 20.
(a) True BETWEEN includes both end values.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
(b) 3 Rows that satisfy the condition: 3.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
(c) 4 Rows that satisfy the condition: 4.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'NCERT';
(d) 4 Rows that satisfy the condition: 4.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT * FROM PRODUCT WHERE Category = 'Home';
(c) 2 Rows that satisfy the condition: 2.
Which data type stores a fixed-length string?
(c) CHAR CHAR(n) always uses n characters of space.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT * FROM STUDENT WHERE Section = 'A';
(b) 3 Rows that satisfy the condition: 3.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName FROM EMPLOYEE WHERE Dept = 'HR' AND Salary >= 50000;
(c) 1 Rows that satisfy the condition: 1.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName FROM EMPLOYEE WHERE City = 'Mumbai' AND Bonus IS NOT NULL;
(d) 0 Rows that satisfy the condition: 0.
Which keyword gives values in a range, both ends included?
(a) BETWEEN BETWEEN 60 AND 80 includes 60, 80 and every value in between.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT * FROM PATIENT WHERE Ward = 'General';
(c) 3 Rows that satisfy the condition: 3.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Stationery';
(c) 5 Rows that satisfy the condition: 5.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName FROM PATIENT WHERE Ward = 'ICU' AND Fee >= 1000;
(d) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName FROM PATIENT WHERE Ward = 'Maternity' AND Fee >= 1500;
(d) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 70000;
(b) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName, Fee FROM PATIENT WHERE Fee < 4000 OR Insurance IS NULL;
(d) 6 Rows that satisfy the condition: 6.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';
(a) 3 Rows that satisfy the condition: 3.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT Title, Price FROM BOOK WHERE Price < 250 OR Member IS NULL;
(b) 5 Rows that satisfy the condition: 5.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName, Dept FROM EMPLOYEE WHERE NOT Dept = 'Sales';
(b) 5 Rows that satisfy the condition: 5.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name FROM STUDENT WHERE Section = 'A' AND Marks >= 60;
(a) 1 Rows that satisfy the condition: 1.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PName FROM PRODUCT WHERE Discount IS NULL;
(c) 2 Rows that satisfy the condition: 2.
SELECT is a
(a) DQL command SELECT only reads (queries) the data, so it is DQL (Data Query Language).
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
(d) 4 Rows that satisfy the condition: 4.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT Title, Subject FROM BOOK WHERE NOT Subject = 'Science';
(d) 5 Rows that satisfy the condition: 5.
Which command removes a table along with its structure?
(d) DROP TABLE DROP TABLE removes the table itself, with its structure and data.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName FROM EMPLOYEE WHERE Dept = 'IT' AND Salary >= 70000;
(a) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName FROM PATIENT WHERE Doctor = 'Dr. Sen' AND Insurance IS NOT NULL;
(d) 0 Rows that satisfy the condition: 0.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Electronics';
(c) 4 Rows that satisfy the condition: 4.
Every SQL statement in MySQL ends with a
(b) semicolon (;) The semicolon tells MySQL that the statement is complete.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT Title FROM BOOK WHERE Member IS NULL;
(c) 3 Rows that satisfy the condition: 3.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName FROM EMPLOYEE WHERE City = 'Pune' AND Bonus IS NOT NULL;
(c) 1 Rows that satisfy the condition: 1.
Which clause filters rows in a SELECT query?
(d) WHERE WHERE gives the condition; only rows that satisfy it are shown.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name, Gender FROM STUDENT WHERE Gender <> 'M';
(a) 3 Rows that satisfy the condition: 3.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Home';
(c) 5 Rows that satisfy the condition: 5.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PName, MfgDate FROM PRODUCT WHERE MfgDate BETWEEN '2025-10-01' AND '2026-01-31';
(c) 3 Rows that satisfy the condition: 3.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PName, Category FROM PRODUCT WHERE Category = 'Electronics' OR Category = 'Stationery';
(c) 5 Rows that satisfy the condition: 5.
Which data type is best for storing a phone number such as 9810011111?
(d) VARCHAR(10) (or CHAR(10)) A phone number is not used for calculation and may start with 0 or +, so text type is best.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName, Ward FROM PATIENT WHERE NOT Ward = 'Maternity';
(d) 5 Rows that satisfy the condition: 5.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'BPB';
(b) 5 Rows that satisfy the condition: 5.
The correct way to find rows where Phone has no value is
(a) WHERE Phone IS NULL NULL means unknown, so = NULL never matches; IS NULL is used.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName, Fee FROM PATIENT WHERE Fee < 1500 OR Insurance IS NULL;
(d) 5 Rows that satisfy the condition: 5.
Which constraint allows only different values in a column?
(d) UNIQUE UNIQUE does not allow the same value in two rows.
DELETE FROM STUDENT; without WHERE will
(d) delete all the rows but keep the table All rows are deleted but the table structure remains; DROP would remove the table.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName, Ward FROM PATIENT WHERE Ward = 'ICU' OR Ward = 'Maternity';
(c) 4 Rows that satisfy the condition: 4.
Which command removes the column Phone from STUDENT?
(a) ALTER TABLE STUDENT DROP Phone; Changing the structure needs ALTER; ALTER TABLE STUDENT DROP Phone; removes the column.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT Title FROM BOOK WHERE Publisher = 'Penguin' AND Member IS NOT NULL;
(c) 0 Rows that satisfy the condition: 0.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName, Doctor FROM PATIENT WHERE Doctor <> 'Dr. Sen';
(d) 5 Rows that satisfy the condition: 5.
In SQL, the 'not equal to' operator is
(b) <> (or !=) Both <> and != mean not equal to in MySQL.
Which command adds a primary key to an existing table T on column ID?
(b) ALTER TABLE T ADD PRIMARY KEY (ID); ALTER TABLE T ADD PRIMARY KEY (ID); sets ID as the primary key.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
(a) 5 Rows that satisfy the condition: 5.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT * FROM PRODUCT WHERE Category = 'Electronics';
(b) 3 Rows that satisfy the condition: 3.
Which SQL command creates a new table?
(d) CREATE TABLE CREATE TABLE name (columns ...); makes a new table.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name FROM STUDENT WHERE Gender = 'M' AND Phone IS NOT NULL;
(c) 3 Rows that satisfy the condition: 3.
Which is the correct way to write a date in a MySQL query?
(c) '2009-04-12' MySQL dates are written in quotes in the order year-month-day.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name, Section FROM STUDENT WHERE Section = 'C' OR Section = 'B';
(c) 4 Rows that satisfy the condition: 4.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 50 AND 70;
(b) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'Sales' OR Dept = 'IT';
(a) 5 Rows that satisfy the condition: 5.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName FROM PATIENT WHERE Doctor = 'Dr. Iyer' AND Insurance IS NOT NULL;
(b) 1 Rows that satisfy the condition: 1.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 60000;
(d) 2 Rows that satisfy the condition: 2.
Which command is used to select a database for use?
(b) USE USE SCHOOL; opens the database SCHOOL for the commands that follow.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName, Ward FROM PATIENT WHERE Ward = 'General' OR Ward = 'ICU';
(d) 5 Rows that satisfy the condition: 5.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT Title, Price FROM BOOK WHERE Price < 300 OR Member IS NULL;
(c) 6 Rows that satisfy the condition: 6.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName, Ward FROM PATIENT WHERE NOT Ward = 'ICU';
(c) 5 Rows that satisfy the condition: 5.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT Title FROM BOOK WHERE Publisher = 'NCERT' AND Member IS NOT NULL;
(a) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName, Bonus FROM EMPLOYEE WHERE Bonus IS NOT NULL;
(c) 4 Rows that satisfy the condition: 4.
Which operator would you use to find employees not in the Sales department?
(a) <> (or NOT ... =) WHERE Dept <> 'Sales' (or WHERE NOT Dept = 'Sales') gives all other departments.
Which command shows the structure of a table?
(c) DESCRIBE (DESC) DESCRIBE STUDENT; (or DESC STUDENT;) shows the columns, types, NULL and keys.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name FROM STUDENT WHERE Section = 'B' AND Marks >= 50;
(d) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 60000 AND 70000;
(d) 1 Rows that satisfy the condition: 1.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT Title FROM BOOK WHERE Subject = 'Computer' AND Price >= 350;
(c) 2 Rows that satisfy the condition: 2.
Which data type stores a variable-length string?
(b) VARCHAR VARCHAR(n) uses only as much space as the value needs, up to n.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName FROM EMPLOYEE WHERE City = 'Delhi' AND Bonus IS NOT NULL;
(d) 3 Rows that satisfy the condition: 3.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PName FROM PRODUCT WHERE Brand = 'Milton' AND Discount IS NOT NULL;
(d) 1 Rows that satisfy the condition: 1.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name, Section FROM STUDENT WHERE Section = 'B' OR Section = 'C';
(b) 4 Rows that satisfy the condition: 4.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Delhi';
(a) 4 Rows that satisfy the condition: 4.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name, Gender FROM STUDENT WHERE Gender <> 'F';
(d) 4 Rows that satisfy the condition: 4.
INSERT INTO STUDENT (RollNo, Name) VALUES (9, 'Isha'); stores what in the other columns?
(c) NULL (unless a default is set) Columns not given a value get NULL, unless a DEFAULT is set (and they are not NOT NULL).
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name, Marks FROM STUDENT WHERE Marks < 70 OR Phone IS NULL;
(c) 6 Rows that satisfy the condition: 6.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT * FROM STUDENT WHERE Section = 'C';
(d) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PName, Brand FROM PRODUCT WHERE Brand <> 'Boat';
(d) 6 Rows that satisfy the condition: 6.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Pune';
(a) 5 Rows that satisfy the condition: 5.
In MySQL, a date is written in the format
(b) 'YYYY-MM-DD' Dates are written in quotes as 'YYYY-MM-DD', e.g. '2009-04-12'.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName FROM PATIENT WHERE Ward = 'General' AND Fee >= 6000;
(d) 0 Rows that satisfy the condition: 0.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name FROM STUDENT WHERE Phone IS NULL;
(c) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name FROM STUDENT WHERE Section = 'A' AND Marks >= 80;
(b) 0 Rows that satisfy the condition: 0.
How many rows will the query display for the table STUDENT given below?
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
SELECT Name, Marks FROM STUDENT WHERE Marks > 60;
(b) 4 Rows that satisfy the condition: 4.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT BookID, Title, Price FROM BOOK WHERE Price BETWEEN 200 AND 300;
(b) 3 Rows that satisfy the condition: 3.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'Penguin';
(c) 6 Rows that satisfy the condition: 6.
How many rows will the query display for the table PATIENT given below?
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
SELECT PName, Fee FROM PATIENT WHERE Fee < 1000 OR Insurance IS NULL;
(d) 4 Rows that satisfy the condition: 4.
UPDATE STUDENT SET Marks = 90; without WHERE will
(b) change the marks of every row to 90 Without WHERE the change applies to every row, so be careful.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PName, Price FROM PRODUCT WHERE Price < 300 OR Discount IS NULL;
(b) 5 Rows that satisfy the condition: 5.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PName, Price FROM PRODUCT WHERE Price > 500;
(a) 2 Rows that satisfy the condition: 2.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PName, Category FROM PRODUCT WHERE Category = 'Home' OR Category = 'Stationery';
(a) 4 Rows that satisfy the condition: 4.
Which command changes the values stored in a table?
(c) UPDATE ... SET UPDATE STUDENT SET Marks = 90 WHERE RollNo = 3; changes values.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Mumbai';
(b) 5 Rows that satisfy the condition: 5.
Which of these is a DDL command?
(c) ALTER ALTER changes the structure of a table, so it is DDL; INSERT, UPDATE are DML; SELECT is DQL.
SELECT * FROM STUDENT; displays
(b) all the columns and rows of STUDENT * means all columns, and without WHERE all rows are shown.
How many rows will the query display for the table PRODUCT given below?
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
SELECT PName FROM PRODUCT WHERE Brand = 'Boat' AND Discount IS NOT NULL;
(a) 1 Rows that satisfy the condition: 1.
How many rows will the query display for the table BOOK given below?
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
SELECT Title, Subject FROM BOOK WHERE Subject = 'Computer' OR Subject = 'Biography';
(b) 5 Rows that satisfy the condition: 5.
How many rows will the query display for the table EMPLOYEE given below?
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
SELECT * FROM EMPLOYEE WHERE Dept = 'IT';
(c) 3 Rows that satisfy the condition: 3.
A device that detects changes such as temperature or motion is a
(a) sensor A sensor detects a physical change and turns it into a signal.
In cloud computing, the user pays
(a) only for the resources used (pay-as-you-go) Cloud services are pay-as-you-go: you pay for what you use.
Netflix suggesting shows based on what you watched is an example of
(a) machine learning (recommendation) The system learns your taste from your history: machine learning.
Which of these is NOT a characteristic (V) of Big Data?
(a) Visibility The Vs are Volume, Velocity, Variety, Veracity and Value; Visibility is not one of them.
A VR headset is used mainly for
(a) immersive experience It gives an immersive experience of a virtual world.
A digital twin, a smart meter and a fitness band are linked to
(b) IoT All of them are connected devices that collect and share data: IoT.
Translating a sentence from Hindi to English automatically is an example of
(c) NLP Translation of human language is a task of NLP.
State True or False: Grid computing uses the computers of many places for one task.
(a) True Grid computing uses unused power of many computers for one task.
Everyday devices connected to the Internet and sharing data form the
(c) Internet of Things (IoT) Smart devices with sensors that share data over the Internet form the IoT.
Making computers understand and speak human languages is
(d) Natural Language Processing (NLP) NLP (Natural Language Processing) deals with human language: speech and text.
A self-driving car mainly uses
(d) AI, sensors and computer vision Cameras and sensors see the road; AI decides how to drive.
In a blockchain, the records are kept
(d) on many computers (decentralised) Copies are kept on many computers (nodes), so there is no single owner.
State True or False: AR replaces the real world completely.
(b) False AR adds to the real world; VR replaces it.
Using computing resources such as storage and software over the Internet, on demand, is
(a) cloud computing Cloud computing gives these resources over the Internet, on demand, pay as you use.
Which technology keeps a record that is very hard to change once added?
(b) Blockchain Changing a block breaks the hash chain on many computers, so blockchain records are tamper-proof.
The 'Value' of Big Data means
(a) the useful insights that can be taken from it Value is the useful knowledge or benefit we get from the data.
The ability of a machine to think and learn like humans is
(c) Artificial Intelligence Artificial Intelligence lets machines learn, reason and take decisions like humans.
Very large data sets that are too big for normal tools are called
(c) Big Data Big Data is data too big, fast or varied for ordinary software.
State True or False: Gmail is an example of SaaS.
(a) True Gmail is ready software used over the Internet.
The large volume of data from sensors in a smart city is an example of
(b) Big Data Huge, fast data from many sensors is Big Data.
Adding digital information on top of the real world, as in Pokemon Go, is
(b) Augmented Reality (AR) AR adds digital images on the camera view of the real world.
Bitcoin is based on
(d) blockchain technology Bitcoin records every transaction in a blockchain.
State True or False: In IoT, devices can share data without human help.
(a) True IoT devices send data to each other and to the cloud automatically.
Which one is a concern with AI?
(c) Bias in decisions learned from biased data AI learns from data; if the data is biased, its decisions can be unfair.
Robots that move on their own and avoid obstacles mainly use
(d) sensors and AI Sensors detect obstacles and AI decides the path.
The 'V' of Big Data that refers to the speed at which data is produced is
(b) Velocity Velocity is the speed at which data is produced, such as posts every second.
A computer-made world that fully replaces what the user sees, using a headset, is
(d) Virtual Reality (VR) In VR the user wears a headset and sees only a computer-made world.
The 'V' of Big Data that refers to the trustworthiness of data is
(a) Veracity Veracity is about how accurate and trustworthy the data is.
Which emerging technology is used by maps apps to show live traffic?
(a) Big Data and IoT (data from phones and sensors) Location data from crores of phones (Big Data from IoT devices) shows live traffic.
Which technology lets a phone translate a menu by pointing the camera at it?
(c) AR with computer vision and NLP The camera view with translated text on top is AR; reading and translating the text needs NLP.
Which of these is an example of a smart city service?
(b) Traffic lights that change with the traffic Smart traffic lights use sensors and data to change with the traffic.
Which of these is an example of IaaS?
(a) Renting virtual servers from Amazon Web Services (EC2) Renting virtual servers is infrastructure; Gmail, Docs, YouTube are SaaS.
Training doctors with 3D virtual operations uses
(d) virtual reality Doctors practise in a fully virtual 3D world: virtual reality.
A part of AI in which machines learn from data without being programmed for every case is
(b) Machine Learning Machine Learning finds patterns in data and improves with experience.
Voice assistants like Alexa and Siri mainly use
(c) NLP They convert speech to text, understand it and reply in speech: that is NLP.
A public cloud is
(b) available to anyone over the Internet A public cloud is offered to anyone over the Internet, such as Google Drive.
Many computers in different places working together on one big task form a
(c) computing grid Grid computing joins many computers to work on one large task.
Which is an example of machine learning?
(c) A spam filter that learns from e-mails marked as spam The filter learns from examples of spam to catch new spam.
A smart home light that turns on when someone enters uses a
(b) motion sensor (IoT) A motion sensor detects the person and the connected bulb switches on: IoT.
Robots that work in car factories mostly do
(a) repetitive tasks like welding and painting Factory robots do repeated, exact jobs like welding and painting.
Each block of a blockchain is linked to the previous block by its
(b) hash Each block stores the hash of the previous block, forming a chain.
Which of these is NOT a cloud service model?
(a) GaaS (Grid as a Service) The three models are SaaS, PaaS and IaaS.
Online storage such as Google Drive and OneDrive is an example of
(b) cloud storage (SaaS) Storage used over the Internet is cloud storage, offered as SaaS.
Which cloud model needs the least technical work from the user?
(c) SaaS In SaaS the user only uses the app; the provider manages everything else.
The 'V' of Big Data that refers to its huge size is
(c) Volume Volume is the huge amount of data, in terabytes and more.
State True or False: Machine learning is a part of Artificial Intelligence.
(a) True ML is one branch of AI.
A temperature sensor in a cold storage that sends alerts to the owner's phone is
(b) an IoT application The sensor sends data over the Internet to the phone: an IoT application.
Chatbots on websites mostly use
(d) NLP and AI Chatbots understand typed questions and reply in language: NLP with AI.
Google Docs and Gmail are examples of
(d) SaaS (Software as a Service) They are ready software used through the browser: Software as a Service.
Smart watches that measure heart rate use
(c) sensors and IoT A heart-rate sensor measures and the watch shares data over the Internet: IoT.
A shared, decentralised ledger in which records are kept in linked blocks is
(c) Blockchain Blockchain keeps records in blocks linked by hashes on many computers.
A machine that can do tasks on its own using sensors and programming is a
(c) robot A robot senses with sensors, decides with a program and acts with motors.
Which is the correct pair?
(d) VR - headset, AR - camera view on a phone VR uses a headset for a full virtual world; AR adds things to the phone camera's view.
The 'V' of Big Data that refers to different forms such as text, images and video is
(d) Variety Variety means many forms: text, images, video, sensor readings.
Which is a use of blockchain other than cryptocurrency?
(b) Keeping land records that cannot be changed secretly Blockchain records cannot be changed secretly, so they suit land records.
Which is an application of AI in daily life?
(d) Face unlock on a phone Face unlock recognises your face using AI; the others need no learning.
Renting virtual machines, storage and networks from the cloud is
(d) IaaS (Infrastructure as a Service) This is the basic infrastructure, so it is IaaS.
Which device is a common example of IoT?
(a) Smart watch A smart watch has sensors and shares data with the phone and the cloud.
Drones and Mars rovers are examples of
(c) robotics Both are robots that move and work on their own.
A cloud service that gives developers a ready platform to build and run apps is
(b) PaaS (Platform as a Service) PaaS gives a platform (OS, tools, database) to build and run apps.
A chatbot that answers questions about train timings uses
(c) NLP Understanding and answering typed questions is NLP.
A city that uses IoT and data to manage traffic, water and electricity is a
(c) smart city A smart city uses sensors and data to run traffic, water, power and waste services.
SETI@home, where home computers help analyse radio signals, is an example of
(b) grid computing Home computers shared their spare power for one big task: grid computing.
Assertion (A): In Python, the expression 7 // 2 gives 3.
Reason (R): // is the floor division operator that gives the quotient rounded down.
(a) Both A and R are true and R is the correct explanation of A. R is the rule behind A: 7 / 2 = 3.5, and // rounds it down to 3.
Assertion (A): Python is called a dynamically typed language.
Reason (R): The type of a variable is decided by the value given to it while the program runs.
(a) Both A and R are true and R is the correct explanation of A. R is exactly the meaning of dynamic typing: x = 5 makes x an int, and later x = "hi" makes it a str.
Assertion (A): A = 5 and a = 5 create two different variables.
Reason (R): Python is case sensitive.
(a) Both A and R are true and R is the correct explanation of A. Because Python is case sensitive (R), A and a are different names (A).
Assertion (A): The expression 2 3 2 gives 512.
Reason (R): The ** operator is evaluated from right to left.
(a) Both A and R are true and R is the correct explanation of A. 3 2 = 9 first, then 2 9 = 512.
Assertion (A): A comment is executed by the Python interpreter.
Reason (R): A comment starts with the symbol #.
(d) A is false but R is true. Comments are ignored by the interpreter.
Assertion (A): A logical error is reported by the interpreter.
Reason (R): A logical error gives a wrong result without any error message.
(d) A is false but R is true. A is false: the interpreter does not report logical errors. R is true: the program runs but gives a wrong result, e.g. using + instead of *.
Assertion (A): A for loop with range(1, 10, 2) runs 5 times.
Reason (R): range(1, 10, 2) gives 1, 3, 5, 7, 9.
(a) Both A and R are true and R is the correct explanation of A. The five values 1, 3, 5, 7, 9 in R are why the loop runs 5 times.
Assertion (A): The else block of a loop runs even after break.
Reason (R): break ends the loop at once.
(d) A is false but R is true. The loop else is skipped when break runs.
Assertion (A): A while loop is called an entry-controlled loop.
Reason (R): Its condition is checked before every round.
(a) Both A and R are true and R is the correct explanation of A. The condition is checked at the entry of every round (R), which is what entry-controlled means (A).
Assertion (A): Indentation is important in Python.
Reason (R): Python uses curly brackets to mark a block.
(c) A is true but R is false. Python uses indentation, not brackets.
Assertion (A): continue ends the loop at once.
Reason (R): continue skips the rest of the current round.
(d) A is false but R is true. A is false: break ends the loop. R is true: continue only skips the rest of the current round and goes to the next round.
Assertion (A): Lists are mutable.
Reason (R): Elements of a list can be changed after the list is made.
(a) Both A and R are true and R is the correct explanation of A. Mutable means changeable; R says list elements can be changed, e.g. L[0] = 9.
Assertion (A): L.append([4, 5]) increases the length of L by 2.
Reason (R): append() adds its argument as one element.
(d) A is false but R is true. The length increases by 1; extend() would add 2.
Assertion (A): L.sort() returns the sorted list.
Reason (R): sort() arranges the list in place.
(d) A is false but R is true. sort() returns None.
Assertion (A): L.pop() removes the last element of L.
Reason (R): pop() without an index works on the last position.
(a) Both A and R are true and R is the correct explanation of A. With no index, pop() uses the last position (R), so it removes the last element (A).
Assertion (A): Two lists can be joined with +.
Reason (R): + is the concatenation operator for lists.
(a) Both A and R are true and R is the correct explanation of A. + is the concatenation operator (R): [1, 2] + [3] gives [1, 2, 3].
Assertion (A): A list can be a key of a dictionary.
Reason (R): Dictionary keys must be immutable.
(d) A is false but R is true. A list is mutable, so it cannot be a key.
Assertion (A): d.get('x') does not give an error when 'x' is not a key.
Reason (R): get() returns None for a missing key.
(a) Both A and R are true and R is the correct explanation of A. get() returns None for a missing key (R), so no KeyError comes (A); d['x'] would give KeyError.
Assertion (A): A dictionary can have two pairs with the same key.
Reason (R): Values in a dictionary can be repeated.
(d) A is false but R is true. Keys are unique; values may repeat.
Assertion (A): L = [1, 2] * 2 gives [1, 2, 1, 2].
Reason (R): * repeats the list.
(a) Both A and R are true and R is the correct explanation of A. * repeats the list (R), so [1, 2] is written twice: [1, 2, 1, 2].
Assertion (A): for i in range(5): print(i) prints the numbers 1 to 5.
Reason (R): range(5) starts from 0.
(d) A is false but R is true. It prints 0 to 4.
Assertion (A): The expression 10 / 2 gives 5.
Reason (R): The / operator always gives a float.
(d) A is false but R is true. 10 / 2 gives 5.0.
Assertion (A): len({'a': 1, 'b': 2, 'a': 3}) is 2.
Reason (R): A repeated key keeps only its last value.
(a) Both A and R are true and R is the correct explanation of A. The repeated key 'a' is stored once with value 3 (R), so only 2 keys remain (A).
Assertion (A): max([3, 'a', 5]) gives an error.
Reason (R): Python cannot compare an int and a str with >.
(a) Both A and R are true and R is the correct explanation of A. max() compares the elements; an int and a str cannot be compared (R), so TypeError comes (A).
Assertion (A): A primary key cannot have duplicate values.
Reason (R): A primary key uniquely identifies each row of a table.
(a) Both A and R are true and R is the correct explanation of A. To identify each row uniquely (R), the primary key values must all be different (A).
Assertion (A): A table can have many alternate keys.
Reason (R): All candidate keys other than the primary key are alternate keys.
(a) Both A and R are true and R is the correct explanation of A. Every candidate key not chosen as primary key is an alternate key (R), so if there are many candidate keys there can be many alternate keys (A).
Assertion (A): DBMS reduces data redundancy.
Reason (R): In a DBMS, data is stored at one place and shared.
(a) Both A and R are true and R is the correct explanation of A. Data kept at one place and shared (R) means it is not repeated in many files (A).
Assertion (A): The degree of a table changes when a new row is added.
Reason (R): Degree is the number of columns.
(d) A is false but R is true. Adding a row changes the cardinality, not the degree.
Assertion (A): Roll number can be a candidate key in a class.
Reason (R): Each student has a different roll number.
(a) Both A and R are true and R is the correct explanation of A. Since every student has a different roll number (R), it can identify each row, so it is a candidate key (A).
Assertion (A): Name is a good primary key for a table of students.
Reason (R): Two students may have the same name.
(d) A is false but R is true. Name can repeat, so it is not a good primary key.
Assertion (A): DROP TABLE removes the structure and the data of a table.
Reason (R): DROP is a DDL command.
(b) Both A and R are true but R is not the correct explanation of A. Both are true, but R does not explain A.
Assertion (A): WHERE Fee = NULL finds the rows where Fee is empty.
Reason (R): NULL cannot be compared with =; IS NULL is used.
(d) A is false but R is true. A is false: = NULL never matches any row. R is true: we must write WHERE Fee IS NULL.
Assertion (A): UPDATE is a DML command.
Reason (R): UPDATE changes the data stored in a table.
(a) Both A and R are true and R is the correct explanation of A. DML commands change the data (R); UPDATE changes data, so it is DML (A).
Assertion (A): VARCHAR(20) saves space for short names.
Reason (R): VARCHAR stores only as many characters as are entered.
(a) Both A and R are true and R is the correct explanation of A. VARCHAR stores only the characters entered (R): "Ria" uses 3, not 20, so space is saved (A).
Assertion (A): BETWEEN 50 AND 60 includes 50 and 60.
Reason (R): BETWEEN includes both the end values.
(a) Both A and R are true and R is the correct explanation of A. Both statements say the same rule: BETWEEN is inclusive, so 50 and 60 are included.
Assertion (A): ALTER TABLE can add a new column.
Reason (R): ALTER is a DML command.
(c) A is true but R is false. ALTER is a DDL command.
Assertion (A): SELECT is used to change the data of a table.
Reason (R): SELECT is used to display data.
(d) A is false but R is true. A is false: UPDATE changes data. R is true: SELECT only displays data.
Assertion (A): A column declared NOT NULL must have a value in every row.
Reason (R): NOT NULL is a constraint.
(b) Both A and R are true but R is not the correct explanation of A. Both are true, but R only names NOT NULL as a constraint; it does not say why a value is needed in every row, so R does not explain A.
Assertion (A): DELETE FROM STUDENT WHERE Marks < 33; removes some rows only.
Reason (R): The WHERE clause chooses the rows to delete.
(a) Both A and R are true and R is the correct explanation of A. The WHERE clause (R) chooses only the rows with Marks < 33, so only those rows are removed (A).
Assertion (A): Text and date values are written in quotes in SQL.
Reason (R): Numbers must also be written in quotes.
(c) A is true but R is false. Numbers are written without quotes.
Assertion (A): SQL commands can be typed in small or capital letters.
Reason (R): SQL keywords are not case sensitive.
(a) Both A and R are true and R is the correct explanation of A. Because SQL keywords are not case sensitive (R), SELECT and select both work (A).
Assertion (A): INSERT INTO T VALUES (1, 'A'); adds a row.
Reason (R): INSERT is a DDL command.
(c) A is true but R is false. INSERT is a DML command.
Assertion (A): A database is better than many separate files.
Reason (R): A database controls redundancy and keeps data consistent.
(a) Both A and R are true and R is the correct explanation of A. Controlling redundancy and keeping data consistent (R) are the reasons a database is better (A).
Assertion (A): CHAR(10) always uses space for 10 characters.
Reason (R): CHAR is a fixed-length data type.
(a) Both A and R are true and R is the correct explanation of A. CHAR is fixed-length (R), so even "Ria" takes space for 10 characters (A).
Assertion (A): Gmail is SaaS.
Reason (R): In SaaS, the user uses ready software over the Internet.
(a) Both A and R are true and R is the correct explanation of A. Gmail is ready software used over the Internet (R), which is SaaS (A).
Assertion (A): AR and VR are the same.
Reason (R): AR adds to the real world, while VR replaces it.
(d) A is false but R is true. A is false: they are different. R is true and shows the difference: AR adds to the real view, VR replaces it with a virtual world.
Assertion (A): np.array([1, 2]) + np.array([3, 4]) gives [4 6].
Reason (R): NumPy adds arrays element by element.
(a) Both A and R are true and R is the correct explanation of A. Element by element (R): 1 + 3 = 4 and 2 + 4 = 6, so the result is [4 6] (A).
Assertion (A): A NumPy array can hold an int and a str as separate types together.
Reason (R): All elements of an array have the same type.
(d) A is false but R is true. NumPy converts them all to one type (here, strings).
Write any two differences between the first generation (vacuum tube) computers and today's computers.
First-generation computers used vacuum tubes, were huge, used a lot of electricity, produced heat and were slow. Today's computers use microprocessors (ICs), are small, fast, cheap and use little power.
What is the stored program concept? Who gave it?
The idea that the program (instructions) and the data are both stored in the computer's memory, so the computer can run different programs without being rewired. It was given by John von Neumann.
Draw a block diagram of a computer and name its parts.
Parts and their work
The parts are joined by buses (data, address and control bus). Arrows in the diagram show the flow: Input → Memory ⇄ CPU → Output.
In daily life: In a school office, forms come in (input), the principal decides (CPU), files are kept in the almirah (memory) and the result is announced on the notice board (output).
Marking: diagram with arrows 1 mark + correct names of the parts 1 mark.
Differentiate between the ALU and the Control Unit.
The ALU does arithmetic (add, subtract) and logical work (compare). The Control Unit fetches and decodes instructions and directs all the other parts of the computer.
What is a system bus? Name its three types.
A set of wires that carries data and signals between the CPU, memory and devices. Types: data bus, address bus and control bus.
Name two input and two output devices used in a bank.
Input: MICR (cheque reader), biometric scanner, keyboard, barcode reader. Output: printer (passbook printer), monitor, speaker. (Any two of each.)
Differentiate between OMR and OCR.
OMR reads marks (filled bubbles) on special sheets, as in exam answer sheets. OCR reads printed or written characters from an image and turns them into editable text.
What is a microprocessor? Give one example.
A CPU made on a single integrated circuit chip. Examples: Intel Core i5, AMD Ryzen, Intel 4004 (the first).
Differentiate between primary and secondary memory.
Primary memory (RAM, ROM, cache) is directly used by the CPU, is fast, costly and small; RAM is volatile. Secondary memory (HDD, SSD, pen drive) stores data permanently, is slower, cheaper and larger.
Differentiate between RAM and ROM.
RAM is volatile, read-write, holds running programs. ROM is non-volatile, mostly read-only, holds the boot (start-up) instructions.
What happens to a file when it is deleted? Can it be recovered?
Usually only its entry is removed and its space is marked free; the data stays on the disk until new data is written over it. So it can often be recovered with data recovery software, if it has not been overwritten.
Why can data recovery be a security concern? How can it be avoided?
Someone who gets an old disk or phone can recover our deleted personal data and misuse it. Avoid it by securely wiping (shredding) data, encrypting the device, or destroying old storage before disposal.
Convert:
(i) 3 x 1024 = 3072 MB. (ii) 16384 / 8 = 2048 bytes.
Arrange in increasing order of size: KB, TB, byte, GB, MB, PB.
byte < KB < MB < GB < TB < PB.
What is cache memory? Why is it used?
A small, very fast memory between the CPU and RAM that keeps often-used data and instructions, so the CPU waits less and works faster.
Differentiate between system software and application software.
System software runs and manages the computer (operating system, device drivers, utilities, translators). Application software does a particular task for the user (word processor, billing, games).
Differentiate between general purpose and specific purpose software with an example each.
General purpose software is made for many users for common tasks, e.g. a spreadsheet. Specific purpose (customised) software is made for a particular user or job, e.g. a school's fee management or a railway reservation system.
Write any two functions of an operating system.
Process management, memory management, file management, device management, providing a user interface, security. (Any two.)
Differentiate between a compiler and an interpreter.
A compiler translates the whole program at once and lists all errors together. An interpreter translates and runs one line at a time and stops at the first error. Python uses an interpreter.
What is utility software? Give two examples.
Software that maintains and protects the computer. Examples: antivirus, disk cleanup, disk defragmenter, backup, file compression.
What is a device driver?
System software that lets the operating system talk to and control a hardware device, such as a printer or a webcam.
Differentiate between open source and proprietary software.
Open source software has its source code available to all and can be changed and shared (Linux, LibreOffice). Proprietary software is owned by a company; its code is secret and a licence must be bought (MS Windows).
What is Artificial Intelligence? Give two examples from daily life.
The ability of a machine to think, learn and take decisions like humans. Examples: face unlock, voice assistants, map route suggestions, spam filters.
Differentiate between AI and Machine Learning.
AI is the broad idea of machines acting intelligently. Machine Learning is a part of AI in which machines learn patterns from data and improve with experience without being programmed for every case.
What is NLP? Give two applications.
Natural Language Processing lets computers understand, process and produce human language. Applications: chatbots, voice assistants, translation, spell check, speech-to-text.
Differentiate between AR and VR.
AR adds computer-made images or information on the real world (Pokemon Go, Snapchat filters). VR creates a fully computer-made world that the user enters with a headset (VR games, flight simulators).
What is robotics? Name two uses of robots.
The branch of technology that designs and builds robots, machines that can sense and act on their own. Uses: factories (car assembly), surgery, space (Mars rover), drones, cleaning.
What is Big Data? Name any three of its characteristics.
Data sets so large and complex that ordinary tools cannot handle them. Characteristics: Volume, Velocity, Variety, Veracity, Value. (Any three.)
What is IoT? Give two examples.
The Internet of Things is a network of everyday devices with sensors that connect to the Internet and share data. Examples: smart watch, smart bulb, smart meter, home security camera.
What is a smart city? Write two features.
A city that uses IoT, sensors and data to manage its services well. Features: smart traffic lights, smart parking, smart water and electricity meters, waste management, CCTV surveillance.
What is cloud computing? Write two advantages.
Using computing resources such as storage, servers and software over the Internet, on demand, paying for what is used. Advantages: no need to buy hardware, access from anywhere, easy to scale, automatic backup.
Differentiate between SaaS and IaaS.
SaaS gives ready software over the Internet (Gmail, Google Docs). IaaS gives basic computing infrastructure such as virtual machines, storage and networks (Amazon EC2); the user installs and manages the software.
Going up the stack, the provider manages more and the user manages less.
What is PaaS? Give an example.
Platform as a Service gives developers a ready platform (operating system, tools, database) to build and run their applications without managing hardware. Example: Google App Engine.
What is grid computing? How is it different from cloud computing?
Many computers in different places are connected to work together on one large task, using their unused power. Cloud computing gives services on demand from a provider's data centres; grid computing shares the power of many separate computers for one job.
What is blockchain? Write one use.
A shared, decentralised digital ledger in which records are stored in blocks linked by hashes, so they are very hard to change. Uses: cryptocurrency (Bitcoin), land records, supply chain, voting.
Why is data in a blockchain secure?
Each block stores the hash of the previous block, so changing one block would change all the following hashes; and many computers keep copies, so a single changed copy is rejected.
What are sensors? Name two types.
Devices that detect a change in the surroundings and convert it into a signal. Types: temperature, motion, light, humidity, gas, touch sensors.
Write two uses of AI in education.
Personalised learning apps that adjust to each student; automatic checking of objective tests; chatbots for doubt solving; speech-to-text for students with disabilities.
Write two concerns related to emerging technologies.
Loss of privacy, misuse of personal data, loss of some jobs due to automation, bias in AI decisions, cyber attacks on IoT devices.
Give one example each of AI, IoT and blockchain in banking.
AI: fraud detection and chatbots. IoT: smart ATMs and card readers. Blockchain: secure money transfer records.
What are the 5 Vs of Big Data? Explain any two.
Volume, Velocity, Variety, Veracity, Value. Volume: the huge amount of data. Velocity: the speed at which data is produced, such as social media posts every second.
How does IoT help in agriculture?
Soil-moisture sensors tell when to water; weather data helps plan sowing; drones spray and watch crops; farmers get alerts on their phones.
Write any two differences between a list and a dictionary.
A list is an ordered collection accessed by integer index, written in [ ]. A dictionary stores key: value pairs accessed by keys, written in { }; keys are unique.
What is the difference between the append() and insert() methods of a list?
append(x) adds x at the end of the list. insert(i, x) adds x at the position i, moving the other elements to the right.
What is meant by traversing a list? Write code to traverse L = [4, 7, 9].
Visiting every element of the list one by one.
for x in L:
print(x)
Write the use of len(), max(), min() and sum() with a list.
len(L) gives the number of elements; max(L) the largest; min(L) the smallest; sum(L) the total of numeric elements.
What are the list operations? Explain concatenation and repetition.
Concatenation (+), repetition (*), membership (in), slicing ([a:b]). [1, 2] + [3] gives [1, 2, 3]; [0] * 3 gives [0, 0, 0].
Differentiate between the pop() and remove() methods.
pop(i) removes the element at index i (the last one by default) and returns it. remove(x) removes the first element equal to x.
Differentiate between L.sort() and sorted(L).
L.sort() sorts the list in place and returns None. sorted(L) gives a new sorted list and leaves L unchanged.
What is a nested list? How do you access 6 in L = [[1, 2], [5, 6]]?
A list inside another list. L[1][1] gives 6.
How is a dictionary created? Give two ways.
D = {'a': 1, 'b': 2} (with braces) or D = dict(a=1, b=2) / D = dict([('a', 1), ('b', 2)]).
Write the use of keys(), values() and items().
keys() gives all the keys, values() all the values, and items() all the (key, value) pairs of a dictionary.
How do you add, update and delete an element in a dictionary? Give code.
D['c'] = 3 adds a new pair; D['a'] = 10 updates; del D['b'] deletes the key 'b'.
Differentiate between D['x'] and D.get('x').
D['x'] gives KeyError if 'x' is not a key. D.get('x') returns None (or a default value) without an error.
Differentiate between del D['k'] and D.clear().
del D['k'] deletes only the key 'k' and its value. D.clear() removes all the pairs; the empty dictionary remains.
Why are dictionaries called mutable? Can keys be changed?
Because pairs can be added, changed and removed after creation. A key itself cannot be changed; it must be removed and a new key added.
What is NumPy? Why are NumPy arrays faster than lists?
NumPy (Numerical Python) is a library for working with arrays of numbers. Arrays store elements of one type close together in memory and do operations on all elements at once, so they are faster.
Differentiate between a Python list and a NumPy array.
A list can hold elements of different types; + joins lists. A NumPy array holds elements of one type; + adds them element by element; it uses less memory and is faster.
Write the use of ndim, shape and size of a NumPy array.
ndim gives the number of dimensions, shape gives the size of each dimension as a tuple such as (2, 3), and size gives the total number of elements.
Write code to create a 1-D and a 2-D NumPy array from lists.
import numpy as np
a = np.array([1, 2, 3])
b = np.array([[1, 2], [3, 4]])
What are the features of Python? Write any four.
Easy to learn and read, free and open source, interpreted, high level, platform independent, case sensitive, has a large library. (Any four.)
What is the difference between a statement and an expression?
An expression is a combination of values, variables and operators that gives a value, e.g. a + b * 2. A statement is an instruction that Python runs, e.g. x = a + b or print(x).
What are l-value and r-value? Give an example.
In x = y + 5, x is the l-value (the name that gets the value, on the left) and y + 5 is the r-value (the value worked out on the right).
What is debugging? Name two ways to debug a program.
Finding and removing errors (bugs) from a program. Ways: read the error message; print the values of variables at different points; dry-run the code; use the debugger of the IDE.
Differentiate between interactive mode and script mode of Python.
Interactive mode: statements are typed one at a time at the >>> prompt and the result is shown at once; the work is not saved. Script mode: the program is written in a .py file, saved, and run as a whole.
Differentiate between = and == in Python.
= is the assignment operator; it gives a value to a variable: x = 5. == is a relational operator; it compares two values and gives True or False: x == 5.
Differentiate between / and // with examples.
/ is true division and always gives a float: 7 / 2 = 3.5. // is floor division and gives the quotient rounded down: 7 // 2 = 3, -7 // 2 = -4.
What is type conversion? Explain its two kinds with an example each.
Changing a value from one data type to another. Implicit: done by Python on its own, e.g. 3 + 2.5 gives 5.5 (int to float). Explicit: done by the programmer using functions, e.g. int('25') gives 25.
Name the three types of errors with one example each.
Syntax error: wrong grammar, e.g. a missing colon after if. Runtime error: occurs while running, e.g. 5 / 0 gives ZeroDivisionError. Logical error: wrong output, e.g. using + in place of * in a formula.
Explain the use of id() and type() functions with an example.
id(x) gives the identity (memory address) of the object x. type(x) gives the data type of x. Example: x = 5; type(x) gives <class 'int'>.
What is the difference between the is and == operators?
== checks whether two values are equal. is checks whether two names refer to the same object in memory. a = [1]; b = [1]: a == b is True but a is b is False.
Write the precedence of these operators from highest to lowest: +, **, not, *, and, <
** , then * , then + , then < , then not , then and.
Differentiate between break and continue.
break ends the loop at once and control goes to the statement after the loop. continue skips the rest of the current round and the loop goes to its next round.
Differentiate between a for loop and a while loop.
A for loop runs over a sequence or range; it is used when the number of rounds is known. A while loop runs as long as a condition is True; it is used when the number of rounds is not known in advance.
What is an infinite loop? Give an example.
A loop whose condition never becomes False, so it never ends. Example: i = 1; while i > 0: i = i + 1
Explain range() with its three parameters, using an example.
range(start, stop, step) gives numbers from start up to stop - 1, jumping by step. Default start is 0 and step is 1. range(2, 11, 3) gives 2, 5, 8.
What is the use of the else clause with a loop?
The else block of a loop runs after the loop ends normally, that is, when no break was executed. It is useful in searching: print 'not found' in the else block.
Rewrite using a while loop:
for i in range(10, 0, -2):
print(i)i = 10
while i > 0:
print(i)
i = i - 2Rewrite using a for loop:
n = 1
while n <= 15:
print(n * n)
n += 3for n in range(1, 16, 3):
print(n * n)Differentiate between append() and extend().
append(x) adds x as one single element at the end; the length increases by 1. extend(L2) adds each element of L2 at the end; the length increases by len(L2).
Differentiate between remove() and pop().
remove(x) deletes the first element equal to x and returns nothing. pop(i) deletes the element at index i (the last one if no index is given) and returns it.
Differentiate between sort() and sorted().
L.sort() arranges L itself and returns None; it works only on lists. sorted(seq) returns a new sorted list and leaves the original unchanged; it works on any sequence.
What is a nested list? How is an element of it accessed?
A list inside another list. L = [[1, 2], [3, 4]]: L[1][0] gives 3 (row 1, item 0).
Differentiate between pop() and popitem() of a dictionary.
pop(key) removes the given key and returns its value. popitem() removes and returns the last inserted (key, value) pair.
Explain keys(), values() and items() with an example.
D = {'a': 1, 'b': 2}. D.keys() gives dict_keys(['a', 'b']); D.values() gives dict_values([1, 2]); D.items() gives dict_items([('a', 1), ('b', 2)]).
Rewrite the code after removing the errors. Underline each correction.
L = [10, 20, 30] L.add(40) print(L[4])
L = [10, 20, 30] L.append(40) print(L[3])
Lists have append(), not add(); after adding, the last index is 3.
Write the output of the following code.
D = {'a': 13, 'c': 2, 'e': 11, 'd': 18}
total = 0
for k in D:
if D[k] > 12:
total += D[k]
print(k, end=" ")
print(total)Output:
a d 31
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'a': 13, 'c': 2, 'e': 11, 'd': 18} | D = {'a': 13, 'c': 2, 'e': 11, 'd': 18} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 12: | condition is True | |
| 5 | total += D[k] | total = 13 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 12: | condition is False | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 12: | condition is False | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 12: | condition is True | |
| 5 | total += D[k] | total = 31 | |
| 6 | print(k, end=" ") | d | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 31⏎ |
Write the output of the following code.
x, y = 7, 11
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
14 10
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 7, 11 | x = 7, y = 11 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 14 | |
| 4 | y = y - 1 | y = 10 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 14 10⏎ |
Write the output of the following code.
n = 55825
s = 0
while n > 0:
d = n % 10
if d % 2 == 0:
s = s + d
n = n // 10
print(s)Output:
10
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 55825 | n = 55825 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 5 | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 5582 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 | |
| 5 | if d % 2 == 0: | condition is True | |
| 6 | s = s + d | s = 2 | |
| 7 | n = n // 10 | n = 558 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 8 | |
| 5 | if d % 2 == 0: | condition is True | |
| 6 | s = s + d | s = 10 | |
| 7 | n = n // 10 | n = 55 |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'b': 4, 'a': 18, 'e': 3, 'c': 12}
total = 0
for k in D:
if D[k] > 4:
total += D[k]
print(k, end=" ")
print(total)Output:
a c 30
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'b': 4, 'a': 18, 'e': 3, 'c': 12} | D = {'b': 4, 'a': 18, 'e': 3, 'c': 12} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 4: | condition is False | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 4: | condition is True | |
| 5 | total += D[k] | total = 18 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 4: | condition is False | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 4: | condition is True | |
| 5 | total += D[k] | total = 30 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 30⏎ |
Write the output of the following code.
n = 45179
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
97154
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 45179 | n = 45179 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 | |
| 5 | s = s * 10 + d | s = 9 | |
| 6 | n = n // 10 | n = 4517 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 | |
| 5 | s = s * 10 + d | s = 97 | |
| 6 | n = n // 10 | n = 451 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 1 | |
| 5 | s = s * 10 + d | s = 971 | |
| 6 | n = n // 10 | n = 45 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 5 |
… the same steps continue for the remaining values.
Write the output of the following code.
a = 3
b = 11
if a % 2 == 0 and b % 2 == 0:
print(a + b)
elif a % 2 == 0 or b > 20:
print(a * b)
else:
print(b - a)Output:
8
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | a = 3 | a = 3 | |
| 2 | b = 11 | b = 11 | |
| 3 | if a % 2 == 0 and b % 2 == 0: | condition is False | |
| 5 | elif a % 2 == 0 or b > 20: | condition is False | |
| 8 | print(b - a) | 8⏎ |
Write the output of the following code.
for i in range(1, 4):
for j in range(i):
print(i, end="")
print()Output:
1 22 333
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(1, 4): | i = 1 | |
| 2 | for j in range(i): | j = 0 | |
| 3 | print(i, end="") | 1 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 4): | i = 2 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 3 | print(i, end="") | 2 | |
| 2 | for j in range(i): | j = 1 | |
| 3 | print(i, end="") | 2 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 4): | i = 3 | |
| 2 | for j in range(i): | j = 0 | |
| 3 | print(i, end="") | 3 | |
| 2 | for j in range(i): | j = 1 |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [2, 1, 7, 4, 6, 2]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{2: 2, 1: 1, 7: 1, 4: 1, 6: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [2, 1, 7, 4, 6, 2] | L = [2, 1, 7, 4, 6, 2] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 2 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {2: 1} | |
| 3 | for x in L: | x = 1 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {2: 1, 1: 1} | |
| 3 | for x in L: | x = 7 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {2: 1, 1: 1, 7: 1} | |
| 3 | for x in L: | x = 4 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {2: 1, 1: 1, 7: 1, 4: 1} | |
| 3 | for x in L: | x = 6 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {2: 1, 1: 1, 7: 1, 4: 1, 6: 1} | |
| 3 | for x in L: | x = 2 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {2: 2, 1: 1, 7: 1, 4: 1, 6: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {2: 2, 1: 1, 7: 1, 4: 1, 6: 1}⏎ |
Write the output of the following code.
n = 17629
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
92671
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 17629 | n = 17629 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 | |
| 5 | s = s * 10 + d | s = 9 | |
| 6 | n = n // 10 | n = 1762 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 | |
| 5 | s = s * 10 + d | s = 92 | |
| 6 | n = n // 10 | n = 176 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 6 | |
| 5 | s = s * 10 + d | s = 926 | |
| 6 | n = n // 10 | n = 17 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 |
… the same steps continue for the remaining values.
Write the output of the following code.
x, y = 9, 13
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
18 12
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 9, 13 | x = 9, y = 13 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 18 | |
| 4 | y = y - 1 | y = 12 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 18 12⏎ |
Write the output of the following code.
x, y = 9, 25
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
36 23
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 9, 25 | x = 9, y = 25 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 18 | |
| 4 | y = y - 1 | y = 24 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 36 | |
| 4 | y = y - 1 | y = 23 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 36 23⏎ |
Rewrite the code after removing the errors. Underline each correction.
L = [5, 3, 8] L = L.sort() print(L[0])
L = [5, 3, 8] L.sort() print(L[0])
sort() returns None; it sorts L in place, so do not assign its result.
Write the output of the following code.
n = 27491
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
19472
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 27491 | n = 27491 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 1 | |
| 5 | s = s * 10 + d | s = 1 | |
| 6 | n = n // 10 | n = 2749 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 | |
| 5 | s = s * 10 + d | s = 19 | |
| 6 | n = n // 10 | n = 274 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 4 | |
| 5 | s = s * 10 + d | s = 194 | |
| 6 | n = n // 10 | n = 27 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [17, 26, 24, 20, 23, 28]
for i in range(len(L)):
if L[i] % 3 == 0:
L[i] = L[i] // 2
else:
L[i] = L[i] * 2
print(L)Output:
[34, 52, 12, 40, 46, 56]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [17, 26, 24, 20, 23, 28] | L = [17, 26, 24, 20, 23, 28] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 3 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [34, 26, 24, 20, 23, 28] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 3 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [34, 52, 24, 20, 23, 28] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 3 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [34, 52, 12, 20, 23, 28] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 3 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [34, 52, 12, 40, 23, 28] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 3 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [34, 52, 12, 40, 46, 28] |
… the same steps continue for the remaining values.
Write the output of the following code.
for i in range(1, 5):
for j in range(1, i + 1):
print(j * i, end=" ")
print()Output:
1 2 4 3 6 9 4 8 12 16
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(1, 5): | i = 1 | |
| 2 | for j in range(1, i + 1): | j = 1 | |
| 3 | print(j * i, end=" ") | 1 | |
| 2 | for j in range(1, i + 1): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 5): | i = 2 | |
| 2 | for j in range(1, i + 1): | loop ends (no more values) | |
| 3 | print(j * i, end=" ") | 2 | |
| 2 | for j in range(1, i + 1): | j = 2 | |
| 3 | print(j * i, end=" ") | 4 | |
| 2 | for j in range(1, i + 1): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 5): | i = 3 | |
| 2 | for j in range(1, i + 1): | j = 1 | |
| 3 | print(j * i, end=" ") | 3 | |
| 2 | for j in range(1, i + 1): | j = 2 |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [6, 6, 4, 3, 7, 8]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{6: 2, 4: 1, 3: 1, 7: 1, 8: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [6, 6, 4, 3, 7, 8] | L = [6, 6, 4, 3, 7, 8] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 6 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 2} | |
| 3 | for x in L: | x = 4 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 2, 4: 1} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 2, 4: 1, 3: 1} | |
| 3 | for x in L: | x = 7 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 2, 4: 1, 3: 1, 7: 1} | |
| 3 | for x in L: | x = 8 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 2, 4: 1, 3: 1, 7: 1, 8: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {6: 2, 4: 1, 3: 1, 7: 1, 8: 1}⏎ |
Write the output of the following code.
import numpy as np a = np.array([14, 24, 5, 7, 33]) b = a // 2 print(b) print(a > 15)
Output:
[ 7 12 2 3 16] [False True False False True]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | a = np.array([14, 24, 5, 7, 33]) | a = array([14, 24, 5, 7, 33]) | |
| 3 | b = a // 2 | b = array([ 7, 12, 2, 3, 16]) | |
| 4 | print(b) | [ 7 12 2 3 16]⏎ | |
| 5 | print(a > 15) | [False True False False True]⏎ |
Write the output of the following code.
D = {'c': 16, 'b': 12, 'e': 14, 'd': 2}
total = 0
for k in D:
if D[k] > 8:
total += D[k]
print(k, end=" ")
print(total)Output:
c b e 42
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'c': 16, 'b': 12, 'e': 14, 'd': 2} | D = {'c': 16, 'b': 12, 'e': 14, 'd': 2} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 8: | condition is True | |
| 5 | total += D[k] | total = 16 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 8: | condition is True | |
| 5 | total += D[k] | total = 28 | |
| 6 | print(k, end=" ") | b | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 8: | condition is True | |
| 5 | total += D[k] | total = 42 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 8: | condition is False | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 42⏎ |
Write the output of the following code.
import numpy as np L = [[9, 6, 15], [4, 6, 16]] a = np.array(L) print(a.shape) print(a[1]) print(a * 10)
Output:
(2, 3) [ 4 6 16] [[ 90 60 150] [ 40 60 160]]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | L = [[9, 6, 15], [4, 6, 16]] | L = [[9, 6, 15], [4, 6, 16]] | |
| 3 | a = np.array(L) | a = array([[ 9, 6, 15],
[ 4, 6, 16]]) | |
| 4 | print(a.shape) | (2, 3)⏎ | |
| 5 | print(a[1]) | [ 4 6 16]⏎ | |
| 6 | print(a * 10) | [[ 90 60 150]⏎ [ 40 60 160]]⏎ |
Write the output of the following code.
L = [21, 7, 16, 20, 14, 18]
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] = L[i] // 3
else:
L[i] = L[i] * 2
print(L)Output:
[42, 14, 5, 6, 4, 6]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [21, 7, 16, 20, 14, 18] | L = [21, 7, 16, 20, 14, 18] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [42, 7, 16, 20, 14, 18] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [42, 14, 16, 20, 14, 18] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [42, 14, 5, 20, 14, 18] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [42, 14, 5, 6, 14, 18] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [42, 14, 5, 6, 4, 18] |
… the same steps continue for the remaining values.
Rewrite the code after removing the errors. Underline each correction.
for i in range(5):
if i == 3:
Break
print(i)
else
print('done')for i in range(5):
if i == 3:
break
print(i)
else:
print('done')break is in small letters; colon after else.
Write the output of the following code.
x, y = 2, 20
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
32 16
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 2, 20 | x = 2, y = 20 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 4 | |
| 4 | y = y - 1 | y = 19 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 8 | |
| 4 | y = y - 1 | y = 18 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 16 | |
| 4 | y = y - 1 | y = 17 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 32 | |
| 4 | y = y - 1 | y = 16 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 32 16⏎ |
Write the output of the following code.
import numpy as np marks = [37, 29, 21, 28, 4] a = np.array(marks) print(a + 5) print(a.size, a.ndim)
Output:
[42 34 26 33 9] 5 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | marks = [37, 29, 21, 28, 4] | marks = [37, 29, 21, 28, 4] | |
| 3 | a = np.array(marks) | a = array([37, 29, 21, 28, 4]) | |
| 4 | print(a + 5) | [42 34 26 33 9]⏎ | |
| 5 | print(a.size, a.ndim) | 5 1⏎ |
Rewrite the code after removing the errors. Underline each correction.
a = 10 b = '20' c = a + b print 'Sum =', c
a = 10
b = '20'
c = a + int(b)
print('Sum =', c)Convert b to int before adding; print is a function and needs brackets.
Write the output of the following code.
L = [26, 15, 22, 18, 24, 12]
for i in range(len(L)):
if L[i] % 5 == 0:
L[i] = L[i] // 2
else:
L[i] = L[i] * 2
print(L)Output:
[52, 7, 44, 36, 48, 24]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [26, 15, 22, 18, 24, 12] | L = [26, 15, 22, 18, 24, 12] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 15, 22, 18, 24, 12] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 5 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [52, 7, 22, 18, 24, 12] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 7, 44, 18, 24, 12] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 7, 44, 36, 24, 12] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 7, 44, 36, 48, 12] |
… the same steps continue for the remaining values.
Write the output of the following code.
x, y = 6, 18
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
24 16
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 6, 18 | x = 6, y = 18 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 12 | |
| 4 | y = y - 1 | y = 17 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 24 | |
| 4 | y = y - 1 | y = 16 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 24 16⏎ |
Write the output of the following code.
a = 9
b = 10
if a % 2 == 0 and b % 2 == 0:
print(a + b)
elif a % 2 == 0 or b > 20:
print(a * b)
else:
print(b - a)Output:
1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | a = 9 | a = 9 | |
| 2 | b = 10 | b = 10 | |
| 3 | if a % 2 == 0 and b % 2 == 0: | condition is False | |
| 5 | elif a % 2 == 0 or b > 20: | condition is False | |
| 8 | print(b - a) | 1⏎ |
Rewrite the code after removing the errors. Underline each correction.
n = 5 while n > 0 print(n) n = n - 1
n = 5
while n > 0:
print(n)
n = n - 1Colon after while; the body must be indented.
Write the output of the following code.
D = {'b': 10, 'e': 18, 'a': 19, 'd': 12}
total = 0
for k in D:
if D[k] > 7:
total += D[k]
print(k, end=" ")
print(total)Output:
b e a d 59
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'b': 10, 'e': 18, 'a': 19, 'd': 12} | D = {'b': 10, 'e': 18, 'a': 19, 'd': 12} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 7: | condition is True | |
| 5 | total += D[k] | total = 10 | |
| 6 | print(k, end=" ") | b | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 7: | condition is True | |
| 5 | total += D[k] | total = 28 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 7: | condition is True | |
| 5 | total += D[k] | total = 47 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 7: | condition is True |
… the same steps continue for the remaining values.
Rewrite the code after removing the errors. Underline each correction.
count = 0
for i in range(10):
if i % 3 == 0:
count = count + 1
print('Count:' count)count = 0
for i in range(10):
if i % 3 == 0:
count = count + 1
print('Count:', count)The body of if must be indented; a comma is needed between the items in print().
Write the output of the following code.
import numpy as np a = np.array([10, 25, 21, 38, 2]) b = a // 2 print(b) print(a > 24)
Output:
[ 5 12 10 19 1] [False True False True False]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | a = np.array([10, 25, 21, 38, 2]) | a = array([10, 25, 21, 38, 2]) | |
| 3 | b = a // 2 | b = array([ 5, 12, 10, 19, 1]) | |
| 4 | print(b) | [ 5 12 10 19 1]⏎ | |
| 5 | print(a > 24) | [False True False True False]⏎ |
Write the output of the following code.
x, y = 6, 13
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
12 12
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 6, 13 | x = 6, y = 13 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 12 | |
| 4 | y = y - 1 | y = 12 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 12 12⏎ |
Write the output of the following code.
L = [9, 8, 8, 8, 7, 9]
S = []
for x in L:
if x not in S:
S.append(x)
print(S, len(L) - len(S))Output:
[9, 8, 7] 3
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [9, 8, 8, 8, 7, 9] | L = [9, 8, 8, 8, 7, 9] | |
| 2 | S = [] | S = [] | |
| 3 | for x in L: | x = 9 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [9] | |
| 3 | for x in L: | x = 8 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [9, 8] | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | if x not in S: | condition is False | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | if x not in S: | condition is False | |
| 3 | for x in L: | x = 7 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [9, 8, 7] | |
| 3 | for x in L: | x = 9 |
… the same steps continue for the remaining values.
Write the output of the following code.
import numpy as np marks = [10, 13, 19, 35, 20] a = np.array(marks) print(a + 5) print(a.size, a.ndim)
Output:
[15 18 24 40 25] 5 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | marks = [10, 13, 19, 35, 20] | marks = [10, 13, 19, 35, 20] | |
| 3 | a = np.array(marks) | a = array([10, 13, 19, 35, 20]) | |
| 4 | print(a + 5) | [15 18 24 40 25]⏎ | |
| 5 | print(a.size, a.ndim) | 5 1⏎ |
Rewrite the code after removing the errors. Underline each correction.
L = [1, 2, 3]
for i in range(len(L))
L[i] = L[i] * 2
print(l)L = [1, 2, 3]
for i in range(len(L)):
L[i] = L[i] * 2
print(L)Colon after for; print L, not l.
Write the output of the following code.
x, y = 3, 27
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
24 24
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 3, 27 | x = 3, y = 27 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 6 | |
| 4 | y = y - 1 | y = 26 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 12 | |
| 4 | y = y - 1 | y = 25 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 24 | |
| 4 | y = y - 1 | y = 24 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 24 24⏎ |
Write the output of the following code.
x, y = 7, 10
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
14 9
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 7, 10 | x = 7, y = 10 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 14 | |
| 4 | y = y - 1 | y = 9 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 14 9⏎ |
Write the output of the following code.
L = [3, 8, 5, 4, 9, 4]
S = []
for x in L:
if x not in S:
S.append(x)
print(S, len(L) - len(S))Output:
[3, 8, 5, 4, 9] 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [3, 8, 5, 4, 9, 4] | L = [3, 8, 5, 4, 9, 4] | |
| 2 | S = [] | S = [] | |
| 3 | for x in L: | x = 3 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [3] | |
| 3 | for x in L: | x = 8 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [3, 8] | |
| 3 | for x in L: | x = 5 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [3, 8, 5] | |
| 3 | for x in L: | x = 4 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [3, 8, 5, 4] | |
| 3 | for x in L: | x = 9 | |
| 4 | if x not in S: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
a = 2
b = 22
if a % 2 == 0 and b % 2 == 0:
print(a + b)
elif a % 2 == 0 or b > 20:
print(a * b)
else:
print(b - a)Output:
24
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | a = 2 | a = 2 | |
| 2 | b = 22 | b = 22 | |
| 3 | if a % 2 == 0 and b % 2 == 0: | condition is True | |
| 4 | print(a + b) | 24⏎ |
Write the output of the following code.
n = 2194
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
4912
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 2194 | n = 2194 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 4 | |
| 5 | s = s * 10 + d | s = 4 | |
| 6 | n = n // 10 | n = 219 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 | |
| 5 | s = s * 10 + d | s = 49 | |
| 6 | n = n // 10 | n = 21 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 1 | |
| 5 | s = s * 10 + d | s = 491 | |
| 6 | n = n // 10 | n = 2 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 |
… the same steps continue for the remaining values.
Rewrite the code after removing the errors. Underline each correction.
T = 1, 2, 3 T += 4 print(T)
T = 1, 2, 3 T += (4,) print(T)
A tuple can be joined only with another tuple; write (4,).
Write the output of the following code.
L = [29, 25, 22, 14, 27, 7]
for i in range(len(L)):
if L[i] % 5 == 0:
L[i] = L[i] // 3
else:
L[i] = L[i] * 2
print(L)Output:
[58, 8, 44, 28, 54, 14]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [29, 25, 22, 14, 27, 7] | L = [29, 25, 22, 14, 27, 7] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [58, 25, 22, 14, 27, 7] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 5 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [58, 8, 22, 14, 27, 7] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [58, 8, 44, 14, 27, 7] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [58, 8, 44, 28, 27, 7] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [58, 8, 44, 28, 54, 7] |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'b': 15, 'd': 12, 'c': 9, 'a': 7}
total = 0
for k in D:
if D[k] > 5:
total += D[k]
print(k, end=" ")
print(total)Output:
b d c a 43
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'b': 15, 'd': 12, 'c': 9, 'a': 7} | D = {'b': 15, 'd': 12, 'c': 9, 'a': 7} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 15 | |
| 6 | print(k, end=" ") | b | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 27 | |
| 6 | print(k, end=" ") | d | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 36 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 5: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'d': 16, 'b': 12, 'a': 4, 'e': 9}
total = 0
for k in D:
if D[k] > 5:
total += D[k]
print(k, end=" ")
print(total)Output:
d b e 37
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'d': 16, 'b': 12, 'a': 4, 'e': 9} | D = {'d': 16, 'b': 12, 'a': 4, 'e': 9} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 16 | |
| 6 | print(k, end=" ") | d | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 28 | |
| 6 | print(k, end=" ") | b | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 5: | condition is False | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 37 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 37⏎ |
Write the output of the following code.
for i in range(1, 5):
print(" " * (4 - i) + "#" * i)Output:
# ## ### ####
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(1, 5): | i = 1 | |
| 2 | print(" " * (4 - i) + "#" * i) | #⏎ | |
| 1 | for i in range(1, 5): | i = 2 | |
| 2 | print(" " * (4 - i) + "#" * i) | ##⏎ | |
| 1 | for i in range(1, 5): | i = 3 | |
| 2 | print(" " * (4 - i) + "#" * i) | ###⏎ | |
| 1 | for i in range(1, 5): | i = 4 | |
| 2 | print(" " * (4 - i) + "#" * i) | ####⏎ | |
| 1 | for i in range(1, 5): | loop ends (no more values) |
Write the output of the following code.
import numpy as np L = [[4, 6, 19], [17, 7, 10]] a = np.array(L) print(a.shape) print(a[1]) print(a * 10)
Output:
(2, 3) [17 7 10] [[ 40 60 190] [170 70 100]]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | L = [[4, 6, 19], [17, 7, 10]] | L = [[4, 6, 19], [17, 7, 10]] | |
| 3 | a = np.array(L) | a = array([[ 4, 6, 19],
[17, 7, 10]]) | |
| 4 | print(a.shape) | (2, 3)⏎ | |
| 5 | print(a[1]) | [17 7 10]⏎ | |
| 6 | print(a * 10) | [[ 40 60 190]⏎ [170 70 100]]⏎ |
Write the output of the following code.
a = 7
b = 15
if a % 2 == 0 and b % 2 == 0:
print(a + b)
elif a % 2 == 0 or b > 20:
print(a * b)
else:
print(b - a)Output:
8
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | a = 7 | a = 7 | |
| 2 | b = 15 | b = 15 | |
| 3 | if a % 2 == 0 and b % 2 == 0: | condition is False | |
| 5 | elif a % 2 == 0 or b > 20: | condition is False | |
| 8 | print(b - a) | 8⏎ |
Write the output of the following code.
L = [3, 2, 6, 3, 6, 3]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{3: 3, 2: 1, 6: 2}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [3, 2, 6, 3, 6, 3] | L = [3, 2, 6, 3, 6, 3] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 1} | |
| 3 | for x in L: | x = 2 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 1, 2: 1} | |
| 3 | for x in L: | x = 6 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 1, 2: 1, 6: 1} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 2: 1, 6: 1} | |
| 3 | for x in L: | x = 6 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 2: 1, 6: 2} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 3, 2: 1, 6: 2} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {3: 3, 2: 1, 6: 2}⏎ |
Write the output of the following code.
L = [2, 8, 3, 3, 4, 2]
S = []
for x in L:
if x not in S:
S.append(x)
print(S, len(L) - len(S))Output:
[2, 8, 3, 4] 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [2, 8, 3, 3, 4, 2] | L = [2, 8, 3, 3, 4, 2] | |
| 2 | S = [] | S = [] | |
| 3 | for x in L: | x = 2 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [2] | |
| 3 | for x in L: | x = 8 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [2, 8] | |
| 3 | for x in L: | x = 3 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [2, 8, 3] | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | if x not in S: | condition is False | |
| 3 | for x in L: | x = 4 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [2, 8, 3, 4] |
… the same steps continue for the remaining values.
Rewrite the code after removing the errors. Underline each correction.
Marks = 90
if Marks >= 90 and <= 100:
print('A1')Marks = 90
if Marks >= 90 and Marks <= 100:
print('A1')Each side of and must be a full condition (or write 90 <= Marks <= 100).
Rewrite the code after removing the errors. Underline each correction.
num = [4, 5, 6] num.insert(10) num.remove(1) print(num.length)
num = [4, 5, 6] num.insert(0, 10) num.remove(4) print(len(num))
insert() needs an index and a value; remove() takes a value present in the list; length is found by len().
Rewrite the code after removing the errors. Underline each correction.
x = 5 y = 2 print(x ^ y, x ** y, x // y, x % y))
x = 5 y = 2 print(x ** y, x // y, x % y)
^ is not power in Python (it is bitwise XOR); one closing bracket too many.
Write the output of the following code.
L = [16, 9, 28, 24, 21, 17]
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] = L[i] // 3
else:
L[i] = L[i] * 2
print(L)Output:
[5, 18, 9, 8, 42, 34]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [16, 9, 28, 24, 21, 17] | L = [16, 9, 28, 24, 21, 17] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [5, 9, 28, 24, 21, 17] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [5, 18, 28, 24, 21, 17] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [5, 18, 9, 24, 21, 17] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [5, 18, 9, 8, 21, 17] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [5, 18, 9, 8, 42, 17] |
… the same steps continue for the remaining values.
Write the output of the following code.
n = 79101
s = 0
while n > 0:
d = n % 10
if d % 2 == 0:
s = s + d
n = n // 10
print(s)Output:
0
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 79101 | n = 79101 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 1 | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 7910 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 0 | |
| 5 | if d % 2 == 0: | condition is True | |
| 7 | n = n // 10 | n = 791 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 1 | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 79 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [6, 3, 3, 8, 2, 3]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{6: 1, 3: 3, 8: 1, 2: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [6, 3, 3, 8, 2, 3] | L = [6, 3, 3, 8, 2, 3] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 6 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 1} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 1, 3: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 1, 3: 2} | |
| 3 | for x in L: | x = 8 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 1, 3: 2, 8: 1} | |
| 3 | for x in L: | x = 2 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 1, 3: 2, 8: 1, 2: 1} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 1, 3: 3, 8: 1, 2: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {6: 1, 3: 3, 8: 1, 2: 1}⏎ |
Write the output of the following code.
L = [29, 26, 23, 24, 2, 21]
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] = L[i] // 2
else:
L[i] = L[i] * 2
print(L)Output:
[58, 13, 46, 12, 1, 42]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [29, 26, 23, 24, 2, 21] | L = [29, 26, 23, 24, 2, 21] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [58, 26, 23, 24, 2, 21] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [58, 13, 23, 24, 2, 21] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [58, 13, 46, 24, 2, 21] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [58, 13, 46, 12, 2, 21] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [58, 13, 46, 12, 1, 21] |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'b': 7, 'a': 12, 'c': 1, 'd': 2}
total = 0
for k in D:
if D[k] > 8:
total += D[k]
print(k, end=" ")
print(total)Output:
a 12
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'b': 7, 'a': 12, 'c': 1, 'd': 2} | D = {'b': 7, 'a': 12, 'c': 1, 'd': 2} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 8: | condition is False | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 8: | condition is True | |
| 5 | total += D[k] | total = 12 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 8: | condition is False | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 8: | condition is False | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 12⏎ |
Write the output of the following code.
for i in range(1, 6):
for j in range(i):
print(i, end="")
print()Output:
1 22 333 4444 55555
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(1, 6): | i = 1 | |
| 2 | for j in range(i): | j = 0 | |
| 3 | print(i, end="") | 1 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 6): | i = 2 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 3 | print(i, end="") | 2 | |
| 2 | for j in range(i): | j = 1 | |
| 3 | print(i, end="") | 2 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 6): | i = 3 | |
| 2 | for j in range(i): | j = 0 | |
| 3 | print(i, end="") | 3 | |
| 2 | for j in range(i): | j = 1 |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [5, 1, 2, 5, 7, 6]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{5: 2, 1: 1, 2: 1, 7: 1, 6: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [5, 1, 2, 5, 7, 6] | L = [5, 1, 2, 5, 7, 6] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 5 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1} | |
| 3 | for x in L: | x = 1 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 1: 1} | |
| 3 | for x in L: | x = 2 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 1: 1, 2: 1} | |
| 3 | for x in L: | x = 5 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 2, 1: 1, 2: 1} | |
| 3 | for x in L: | x = 7 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 2, 1: 1, 2: 1, 7: 1} | |
| 3 | for x in L: | x = 6 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 2, 1: 1, 2: 1, 7: 1, 6: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {5: 2, 1: 1, 2: 1, 7: 1, 6: 1}⏎ |
Write the output of the following code.
L = [3, 21, 19, 10, 15, 27]
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] = L[i] // 3
else:
L[i] = L[i] * 2
print(L)Output:
[6, 42, 38, 3, 30, 54]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [3, 21, 19, 10, 15, 27] | L = [3, 21, 19, 10, 15, 27] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [6, 21, 19, 10, 15, 27] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [6, 42, 19, 10, 15, 27] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [6, 42, 38, 10, 15, 27] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [6, 42, 38, 3, 15, 27] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [6, 42, 38, 3, 30, 27] |
… the same steps continue for the remaining values.
Write the output of the following code.
import numpy as np a = np.array([20, 12, 14, 34, 16]) b = a // 2 print(b) print(a > 19)
Output:
[10 6 7 17 8] [ True False False True False]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | a = np.array([20, 12, 14, 34, 16]) | a = array([20, 12, 14, 34, 16]) | |
| 3 | b = a // 2 | b = array([10, 6, 7, 17, 8]) | |
| 4 | print(b) | [10 6 7 17 8]⏎ | |
| 5 | print(a > 19) | [ True False False True False]⏎ |
Write the output of the following code.
L = [3, 9, 3, 1, 9, 9]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{3: 2, 9: 3, 1: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [3, 9, 3, 1, 9, 9] | L = [3, 9, 3, 1, 9, 9] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 1} | |
| 3 | for x in L: | x = 9 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 1, 9: 1} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 9: 1} | |
| 3 | for x in L: | x = 1 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 9: 1, 1: 1} | |
| 3 | for x in L: | x = 9 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 9: 2, 1: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 9: 3, 1: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {3: 2, 9: 3, 1: 1}⏎ |
Write the output of the following code.
n = 2287
s = 0
while n > 0:
d = n % 10
if d % 2 == 0:
s = s + d
n = n // 10
print(s)Output:
12
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 2287 | n = 2287 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 228 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 8 | |
| 5 | if d % 2 == 0: | condition is True | |
| 6 | s = s + d | s = 8 | |
| 7 | n = n // 10 | n = 22 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 | |
| 5 | if d % 2 == 0: | condition is True | |
| 6 | s = s + d | s = 10 | |
| 7 | n = n // 10 | n = 2 |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'c': 13, 'd': 15, 'e': 14, 'a': 19}
total = 0
for k in D:
if D[k] > 5:
total += D[k]
print(k, end=" ")
print(total)Output:
c d e a 61
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'c': 13, 'd': 15, 'e': 14, 'a': 19} | D = {'c': 13, 'd': 15, 'e': 14, 'a': 19} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 13 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 28 | |
| 6 | print(k, end=" ") | d | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 42 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 5: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
x, y = 6, 10
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
12 9
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 6, 10 | x = 6, y = 10 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 12 | |
| 4 | y = y - 1 | y = 9 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 12 9⏎ |
Write the output of the following code.
import numpy as np marks = [6, 35, 14, 5, 25] a = np.array(marks) print(a + 5) print(a.size, a.ndim)
Output:
[11 40 19 10 30] 5 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | marks = [6, 35, 14, 5, 25] | marks = [6, 35, 14, 5, 25] | |
| 3 | a = np.array(marks) | a = array([ 6, 35, 14, 5, 25]) | |
| 4 | print(a + 5) | [11 40 19 10 30]⏎ | |
| 5 | print(a.size, a.ndim) | 5 1⏎ |
Rewrite the code after removing the errors. Underline each correction.
def = 5
for i in range(def):
print(i)d = 5
for i in range(d):
print(i)def is a keyword; it cannot be a variable name.
Write the output of the following code.
L = [25, 2, 8, 12, 4, 13]
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] = L[i] // 2
else:
L[i] = L[i] * 2
print(L)Output:
[50, 1, 4, 6, 2, 26]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [25, 2, 8, 12, 4, 13] | L = [25, 2, 8, 12, 4, 13] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [50, 2, 8, 12, 4, 13] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [50, 1, 8, 12, 4, 13] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [50, 1, 4, 12, 4, 13] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [50, 1, 4, 6, 4, 13] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [50, 1, 4, 6, 2, 13] |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [7, 6, 4, 6, 2, 2]
S = []
for x in L:
if x not in S:
S.append(x)
print(S, len(L) - len(S))Output:
[7, 6, 4, 2] 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [7, 6, 4, 6, 2, 2] | L = [7, 6, 4, 6, 2, 2] | |
| 2 | S = [] | S = [] | |
| 3 | for x in L: | x = 7 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [7] | |
| 3 | for x in L: | x = 6 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [7, 6] | |
| 3 | for x in L: | x = 4 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [7, 6, 4] | |
| 3 | for x in L: | x = 6 | |
| 4 | if x not in S: | condition is False | |
| 3 | for x in L: | x = 2 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [7, 6, 4, 2] |
… the same steps continue for the remaining values.
Rewrite the code after removing the errors. Underline each correction.
L = [1, 2, 3] L[3] = 4 print(L)
L = [1, 2, 3] L.append(4) print(L)
Index 3 does not exist (IndexError); add a new element with append().
Write the output of the following code.
import numpy as np a = np.array([17, 22, 20, 7, 34]) b = a // 2 print(b) print(a > 10)
Output:
[ 8 11 10 3 17] [ True True True False True]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | a = np.array([17, 22, 20, 7, 34]) | a = array([17, 22, 20, 7, 34]) | |
| 3 | b = a // 2 | b = array([ 8, 11, 10, 3, 17]) | |
| 4 | print(b) | [ 8 11 10 3 17]⏎ | |
| 5 | print(a > 10) | [ True True True False True]⏎ |
Write the output of the following code.
x, y = 2, 29
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
32 25
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 2, 29 | x = 2, y = 29 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 4 | |
| 4 | y = y - 1 | y = 28 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 8 | |
| 4 | y = y - 1 | y = 27 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 16 | |
| 4 | y = y - 1 | y = 26 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 32 | |
| 4 | y = y - 1 | y = 25 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 32 25⏎ |
Write the output of the following code.
n = 75259
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
95257
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 75259 | n = 75259 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 | |
| 5 | s = s * 10 + d | s = 9 | |
| 6 | n = n // 10 | n = 7525 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 5 | |
| 5 | s = s * 10 + d | s = 95 | |
| 6 | n = n // 10 | n = 752 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 | |
| 5 | s = s * 10 + d | s = 952 | |
| 6 | n = n // 10 | n = 75 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 5 |
… the same steps continue for the remaining values.
Write the output of the following code.
x, y = 3, 17
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
24 14
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 3, 17 | x = 3, y = 17 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 6 | |
| 4 | y = y - 1 | y = 16 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 12 | |
| 4 | y = y - 1 | y = 15 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 24 | |
| 4 | y = y - 1 | y = 14 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 24 14⏎ |
Write the output of the following code.
L = [3, 5, 6, 3, 1, 2]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{3: 2, 5: 1, 6: 1, 1: 1, 2: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [3, 5, 6, 3, 1, 2] | L = [3, 5, 6, 3, 1, 2] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 1} | |
| 3 | for x in L: | x = 5 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 1, 5: 1} | |
| 3 | for x in L: | x = 6 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 1, 5: 1, 6: 1} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 5: 1, 6: 1} | |
| 3 | for x in L: | x = 1 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 5: 1, 6: 1, 1: 1} | |
| 3 | for x in L: | x = 2 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 5: 1, 6: 1, 1: 1, 2: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {3: 2, 5: 1, 6: 1, 1: 1, 2: 1}⏎ |
Write the output of the following code.
L = [8, 7, 1, 2, 4, 7]
S = []
for x in L:
if x not in S:
S.append(x)
print(S, len(L) - len(S))Output:
[8, 7, 1, 2, 4] 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [8, 7, 1, 2, 4, 7] | L = [8, 7, 1, 2, 4, 7] | |
| 2 | S = [] | S = [] | |
| 3 | for x in L: | x = 8 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [8] | |
| 3 | for x in L: | x = 7 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [8, 7] | |
| 3 | for x in L: | x = 1 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [8, 7, 1] | |
| 3 | for x in L: | x = 2 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [8, 7, 1, 2] | |
| 3 | for x in L: | x = 4 | |
| 4 | if x not in S: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
n = 55018
s = 0
while n > 0:
d = n % 10
if d % 2 == 0:
s = s + d
n = n // 10
print(s)Output:
8
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 55018 | n = 55018 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 8 | |
| 5 | if d % 2 == 0: | condition is True | |
| 6 | s = s + d | s = 8 | |
| 7 | n = n // 10 | n = 5501 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 1 | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 550 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 0 | |
| 5 | if d % 2 == 0: | condition is True | |
| 7 | n = n // 10 | n = 55 | |
| 3 | while n > 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
for i in range(1, 5):
for j in range(i):
print(i, end="")
print()Output:
1 22 333 4444
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(1, 5): | i = 1 | |
| 2 | for j in range(i): | j = 0 | |
| 3 | print(i, end="") | 1 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 5): | i = 2 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 3 | print(i, end="") | 2 | |
| 2 | for j in range(i): | j = 1 | |
| 3 | print(i, end="") | 2 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 5): | i = 3 | |
| 2 | for j in range(i): | j = 0 | |
| 3 | print(i, end="") | 3 | |
| 2 | for j in range(i): | j = 1 |
… the same steps continue for the remaining values.
Write the output of the following code.
for i in range(1, 6):
print(" " * (5 - i) + "#" * i)Output:
# ## ### #### #####
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(1, 6): | i = 1 | |
| 2 | print(" " * (5 - i) + "#" * i) | #⏎ | |
| 1 | for i in range(1, 6): | i = 2 | |
| 2 | print(" " * (5 - i) + "#" * i) | ##⏎ | |
| 1 | for i in range(1, 6): | i = 3 | |
| 2 | print(" " * (5 - i) + "#" * i) | ###⏎ | |
| 1 | for i in range(1, 6): | i = 4 | |
| 2 | print(" " * (5 - i) + "#" * i) | ####⏎ | |
| 1 | for i in range(1, 6): | i = 5 | |
| 2 | print(" " * (5 - i) + "#" * i) | #####⏎ | |
| 1 | for i in range(1, 6): | loop ends (no more values) |
Write the output of the following code.
L = [4, 1, 7, 4, 9, 4]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{4: 3, 1: 1, 7: 1, 9: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [4, 1, 7, 4, 9, 4] | L = [4, 1, 7, 4, 9, 4] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 4 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {4: 1} | |
| 3 | for x in L: | x = 1 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {4: 1, 1: 1} | |
| 3 | for x in L: | x = 7 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {4: 1, 1: 1, 7: 1} | |
| 3 | for x in L: | x = 4 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {4: 2, 1: 1, 7: 1} | |
| 3 | for x in L: | x = 9 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {4: 2, 1: 1, 7: 1, 9: 1} | |
| 3 | for x in L: | x = 4 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {4: 3, 1: 1, 7: 1, 9: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {4: 3, 1: 1, 7: 1, 9: 1}⏎ |
Write the output of the following code.
D = {'b': 14, 'e': 4, 'c': 15, 'a': 2}
total = 0
for k in D:
if D[k] > 10:
total += D[k]
print(k, end=" ")
print(total)Output:
b c 29
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'b': 14, 'e': 4, 'c': 15, 'a': 2} | D = {'b': 14, 'e': 4, 'c': 15, 'a': 2} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 10: | condition is True | |
| 5 | total += D[k] | total = 14 | |
| 6 | print(k, end=" ") | b | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 10: | condition is False | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 10: | condition is True | |
| 5 | total += D[k] | total = 29 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 10: | condition is False | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 29⏎ |
Write the output of the following code.
n = 66407
s = 0
while n > 0:
d = n % 10
if d % 2 == 0:
s = s + d
n = n // 10
print(s)Output:
16
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 66407 | n = 66407 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 6640 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 0 | |
| 5 | if d % 2 == 0: | condition is True | |
| 7 | n = n // 10 | n = 664 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 4 | |
| 5 | if d % 2 == 0: | condition is True | |
| 6 | s = s + d | s = 4 | |
| 7 | n = n // 10 | n = 66 | |
| 3 | while n > 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
n = 76794
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
49767
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 76794 | n = 76794 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 4 | |
| 5 | s = s * 10 + d | s = 4 | |
| 6 | n = n // 10 | n = 7679 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 | |
| 5 | s = s * 10 + d | s = 49 | |
| 6 | n = n // 10 | n = 767 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 | |
| 5 | s = s * 10 + d | s = 497 | |
| 6 | n = n // 10 | n = 76 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 6 |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'b': 7, 'c': 13, 'e': 15, 'a': 16}
total = 0
for k in D:
if D[k] > 9:
total += D[k]
print(k, end=" ")
print(total)Output:
c e a 44
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'b': 7, 'c': 13, 'e': 15, 'a': 16} | D = {'b': 7, 'c': 13, 'e': 15, 'a': 16} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 9: | condition is False | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 9: | condition is True | |
| 5 | total += D[k] | total = 13 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 9: | condition is True | |
| 5 | total += D[k] | total = 28 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 9: | condition is True | |
| 5 | total += D[k] | total = 44 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 44⏎ |
Write the output of the following code.
D = {'c': 7, 'b': 6, 'e': 4, 'a': 1}
total = 0
for k in D:
if D[k] > 10:
total += D[k]
print(k, end=" ")
print(total)Output:
0
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'c': 7, 'b': 6, 'e': 4, 'a': 1} | D = {'c': 7, 'b': 6, 'e': 4, 'a': 1} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 10: | condition is False | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 10: | condition is False | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 10: | condition is False | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 10: | condition is False | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 0⏎ |
Rewrite the code after removing the errors. Underline each correction.
D = dict() D[1] = 'one' D.[2] = 'two' print(D.key())
D = dict() D[1] = 'one' D[2] = 'two' print(D.keys())
Use D[2] to add; the method is keys().
Rewrite the code after removing the errors. Underline each correction.
x = input('Enter a number')
if x % 2 = 0
print('Even')
else
print('Odd')x = int(input('Enter a number'))
if x % 2 == 0:
print('Even')
else:
print('Odd')input() gives a string: use int(); use == to compare; colons are needed after if and else.
Rewrite the code after removing the errors. Underline each correction.
i = 1
while i < 10:
if i % 2 = 0:
continue
print(i)
i =+ 1i = 1
while i < 10:
if i % 2 == 0:
i += 1
continue
print(i)
i += 1Use == to compare; =+ means 'assign +1', write += 1; i must change before continue, or the loop never ends.
Write the output of the following code.
L = [1, 9, 9, 8, 3, 6]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{1: 1, 9: 2, 8: 1, 3: 1, 6: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [1, 9, 9, 8, 3, 6] | L = [1, 9, 9, 8, 3, 6] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 1 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {1: 1} | |
| 3 | for x in L: | x = 9 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {1: 1, 9: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {1: 1, 9: 2} | |
| 3 | for x in L: | x = 8 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {1: 1, 9: 2, 8: 1} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {1: 1, 9: 2, 8: 1, 3: 1} | |
| 3 | for x in L: | x = 6 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {1: 1, 9: 2, 8: 1, 3: 1, 6: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {1: 1, 9: 2, 8: 1, 3: 1, 6: 1}⏎ |
Write the output of the following code.
L = [26, 2, 6, 25, 8, 12]
for i in range(len(L)):
if L[i] % 5 == 0:
L[i] = L[i] // 3
else:
L[i] = L[i] * 2
print(L)Output:
[52, 4, 12, 8, 16, 24]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [26, 2, 6, 25, 8, 12] | L = [26, 2, 6, 25, 8, 12] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 2, 6, 25, 8, 12] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 4, 6, 25, 8, 12] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 4, 12, 25, 8, 12] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 5 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [52, 4, 12, 8, 8, 12] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 4, 12, 8, 16, 12] |
… the same steps continue for the remaining values.
Write the output of the following code.
n = 60528
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
82506
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 60528 | n = 60528 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 8 | |
| 5 | s = s * 10 + d | s = 8 | |
| 6 | n = n // 10 | n = 6052 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 | |
| 5 | s = s * 10 + d | s = 82 | |
| 6 | n = n // 10 | n = 605 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 5 | |
| 5 | s = s * 10 + d | s = 825 | |
| 6 | n = n // 10 | n = 60 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 0 |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'d': 6, 'e': 8, 'c': 10, 'a': 13}
total = 0
for k in D:
if D[k] > 9:
total += D[k]
print(k, end=" ")
print(total)Output:
c a 23
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'d': 6, 'e': 8, 'c': 10, 'a': 13} | D = {'d': 6, 'e': 8, 'c': 10, 'a': 13} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 9: | condition is False | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 9: | condition is False | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 9: | condition is True | |
| 5 | total += D[k] | total = 10 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 9: | condition is True | |
| 5 | total += D[k] | total = 23 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 23⏎ |
Write the output of the following code.
L = [7, 1, 1, 2, 7, 5]
S = []
for x in L:
if x not in S:
S.append(x)
print(S, len(L) - len(S))Output:
[7, 1, 2, 5] 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [7, 1, 1, 2, 7, 5] | L = [7, 1, 1, 2, 7, 5] | |
| 2 | S = [] | S = [] | |
| 3 | for x in L: | x = 7 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [7] | |
| 3 | for x in L: | x = 1 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [7, 1] | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | if x not in S: | condition is False | |
| 3 | for x in L: | x = 2 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [7, 1, 2] | |
| 3 | for x in L: | x = 7 | |
| 4 | if x not in S: | condition is False | |
| 3 | for x in L: | x = 5 |
… the same steps continue for the remaining values.
Write the output of the following code.
n = 49478
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
87494
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 49478 | n = 49478 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 8 | |
| 5 | s = s * 10 + d | s = 8 | |
| 6 | n = n // 10 | n = 4947 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 | |
| 5 | s = s * 10 + d | s = 87 | |
| 6 | n = n // 10 | n = 494 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 4 | |
| 5 | s = s * 10 + d | s = 874 | |
| 6 | n = n // 10 | n = 49 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 |
… the same steps continue for the remaining values.
Write the output of the following code.
a = 4
b = 18
if a % 2 == 0 and b % 2 == 0:
print(a + b)
elif a % 2 == 0 or b > 20:
print(a * b)
else:
print(b - a)Output:
22
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | a = 4 | a = 4 | |
| 2 | b = 18 | b = 18 | |
| 3 | if a % 2 == 0 and b % 2 == 0: | condition is True | |
| 4 | print(a + b) | 22⏎ |
Rewrite the code after removing the errors. Underline each correction.
student = {'name' = 'Asha', 'age' = 16}
print(student[name])student = {'name': 'Asha', 'age': 16}
print(student['name'])Use : between key and value; the key is the string 'name'.
Write the output of the following code.
n = 35715
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
51753
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 35715 | n = 35715 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 5 | |
| 5 | s = s * 10 + d | s = 5 | |
| 6 | n = n // 10 | n = 3571 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 1 | |
| 5 | s = s * 10 + d | s = 51 | |
| 6 | n = n // 10 | n = 357 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 | |
| 5 | s = s * 10 + d | s = 517 | |
| 6 | n = n // 10 | n = 35 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 5 |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [2, 7, 3, 2, 7, 9]
S = []
for x in L:
if x not in S:
S.append(x)
print(S, len(L) - len(S))Output:
[2, 7, 3, 9] 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [2, 7, 3, 2, 7, 9] | L = [2, 7, 3, 2, 7, 9] | |
| 2 | S = [] | S = [] | |
| 3 | for x in L: | x = 2 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [2] | |
| 3 | for x in L: | x = 7 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [2, 7] | |
| 3 | for x in L: | x = 3 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [2, 7, 3] | |
| 3 | for x in L: | x = 2 | |
| 4 | if x not in S: | condition is False | |
| 3 | for x in L: | x = 7 | |
| 4 | if x not in S: | condition is False | |
| 3 | for x in L: | x = 9 |
… the same steps continue for the remaining values.
Write the output of the following code.
for i in range(1, 4):
for j in range(1, i + 1):
print(j * i, end=" ")
print()Output:
1 2 4 3 6 9
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(1, 4): | i = 1 | |
| 2 | for j in range(1, i + 1): | j = 1 | |
| 3 | print(j * i, end=" ") | 1 | |
| 2 | for j in range(1, i + 1): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 4): | i = 2 | |
| 2 | for j in range(1, i + 1): | loop ends (no more values) | |
| 3 | print(j * i, end=" ") | 2 | |
| 2 | for j in range(1, i + 1): | j = 2 | |
| 3 | print(j * i, end=" ") | 4 | |
| 2 | for j in range(1, i + 1): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 4): | i = 3 | |
| 2 | for j in range(1, i + 1): | j = 1 | |
| 3 | print(j * i, end=" ") | 3 | |
| 2 | for j in range(1, i + 1): | j = 2 |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [16, 3, 15, 17, 20, 5]
for i in range(len(L)):
if L[i] % 5 == 0:
L[i] = L[i] // 2
else:
L[i] = L[i] * 2
print(L)Output:
[32, 6, 7, 34, 10, 2]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [16, 3, 15, 17, 20, 5] | L = [16, 3, 15, 17, 20, 5] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [32, 3, 15, 17, 20, 5] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [32, 6, 15, 17, 20, 5] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 5 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [32, 6, 7, 17, 20, 5] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [32, 6, 7, 34, 20, 5] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 5 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [32, 6, 7, 34, 10, 5] |
… the same steps continue for the remaining values.
Rewrite the code after removing the errors. Underline each correction.
D = {'a': 1, 'b': 2]
for k in D
print(k, D(k))D = {'a': 1, 'b': 2}
for k in D:
print(k, D[k])Close the dictionary with }; colon after for; values are accessed with D[k].
Write the output of the following code.
n = 50472
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
27405
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 50472 | n = 50472 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 | |
| 5 | s = s * 10 + d | s = 2 | |
| 6 | n = n // 10 | n = 5047 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 | |
| 5 | s = s * 10 + d | s = 27 | |
| 6 | n = n // 10 | n = 504 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 4 | |
| 5 | s = s * 10 + d | s = 274 | |
| 6 | n = n // 10 | n = 50 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 0 |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'b': 18, 'c': 19, 'd': 14, 'a': 15}
total = 0
for k in D:
if D[k] > 12:
total += D[k]
print(k, end=" ")
print(total)Output:
b c d a 66
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'b': 18, 'c': 19, 'd': 14, 'a': 15} | D = {'b': 18, 'c': 19, 'd': 14, 'a': 15} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 12: | condition is True | |
| 5 | total += D[k] | total = 18 | |
| 6 | print(k, end=" ") | b | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 12: | condition is True | |
| 5 | total += D[k] | total = 37 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 12: | condition is True | |
| 5 | total += D[k] | total = 51 | |
| 6 | print(k, end=" ") | d | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 12: | condition is True |
… the same steps continue for the remaining values.
Rewrite the code after removing the errors. Underline each correction.
a = int(input('A: ')
b = float(input('B: '))
print('Total' + a + b)a = int(input('A: '))
b = float(input('B: '))
print('Total', a + b)Missing closing bracket; a string cannot be joined to numbers with +, use a comma.
Rewrite the code after removing the errors. Underline each correction.
for i in range(1, 6)
sum = sum + i
print(Sum)sum = 0
for i in range(1, 6):
sum = sum + i
print(sum)sum must be given a starting value; colon after for; Python is case sensitive (Sum).
Rewrite the code after removing the errors. Underline each correction.
num = int(input('N: '))
if num > 0:
print('Positive')
elif num = 0:
print('Zero')
else if num < 0:
print('Negative')num = int(input('N: '))
if num > 0:
print('Positive')
elif num == 0:
print('Zero')
else:
print('Negative')Indent the body of if; use == ; Python uses elif or else, not 'else if'.
Write the output of the following code.
n = 73711
s = 0
while n > 0:
d = n % 10
if d % 2 == 0:
s = s + d
n = n // 10
print(s)Output:
0
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 73711 | n = 73711 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 1 | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 7371 | |
| 3 | while n > 0: | condition is True | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 737 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 73 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 3 | |
| 5 | if d % 2 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code.
for i in range(4, 0, -1):
print("*" * i)Output:
**** *** ** *
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(4, 0, -1): | i = 4 | |
| 2 | print("*" * i) | ****⏎ | |
| 1 | for i in range(4, 0, -1): | i = 3 | |
| 2 | print("*" * i) | ***⏎ | |
| 1 | for i in range(4, 0, -1): | i = 2 | |
| 2 | print("*" * i) | **⏎ | |
| 1 | for i in range(4, 0, -1): | i = 1 | |
| 2 | print("*" * i) | *⏎ | |
| 1 | for i in range(4, 0, -1): | loop ends (no more values) |
Write the output of the following code.
L = [5, 6, 2, 3, 5, 1]
S = []
for x in L:
if x not in S:
S.append(x)
print(S, len(L) - len(S))Output:
[5, 6, 2, 3, 1] 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [5, 6, 2, 3, 5, 1] | L = [5, 6, 2, 3, 5, 1] | |
| 2 | S = [] | S = [] | |
| 3 | for x in L: | x = 5 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [5] | |
| 3 | for x in L: | x = 6 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [5, 6] | |
| 3 | for x in L: | x = 2 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [5, 6, 2] | |
| 3 | for x in L: | x = 3 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [5, 6, 2, 3] | |
| 3 | for x in L: | x = 5 | |
| 4 | if x not in S: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code.
x, y = 8, 21
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
32 19
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 8, 21 | x = 8, y = 21 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 16 | |
| 4 | y = y - 1 | y = 20 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 32 | |
| 4 | y = y - 1 | y = 19 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 32 19⏎ |
Write the output of the following code.
x, y = 9, 30
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
36 28
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 9, 30 | x = 9, y = 30 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 18 | |
| 4 | y = y - 1 | y = 29 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 36 | |
| 4 | y = y - 1 | y = 28 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 36 28⏎ |
Write the output of the following code.
L = [20, 14, 12, 27, 10, 19]
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] = L[i] // 3
else:
L[i] = L[i] * 2
print(L)Output:
[6, 4, 4, 54, 3, 38]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [20, 14, 12, 27, 10, 19] | L = [20, 14, 12, 27, 10, 19] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [6, 14, 12, 27, 10, 19] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [6, 4, 12, 27, 10, 19] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [6, 4, 4, 27, 10, 19] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [6, 4, 4, 54, 10, 19] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [6, 4, 4, 54, 3, 19] |
… the same steps continue for the remaining values.
Write the output of the following code.
for i in range(3, 0, -1):
print("*" * i)Output:
*** ** *
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(3, 0, -1): | i = 3 | |
| 2 | print("*" * i) | ***⏎ | |
| 1 | for i in range(3, 0, -1): | i = 2 | |
| 2 | print("*" * i) | **⏎ | |
| 1 | for i in range(3, 0, -1): | i = 1 | |
| 2 | print("*" * i) | *⏎ | |
| 1 | for i in range(3, 0, -1): | loop ends (no more values) |
Rewrite the code after removing the errors. Underline each correction.
L = [3, 6, 9] L.insert(1) print(L.sort())
L = [3, 6, 9] L.insert(1, 4) L.sort() print(L)
insert() needs an index and a value; sort() returns None, so sort first and then print L.
Write the output of the following code.
D = {'e': 12, 'a': 15, 'b': 17, 'c': 1}
total = 0
for k in D:
if D[k] > 10:
total += D[k]
print(k, end=" ")
print(total)Output:
e a b 44
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'e': 12, 'a': 15, 'b': 17, 'c': 1} | D = {'e': 12, 'a': 15, 'b': 17, 'c': 1} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 10: | condition is True | |
| 5 | total += D[k] | total = 12 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 10: | condition is True | |
| 5 | total += D[k] | total = 27 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 10: | condition is True | |
| 5 | total += D[k] | total = 44 | |
| 6 | print(k, end=" ") | b | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 10: | condition is False | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 44⏎ |
Write the output of the following code.
import numpy as np L = [[3, 13, 5], [1, 4, 8]] a = np.array(L) print(a.shape) print(a[1]) print(a * 10)
Output:
(2, 3) [1 4 8] [[ 30 130 50] [ 10 40 80]]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | L = [[3, 13, 5], [1, 4, 8]] | L = [[3, 13, 5], [1, 4, 8]] | |
| 3 | a = np.array(L) | a = array([[ 3, 13, 5],
[ 1, 4, 8]]) | |
| 4 | print(a.shape) | (2, 3)⏎ | |
| 5 | print(a[1]) | [1 4 8]⏎ | |
| 6 | print(a * 10) | [[ 30 130 50]⏎ [ 10 40 80]]⏎ |
Rewrite the code after removing the errors. Underline each correction.
D = {[1, 2]: 'a', 'b': 2}
print(D.items)D = {(1, 2): 'a', 'b': 2}
print(D.items())A list cannot be a key (it is mutable); use a tuple. items() needs brackets.
Write the output of the following code.
n = 22202
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
20222
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 22202 | n = 22202 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 | |
| 5 | s = s * 10 + d | s = 2 | |
| 6 | n = n // 10 | n = 2220 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 0 | |
| 5 | s = s * 10 + d | s = 20 | |
| 6 | n = n // 10 | n = 222 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 | |
| 5 | s = s * 10 + d | s = 202 | |
| 6 | n = n // 10 | n = 22 | |
| 3 | while n > 0: | condition is True | |
| 5 | s = s * 10 + d | s = 2022 |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [9, 5, 3, 4, 3, 7]
S = []
for x in L:
if x not in S:
S.append(x)
print(S, len(L) - len(S))Output:
[9, 5, 3, 4, 7] 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [9, 5, 3, 4, 3, 7] | L = [9, 5, 3, 4, 3, 7] | |
| 2 | S = [] | S = [] | |
| 3 | for x in L: | x = 9 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [9] | |
| 3 | for x in L: | x = 5 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [9, 5] | |
| 3 | for x in L: | x = 3 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [9, 5, 3] | |
| 3 | for x in L: | x = 4 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [9, 5, 3, 4] | |
| 3 | for x in L: | x = 3 | |
| 4 | if x not in S: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code.
import numpy as np L = [[5, 7, 10], [14, 2, 11]] a = np.array(L) print(a.shape) print(a[1]) print(a * 10)
Output:
(2, 3) [14 2 11] [[ 50 70 100] [140 20 110]]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | L = [[5, 7, 10], [14, 2, 11]] | L = [[5, 7, 10], [14, 2, 11]] | |
| 3 | a = np.array(L) | a = array([[ 5, 7, 10],
[14, 2, 11]]) | |
| 4 | print(a.shape) | (2, 3)⏎ | |
| 5 | print(a[1]) | [14 2 11]⏎ | |
| 6 | print(a * 10) | [[ 50 70 100]⏎ [140 20 110]]⏎ |
Write the output of the following code.
D = {'c': 10, 'e': 15, 'b': 7, 'd': 2}
total = 0
for k in D:
if D[k] > 12:
total += D[k]
print(k, end=" ")
print(total)Output:
e 15
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'c': 10, 'e': 15, 'b': 7, 'd': 2} | D = {'c': 10, 'e': 15, 'b': 7, 'd': 2} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 12: | condition is False | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 12: | condition is True | |
| 5 | total += D[k] | total = 15 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 12: | condition is False | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 12: | condition is False | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 15⏎ |
Write the output of the following code.
n = 78519
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
91587
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 78519 | n = 78519 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 | |
| 5 | s = s * 10 + d | s = 9 | |
| 6 | n = n // 10 | n = 7851 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 1 | |
| 5 | s = s * 10 + d | s = 91 | |
| 6 | n = n // 10 | n = 785 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 5 | |
| 5 | s = s * 10 + d | s = 915 | |
| 6 | n = n // 10 | n = 78 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 8 |
… the same steps continue for the remaining values.
Write the output of the following code.
n = 85359
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
95358
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 85359 | n = 85359 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 | |
| 5 | s = s * 10 + d | s = 9 | |
| 6 | n = n // 10 | n = 8535 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 5 | |
| 5 | s = s * 10 + d | s = 95 | |
| 6 | n = n // 10 | n = 853 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 3 | |
| 5 | s = s * 10 + d | s = 953 | |
| 6 | n = n // 10 | n = 85 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 5 |
… the same steps continue for the remaining values.
Write the output of the following code.
import numpy as np a = np.array([4, 5, 23, 31, 8]) b = a // 2 print(b) print(a > 10)
Output:
[ 2 2 11 15 4] [False False True True False]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | a = np.array([4, 5, 23, 31, 8]) | a = array([ 4, 5, 23, 31, 8]) | |
| 3 | b = a // 2 | b = array([ 2, 2, 11, 15, 4]) | |
| 4 | print(b) | [ 2 2 11 15 4]⏎ | |
| 5 | print(a > 10) | [False False True True False]⏎ |
Write the output of the following code.
import numpy as np marks = [30, 29, 12, 28, 22] a = np.array(marks) print(a + 5) print(a.size, a.ndim)
Output:
[35 34 17 33 27] 5 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | marks = [30, 29, 12, 28, 22] | marks = [30, 29, 12, 28, 22] | |
| 3 | a = np.array(marks) | a = array([30, 29, 12, 28, 22]) | |
| 4 | print(a + 5) | [35 34 17 33 27]⏎ | |
| 5 | print(a.size, a.ndim) | 5 1⏎ |
Write the output of the following code.
L = [26, 10, 27, 19, 23, 17]
for i in range(len(L)):
if L[i] % 5 == 0:
L[i] = L[i] // 3
else:
L[i] = L[i] * 2
print(L)Output:
[52, 3, 54, 38, 46, 34]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [26, 10, 27, 19, 23, 17] | L = [26, 10, 27, 19, 23, 17] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 10, 27, 19, 23, 17] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 5 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [52, 3, 27, 19, 23, 17] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 3, 54, 19, 23, 17] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 3, 54, 38, 23, 17] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 3, 54, 38, 46, 17] |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [5, 2, 1, 2, 5, 4]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{5: 2, 2: 2, 1: 1, 4: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [5, 2, 1, 2, 5, 4] | L = [5, 2, 1, 2, 5, 4] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 5 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1} | |
| 3 | for x in L: | x = 2 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 2: 1} | |
| 3 | for x in L: | x = 1 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 2: 1, 1: 1} | |
| 3 | for x in L: | x = 2 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 2: 2, 1: 1} | |
| 3 | for x in L: | x = 5 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 2, 2: 2, 1: 1} | |
| 3 | for x in L: | x = 4 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 2, 2: 2, 1: 1, 4: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {5: 2, 2: 2, 1: 1, 4: 1}⏎ |
Write the output of the following code.
D = {'c': 11, 'a': 2, 'b': 9, 'e': 3}
total = 0
for k in D:
if D[k] > 10:
total += D[k]
print(k, end=" ")
print(total)Output:
c 11
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'c': 11, 'a': 2, 'b': 9, 'e': 3} | D = {'c': 11, 'a': 2, 'b': 9, 'e': 3} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 10: | condition is True | |
| 5 | total += D[k] | total = 11 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 10: | condition is False | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 10: | condition is False | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 10: | condition is False | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 11⏎ |
Write the output of the following code.
D = {'e': 9, 'd': 11, 'a': 16, 'c': 15}
total = 0
for k in D:
if D[k] > 7:
total += D[k]
print(k, end=" ")
print(total)Output:
e d a c 51
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'e': 9, 'd': 11, 'a': 16, 'c': 15} | D = {'e': 9, 'd': 11, 'a': 16, 'c': 15} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 7: | condition is True | |
| 5 | total += D[k] | total = 9 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 7: | condition is True | |
| 5 | total += D[k] | total = 20 | |
| 6 | print(k, end=" ") | d | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 7: | condition is True | |
| 5 | total += D[k] | total = 36 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 7: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
x, y = 4, 25
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
32 22
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 4, 25 | x = 4, y = 25 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 8 | |
| 4 | y = y - 1 | y = 24 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 16 | |
| 4 | y = y - 1 | y = 23 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 32 | |
| 4 | y = y - 1 | y = 22 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 32 22⏎ |
Rewrite the code after removing the errors. Underline each correction.
marks = [70, 80, 90]
total = 0
for m in range(marks):
total += m
print(total / len[marks])marks = [70, 80, 90]
total = 0
for m in marks:
total += m
print(total / len(marks))Loop directly over the list (range needs a number); len() uses round brackets.
Rewrite the code after removing the errors. Underline each correction.
x = 10
y = 0
if y != 0:
print(x / y)
Else:
print('Cannot divide')x = 10
y = 0
if y != 0:
print(x / y)
else:
print('Cannot divide')Python is case sensitive: the keyword is else.
Rewrite the code after removing the errors. Underline each correction.
N = 4
for i in range(1, N+1):
for j in range(i)
print('*', end=' ')
print()N = 4
for i in range(1, N+1):
for j in range(i):
print('*', end=' ')
print()Colon after the inner for; keep the indentation consistent.
Write the output of the following code.
a = 5
b = 20
if a % 2 == 0 and b % 2 == 0:
print(a + b)
elif a % 2 == 0 or b > 20:
print(a * b)
else:
print(b - a)Output:
15
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | a = 5 | a = 5 | |
| 2 | b = 20 | b = 20 | |
| 3 | if a % 2 == 0 and b % 2 == 0: | condition is False | |
| 5 | elif a % 2 == 0 or b > 20: | condition is False | |
| 8 | print(b - a) | 15⏎ |
Write the output of the following code.
L = [11, 2, 28, 6, 8, 14]
for i in range(len(L)):
if L[i] % 3 == 0:
L[i] = L[i] // 2
else:
L[i] = L[i] * 2
print(L)Output:
[22, 4, 56, 3, 16, 28]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [11, 2, 28, 6, 8, 14] | L = [11, 2, 28, 6, 8, 14] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 3 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [22, 2, 28, 6, 8, 14] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 3 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [22, 4, 28, 6, 8, 14] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 3 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [22, 4, 56, 6, 8, 14] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 3 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [22, 4, 56, 3, 8, 14] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 3 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [22, 4, 56, 3, 16, 14] |
… the same steps continue for the remaining values.
Rewrite the code after removing the errors. Underline each correction.
t = (10, 20, 30) a, b = t print(a + b)
t = (10, 20, 30) a, b, c = t print(a + b)
The number of variables must match the number of values when unpacking.
Write the output of the following code.
n = 65299
s = 0
while n > 0:
d = n % 10
if d % 2 == 0:
s = s + d
n = n // 10
print(s)Output:
8
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 65299 | n = 65299 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 6529 | |
| 3 | while n > 0: | condition is True | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 652 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 | |
| 5 | if d % 2 == 0: | condition is True | |
| 6 | s = s + d | s = 2 | |
| 7 | n = n // 10 | n = 65 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 5 |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'e': 13, 'a': 18, 'c': 9, 'b': 2}
total = 0
for k in D:
if D[k] > 6:
total += D[k]
print(k, end=" ")
print(total)Output:
e a c 40
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'e': 13, 'a': 18, 'c': 9, 'b': 2} | D = {'e': 13, 'a': 18, 'c': 9, 'b': 2} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 6: | condition is True | |
| 5 | total += D[k] | total = 13 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 6: | condition is True | |
| 5 | total += D[k] | total = 31 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 6: | condition is True | |
| 5 | total += D[k] | total = 40 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 6: | condition is False | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 40⏎ |
Write the output of the following code.
for i in range(1, 4):
print(" " * (3 - i) + "#" * i)Output:
# ## ###
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(1, 4): | i = 1 | |
| 2 | print(" " * (3 - i) + "#" * i) | #⏎ | |
| 1 | for i in range(1, 4): | i = 2 | |
| 2 | print(" " * (3 - i) + "#" * i) | ##⏎ | |
| 1 | for i in range(1, 4): | i = 3 | |
| 2 | print(" " * (3 - i) + "#" * i) | ###⏎ | |
| 1 | for i in range(1, 4): | loop ends (no more values) |
Write the output of the following code.
L = [5, 2, 8, 8, 8, 7]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{5: 1, 2: 1, 8: 3, 7: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [5, 2, 8, 8, 8, 7] | L = [5, 2, 8, 8, 8, 7] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 5 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1} | |
| 3 | for x in L: | x = 2 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 2: 1} | |
| 3 | for x in L: | x = 8 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 2: 1, 8: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 2: 1, 8: 2} | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 2: 1, 8: 3} | |
| 3 | for x in L: | x = 7 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 2: 1, 8: 3, 7: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {5: 1, 2: 1, 8: 3, 7: 1}⏎ |
Write the output of the following code.
import numpy as np marks = [7, 33, 24, 27, 36] a = np.array(marks) print(a + 5) print(a.size, a.ndim)
Output:
[12 38 29 32 41] 5 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | marks = [7, 33, 24, 27, 36] | marks = [7, 33, 24, 27, 36] | |
| 3 | a = np.array(marks) | a = array([ 7, 33, 24, 27, 36]) | |
| 4 | print(a + 5) | [12 38 29 32 41]⏎ | |
| 5 | print(a.size, a.ndim) | 5 1⏎ |
Write the output of the following code.
D = {'b': 4, 'e': 3, 'd': 7, 'c': 13}
total = 0
for k in D:
if D[k] > 8:
total += D[k]
print(k, end=" ")
print(total)Output:
c 13
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'b': 4, 'e': 3, 'd': 7, 'c': 13} | D = {'b': 4, 'e': 3, 'd': 7, 'c': 13} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 8: | condition is False | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 8: | condition is False | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 8: | condition is False | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 8: | condition is True | |
| 5 | total += D[k] | total = 13 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 13⏎ |
Rewrite the code after removing the errors. Underline each correction.
1st_num = 10 second num = 20 print(1st_num + second num)
num1 = 10 second_num = 20 print(num1 + second_num)
An identifier cannot start with a digit or have a space.
What is a database? Why is a DBMS better than a file system?
An organised collection of related data. A DBMS reduces redundancy and inconsistency, allows sharing, gives security and makes searching easy.
What is a DBMS? Give two examples.
Software to create, store, manage and retrieve data in a database. Examples: MySQL, Oracle, MS Access, PostgreSQL, SQL Server.
Define:
(i) A relation is a table of rows and columns. (ii) A tuple is a row of a relation; it holds the data of one entity.
Define degree and cardinality with an example.
Degree is the number of attributes (columns); cardinality is the number of tuples (rows). A table with 4 columns and 10 rows has degree 4 and cardinality 10.
What is a domain? Give an example.
The set of all valid values of an attribute. The domain of Gender may be {M, F}; of Marks, whole numbers 0 to 100.
Differentiate between a primary key and a candidate key.
A candidate key is any attribute (or set) that can uniquely identify each row; a table may have many. The primary key is the one candidate key chosen to identify the rows.
What is an alternate key? Give an example.
A candidate key that is not chosen as the primary key. In STUDENT(AdmNo, RollNo, Name), if AdmNo is the primary key, RollNo is an alternate key.
What is data redundancy? Why is it a problem?
Keeping the same data in more than one place. It wastes space and leads to inconsistency when one copy is changed and the other is not.
Differentiate between schema and instance of a database.
Schema is the design: table names, columns and types; it rarely changes. Instance is the actual data stored at a moment; it changes often.
What are the limitations of a file system?
Data redundancy, data inconsistency, difficulty in accessing data, data isolation, poor security and no control over sharing.
What is SQL? Write two of its advantages.
Structured Query Language, used to create and work with relational databases. Advantages: easy English-like commands, works on most DBMS, fast data retrieval, no coding of procedures needed.
Differentiate between DDL and DML with two commands each.
DDL defines or changes the structure of tables: CREATE, ALTER, DROP. DML changes the data in tables: INSERT, UPDATE, DELETE.
Differentiate between CHAR and VARCHAR.
CHAR(n) is fixed length: it always uses n characters of space. VARCHAR(n) is variable length: it uses only as much space as the value needs, up to n.
Differentiate between DELETE and DROP.
DELETE (DML) removes rows from a table; the structure remains. DROP (DDL) removes the whole table, structure and data, from the database.
Differentiate between ALTER and UPDATE.
ALTER (DDL) changes the structure of a table, such as adding a column. UPDATE (DML) changes the values stored in rows.
What is a constraint? Name any three.
A rule applied on a column to keep the data valid. NOT NULL, UNIQUE, PRIMARY KEY, DEFAULT. (Any three.)
What is NULL? How do we search for NULL values?
NULL means an unknown or missing value; it is not zero or a blank space. We use IS NULL or IS NOT NULL, because = NULL does not work.
Write the use of the BETWEEN operator with an example.
It selects values in a range, both ends included. SELECT * FROM STUDENT WHERE Marks BETWEEN 60 AND 80;
Write the commands to:
(i) CREATE DATABASE SCHOOL; (ii) USE SCHOOL;
Write the commands to:
(i) SHOW DATABASES; (ii) SHOW TABLES;
Write the command to add a column Email VARCHAR(40) to the table STUDENT, and to remove it again.
ALTER TABLE STUDENT ADD Email VARCHAR(40); ALTER TABLE STUDENT DROP Email;
Write the command to make RollNo the primary key of an existing table STUDENT, and to remove the primary key.
ALTER TABLE STUDENT ADD PRIMARY KEY (RollNo); ALTER TABLE STUDENT DROP PRIMARY KEY;
What is the use of the DESCRIBE command? Write its syntax.
It shows the structure of a table: column names, types, NULL allowed, keys. Syntax: DESCRIBE STUDENT; or DESC STUDENT;
Differentiate between the AND and OR operators in SQL.
AND gives a row only if both conditions are true. OR gives a row if at least one condition is true. WHERE Marks > 80 AND Gender = 'F'; WHERE City = 'Delhi' OR City = 'Pune';
Why is a primary key important? What happens if we insert a duplicate value in it?
It identifies each row uniquely and keeps the table free of duplicate records. Inserting a duplicate value gives an error and the row is not added.
Write any four data types of MySQL with their use.
INT: whole numbers; FLOAT / DECIMAL: numbers with decimals; CHAR(n): fixed-length text; VARCHAR(n): variable-length text; DATE: dates as 'YYYY-MM-DD'. (Any four.)
What is the difference between the = and IS operators in SQL?
= compares a column with a value (Marks = 80). IS is used with NULL (Phone IS NULL), because NULL is unknown and cannot be compared with =.
What is MySQL? Write two of its features.
A free, open-source relational DBMS that uses SQL. Features: free and open source, fast, works on many platforms, supports many users, secure.
Explain the use of the logical operator NOT with an example.
NOT reverses a condition. SELECT * FROM EMP WHERE NOT Dept = 'Sales'; shows employees of all departments other than Sales.
Write the general syntax of the SELECT command with WHERE.
SELECT column1, column2, ... FROM table_name WHERE condition;
Identify the degree and cardinality: a table EMP has columns EmpID, Name, Dept, Salary and 12 employees. After adding 3 employees and a column Phone, what are they?
At first: degree 4, cardinality 12. After the changes: degree 5, cardinality 15.
Can a table have no primary key? Is it a good idea?
Yes, MySQL allows it, but it is not a good idea: duplicate rows may be entered and rows cannot be identified uniquely.
Give two examples of real-life databases.
School records of students, bank account records, railway reservations, library catalogue, hospital patient records. (Any two.)
What is data inconsistency? Give an example.
When copies of the same data have different values. A student's address is changed in the office file but not in the library file.
Why is Aadhaar number a candidate key in a table of citizens?
Because every citizen has a unique Aadhaar number, so it can identify each row uniquely.
What is the difference between DDL and DQL?
DDL commands (CREATE, ALTER, DROP) define the structure of the database. DQL (SELECT) only reads and displays data.
Write the output of: SELECT 5 * 4 + 3; and SELECT 17 > 10;
23 and 1 (MySQL shows a true condition as 1).
Write two rules for writing SQL statements.
Each statement ends with a semicolon; text and dates are written in single quotes; keywords are not case sensitive; commas separate the column names.
Write a command to insert a row (101, 'Asha', 'XI', 92) into STUDENT(RollNo, Name, Class, Marks).
INSERT INTO STUDENT VALUES (101, 'Asha', 'XI', 92);
Explanation: INSERT adds a new row; values are given in the order of the columns, text and dates in quotes.
Write a command to change the marks of roll number 101 to 95 in STUDENT.
UPDATE STUDENT SET Marks = 95 WHERE RollNo = 101;
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 300 AND 400;
| PCode | PName | Price |
|---|---|---|
| P05 | Water Bottle | 320 |
Explanation: WHERE keeps only the rows where Price is from 300 to 400 (both included): 1 of the 7 rows matches (Water Bottle). SELECT then shows only the columns PCode, PName, Price.
(ii)
SELECT PName FROM PRODUCT WHERE Discount IS NULL;
| PName |
|---|
| Pen Drive |
| Water Bottle |
Explanation: WHERE keeps only the rows where Discount is empty (NULL): 2 of the 7 rows match (Pen Drive, Water Bottle). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'IT' OR Dept = 'Sales';
| EName | Dept |
|---|---|
| Ravi | Sales |
| Tarun | IT |
| Usha | Sales |
| Vikas | IT |
| Yamini | IT |
Explanation: WHERE keeps only the rows where Dept is 'IT' or Dept is 'Sales': 5 of the 7 rows match (Ravi, Tarun, Usha, Vikas, Yamini). SELECT then shows only the columns EName, Dept.
(ii)
SELECT EName FROM EMPLOYEE WHERE Dept = 'HR' AND Salary >= 60000;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Dept is 'HR' and Salary is at least 60000. No row satisfies this, so the result is an empty set.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 60 AND 70;
| RollNo | Name | Marks |
|---|---|---|
| 4 | Divya | 66 |
Explanation: WHERE keeps only the rows where Marks is from 60 to 70 (both included): 1 of the 7 rows matches (Divya). SELECT then shows only the columns RollNo, Name, Marks.
(ii)
SELECT Name, Section FROM STUDENT WHERE Section = 'B' OR Section = 'A';
| Name | Section |
|---|---|
| Aarav | A |
| Bhavya | B |
| Chirag | A |
| Eshan | B |
| Farah | A |
Explanation: WHERE keeps only the rows where Section is 'B' or Section is 'A': 5 of the 7 rows match (Aarav, Bhavya, Chirag, Eshan, Farah). SELECT then shows only the columns Name, Section.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName, Price FROM PRODUCT WHERE Price < 100 OR Discount IS NULL;
| PName | Price |
|---|---|
| Notebook | 60 |
| Pen Drive | 450 |
| Water Bottle | 320 |
Explanation: WHERE keeps only the rows where Price is less than 100 or Discount is empty (NULL): 3 of the 7 rows match (Notebook, Pen Drive, Water Bottle). SELECT then shows only the columns PName, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PCode, Price, Price + 10 FROM PRODUCT;
| PCode | Price | Price + 10 |
|---|---|---|
| P01 | 60 | 70 |
| P02 | 450 | 460 |
| P03 | 180 | 190 |
| P04 | 650 | 660 |
| P05 | 320 | 330 |
| P06 | 899 | 909 |
| P07 | 275 | 285 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PCode, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT RollNo, Marks, Marks + 10 FROM STUDENT;
| RollNo | Marks | Marks + 10 |
|---|---|---|
| 1 | 78 | 88 |
| 2 | 92 | 102 |
| 3 | 45 | 55 |
| 4 | 66 | 76 |
| 5 | 88 | 98 |
| 6 | 31 | 41 |
| 7 | 59 | 69 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns RollNo, Marks, Marks + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT Name, Section FROM STUDENT WHERE Section = 'B' OR Section = 'C';
| Name | Section |
|---|---|
| Bhavya | B |
| Divya | C |
| Eshan | B |
| Gaurav | C |
Explanation: WHERE keeps only the rows where Section is 'B' or Section is 'C': 4 of the 7 rows match (Bhavya, Divya, Eshan, Gaurav). SELECT then shows only the columns Name, Section.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName, Category FROM PRODUCT WHERE Category = 'Electronics' OR Category = 'Stationery';
| PName | Category |
|---|---|
| Notebook | Stationery |
| Pen Drive | Electronics |
| Geometry Box | Stationery |
| Mouse | Electronics |
| Earphones | Electronics |
Explanation: WHERE keeps only the rows where Category is 'Electronics' or Category is 'Stationery': 5 of the 7 rows match (Notebook, Pen Drive, Geometry Box, Mouse, Earphones). SELECT then shows only the columns PName, Category.
(ii)
SELECT PName, Price FROM PRODUCT WHERE Price > 400;
| PName | Price |
|---|---|
| Pen Drive | 450 |
| Mouse | 650 |
| Earphones | 899 |
Explanation: WHERE keeps only the rows where Price is more than 400: 3 of the 7 rows match (Pen Drive, Mouse, Earphones). SELECT then shows only the columns PName, Price.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName, Fee FROM PATIENT WHERE Fee < 1500 OR Insurance IS NULL;
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Om | 1200 |
| Qasim | 9500 |
| Rekha | 4500 |
| Sahil | 900 |
Explanation: WHERE keeps only the rows where Fee is less than 1500 or Insurance is empty (NULL): 5 of the 7 rows match (Nisha, Om, Qasim, Rekha, Sahil). SELECT then shows only the columns PName, Fee. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName FROM PATIENT WHERE Doctor = 'Dr. Iyer' AND Insurance IS NOT NULL;
| PName |
|---|
| Pooja |
Explanation: WHERE keeps only the rows where Doctor is 'Dr. Iyer' and Insurance has a value (is not NULL): 1 of the 7 rows matches (Pooja). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title, Member FROM BOOK WHERE Member IS NOT NULL;
| Title | Member |
|---|---|
| Informatics Practices | Asha |
| Wings of Fire | Ravi |
| Chemistry Part 1 | Neha |
| Learn SQL | Karan |
Explanation: WHERE keeps only the rows where Member has a value (is not NULL): 4 of the 7 rows match (Informatics Practices, Wings of Fire, Chemistry Part 1, Learn SQL). SELECT then shows only the columns Title, Member. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Title, Price FROM BOOK WHERE Price > 200;
| Title | Price |
|---|---|
| Informatics Practices | 210 |
| Wings of Fire | 299 |
| Python Basics | 350 |
| The Story of My Experiments | 250 |
| Learn SQL | 400 |
Explanation: WHERE keeps only the rows where Price is more than 200: 5 of the 7 rows match (Informatics Practices, Wings of Fire, Python Basics, The Story of My Experiments, Learn SQL). SELECT then shows only the columns Title, Price.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PID, Fee, Fee + 10 FROM PATIENT;
| PID | Fee | Fee + 10 |
|---|---|---|
| 11 | 1500 | 1510 |
| 12 | 8000 | 8010 |
| 13 | 1200 | 1210 |
| 14 | 5000 | 5010 |
| 15 | 9500 | 9510 |
| 16 | 4500 | 4510 |
| 17 | 900 | 910 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PID, Fee, Fee + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT PID, PName, Fee FROM PATIENT WHERE Fee BETWEEN 4000 AND 6000;
| PID | PName | Fee |
|---|---|---|
| 14 | Pooja | 5000 |
| 16 | Rekha | 4500 |
Explanation: WHERE keeps only the rows where Fee is from 4000 to 6000 (both included): 2 of the 7 rows match (Pooja, Rekha). SELECT then shows only the columns PID, PName, Fee.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';
| EName | DOJ |
|---|---|
| Ravi | 2018-06-01 |
| Seema | 2020-01-15 |
| Vikas | 2019-11-05 |
Explanation: WHERE keeps only the rows where DOJ is from '2018-01-01' to '2020-12-31' (both included): 3 of the 7 rows match (Ravi, Seema, Vikas). SELECT then shows only the columns EName, DOJ.
(ii)
SELECT EName FROM EMPLOYEE WHERE City = 'Mumbai' AND Bonus IS NOT NULL;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where City is 'Mumbai' and Bonus has a value (is not NULL). No row satisfies this, so the result is an empty set. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName, Fee FROM PATIENT WHERE Fee > 4000;
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Pooja | 5000 |
| Qasim | 9500 |
| Rekha | 4500 |
Explanation: WHERE keeps only the rows where Fee is more than 4000: 4 of the 7 rows match (Nisha, Pooja, Qasim, Rekha). SELECT then shows only the columns PName, Fee.
(ii)
SELECT PName FROM PATIENT WHERE Doctor = 'Dr. Sen' AND Insurance IS NOT NULL;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Doctor is 'Dr. Sen' and Insurance has a value (is not NULL). No row satisfies this, so the result is an empty set. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 100 AND 300;
| PCode | PName | Price |
|---|---|---|
| P03 | Geometry Box | 180 |
| P07 | Lunch Box | 275 |
Explanation: WHERE keeps only the rows where Price is from 100 to 300 (both included): 2 of the 7 rows match (Geometry Box, Lunch Box). SELECT then shows only the columns PCode, PName, Price.
(ii)
SELECT PName, Price FROM PRODUCT WHERE Price > 400;
| PName | Price |
|---|---|
| Pen Drive | 450 |
| Mouse | 650 |
| Earphones | 899 |
Explanation: WHERE keeps only the rows where Price is more than 400: 3 of the 7 rows match (Pen Drive, Mouse, Earphones). SELECT then shows only the columns PName, Price.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName, Price FROM PRODUCT WHERE Price < 300 OR Discount IS NULL;
| PName | Price |
|---|---|
| Notebook | 60 |
| Pen Drive | 450 |
| Geometry Box | 180 |
| Water Bottle | 320 |
| Lunch Box | 275 |
Explanation: WHERE keeps only the rows where Price is less than 300 or Discount is empty (NULL): 5 of the 7 rows match (Notebook, Pen Drive, Geometry Box, Water Bottle, Lunch Box). SELECT then shows only the columns PName, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
| PName | Discount |
|---|---|
| Notebook | 5 |
| Geometry Box | 10 |
| Mouse | 15 |
| Earphones | 20 |
| Lunch Box | 8 |
Explanation: WHERE keeps only the rows where Discount has a value (is not NULL): 5 of the 7 rows match (Notebook, Geometry Box, Mouse, Earphones, Lunch Box). SELECT then shows only the columns PName, Discount. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
| Name | Phone |
|---|---|
| Aarav | 9810011111 |
| Chirag | 9810033333 |
| Divya | 9810044444 |
| Farah | 9810066666 |
| Gaurav | 9810077777 |
Explanation: WHERE keeps only the rows where Phone has a value (is not NULL): 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Phone. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Name FROM STUDENT WHERE Gender = 'M' AND Phone IS NOT NULL;
| Name |
|---|
| Aarav |
| Chirag |
| Gaurav |
Explanation: WHERE keeps only the rows where Gender is 'M' and Phone has a value (is not NULL): 3 of the 7 rows match (Aarav, Chirag, Gaurav). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName, Ward FROM PATIENT WHERE NOT Ward = 'General';
| PName | Ward |
|---|---|
| Nisha | ICU |
| Pooja | Maternity |
| Qasim | ICU |
| Rekha | Maternity |
Explanation: WHERE keeps only the rows where Ward is not 'General': 4 of the 7 rows match (Nisha, Pooja, Qasim, Rekha). SELECT then shows only the columns PName, Ward.
(ii)
SELECT PName FROM PATIENT WHERE Insurance IS NULL;
| PName |
|---|
| Nisha |
| Qasim |
| Rekha |
Explanation: WHERE keeps only the rows where Insurance is empty (NULL): 3 of the 7 rows match (Nisha, Qasim, Rekha). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
| PName | AdmitDate |
|---|---|
| Nisha | 2026-09-05 |
| Om | 2026-09-10 |
| Pooja | 2026-09-12 |
| Qasim | 2026-09-15 |
Explanation: WHERE keeps only the rows where AdmitDate is from '2026-09-05' to '2026-09-15' (both included): 4 of the 7 rows match (Nisha, Om, Pooja, Qasim). SELECT then shows only the columns PName, AdmitDate.
(ii)
SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
| PName | Insurance |
|---|---|
| Mohan | LIC |
| Om | Star |
| Pooja | LIC |
| Sahil | Star |
Explanation: WHERE keeps only the rows where Insurance has a value (is not NULL): 4 of the 7 rows match (Mohan, Om, Pooja, Sahil). SELECT then shows only the columns PName, Insurance. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title, Price FROM BOOK WHERE Price > 300;
| Title | Price |
|---|---|
| Python Basics | 350 |
| Learn SQL | 400 |
Explanation: WHERE keeps only the rows where Price is more than 300: 2 of the 7 rows match (Python Basics, Learn SQL). SELECT then shows only the columns Title, Price.
(ii)
SELECT Title, Price FROM BOOK WHERE Price < 300 OR Member IS NULL;
| Title | Price |
|---|---|
| Informatics Practices | 210 |
| Physics Part 1 | 180 |
| Wings of Fire | 299 |
| Python Basics | 350 |
| Chemistry Part 1 | 190 |
| The Story of My Experiments | 250 |
Explanation: WHERE keeps only the rows where Price is less than 300 or Member is empty (NULL): 6 of the 7 rows match (Informatics Practices, Physics Part 1, Wings of Fire, Python Basics, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
| PName | AdmitDate |
|---|---|
| Nisha | 2026-09-05 |
| Om | 2026-09-10 |
| Pooja | 2026-09-12 |
| Qasim | 2026-09-15 |
Explanation: WHERE keeps only the rows where AdmitDate is from '2026-09-05' to '2026-09-15' (both included): 4 of the 7 rows match (Nisha, Om, Pooja, Qasim). SELECT then shows only the columns PName, AdmitDate.
(ii)
SELECT PName, Ward FROM PATIENT WHERE Ward = 'General' OR Ward = 'Maternity';
| PName | Ward |
|---|---|
| Mohan | General |
| Om | General |
| Pooja | Maternity |
| Rekha | Maternity |
| Sahil | General |
Explanation: WHERE keeps only the rows where Ward is 'General' or Ward is 'Maternity': 5 of the 7 rows match (Mohan, Om, Pooja, Rekha, Sahil). SELECT then shows only the columns PName, Ward.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name FROM STUDENT WHERE Section = 'C' AND Marks >= 50;
| Name |
|---|
| Divya |
| Gaurav |
Explanation: WHERE keeps only the rows where Section is 'C' and Marks is at least 50: 2 of the 7 rows match (Divya, Gaurav). SELECT then shows only the column Name.
(ii)
SELECT Name, Section FROM STUDENT WHERE Section = 'A' OR Section = 'B';
| Name | Section |
|---|---|
| Aarav | A |
| Bhavya | B |
| Chirag | A |
| Eshan | B |
| Farah | A |
Explanation: WHERE keeps only the rows where Section is 'A' or Section is 'B': 5 of the 7 rows match (Aarav, Bhavya, Chirag, Eshan, Farah). SELECT then shows only the columns Name, Section.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
| Name | DOB |
|---|---|
| Bhavya | 2009-11-30 |
| Divya | 2009-07-21 |
| Farah | 2009-09-09 |
Explanation: WHERE keeps only the rows where DOB is from '2009-06-01' to '2009-12-31' (both included): 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, DOB.
(ii)
SELECT Name FROM STUDENT WHERE Phone IS NULL;
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Phone is empty (NULL): 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName, Ward FROM PATIENT WHERE NOT Ward = 'Maternity';
| PName | Ward |
|---|---|
| Mohan | General |
| Nisha | ICU |
| Om | General |
| Qasim | ICU |
| Sahil | General |
Explanation: WHERE keeps only the rows where Ward is not 'Maternity': 5 of the 7 rows match (Mohan, Nisha, Om, Qasim, Sahil). SELECT then shows only the columns PName, Ward.
(ii)
SELECT PName, Fee FROM PATIENT WHERE Fee < 1500 OR Insurance IS NULL;
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Om | 1200 |
| Qasim | 9500 |
| Rekha | 4500 |
| Sahil | 900 |
Explanation: WHERE keeps only the rows where Fee is less than 1500 or Insurance is empty (NULL): 5 of the 7 rows match (Nisha, Om, Qasim, Rekha, Sahil). SELECT then shows only the columns PName, Fee. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName FROM PRODUCT WHERE Discount IS NULL;
| PName |
|---|
| Pen Drive |
| Water Bottle |
Explanation: WHERE keeps only the rows where Discount is empty (NULL): 2 of the 7 rows match (Pen Drive, Water Bottle). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName FROM PRODUCT WHERE Brand = 'Boat' AND Discount IS NOT NULL;
| PName |
|---|
| Earphones |
Explanation: WHERE keeps only the rows where Brand is 'Boat' and Discount has a value (is not NULL): 1 of the 7 rows matches (Earphones). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'IT' OR Dept = 'HR';
| EName | Dept |
|---|---|
| Seema | HR |
| Tarun | IT |
| Vikas | IT |
| Wasim | HR |
| Yamini | IT |
Explanation: WHERE keeps only the rows where Dept is 'IT' or Dept is 'HR': 5 of the 7 rows match (Seema, Tarun, Vikas, Wasim, Yamini). SELECT then shows only the columns EName, Dept.
(ii)
SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';
| EName | DOJ |
|---|---|
| Ravi | 2018-06-01 |
| Seema | 2020-01-15 |
| Vikas | 2019-11-05 |
Explanation: WHERE keeps only the rows where DOJ is from '2018-01-01' to '2020-12-31' (both included): 3 of the 7 rows match (Ravi, Seema, Vikas). SELECT then shows only the columns EName, DOJ.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name, Gender FROM STUDENT WHERE Gender <> 'M';
| Name | Gender |
|---|---|
| Bhavya | F |
| Divya | F |
| Farah | F |
Explanation: WHERE keeps only the rows where Gender is not 'M': 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, Gender.
(ii)
SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
| Name | DOB |
|---|---|
| Bhavya | 2009-11-30 |
| Divya | 2009-07-21 |
| Farah | 2009-09-09 |
Explanation: WHERE keeps only the rows where DOB is from '2009-06-01' to '2009-12-31' (both included): 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, DOB.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';
| EName | DOJ |
|---|---|
| Ravi | 2018-06-01 |
| Seema | 2020-01-15 |
| Vikas | 2019-11-05 |
Explanation: WHERE keeps only the rows where DOJ is from '2018-01-01' to '2020-12-31' (both included): 3 of the 7 rows match (Ravi, Seema, Vikas). SELECT then shows only the columns EName, DOJ.
(ii)
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Delhi';
| EName | City |
|---|---|
| Seema | Pune |
| Usha | Mumbai |
| Vikas | Pune |
| Yamini | Mumbai |
Explanation: WHERE keeps only the rows where City is not 'Delhi': 4 of the 7 rows match (Seema, Usha, Vikas, Yamini). SELECT then shows only the columns EName, City.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName, Doctor FROM PATIENT WHERE Doctor <> 'Dr. Sen';
| PName | Doctor |
|---|---|
| Mohan | Dr. Rao |
| Om | Dr. Rao |
| Pooja | Dr. Iyer |
| Rekha | Dr. Iyer |
| Sahil | Dr. Rao |
Explanation: WHERE keeps only the rows where Doctor is not 'Dr. Sen': 5 of the 7 rows match (Mohan, Om, Pooja, Rekha, Sahil). SELECT then shows only the columns PName, Doctor.
(ii)
SELECT PID, PName, Fee FROM PATIENT WHERE Fee BETWEEN 1500 AND 4000;
| PID | PName | Fee |
|---|---|---|
| 11 | Mohan | 1500 |
Explanation: WHERE keeps only the rows where Fee is from 1500 to 4000 (both included): 1 of the 7 rows matches (Mohan). SELECT then shows only the columns PID, PName, Fee.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name FROM STUDENT WHERE Gender = 'M' AND Phone IS NOT NULL;
| Name |
|---|
| Aarav |
| Chirag |
| Gaurav |
Explanation: WHERE keeps only the rows where Gender is 'M' and Phone has a value (is not NULL): 3 of the 7 rows match (Aarav, Chirag, Gaurav). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT * FROM STUDENT WHERE Section = 'B';
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
Explanation: WHERE keeps only the rows where Section is 'B': 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows all the columns (*).
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
| PName | Discount |
|---|---|
| Notebook | 5 |
| Geometry Box | 10 |
| Mouse | 15 |
| Earphones | 20 |
| Lunch Box | 8 |
Explanation: WHERE keeps only the rows where Discount has a value (is not NULL): 5 of the 7 rows match (Notebook, Geometry Box, Mouse, Earphones, Lunch Box). SELECT then shows only the columns PName, Discount. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName, Price FROM PRODUCT WHERE Price < 300 OR Discount IS NULL;
| PName | Price |
|---|---|
| Notebook | 60 |
| Pen Drive | 450 |
| Geometry Box | 180 |
| Water Bottle | 320 |
| Lunch Box | 275 |
Explanation: WHERE keeps only the rows where Price is less than 300 or Discount is empty (NULL): 5 of the 7 rows match (Notebook, Pen Drive, Geometry Box, Water Bottle, Lunch Box). SELECT then shows only the columns PName, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT * FROM STUDENT WHERE Section = 'C';
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Explanation: WHERE keeps only the rows where Section is 'C': 2 of the 7 rows match (Divya, Gaurav). SELECT then shows all the columns (*).
(ii)
SELECT Name, Section FROM STUDENT WHERE NOT Section = 'C';
| Name | Section |
|---|---|
| Aarav | A |
| Bhavya | B |
| Chirag | A |
| Eshan | B |
| Farah | A |
Explanation: WHERE keeps only the rows where Section is not 'C': 5 of the 7 rows match (Aarav, Bhavya, Chirag, Eshan, Farah). SELECT then shows only the columns Name, Section.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name, Section FROM STUDENT WHERE Section = 'B' OR Section = 'C';
| Name | Section |
|---|---|
| Bhavya | B |
| Divya | C |
| Eshan | B |
| Gaurav | C |
Explanation: WHERE keeps only the rows where Section is 'B' or Section is 'C': 4 of the 7 rows match (Bhavya, Divya, Eshan, Gaurav). SELECT then shows only the columns Name, Section.
(ii)
SELECT Name, Section FROM STUDENT WHERE NOT Section = 'B';
| Name | Section |
|---|---|
| Aarav | A |
| Chirag | A |
| Divya | C |
| Farah | A |
| Gaurav | C |
Explanation: WHERE keeps only the rows where Section is not 'B': 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Section.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title FROM BOOK WHERE Subject = 'Biography' AND Price >= 200;
| Title |
|---|
| Wings of Fire |
| The Story of My Experiments |
Explanation: WHERE keeps only the rows where Subject is 'Biography' and Price is at least 200: 2 of the 7 rows match (Wings of Fire, The Story of My Experiments). SELECT then shows only the column Title.
(ii)
SELECT Title, IssueDate FROM BOOK WHERE IssueDate BETWEEN '2026-07-01' AND '2026-07-31';
| Title | IssueDate |
|---|---|
| Informatics Practices | 2026-07-03 |
| Physics Part 1 | 2026-07-10 |
| Chemistry Part 1 | 2026-07-15 |
Explanation: WHERE keeps only the rows where IssueDate is from '2026-07-01' to '2026-07-31' (both included): 3 of the 7 rows match (Informatics Practices, Physics Part 1, Chemistry Part 1). SELECT then shows only the columns Title, IssueDate.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title, Subject FROM BOOK WHERE Subject = 'Computer' OR Subject = 'Biography';
| Title | Subject |
|---|---|
| Informatics Practices | Computer |
| Wings of Fire | Biography |
| Python Basics | Computer |
| The Story of My Experiments | Biography |
| Learn SQL | Computer |
Explanation: WHERE keeps only the rows where Subject is 'Computer' or Subject is 'Biography': 5 of the 7 rows match (Informatics Practices, Wings of Fire, Python Basics, The Story of My Experiments, Learn SQL). SELECT then shows only the columns Title, Subject.
(ii)
SELECT * FROM BOOK WHERE Subject = 'Science';
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
Explanation: WHERE keeps only the rows where Subject is 'Science': 2 of the 7 rows match (Physics Part 1, Chemistry Part 1). SELECT then shows all the columns (*).
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
| PName | Discount |
|---|---|
| Notebook | 5 |
| Geometry Box | 10 |
| Mouse | 15 |
| Earphones | 20 |
| Lunch Box | 8 |
Explanation: WHERE keeps only the rows where Discount has a value (is not NULL): 5 of the 7 rows match (Notebook, Geometry Box, Mouse, Earphones, Lunch Box). SELECT then shows only the columns PName, Discount. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PCode, Price, Price + 10 FROM PRODUCT;
| PCode | Price | Price + 10 |
|---|---|---|
| P01 | 60 | 70 |
| P02 | 450 | 460 |
| P03 | 180 | 190 |
| P04 | 650 | 660 |
| P05 | 320 | 330 |
| P06 | 899 | 909 |
| P07 | 275 | 285 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PCode, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT RollNo, Marks, Marks + 10 FROM STUDENT;
| RollNo | Marks | Marks + 10 |
|---|---|---|
| 1 | 78 | 88 |
| 2 | 92 | 102 |
| 3 | 45 | 55 |
| 4 | 66 | 76 |
| 5 | 88 | 98 |
| 6 | 31 | 41 |
| 7 | 59 | 69 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns RollNo, Marks, Marks + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
| Name | DOB |
|---|---|
| Bhavya | 2009-11-30 |
| Divya | 2009-07-21 |
| Farah | 2009-09-09 |
Explanation: WHERE keeps only the rows where DOB is from '2009-06-01' to '2009-12-31' (both included): 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, DOB.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName FROM PATIENT WHERE Doctor = 'Dr. Sen' AND Insurance IS NOT NULL;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Doctor is 'Dr. Sen' and Insurance has a value (is not NULL). No row satisfies this, so the result is an empty set. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
| PName | AdmitDate |
|---|---|
| Nisha | 2026-09-05 |
| Om | 2026-09-10 |
| Pooja | 2026-09-12 |
| Qasim | 2026-09-15 |
Explanation: WHERE keeps only the rows where AdmitDate is from '2026-09-05' to '2026-09-15' (both included): 4 of the 7 rows match (Nisha, Om, Pooja, Qasim). SELECT then shows only the columns PName, AdmitDate.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
| Name | Phone |
|---|---|
| Aarav | 9810011111 |
| Chirag | 9810033333 |
| Divya | 9810044444 |
| Farah | 9810066666 |
| Gaurav | 9810077777 |
Explanation: WHERE keeps only the rows where Phone has a value (is not NULL): 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Phone. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Name FROM STUDENT WHERE Phone IS NULL;
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Phone is empty (NULL): 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName, Doctor FROM PATIENT WHERE Doctor <> 'Dr. Sen';
| PName | Doctor |
|---|---|
| Mohan | Dr. Rao |
| Om | Dr. Rao |
| Pooja | Dr. Iyer |
| Rekha | Dr. Iyer |
| Sahil | Dr. Rao |
Explanation: WHERE keeps only the rows where Doctor is not 'Dr. Sen': 5 of the 7 rows match (Mohan, Om, Pooja, Rekha, Sahil). SELECT then shows only the columns PName, Doctor.
(ii)
SELECT PName, Ward FROM PATIENT WHERE NOT Ward = 'ICU';
| PName | Ward |
|---|---|
| Mohan | General |
| Om | General |
| Pooja | Maternity |
| Rekha | Maternity |
| Sahil | General |
Explanation: WHERE keeps only the rows where Ward is not 'ICU': 5 of the 7 rows match (Mohan, Om, Pooja, Rekha, Sahil). SELECT then shows only the columns PName, Ward.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EName FROM EMPLOYEE WHERE Bonus IS NULL;
| EName |
|---|
| Seema |
| Usha |
| Yamini |
Explanation: WHERE keeps only the rows where Bonus is empty (NULL): 3 of the 7 rows match (Seema, Usha, Yamini). SELECT then shows only the column EName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT EName, Dept FROM EMPLOYEE WHERE NOT Dept = 'IT';
| EName | Dept |
|---|---|
| Ravi | Sales |
| Seema | HR |
| Usha | Sales |
| Wasim | HR |
Explanation: WHERE keeps only the rows where Dept is not 'IT': 4 of the 7 rows match (Ravi, Seema, Usha, Wasim). SELECT then shows only the columns EName, Dept.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName FROM PATIENT WHERE Ward = 'ICU' AND Fee >= 4000;
| PName |
|---|
| Nisha |
| Qasim |
Explanation: WHERE keeps only the rows where Ward is 'ICU' and Fee is at least 4000: 2 of the 7 rows match (Nisha, Qasim). SELECT then shows only the column PName.
(ii)
SELECT PID, PName, Fee FROM PATIENT WHERE Fee BETWEEN 1500 AND 4000;
| PID | PName | Fee |
|---|---|---|
| 11 | Mohan | 1500 |
Explanation: WHERE keeps only the rows where Fee is from 1500 to 4000 (both included): 1 of the 7 rows matches (Mohan). SELECT then shows only the columns PID, PName, Fee.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
| PName | Insurance |
|---|---|
| Mohan | LIC |
| Om | Star |
| Pooja | LIC |
| Sahil | Star |
Explanation: WHERE keeps only the rows where Insurance has a value (is not NULL): 4 of the 7 rows match (Mohan, Om, Pooja, Sahil). SELECT then shows only the columns PName, Insurance. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName, Fee FROM PATIENT WHERE Fee > 6000;
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Qasim | 9500 |
Explanation: WHERE keeps only the rows where Fee is more than 6000: 2 of the 7 rows match (Nisha, Qasim). SELECT then shows only the columns PName, Fee.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EName, Dept FROM EMPLOYEE WHERE NOT Dept = 'Sales';
| EName | Dept |
|---|---|
| Seema | HR |
| Tarun | IT |
| Vikas | IT |
| Wasim | HR |
| Yamini | IT |
Explanation: WHERE keeps only the rows where Dept is not 'Sales': 5 of the 7 rows match (Seema, Tarun, Vikas, Wasim, Yamini). SELECT then shows only the columns EName, Dept.
(ii)
SELECT EName, Bonus FROM EMPLOYEE WHERE Bonus IS NOT NULL;
| EName | Bonus |
|---|---|
| Ravi | 3000 |
| Tarun | 5000 |
| Vikas | 4000 |
| Wasim | 2000 |
Explanation: WHERE keeps only the rows where Bonus has a value (is not NULL): 4 of the 7 rows match (Ravi, Tarun, Vikas, Wasim). SELECT then shows only the columns EName, Bonus. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName FROM PRODUCT WHERE Category = 'Home' AND Price >= 300;
| PName |
|---|
| Water Bottle |
Explanation: WHERE keeps only the rows where Category is 'Home' and Price is at least 300: 1 of the 7 rows matches (Water Bottle). SELECT then shows only the column PName.
(ii)
SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
| PName | Discount |
|---|---|
| Notebook | 5 |
| Geometry Box | 10 |
| Mouse | 15 |
| Earphones | 20 |
| Lunch Box | 8 |
Explanation: WHERE keeps only the rows where Discount has a value (is not NULL): 5 of the 7 rows match (Notebook, Geometry Box, Mouse, Earphones, Lunch Box). SELECT then shows only the columns PName, Discount. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT BookID, Price, Price + 10 FROM BOOK;
| BookID | Price | Price + 10 |
|---|---|---|
| 201 | 210 | 220 |
| 202 | 180 | 190 |
| 203 | 299 | 309 |
| 204 | 350 | 360 |
| 205 | 190 | 200 |
| 206 | 250 | 260 |
| 207 | 400 | 410 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns BookID, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT BookID, Title, Price FROM BOOK WHERE Price BETWEEN 200 AND 300;
| BookID | Title | Price |
|---|---|---|
| 201 | Informatics Practices | 210 |
| 203 | Wings of Fire | 299 |
| 206 | The Story of My Experiments | 250 |
Explanation: WHERE keeps only the rows where Price is from 200 to 300 (both included): 3 of the 7 rows match (Informatics Practices, Wings of Fire, The Story of My Experiments). SELECT then shows only the columns BookID, Title, Price.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Stationery';
| PName | Category |
|---|---|
| Pen Drive | Electronics |
| Mouse | Electronics |
| Water Bottle | Home |
| Earphones | Electronics |
| Lunch Box | Home |
Explanation: WHERE keeps only the rows where Category is not 'Stationery': 5 of the 7 rows match (Pen Drive, Mouse, Water Bottle, Earphones, Lunch Box). SELECT then shows only the columns PName, Category.
(ii)
SELECT PName, MfgDate FROM PRODUCT WHERE MfgDate BETWEEN '2025-10-01' AND '2026-01-31';
| PName | MfgDate |
|---|---|
| Notebook | 2026-01-10 |
| Geometry Box | 2025-11-02 |
| Lunch Box | 2025-12-18 |
Explanation: WHERE keeps only the rows where MfgDate is from '2025-10-01' to '2026-01-31' (both included): 3 of the 7 rows match (Notebook, Geometry Box, Lunch Box). SELECT then shows only the columns PName, MfgDate.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Stationery';
| PName | Category |
|---|---|
| Pen Drive | Electronics |
| Mouse | Electronics |
| Water Bottle | Home |
| Earphones | Electronics |
| Lunch Box | Home |
Explanation: WHERE keeps only the rows where Category is not 'Stationery': 5 of the 7 rows match (Pen Drive, Mouse, Water Bottle, Earphones, Lunch Box). SELECT then shows only the columns PName, Category.
(ii)
SELECT PCode, Price, Price + 10 FROM PRODUCT;
| PCode | Price | Price + 10 |
|---|---|---|
| P01 | 60 | 70 |
| P02 | 450 | 460 |
| P03 | 180 | 190 |
| P04 | 650 | 660 |
| P05 | 320 | 330 |
| P06 | 899 | 909 |
| P07 | 275 | 285 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PCode, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title, Price FROM BOOK WHERE Price < 200 OR Member IS NULL;
| Title | Price |
|---|---|
| Physics Part 1 | 180 |
| Python Basics | 350 |
| Chemistry Part 1 | 190 |
| The Story of My Experiments | 250 |
Explanation: WHERE keeps only the rows where Price is less than 200 or Member is empty (NULL): 4 of the 7 rows match (Physics Part 1, Python Basics, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Title FROM BOOK WHERE Publisher = 'BPB' AND Member IS NOT NULL;
| Title |
|---|
| Learn SQL |
Explanation: WHERE keeps only the rows where Publisher is 'BPB' and Member has a value (is not NULL): 1 of the 7 rows matches (Learn SQL). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name, Marks FROM STUDENT WHERE Marks < 60 OR Phone IS NULL;
| Name | Marks |
|---|---|
| Bhavya | 92 |
| Chirag | 45 |
| Eshan | 88 |
| Farah | 31 |
| Gaurav | 59 |
Explanation: WHERE keeps only the rows where Marks is less than 60 or Phone is empty (NULL): 5 of the 7 rows match (Bhavya, Chirag, Eshan, Farah, Gaurav). SELECT then shows only the columns Name, Marks. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Name, Section FROM STUDENT WHERE NOT Section = 'C';
| Name | Section |
|---|---|
| Aarav | A |
| Bhavya | B |
| Chirag | A |
| Eshan | B |
| Farah | A |
Explanation: WHERE keeps only the rows where Section is not 'C': 5 of the 7 rows match (Aarav, Bhavya, Chirag, Eshan, Farah). SELECT then shows only the columns Name, Section.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title FROM BOOK WHERE Member IS NULL;
| Title |
|---|
| Physics Part 1 |
| Python Basics |
| The Story of My Experiments |
Explanation: WHERE keeps only the rows where Member is empty (NULL): 3 of the 7 rows match (Physics Part 1, Python Basics, The Story of My Experiments). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'NCERT';
| Title | Publisher |
|---|---|
| Wings of Fire | Universities |
| Python Basics | BPB |
| The Story of My Experiments | Penguin |
| Learn SQL | BPB |
Explanation: WHERE keeps only the rows where Publisher is not 'NCERT': 4 of the 7 rows match (Wings of Fire, Python Basics, The Story of My Experiments, Learn SQL). SELECT then shows only the columns Title, Publisher.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';
| EName | DOJ |
|---|---|
| Ravi | 2018-06-01 |
| Seema | 2020-01-15 |
| Vikas | 2019-11-05 |
Explanation: WHERE keeps only the rows where DOJ is from '2018-01-01' to '2020-12-31' (both included): 3 of the 7 rows match (Ravi, Seema, Vikas). SELECT then shows only the columns EName, DOJ.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PID, Fee, Fee + 10 FROM PATIENT;
| PID | Fee | Fee + 10 |
|---|---|---|
| 11 | 1500 | 1510 |
| 12 | 8000 | 8010 |
| 13 | 1200 | 1210 |
| 14 | 5000 | 5010 |
| 15 | 9500 | 9510 |
| 16 | 4500 | 4510 |
| 17 | 900 | 910 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PID, Fee, Fee + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT PName FROM PATIENT WHERE Insurance IS NULL;
| PName |
|---|
| Nisha |
| Qasim |
| Rekha |
Explanation: WHERE keeps only the rows where Insurance is empty (NULL): 3 of the 7 rows match (Nisha, Qasim, Rekha). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName, Fee FROM PATIENT WHERE Fee < 4000 OR Insurance IS NULL;
| PName | Fee |
|---|---|
| Mohan | 1500 |
| Nisha | 8000 |
| Om | 1200 |
| Qasim | 9500 |
| Rekha | 4500 |
| Sahil | 900 |
Explanation: WHERE keeps only the rows where Fee is less than 4000 or Insurance is empty (NULL): 6 of the 7 rows match (Mohan, Nisha, Om, Qasim, Rekha, Sahil). SELECT then shows only the columns PName, Fee. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
| PName | Insurance |
|---|---|
| Mohan | LIC |
| Om | Star |
| Pooja | LIC |
| Sahil | Star |
Explanation: WHERE keeps only the rows where Insurance has a value (is not NULL): 4 of the 7 rows match (Mohan, Om, Pooja, Sahil). SELECT then shows only the columns PName, Insurance. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
| Name | Phone |
|---|---|
| Aarav | 9810011111 |
| Chirag | 9810033333 |
| Divya | 9810044444 |
| Farah | 9810066666 |
| Gaurav | 9810077777 |
Explanation: WHERE keeps only the rows where Phone has a value (is not NULL): 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Phone. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Name, Section FROM STUDENT WHERE Section = 'B' OR Section = 'A';
| Name | Section |
|---|---|
| Aarav | A |
| Bhavya | B |
| Chirag | A |
| Eshan | B |
| Farah | A |
Explanation: WHERE keeps only the rows where Section is 'B' or Section is 'A': 5 of the 7 rows match (Aarav, Bhavya, Chirag, Eshan, Farah). SELECT then shows only the columns Name, Section.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 70000;
| EmpID | EName | Salary |
|---|---|---|
| E101 | Ravi | 42000 |
| E102 | Seema | 58000 |
| E105 | Vikas | 64000 |
Explanation: WHERE keeps only the rows where Salary is from 40000 to 70000 (both included): 3 of the 7 rows match (Ravi, Seema, Vikas). SELECT then shows only the columns EmpID, EName, Salary.
(ii)
SELECT EName FROM EMPLOYEE WHERE Bonus IS NULL;
| EName |
|---|
| Seema |
| Usha |
| Yamini |
Explanation: WHERE keeps only the rows where Bonus is empty (NULL): 3 of the 7 rows match (Seema, Usha, Yamini). SELECT then shows only the column EName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName FROM PRODUCT WHERE Brand = 'Milton' AND Discount IS NOT NULL;
| PName |
|---|
| Lunch Box |
Explanation: WHERE keeps only the rows where Brand is 'Milton' and Discount has a value (is not NULL): 1 of the 7 rows matches (Lunch Box). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT * FROM PRODUCT WHERE Category = 'Electronics';
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
Explanation: WHERE keeps only the rows where Category is 'Electronics': 3 of the 7 rows match (Pen Drive, Mouse, Earphones). SELECT then shows all the columns (*).
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT BookID, Price, Price + 10 FROM BOOK;
| BookID | Price | Price + 10 |
|---|---|---|
| 201 | 210 | 220 |
| 202 | 180 | 190 |
| 203 | 299 | 309 |
| 204 | 350 | 360 |
| 205 | 190 | 200 |
| 206 | 250 | 260 |
| 207 | 400 | 410 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns BookID, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT * FROM BOOK WHERE Subject = 'Biography';
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
Explanation: WHERE keeps only the rows where Subject is 'Biography': 2 of the 7 rows match (Wings of Fire, The Story of My Experiments). SELECT then shows all the columns (*).
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName FROM PRODUCT WHERE Discount IS NULL;
| PName |
|---|
| Pen Drive |
| Water Bottle |
Explanation: WHERE keeps only the rows where Discount is empty (NULL): 2 of the 7 rows match (Pen Drive, Water Bottle). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PCode, Price, Price + 10 FROM PRODUCT;
| PCode | Price | Price + 10 |
|---|---|---|
| P01 | 60 | 70 |
| P02 | 450 | 460 |
| P03 | 180 | 190 |
| P04 | 650 | 660 |
| P05 | 320 | 330 |
| P06 | 899 | 909 |
| P07 | 275 | 285 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PCode, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EName FROM EMPLOYEE WHERE City = 'Pune' AND Bonus IS NOT NULL;
| EName |
|---|
| Vikas |
Explanation: WHERE keeps only the rows where City is 'Pune' and Bonus has a value (is not NULL): 1 of the 7 rows matches (Vikas). SELECT then shows only the column EName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT * FROM EMPLOYEE WHERE Dept = 'HR';
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
Explanation: WHERE keeps only the rows where Dept is 'HR': 2 of the 7 rows match (Seema, Wasim). SELECT then shows all the columns (*).
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 50000;
| EmpID | EName | Salary |
|---|---|---|
| E101 | Ravi | 42000 |
Explanation: WHERE keeps only the rows where Salary is from 40000 to 50000 (both included): 1 of the 7 rows matches (Ravi). SELECT then shows only the columns EmpID, EName, Salary.
(ii)
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Mumbai';
| EName | City |
|---|---|
| Ravi | Delhi |
| Seema | Pune |
| Tarun | Delhi |
| Vikas | Pune |
| Wasim | Delhi |
Explanation: WHERE keeps only the rows where City is not 'Mumbai': 5 of the 7 rows match (Ravi, Seema, Tarun, Vikas, Wasim). SELECT then shows only the columns EName, City.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name FROM STUDENT WHERE Gender = 'F' AND Phone IS NOT NULL;
| Name |
|---|
| Divya |
| Farah |
Explanation: WHERE keeps only the rows where Gender is 'F' and Phone has a value (is not NULL): 2 of the 7 rows match (Divya, Farah). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Name, Marks FROM STUDENT WHERE Marks < 50 OR Phone IS NULL;
| Name | Marks |
|---|---|
| Bhavya | 92 |
| Chirag | 45 |
| Eshan | 88 |
| Farah | 31 |
Explanation: WHERE keeps only the rows where Marks is less than 50 or Phone is empty (NULL): 4 of the 7 rows match (Bhavya, Chirag, Eshan, Farah). SELECT then shows only the columns Name, Marks. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT BookID, Price, Price + 10 FROM BOOK;
| BookID | Price | Price + 10 |
|---|---|---|
| 201 | 210 | 220 |
| 202 | 180 | 190 |
| 203 | 299 | 309 |
| 204 | 350 | 360 |
| 205 | 190 | 200 |
| 206 | 250 | 260 |
| 207 | 400 | 410 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns BookID, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT Title, Subject FROM BOOK WHERE NOT Subject = 'Computer';
| Title | Subject |
|---|---|
| Physics Part 1 | Science |
| Wings of Fire | Biography |
| Chemistry Part 1 | Science |
| The Story of My Experiments | Biography |
Explanation: WHERE keeps only the rows where Subject is not 'Computer': 4 of the 7 rows match (Physics Part 1, Wings of Fire, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Subject.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PCode, Price, Price + 10 FROM PRODUCT;
| PCode | Price | Price + 10 |
|---|---|---|
| P01 | 60 | 70 |
| P02 | 450 | 460 |
| P03 | 180 | 190 |
| P04 | 650 | 660 |
| P05 | 320 | 330 |
| P06 | 899 | 909 |
| P07 | 275 | 285 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PCode, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 300 AND 400;
| PCode | PName | Price |
|---|---|---|
| P05 | Water Bottle | 320 |
Explanation: WHERE keeps only the rows where Price is from 300 to 400 (both included): 1 of the 7 rows matches (Water Bottle). SELECT then shows only the columns PCode, PName, Price.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
| PName | AdmitDate |
|---|---|
| Nisha | 2026-09-05 |
| Om | 2026-09-10 |
| Pooja | 2026-09-12 |
| Qasim | 2026-09-15 |
Explanation: WHERE keeps only the rows where AdmitDate is from '2026-09-05' to '2026-09-15' (both included): 4 of the 7 rows match (Nisha, Om, Pooja, Qasim). SELECT then shows only the columns PName, AdmitDate.
(ii)
SELECT PName FROM PATIENT WHERE Ward = 'General' AND Fee >= 1000;
| PName |
|---|
| Mohan |
| Om |
Explanation: WHERE keeps only the rows where Ward is 'General' and Fee is at least 1000: 2 of the 7 rows match (Mohan, Om). SELECT then shows only the column PName.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name FROM STUDENT WHERE Gender = 'M' AND Phone IS NOT NULL;
| Name |
|---|
| Aarav |
| Chirag |
| Gaurav |
Explanation: WHERE keeps only the rows where Gender is 'M' and Phone has a value (is not NULL): 3 of the 7 rows match (Aarav, Chirag, Gaurav). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
| Name | DOB |
|---|---|
| Bhavya | 2009-11-30 |
| Divya | 2009-07-21 |
| Farah | 2009-09-09 |
Explanation: WHERE keeps only the rows where DOB is from '2009-06-01' to '2009-12-31' (both included): 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, DOB.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EName FROM EMPLOYEE WHERE Dept = 'IT' AND Salary >= 40000;
| EName |
|---|
| Tarun |
| Vikas |
| Yamini |
Explanation: WHERE keeps only the rows where Dept is 'IT' and Salary is at least 40000: 3 of the 7 rows match (Tarun, Vikas, Yamini). SELECT then shows only the column EName.
(ii)
SELECT EName, Salary FROM EMPLOYEE WHERE Salary < 40000 OR Bonus IS NULL;
| EName | Salary |
|---|---|
| Seema | 58000 |
| Usha | 36000 |
| Wasim | 39000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is less than 40000 or Bonus is empty (NULL): 4 of the 7 rows match (Seema, Usha, Wasim, Yamini). SELECT then shows only the columns EName, Salary. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT * FROM BOOK WHERE Subject = 'Science';
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
Explanation: WHERE keeps only the rows where Subject is 'Science': 2 of the 7 rows match (Physics Part 1, Chemistry Part 1). SELECT then shows all the columns (*).
(ii)
SELECT Title FROM BOOK WHERE Member IS NULL;
| Title |
|---|
| Physics Part 1 |
| Python Basics |
| The Story of My Experiments |
Explanation: WHERE keeps only the rows where Member is empty (NULL): 3 of the 7 rows match (Physics Part 1, Python Basics, The Story of My Experiments). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
| PName | AdmitDate |
|---|---|
| Nisha | 2026-09-05 |
| Om | 2026-09-10 |
| Pooja | 2026-09-12 |
| Qasim | 2026-09-15 |
Explanation: WHERE keeps only the rows where AdmitDate is from '2026-09-05' to '2026-09-15' (both included): 4 of the 7 rows match (Nisha, Om, Pooja, Qasim). SELECT then shows only the columns PName, AdmitDate.
(ii)
SELECT PName, Ward FROM PATIENT WHERE NOT Ward = 'Maternity';
| PName | Ward |
|---|---|
| Mohan | General |
| Nisha | ICU |
| Om | General |
| Qasim | ICU |
| Sahil | General |
Explanation: WHERE keeps only the rows where Ward is not 'Maternity': 5 of the 7 rows match (Mohan, Nisha, Om, Qasim, Sahil). SELECT then shows only the columns PName, Ward.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title, Subject FROM BOOK WHERE Subject = 'Biography' OR Subject = 'Science';
| Title | Subject |
|---|---|
| Physics Part 1 | Science |
| Wings of Fire | Biography |
| Chemistry Part 1 | Science |
| The Story of My Experiments | Biography |
Explanation: WHERE keeps only the rows where Subject is 'Biography' or Subject is 'Science': 4 of the 7 rows match (Physics Part 1, Wings of Fire, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Subject.
(ii)
SELECT Title, Subject FROM BOOK WHERE NOT Subject = 'Computer';
| Title | Subject |
|---|---|
| Physics Part 1 | Science |
| Wings of Fire | Biography |
| Chemistry Part 1 | Science |
| The Story of My Experiments | Biography |
Explanation: WHERE keeps only the rows where Subject is not 'Computer': 4 of the 7 rows match (Physics Part 1, Wings of Fire, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Subject.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName, Brand FROM PRODUCT WHERE Brand <> 'Camlin';
| PName | Brand |
|---|---|
| Notebook | Classmate |
| Pen Drive | SanDisk |
| Mouse | Logitech |
| Water Bottle | Milton |
| Earphones | Boat |
| Lunch Box | Milton |
Explanation: WHERE keeps only the rows where Brand is not 'Camlin': 6 of the 7 rows match (Notebook, Pen Drive, Mouse, Water Bottle, Earphones, Lunch Box). SELECT then shows only the columns PName, Brand.
(ii)
SELECT PName FROM PRODUCT WHERE Discount IS NULL;
| PName |
|---|
| Pen Drive |
| Water Bottle |
Explanation: WHERE keeps only the rows where Discount is empty (NULL): 2 of the 7 rows match (Pen Drive, Water Bottle). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title, Price FROM BOOK WHERE Price < 300 OR Member IS NULL;
| Title | Price |
|---|---|
| Informatics Practices | 210 |
| Physics Part 1 | 180 |
| Wings of Fire | 299 |
| Python Basics | 350 |
| Chemistry Part 1 | 190 |
| The Story of My Experiments | 250 |
Explanation: WHERE keeps only the rows where Price is less than 300 or Member is empty (NULL): 6 of the 7 rows match (Informatics Practices, Physics Part 1, Wings of Fire, Python Basics, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Title FROM BOOK WHERE Member IS NULL;
| Title |
|---|
| Physics Part 1 |
| Python Basics |
| The Story of My Experiments |
Explanation: WHERE keeps only the rows where Member is empty (NULL): 3 of the 7 rows match (Physics Part 1, Python Basics, The Story of My Experiments). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName, Brand FROM PRODUCT WHERE Brand <> 'Boat';
| PName | Brand |
|---|---|
| Notebook | Classmate |
| Pen Drive | SanDisk |
| Geometry Box | Camlin |
| Mouse | Logitech |
| Water Bottle | Milton |
| Lunch Box | Milton |
Explanation: WHERE keeps only the rows where Brand is not 'Boat': 6 of the 7 rows match (Notebook, Pen Drive, Geometry Box, Mouse, Water Bottle, Lunch Box). SELECT then shows only the columns PName, Brand.
(ii)
SELECT PName FROM PRODUCT WHERE Category = 'Electronics' AND Price >= 300;
| PName |
|---|
| Pen Drive |
| Mouse |
| Earphones |
Explanation: WHERE keeps only the rows where Category is 'Electronics' and Price is at least 300: 3 of the 7 rows match (Pen Drive, Mouse, Earphones). SELECT then shows only the column PName.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name, Gender FROM STUDENT WHERE Gender <> 'F';
| Name | Gender |
|---|---|
| Aarav | M |
| Chirag | M |
| Eshan | M |
| Gaurav | M |
Explanation: WHERE keeps only the rows where Gender is not 'F': 4 of the 7 rows match (Aarav, Chirag, Eshan, Gaurav). SELECT then shows only the columns Name, Gender.
(ii)
SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
| Name | DOB |
|---|---|
| Bhavya | 2009-11-30 |
| Divya | 2009-07-21 |
| Farah | 2009-09-09 |
Explanation: WHERE keeps only the rows where DOB is from '2009-06-01' to '2009-12-31' (both included): 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, DOB.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
| PName | AdmitDate |
|---|---|
| Nisha | 2026-09-05 |
| Om | 2026-09-10 |
| Pooja | 2026-09-12 |
| Qasim | 2026-09-15 |
Explanation: WHERE keeps only the rows where AdmitDate is from '2026-09-05' to '2026-09-15' (both included): 4 of the 7 rows match (Nisha, Om, Pooja, Qasim). SELECT then shows only the columns PName, AdmitDate.
(ii)
SELECT PName, Fee FROM PATIENT WHERE Fee > 1500;
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Pooja | 5000 |
| Qasim | 9500 |
| Rekha | 4500 |
Explanation: WHERE keeps only the rows where Fee is more than 1500: 4 of the 7 rows match (Nisha, Pooja, Qasim, Rekha). SELECT then shows only the columns PName, Fee.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
| PName | Insurance |
|---|---|
| Mohan | LIC |
| Om | Star |
| Pooja | LIC |
| Sahil | Star |
Explanation: WHERE keeps only the rows where Insurance has a value (is not NULL): 4 of the 7 rows match (Mohan, Om, Pooja, Sahil). SELECT then shows only the columns PName, Insurance. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT * FROM PATIENT WHERE Ward = 'ICU';
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
Explanation: WHERE keeps only the rows where Ward is 'ICU': 2 of the 7 rows match (Nisha, Qasim). SELECT then shows all the columns (*).
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name, Marks FROM STUDENT WHERE Marks > 70;
| Name | Marks |
|---|---|
| Aarav | 78 |
| Bhavya | 92 |
| Eshan | 88 |
Explanation: WHERE keeps only the rows where Marks is more than 70: 3 of the 7 rows match (Aarav, Bhavya, Eshan). SELECT then shows only the columns Name, Marks.
(ii)
SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
| Name | Phone |
|---|---|
| Aarav | 9810011111 |
| Chirag | 9810033333 |
| Divya | 9810044444 |
| Farah | 9810066666 |
| Gaurav | 9810077777 |
Explanation: WHERE keeps only the rows where Phone has a value (is not NULL): 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Phone. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title, Member FROM BOOK WHERE Member IS NOT NULL;
| Title | Member |
|---|---|
| Informatics Practices | Asha |
| Wings of Fire | Ravi |
| Chemistry Part 1 | Neha |
| Learn SQL | Karan |
Explanation: WHERE keeps only the rows where Member has a value (is not NULL): 4 of the 7 rows match (Informatics Practices, Wings of Fire, Chemistry Part 1, Learn SQL). SELECT then shows only the columns Title, Member. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT BookID, Price, Price + 10 FROM BOOK;
| BookID | Price | Price + 10 |
|---|---|---|
| 201 | 210 | 220 |
| 202 | 180 | 190 |
| 203 | 299 | 309 |
| 204 | 350 | 360 |
| 205 | 190 | 200 |
| 206 | 250 | 260 |
| 207 | 400 | 410 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns BookID, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title, Price FROM BOOK WHERE Price < 200 OR Member IS NULL;
| Title | Price |
|---|---|
| Physics Part 1 | 180 |
| Python Basics | 350 |
| Chemistry Part 1 | 190 |
| The Story of My Experiments | 250 |
Explanation: WHERE keeps only the rows where Price is less than 200 or Member is empty (NULL): 4 of the 7 rows match (Physics Part 1, Python Basics, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT BookID, Title, Price FROM BOOK WHERE Price BETWEEN 200 AND 350;
| BookID | Title | Price |
|---|---|---|
| 201 | Informatics Practices | 210 |
| 203 | Wings of Fire | 299 |
| 204 | Python Basics | 350 |
| 206 | The Story of My Experiments | 250 |
Explanation: WHERE keeps only the rows where Price is from 200 to 350 (both included): 4 of the 7 rows match (Informatics Practices, Wings of Fire, Python Basics, The Story of My Experiments). SELECT then shows only the columns BookID, Title, Price.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title, Subject FROM BOOK WHERE Subject = 'Science' OR Subject = 'Biography';
| Title | Subject |
|---|---|
| Physics Part 1 | Science |
| Wings of Fire | Biography |
| Chemistry Part 1 | Science |
| The Story of My Experiments | Biography |
Explanation: WHERE keeps only the rows where Subject is 'Science' or Subject is 'Biography': 4 of the 7 rows match (Physics Part 1, Wings of Fire, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Subject.
(ii)
SELECT BookID, Title, Price FROM BOOK WHERE Price BETWEEN 300 AND 350;
| BookID | Title | Price |
|---|---|---|
| 204 | Python Basics | 350 |
Explanation: WHERE keeps only the rows where Price is from 300 to 350 (both included): 1 of the 7 rows matches (Python Basics). SELECT then shows only the columns BookID, Title, Price.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title FROM BOOK WHERE Publisher = 'BPB' AND Member IS NOT NULL;
| Title |
|---|
| Learn SQL |
Explanation: WHERE keeps only the rows where Publisher is 'BPB' and Member has a value (is not NULL): 1 of the 7 rows matches (Learn SQL). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Title, Price FROM BOOK WHERE Price < 300 OR Member IS NULL;
| Title | Price |
|---|---|
| Informatics Practices | 210 |
| Physics Part 1 | 180 |
| Wings of Fire | 299 |
| Python Basics | 350 |
| Chemistry Part 1 | 190 |
| The Story of My Experiments | 250 |
Explanation: WHERE keeps only the rows where Price is less than 300 or Member is empty (NULL): 6 of the 7 rows match (Informatics Practices, Physics Part 1, Wings of Fire, Python Basics, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName, Price FROM PRODUCT WHERE Price > 100;
| PName | Price |
|---|---|
| Pen Drive | 450 |
| Geometry Box | 180 |
| Mouse | 650 |
| Water Bottle | 320 |
| Earphones | 899 |
| Lunch Box | 275 |
Explanation: WHERE keeps only the rows where Price is more than 100: 6 of the 7 rows match (Pen Drive, Geometry Box, Mouse, Water Bottle, Earphones, Lunch Box). SELECT then shows only the columns PName, Price.
(ii)
SELECT PName, Price FROM PRODUCT WHERE Price < 400 OR Discount IS NULL;
| PName | Price |
|---|---|
| Notebook | 60 |
| Pen Drive | 450 |
| Geometry Box | 180 |
| Water Bottle | 320 |
| Lunch Box | 275 |
Explanation: WHERE keeps only the rows where Price is less than 400 or Discount is empty (NULL): 5 of the 7 rows match (Notebook, Pen Drive, Geometry Box, Water Bottle, Lunch Box). SELECT then shows only the columns PName, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EName FROM EMPLOYEE WHERE Dept = 'HR' AND Salary >= 40000;
| EName |
|---|
| Seema |
Explanation: WHERE keeps only the rows where Dept is 'HR' and Salary is at least 40000: 1 of the 7 rows matches (Seema). SELECT then shows only the column EName.
(ii)
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Pune';
| EName | City |
|---|---|
| Ravi | Delhi |
| Tarun | Delhi |
| Usha | Mumbai |
| Wasim | Delhi |
| Yamini | Mumbai |
Explanation: WHERE keeps only the rows where City is not 'Pune': 5 of the 7 rows match (Ravi, Tarun, Usha, Wasim, Yamini). SELECT then shows only the columns EName, City.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName FROM PATIENT WHERE Insurance IS NULL;
| PName |
|---|
| Nisha |
| Qasim |
| Rekha |
Explanation: WHERE keeps only the rows where Insurance is empty (NULL): 3 of the 7 rows match (Nisha, Qasim, Rekha). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName, Fee FROM PATIENT WHERE Fee < 1000 OR Insurance IS NULL;
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Qasim | 9500 |
| Rekha | 4500 |
| Sahil | 900 |
Explanation: WHERE keeps only the rows where Fee is less than 1000 or Insurance is empty (NULL): 4 of the 7 rows match (Nisha, Qasim, Rekha, Sahil). SELECT then shows only the columns PName, Fee. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT EName FROM EMPLOYEE WHERE Bonus IS NULL;
| EName |
|---|
| Seema |
| Usha |
| Yamini |
Explanation: WHERE keeps only the rows where Bonus is empty (NULL): 3 of the 7 rows match (Seema, Usha, Yamini). SELECT then shows only the column EName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName, MfgDate FROM PRODUCT WHERE MfgDate BETWEEN '2025-10-01' AND '2026-01-31';
| PName | MfgDate |
|---|---|
| Notebook | 2026-01-10 |
| Geometry Box | 2025-11-02 |
| Lunch Box | 2025-12-18 |
Explanation: WHERE keeps only the rows where MfgDate is from '2025-10-01' to '2026-01-31' (both included): 3 of the 7 rows match (Notebook, Geometry Box, Lunch Box). SELECT then shows only the columns PName, MfgDate.
(ii)
SELECT PName, Price FROM PRODUCT WHERE Price < 300 OR Discount IS NULL;
| PName | Price |
|---|---|
| Notebook | 60 |
| Pen Drive | 450 |
| Geometry Box | 180 |
| Water Bottle | 320 |
| Lunch Box | 275 |
Explanation: WHERE keeps only the rows where Price is less than 300 or Discount is empty (NULL): 5 of the 7 rows match (Notebook, Pen Drive, Geometry Box, Water Bottle, Lunch Box). SELECT then shows only the columns PName, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT EName FROM EMPLOYEE WHERE Dept = 'HR' AND Salary >= 40000;
| EName |
|---|
| Seema |
Explanation: WHERE keeps only the rows where Dept is 'HR' and Salary is at least 40000: 1 of the 7 rows matches (Seema). SELECT then shows only the column EName.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName, Category FROM PRODUCT WHERE Category = 'Stationery' OR Category = 'Home';
| PName | Category |
|---|---|
| Notebook | Stationery |
| Geometry Box | Stationery |
| Water Bottle | Home |
| Lunch Box | Home |
Explanation: WHERE keeps only the rows where Category is 'Stationery' or Category is 'Home': 4 of the 7 rows match (Notebook, Geometry Box, Water Bottle, Lunch Box). SELECT then shows only the columns PName, Category.
(ii)
SELECT PName FROM PRODUCT WHERE Category = 'Electronics' AND Price >= 300;
| PName |
|---|
| Pen Drive |
| Mouse |
| Earphones |
Explanation: WHERE keeps only the rows where Category is 'Electronics' and Price is at least 300: 3 of the 7 rows match (Pen Drive, Mouse, Earphones). SELECT then shows only the column PName.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title FROM BOOK WHERE Publisher = 'BPB' AND Member IS NOT NULL;
| Title |
|---|
| Learn SQL |
Explanation: WHERE keeps only the rows where Publisher is 'BPB' and Member has a value (is not NULL): 1 of the 7 rows matches (Learn SQL). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Title FROM BOOK WHERE Member IS NULL;
| Title |
|---|
| Physics Part 1 |
| Python Basics |
| The Story of My Experiments |
Explanation: WHERE keeps only the rows where Member is empty (NULL): 3 of the 7 rows match (Physics Part 1, Python Basics, The Story of My Experiments). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Home';
| PName | Category |
|---|---|
| Notebook | Stationery |
| Pen Drive | Electronics |
| Geometry Box | Stationery |
| Mouse | Electronics |
| Earphones | Electronics |
Explanation: WHERE keeps only the rows where Category is not 'Home': 5 of the 7 rows match (Notebook, Pen Drive, Geometry Box, Mouse, Earphones). SELECT then shows only the columns PName, Category.
(ii)
SELECT PName FROM PRODUCT WHERE Brand = 'Milton' AND Discount IS NOT NULL;
| PName |
|---|
| Lunch Box |
Explanation: WHERE keeps only the rows where Brand is 'Milton' and Discount has a value (is not NULL): 1 of the 7 rows matches (Lunch Box). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EName, Dept FROM EMPLOYEE WHERE NOT Dept = 'IT';
| EName | Dept |
|---|---|
| Ravi | Sales |
| Seema | HR |
| Usha | Sales |
| Wasim | HR |
Explanation: WHERE keeps only the rows where Dept is not 'IT': 4 of the 7 rows match (Ravi, Seema, Usha, Wasim). SELECT then shows only the columns EName, Dept.
(ii)
SELECT * FROM EMPLOYEE WHERE Dept = 'IT';
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Explanation: WHERE keeps only the rows where Dept is 'IT': 3 of the 7 rows match (Tarun, Vikas, Yamini). SELECT then shows all the columns (*).
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name, Marks FROM STUDENT WHERE Marks < 60 OR Phone IS NULL;
| Name | Marks |
|---|---|
| Bhavya | 92 |
| Chirag | 45 |
| Eshan | 88 |
| Farah | 31 |
| Gaurav | 59 |
Explanation: WHERE keeps only the rows where Marks is less than 60 or Phone is empty (NULL): 5 of the 7 rows match (Bhavya, Chirag, Eshan, Farah, Gaurav). SELECT then shows only the columns Name, Marks. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Name, Marks FROM STUDENT WHERE Marks > 60;
| Name | Marks |
|---|---|
| Aarav | 78 |
| Bhavya | 92 |
| Divya | 66 |
| Eshan | 88 |
Explanation: WHERE keeps only the rows where Marks is more than 60: 4 of the 7 rows match (Aarav, Bhavya, Divya, Eshan). SELECT then shows only the columns Name, Marks.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title FROM BOOK WHERE Subject = 'Computer' AND Price >= 250;
| Title |
|---|
| Python Basics |
| Learn SQL |
Explanation: WHERE keeps only the rows where Subject is 'Computer' and Price is at least 250: 2 of the 7 rows match (Python Basics, Learn SQL). SELECT then shows only the column Title.
(ii)
SELECT Title, IssueDate FROM BOOK WHERE IssueDate BETWEEN '2026-07-01' AND '2026-07-31';
| Title | IssueDate |
|---|---|
| Informatics Practices | 2026-07-03 |
| Physics Part 1 | 2026-07-10 |
| Chemistry Part 1 | 2026-07-15 |
Explanation: WHERE keeps only the rows where IssueDate is from '2026-07-01' to '2026-07-31' (both included): 3 of the 7 rows match (Informatics Practices, Physics Part 1, Chemistry Part 1). SELECT then shows only the columns Title, IssueDate.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title FROM BOOK WHERE Publisher = 'Penguin' AND Member IS NOT NULL;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Publisher is 'Penguin' and Member has a value (is not NULL). No row satisfies this, so the result is an empty set. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Title, Member FROM BOOK WHERE Member IS NOT NULL;
| Title | Member |
|---|---|
| Informatics Practices | Asha |
| Wings of Fire | Ravi |
| Chemistry Part 1 | Neha |
| Learn SQL | Karan |
Explanation: WHERE keeps only the rows where Member has a value (is not NULL): 4 of the 7 rows match (Informatics Practices, Wings of Fire, Chemistry Part 1, Learn SQL). SELECT then shows only the columns Title, Member. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 50000;
| EmpID | EName | Salary |
|---|---|---|
| E101 | Ravi | 42000 |
Explanation: WHERE keeps only the rows where Salary is from 40000 to 50000 (both included): 1 of the 7 rows matches (Ravi). SELECT then shows only the columns EmpID, EName, Salary.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
| PName | Discount |
|---|---|
| Notebook | 5 |
| Geometry Box | 10 |
| Mouse | 15 |
| Earphones | 20 |
| Lunch Box | 8 |
Explanation: WHERE keeps only the rows where Discount has a value (is not NULL): 5 of the 7 rows match (Notebook, Geometry Box, Mouse, Earphones, Lunch Box). SELECT then shows only the columns PName, Discount. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName FROM PRODUCT WHERE Brand = 'Boat' AND Discount IS NOT NULL;
| PName |
|---|
| Earphones |
Explanation: WHERE keeps only the rows where Brand is 'Boat' and Discount has a value (is not NULL): 1 of the 7 rows matches (Earphones). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title, Subject FROM BOOK WHERE Subject = 'Biography' OR Subject = 'Computer';
| Title | Subject |
|---|---|
| Informatics Practices | Computer |
| Wings of Fire | Biography |
| Python Basics | Computer |
| The Story of My Experiments | Biography |
| Learn SQL | Computer |
Explanation: WHERE keeps only the rows where Subject is 'Biography' or Subject is 'Computer': 5 of the 7 rows match (Informatics Practices, Wings of Fire, Python Basics, The Story of My Experiments, Learn SQL). SELECT then shows only the columns Title, Subject.
(ii)
SELECT Title, Price FROM BOOK WHERE Price > 350;
| Title | Price |
|---|---|
| Learn SQL | 400 |
Explanation: WHERE keeps only the rows where Price is more than 350: 1 of the 7 rows matches (Learn SQL). SELECT then shows only the columns Title, Price.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name, Section FROM STUDENT WHERE Section = 'C' OR Section = 'A';
| Name | Section |
|---|---|
| Aarav | A |
| Chirag | A |
| Divya | C |
| Farah | A |
| Gaurav | C |
Explanation: WHERE keeps only the rows where Section is 'C' or Section is 'A': 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Section.
(ii)
SELECT Name, Marks FROM STUDENT WHERE Marks > 80;
| Name | Marks |
|---|---|
| Bhavya | 92 |
| Eshan | 88 |
Explanation: WHERE keeps only the rows where Marks is more than 80: 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the columns Name, Marks.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title, IssueDate FROM BOOK WHERE IssueDate BETWEEN '2026-07-01' AND '2026-07-31';
| Title | IssueDate |
|---|---|
| Informatics Practices | 2026-07-03 |
| Physics Part 1 | 2026-07-10 |
| Chemistry Part 1 | 2026-07-15 |
Explanation: WHERE keeps only the rows where IssueDate is from '2026-07-01' to '2026-07-31' (both included): 3 of the 7 rows match (Informatics Practices, Physics Part 1, Chemistry Part 1). SELECT then shows only the columns Title, IssueDate.
(ii)
SELECT Title FROM BOOK WHERE Subject = 'Biography' AND Price >= 250;
| Title |
|---|
| Wings of Fire |
| The Story of My Experiments |
Explanation: WHERE keeps only the rows where Subject is 'Biography' and Price is at least 250: 2 of the 7 rows match (Wings of Fire, The Story of My Experiments). SELECT then shows only the column Title.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 60000;
| EmpID | EName | Salary |
|---|---|---|
| E101 | Ravi | 42000 |
| E102 | Seema | 58000 |
Explanation: WHERE keeps only the rows where Salary is from 40000 to 60000 (both included): 2 of the 7 rows match (Ravi, Seema). SELECT then shows only the columns EmpID, EName, Salary.
(ii)
SELECT EName, Dept FROM EMPLOYEE WHERE NOT Dept = 'IT';
| EName | Dept |
|---|---|
| Ravi | Sales |
| Seema | HR |
| Usha | Sales |
| Wasim | HR |
Explanation: WHERE keeps only the rows where Dept is not 'IT': 4 of the 7 rows match (Ravi, Seema, Usha, Wasim). SELECT then shows only the columns EName, Dept.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 100 AND 500;
| PCode | PName | Price |
|---|---|---|
| P02 | Pen Drive | 450 |
| P03 | Geometry Box | 180 |
| P05 | Water Bottle | 320 |
| P07 | Lunch Box | 275 |
Explanation: WHERE keeps only the rows where Price is from 100 to 500 (both included): 4 of the 7 rows match (Pen Drive, Geometry Box, Water Bottle, Lunch Box). SELECT then shows only the columns PCode, PName, Price.
(ii)
SELECT PName FROM PRODUCT WHERE Brand = 'Camlin' AND Discount IS NOT NULL;
| PName |
|---|
| Geometry Box |
Explanation: WHERE keeps only the rows where Brand is 'Camlin' and Discount has a value (is not NULL): 1 of the 7 rows matches (Geometry Box). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL queries for the following:
(i)
SELECT PName FROM PRODUCT WHERE Brand = 'Camlin' AND Discount IS NOT NULL;
| PName |
|---|
| Geometry Box |
Explanation: WHERE keeps only the rows where Brand is 'Camlin' and Discount has a value (is not NULL): 1 of the 7 rows matches (Geometry Box). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName FROM PRODUCT WHERE Discount IS NULL;
| PName |
|---|
| Pen Drive |
| Water Bottle |
Explanation: WHERE keeps only the rows where Discount is empty (NULL): 2 of the 7 rows match (Pen Drive, Water Bottle). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
| PName | Insurance |
|---|---|
| Mohan | LIC |
| Om | Star |
| Pooja | LIC |
| Sahil | Star |
Explanation: WHERE keeps only the rows where Insurance has a value (is not NULL): 4 of the 7 rows match (Mohan, Om, Pooja, Sahil). SELECT then shows only the columns PName, Insurance. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName FROM PATIENT WHERE Insurance IS NULL;
| PName |
|---|
| Nisha |
| Qasim |
| Rekha |
Explanation: WHERE keeps only the rows where Insurance is empty (NULL): 3 of the 7 rows match (Nisha, Qasim, Rekha). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name, Marks FROM STUDENT WHERE Marks > 80;
| Name | Marks |
|---|---|
| Bhavya | 92 |
| Eshan | 88 |
Explanation: WHERE keeps only the rows where Marks is more than 80: 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the columns Name, Marks.
(ii)
SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
| Name | Phone |
|---|---|
| Aarav | 9810011111 |
| Chirag | 9810033333 |
| Divya | 9810044444 |
| Farah | 9810066666 |
| Gaurav | 9810077777 |
Explanation: WHERE keeps only the rows where Phone has a value (is not NULL): 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Phone. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 50 AND 70;
| RollNo | Name | Marks |
|---|---|---|
| 4 | Divya | 66 |
| 7 | Gaurav | 59 |
Explanation: WHERE keeps only the rows where Marks is from 50 to 70 (both included): 2 of the 7 rows match (Divya, Gaurav). SELECT then shows only the columns RollNo, Name, Marks.
(ii)
SELECT Name FROM STUDENT WHERE Gender = 'F' AND Phone IS NOT NULL;
| Name |
|---|
| Divya |
| Farah |
Explanation: WHERE keeps only the rows where Gender is 'F' and Phone has a value (is not NULL): 2 of the 7 rows match (Divya, Farah). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'IT' OR Dept = 'HR';
| EName | Dept |
|---|---|
| Seema | HR |
| Tarun | IT |
| Vikas | IT |
| Wasim | HR |
| Yamini | IT |
Explanation: WHERE keeps only the rows where Dept is 'IT' or Dept is 'HR': 5 of the 7 rows match (Seema, Tarun, Vikas, Wasim, Yamini). SELECT then shows only the columns EName, Dept.
(ii)
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 60000;
| EmpID | EName | Salary |
|---|---|---|
| E101 | Ravi | 42000 |
| E102 | Seema | 58000 |
Explanation: WHERE keeps only the rows where Salary is from 40000 to 60000 (both included): 2 of the 7 rows match (Ravi, Seema). SELECT then shows only the columns EmpID, EName, Salary.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'BPB';
| Title | Publisher |
|---|---|
| Informatics Practices | NCERT |
| Physics Part 1 | NCERT |
| Wings of Fire | Universities |
| Chemistry Part 1 | NCERT |
| The Story of My Experiments | Penguin |
Explanation: WHERE keeps only the rows where Publisher is not 'BPB': 5 of the 7 rows match (Informatics Practices, Physics Part 1, Wings of Fire, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Publisher.
(ii)
SELECT Title FROM BOOK WHERE Member IS NULL;
| Title |
|---|
| Physics Part 1 |
| Python Basics |
| The Story of My Experiments |
Explanation: WHERE keeps only the rows where Member is empty (NULL): 3 of the 7 rows match (Physics Part 1, Python Basics, The Story of My Experiments). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL queries for the following:
(i)
SELECT Title FROM BOOK WHERE Subject = 'Science' AND Price >= 250;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Subject is 'Science' and Price is at least 250. No row satisfies this, so the result is an empty set.
(ii)
SELECT Title, Price FROM BOOK WHERE Price > 250;
| Title | Price |
|---|---|
| Wings of Fire | 299 |
| Python Basics | 350 |
| Learn SQL | 400 |
Explanation: WHERE keeps only the rows where Price is more than 250: 3 of the 7 rows match (Wings of Fire, Python Basics, Learn SQL). SELECT then shows only the columns Title, Price.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL queries for the following:
(i)
SELECT EName, Salary FROM EMPLOYEE WHERE Salary < 40000 OR Bonus IS NULL;
| EName | Salary |
|---|---|
| Seema | 58000 |
| Usha | 36000 |
| Wasim | 39000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is less than 40000 or Bonus is empty (NULL): 4 of the 7 rows match (Seema, Usha, Wasim, Yamini). SELECT then shows only the columns EName, Salary. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name FROM STUDENT WHERE Phone IS NULL;
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Phone is empty (NULL): 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 60 AND 80;
| RollNo | Name | Marks |
|---|---|---|
| 1 | Aarav | 78 |
| 4 | Divya | 66 |
Explanation: WHERE keeps only the rows where Marks is from 60 to 80 (both included): 2 of the 7 rows match (Aarav, Divya). SELECT then shows only the columns RollNo, Name, Marks.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name, Section FROM STUDENT WHERE Section = 'A' OR Section = 'B';
| Name | Section |
|---|---|
| Aarav | A |
| Bhavya | B |
| Chirag | A |
| Eshan | B |
| Farah | A |
Explanation: WHERE keeps only the rows where Section is 'A' or Section is 'B': 5 of the 7 rows match (Aarav, Bhavya, Chirag, Eshan, Farah). SELECT then shows only the columns Name, Section.
(ii)
SELECT Name FROM STUDENT WHERE Phone IS NULL;
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Phone is empty (NULL): 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL queries for the following:
(i)
SELECT PID, Fee, Fee + 10 FROM PATIENT;
| PID | Fee | Fee + 10 |
|---|---|---|
| 11 | 1500 | 1510 |
| 12 | 8000 | 8010 |
| 13 | 1200 | 1210 |
| 14 | 5000 | 5010 |
| 15 | 9500 | 9510 |
| 16 | 4500 | 4510 |
| 17 | 900 | 910 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PID, Fee, Fee + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT PName, Ward FROM PATIENT WHERE Ward = 'Maternity' OR Ward = 'ICU';
| PName | Ward |
|---|---|
| Nisha | ICU |
| Pooja | Maternity |
| Qasim | ICU |
| Rekha | Maternity |
Explanation: WHERE keeps only the rows where Ward is 'Maternity' or Ward is 'ICU': 4 of the 7 rows match (Nisha, Pooja, Qasim, Rekha). SELECT then shows only the columns PName, Ward.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL queries for the following:
(i)
SELECT Name, Gender FROM STUDENT WHERE Gender <> 'F';
| Name | Gender |
|---|---|
| Aarav | M |
| Chirag | M |
| Eshan | M |
| Gaurav | M |
Explanation: WHERE keeps only the rows where Gender is not 'F': 4 of the 7 rows match (Aarav, Chirag, Eshan, Gaurav). SELECT then shows only the columns Name, Gender.
(ii)
SELECT Name, Section FROM STUDENT WHERE Section = 'A' OR Section = 'B';
| Name | Section |
|---|---|
| Aarav | A |
| Bhavya | B |
| Chirag | A |
| Eshan | B |
| Farah | A |
Explanation: WHERE keeps only the rows where Section is 'A' or Section is 'B': 5 of the 7 rows match (Aarav, Bhavya, Chirag, Eshan, Farah). SELECT then shows only the columns Name, Section.
Write the output of the following code. Show your working in short.
stock = {'Bag': 20, 'Map': 80, 'Pen': 15, 'Ink': 10}
for item in stock:
if stock[item] < 51:
stock[item] += 10
stock["Glue"] = 7
del stock['Bag']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Map': 80, 'Pen': 25, 'Ink': 20, 'Glue': 7}
4 132Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 20, 'Map': 80, 'Pen': 15, 'Ink': 10} | stock = {'Bag': 20, 'Map': 80, 'Pen': 15, 'Ink': 10} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 51: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 30, 'Map': 80, 'Pen': 15, 'Ink': 10} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 51: | condition is False | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 51: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 30, 'Map': 80, 'Pen': 25, 'Ink': 10} | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 51: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 30, 'Map': 80, 'Pen': 25, 'Ink': 20} | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 7 | stock = {'Bag': 30, 'Map': 80, 'Pen': 25, 'Ink': 20, 'Glue': 7} | |
| 6 | del stock['Bag'] | stock = {'Map': 80, 'Pen': 25, 'Ink': 20, 'Glue': 7} | |
| 7 | print(stock) | {'Map': 80, 'Pen': 25, 'Ink': 20, 'Glue': 7}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 132⏎ |
Write the output of the following code. Show your working in short.
L = [19, 58, 39, 27, 22, 11]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::4], max(L) % 9)Output:
[77, 97, 66, 49, 33, 11] [77, 33] 7
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [19, 58, 39, 27, 22, 11] | L = [19, 58, 39, 27, 22, 11] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [77, 58, 39, 27, 22, 11] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [77, 97, 39, 27, 22, 11] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [77, 97, 66, 27, 22, 11] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [77, 97, 66, 49, 22, 11] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [77, 97, 66, 49, 33, 11] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [77, 97, 66, 49, 33, 11]⏎ | |
| 5 | print(L[::4], max(L) % 9) | [77, 33] 7⏎ |
Write the output of the following code. Show your working in short.
n = 5
for i in range(1, n + 1):
print(" " * (n - i), end="")
for j in range(1, i + 1):
print(j, end="")
for j in range(i - 1, 0, -1):
print(j, end="")
print()Output:
1 121 12321 1234321 123454321
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 5 | n = 5 | |
| 2 | for i in range(1, n + 1): | i = 1 | |
| 3 | print(" " * (n - i), end="") | | |
| 4 | for j in range(1, i + 1): | j = 1 | |
| 5 | print(j, end="") | 1 | |
| 4 | for j in range(1, i + 1): | loop ends (no more values) | |
| 6 | for j in range(i - 1, 0, -1): | loop ends (no more values) | |
| 8 | print() | ⏎ | |
| 2 | for i in range(1, n + 1): | i = 2 | |
| 3 | print(" " * (n - i), end="") | | |
| 4 | for j in range(1, i + 1): | loop ends (no more values) | |
| 5 | print(j, end="") | 1 | |
| 4 | for j in range(1, i + 1): | j = 2 | |
| 5 | print(j, end="") | 2 | |
| 4 | for j in range(1, i + 1): | loop ends (no more values) | |
| 6 | for j in range(i - 1, 0, -1): | j = 1 |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [25, 56, 36, 49, 39, 47]
A, B = [], []
for x in L:
if x % 4 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[56, 36] [47, 39, 49, 25] [56, 36, 47, 39]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [25, 56, 36, 49, 39, 47] | L = [25, 56, 36, 49, 39, 47] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 25 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [25] | |
| 3 | for x in L: | x = 56 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [56] | |
| 3 | for x in L: | x = 36 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [56, 36] | |
| 3 | for x in L: | x = 49 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [49, 25] | |
| 3 | for x in L: | x = 39 | |
| 4 | if x % 4 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
a, b = 0, 1
for i in range(7):
print(a, end=" ")
a, b = b, a + b
print()
print(a + b)Output:
0 1 1 2 3 5 8 34
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | a, b = 0, 1 | a = 0, b = 1 | |
| 2 | for i in range(7): | i = 0 | |
| 3 | print(a, end=" ") | 0 | |
| 4 | a, b = b, a + b | a = 1 | |
| 2 | for i in range(7): | i = 1 | |
| 3 | print(a, end=" ") | 1 | |
| 4 | a, b = b, a + b | b = 2 | |
| 2 | for i in range(7): | i = 2 | |
| 3 | print(a, end=" ") | 1 | |
| 4 | a, b = b, a + b | a = 2, b = 3 | |
| 2 | for i in range(7): | i = 3 | |
| 3 | print(a, end=" ") | 2 | |
| 4 | a, b = b, a + b | a = 3, b = 5 | |
| 2 | for i in range(7): | i = 4 | |
| 3 | print(a, end=" ") | 3 | |
| 4 | a, b = b, a + b | a = 5, b = 8 |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [43, 5, 44, 49, 9, 37]
A, B = [], []
for x in L:
if x % 2 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[44] [37, 9, 49, 5, 43] [44, 37, 9]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [43, 5, 44, 49, 9, 37] | L = [43, 5, 44, 49, 9, 37] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 43 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [43] | |
| 3 | for x in L: | x = 5 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [5, 43] | |
| 3 | for x in L: | x = 44 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [44] | |
| 3 | for x in L: | x = 49 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [49, 5, 43] | |
| 3 | for x in L: | x = 9 | |
| 4 | if x % 2 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [12, 22, 29, 35, 46, 32]
A, B = [], []
for x in L:
if x % 4 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[12, 32] [46, 35, 29, 22] [12, 32, 46, 35]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [12, 22, 29, 35, 46, 32] | L = [12, 22, 29, 35, 46, 32] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 12 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [12] | |
| 3 | for x in L: | x = 22 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [22] | |
| 3 | for x in L: | x = 29 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [29, 22] | |
| 3 | for x in L: | x = 35 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [35, 29, 22] | |
| 3 | for x in L: | x = 46 | |
| 4 | if x % 4 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Map': 75, 'Bag': 85, 'Ink': 65, 'Book': 70}
for item in stock:
if stock[item] < 37:
stock[item] += 10
stock["Glue"] = 17
del stock['Bag']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Map': 75, 'Ink': 65, 'Book': 70, 'Glue': 17}
4 227Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Map': 75, 'Bag': 85, 'Ink': 65, 'Book': 70} | stock = {'Map': 75, 'Bag': 85, 'Ink': 65, 'Book': 70} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 37: | condition is False | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 37: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 37: | condition is False | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 37: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 17 | stock = {'Map': 75, 'Bag': 85, 'Ink': 65, 'Book': 70, 'Glue': 17} | |
| 6 | del stock['Bag'] | stock = {'Map': 75, 'Ink': 65, 'Book': 70, 'Glue': 17} | |
| 7 | print(stock) | {'Map': 75, 'Ink': 65, 'Book': 70, 'Glue': 17}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 227⏎ |
Write the output of the following code. Show your working in short.
a, b = 0, 1
for i in range(8):
print(a, end=" ")
a, b = b, a + b
print()
print(a + b)Output:
0 1 1 2 3 5 8 13 55
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | a, b = 0, 1 | a = 0, b = 1 | |
| 2 | for i in range(8): | i = 0 | |
| 3 | print(a, end=" ") | 0 | |
| 4 | a, b = b, a + b | a = 1 | |
| 2 | for i in range(8): | i = 1 | |
| 3 | print(a, end=" ") | 1 | |
| 4 | a, b = b, a + b | b = 2 | |
| 2 | for i in range(8): | i = 2 | |
| 3 | print(a, end=" ") | 1 | |
| 4 | a, b = b, a + b | a = 2, b = 3 | |
| 2 | for i in range(8): | i = 3 | |
| 3 | print(a, end=" ") | 2 | |
| 4 | a, b = b, a + b | a = 3, b = 5 | |
| 2 | for i in range(8): | i = 4 | |
| 3 | print(a, end=" ") | 3 | |
| 4 | a, b = b, a + b | a = 5, b = 8 |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [10, 18, 16, 12, 41, 6]
A, B = [], []
for x in L:
if x % 2 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[10, 18, 16, 12, 6] [41] [10, 18, 16, 12, 6, 41]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [10, 18, 16, 12, 41, 6] | L = [10, 18, 16, 12, 41, 6] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 10 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [10] | |
| 3 | for x in L: | x = 18 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [10, 18] | |
| 3 | for x in L: | x = 16 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [10, 18, 16] | |
| 3 | for x in L: | x = 12 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [10, 18, 16, 12] | |
| 3 | for x in L: | x = 41 | |
| 4 | if x % 2 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [51, 9, 54, 48, 38, 44]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::3], max(L) % 9)Output:
[60, 63, 102, 86, 82, 44] [60, 86] 3
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [51, 9, 54, 48, 38, 44] | L = [51, 9, 54, 48, 38, 44] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [60, 9, 54, 48, 38, 44] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [60, 63, 54, 48, 38, 44] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [60, 63, 102, 48, 38, 44] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [60, 63, 102, 86, 38, 44] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [60, 63, 102, 86, 82, 44] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [60, 63, 102, 86, 82, 44]⏎ | |
| 5 | print(L[::3], max(L) % 9) | [60, 86] 3⏎ |
Write the output of the following code. Show your working in short.
L = [14, 50, 45, 26, 29, 56]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::2], max(L) % 7)Output:
[64, 95, 71, 55, 85, 56] [64, 71, 85] 4
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [14, 50, 45, 26, 29, 56] | L = [14, 50, 45, 26, 29, 56] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [64, 50, 45, 26, 29, 56] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [64, 95, 45, 26, 29, 56] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [64, 95, 71, 26, 29, 56] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [64, 95, 71, 55, 29, 56] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [64, 95, 71, 55, 85, 56] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [64, 95, 71, 55, 85, 56]⏎ | |
| 5 | print(L[::2], max(L) % 7) | [64, 71, 85] 4⏎ |
Write the output of the following code. Show your working in short.
L = [37, 22, 7, 16, 58, 34]
A, B = [], []
for x in L:
if x % 4 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[16] [34, 58, 7, 22, 37] [16, 34, 58]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [37, 22, 7, 16, 58, 34] | L = [37, 22, 7, 16, 58, 34] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 37 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [37] | |
| 3 | for x in L: | x = 22 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [22, 37] | |
| 3 | for x in L: | x = 7 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [7, 22, 37] | |
| 3 | for x in L: | x = 16 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [16] | |
| 3 | for x in L: | x = 58 | |
| 4 | if x % 4 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [25, 59, 44, 17, 27, 57]
A, B = [], []
for x in L:
if x % 2 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[44] [57, 27, 17, 59, 25] [44, 57, 27]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [25, 59, 44, 17, 27, 57] | L = [25, 59, 44, 17, 27, 57] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 25 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [25] | |
| 3 | for x in L: | x = 59 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [59, 25] | |
| 3 | for x in L: | x = 44 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [44] | |
| 3 | for x in L: | x = 17 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [17, 59, 25] | |
| 3 | for x in L: | x = 27 | |
| 4 | if x % 2 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Map': 45, 'Ruler': 30, 'Ink': 55, 'Pen': 35}
for item in stock:
if stock[item] < 49:
stock[item] += 10
stock["Glue"] = 13
del stock['Map']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Ruler': 40, 'Ink': 55, 'Pen': 45, 'Glue': 13}
4 153Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Map': 45, 'Ruler': 30, 'Ink': 55, 'Pen': 35} | stock = {'Map': 45, 'Ruler': 30, 'Ink': 55, 'Pen': 35} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 49: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Map': 55, 'Ruler': 30, 'Ink': 55, 'Pen': 35} | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 49: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Map': 55, 'Ruler': 40, 'Ink': 55, 'Pen': 35} | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 49: | condition is False | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 49: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Map': 55, 'Ruler': 40, 'Ink': 55, 'Pen': 45} | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 13 | stock = {'Map': 55, 'Ruler': 40, 'Ink': 55, 'Pen': 45, 'Glue': 13} | |
| 6 | del stock['Map'] | stock = {'Ruler': 40, 'Ink': 55, 'Pen': 45, 'Glue': 13} | |
| 7 | print(stock) | {'Ruler': 40, 'Ink': 55, 'Pen': 45, 'Glue': 13}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 153⏎ |
Write the output of the following code. Show your working in short.
stock = {'Bag': 50, 'Ruler': 15, 'Map': 80, 'Ink': 65}
for item in stock:
if stock[item] < 38:
stock[item] += 10
stock["Glue"] = 12
del stock['Ink']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Bag': 50, 'Ruler': 25, 'Map': 80, 'Glue': 12}
4 167Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 50, 'Ruler': 15, 'Map': 80, 'Ink': 65} | stock = {'Bag': 50, 'Ruler': 15, 'Map': 80, 'Ink': 65} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 38: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 50, 'Ruler': 25, 'Map': 80, 'Ink': 65} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 12 | stock = {'Bag': 50, 'Ruler': 25, 'Map': 80, 'Ink': 65, 'Glue': 12} | |
| 6 | del stock['Ink'] | stock = {'Bag': 50, 'Ruler': 25, 'Map': 80, 'Glue': 12} | |
| 7 | print(stock) | {'Bag': 50, 'Ruler': 25, 'Map': 80, 'Glue': 12}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 167⏎ |
Write the output of the following code. Show your working in short.
L = [37, 40, 12, 8, 50, 44]
A, B = [], []
for x in L:
if x % 4 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[40, 12, 8, 44] [50, 37] [40, 12, 8, 44, 50, 37]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [37, 40, 12, 8, 50, 44] | L = [37, 40, 12, 8, 50, 44] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 37 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [37] | |
| 3 | for x in L: | x = 40 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [40] | |
| 3 | for x in L: | x = 12 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [40, 12] | |
| 3 | for x in L: | x = 8 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [40, 12, 8] | |
| 3 | for x in L: | x = 50 | |
| 4 | if x % 4 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [44, 8, 57, 59, 10, 29]
A, B = [], []
for x in L:
if x % 3 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[57] [29, 10, 59, 8, 44] [57, 29, 10]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [44, 8, 57, 59, 10, 29] | L = [44, 8, 57, 59, 10, 29] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 44 | |
| 4 | if x % 3 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [44] | |
| 3 | for x in L: | x = 8 | |
| 4 | if x % 3 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [8, 44] | |
| 3 | for x in L: | x = 57 | |
| 4 | if x % 3 == 0: | condition is True | |
| 5 | A.append(x) | A = [57] | |
| 3 | for x in L: | x = 59 | |
| 4 | if x % 3 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [59, 8, 44] | |
| 3 | for x in L: | x = 10 | |
| 4 | if x % 3 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [19, 34, 21, 38, 58, 15]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::2], max(L) % 5)Output:
[53, 55, 59, 96, 73, 15] [53, 59, 73] 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [19, 34, 21, 38, 58, 15] | L = [19, 34, 21, 38, 58, 15] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 34, 21, 38, 58, 15] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 55, 21, 38, 58, 15] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 55, 59, 38, 58, 15] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 55, 59, 96, 58, 15] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 55, 59, 96, 73, 15] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [53, 55, 59, 96, 73, 15]⏎ | |
| 5 | print(L[::2], max(L) % 5) | [53, 59, 73] 1⏎ |
Write the output of the following code. Show your working in short.
L = [8, 45, 30, 23, 46, 42]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::4], max(L) % 5)Output:
[53, 75, 53, 69, 88, 42] [53, 88] 3
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [8, 45, 30, 23, 46, 42] | L = [8, 45, 30, 23, 46, 42] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 45, 30, 23, 46, 42] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 75, 30, 23, 46, 42] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 75, 53, 23, 46, 42] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 75, 53, 69, 46, 42] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 75, 53, 69, 88, 42] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [53, 75, 53, 69, 88, 42]⏎ | |
| 5 | print(L[::4], max(L) % 5) | [53, 88] 3⏎ |
Write the output of the following code. Show your working in short.
stock = {'Pen': 50, 'Bag': 10, 'Ruler': 55, 'Map': 20}
for item in stock:
if stock[item] < 32:
stock[item] += 10
stock["Glue"] = 15
del stock['Ruler']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Pen': 50, 'Bag': 20, 'Map': 30, 'Glue': 15}
4 115Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Pen': 50, 'Bag': 10, 'Ruler': 55, 'Map': 20} | stock = {'Pen': 50, 'Bag': 10, 'Ruler': 55, 'Map': 20} | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 32: | condition is False | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 32: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Pen': 50, 'Bag': 20, 'Ruler': 55, 'Map': 20} | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 32: | condition is False | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 32: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Pen': 50, 'Bag': 20, 'Ruler': 55, 'Map': 30} | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 15 | stock = {'Pen': 50, 'Bag': 20, 'Ruler': 55, 'Map': 30, 'Glue': 15} | |
| 6 | del stock['Ruler'] | stock = {'Pen': 50, 'Bag': 20, 'Map': 30, 'Glue': 15} | |
| 7 | print(stock) | {'Pen': 50, 'Bag': 20, 'Map': 30, 'Glue': 15}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 115⏎ |
Write the output of the following code. Show your working in short.
L = [36, 16, 59, 19, 38, 10]
A, B = [], []
for x in L:
if x % 2 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[36, 16, 38, 10] [19, 59] [36, 16, 38, 10, 19, 59]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [36, 16, 59, 19, 38, 10] | L = [36, 16, 59, 19, 38, 10] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 36 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [36] | |
| 3 | for x in L: | x = 16 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [36, 16] | |
| 3 | for x in L: | x = 59 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [59] | |
| 3 | for x in L: | x = 19 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [19, 59] | |
| 3 | for x in L: | x = 38 | |
| 4 | if x % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Map': 65, 'Bag': 70, 'Ink': 50, 'Book': 20}
for item in stock:
if stock[item] < 53:
stock[item] += 10
stock["Glue"] = 14
del stock['Book']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Map': 65, 'Bag': 70, 'Ink': 60, 'Glue': 14}
4 209Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Map': 65, 'Bag': 70, 'Ink': 50, 'Book': 20} | stock = {'Map': 65, 'Bag': 70, 'Ink': 50, 'Book': 20} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 53: | condition is False | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 53: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 53: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Map': 65, 'Bag': 70, 'Ink': 60, 'Book': 20} | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 53: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Map': 65, 'Bag': 70, 'Ink': 60, 'Book': 30} | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 14 | stock = {'Map': 65, 'Bag': 70, 'Ink': 60, 'Book': 30, 'Glue': 14} | |
| 6 | del stock['Book'] | stock = {'Map': 65, 'Bag': 70, 'Ink': 60, 'Glue': 14} | |
| 7 | print(stock) | {'Map': 65, 'Bag': 70, 'Ink': 60, 'Glue': 14}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 209⏎ |
Write the output of the following code. Show your working in short.
L = [32, 50, 7, 23, 56, 31]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::3], max(L) % 8)Output:
[82, 57, 30, 79, 87, 31] [82, 79] 7
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [32, 50, 7, 23, 56, 31] | L = [32, 50, 7, 23, 56, 31] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [82, 50, 7, 23, 56, 31] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [82, 57, 7, 23, 56, 31] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [82, 57, 30, 23, 56, 31] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [82, 57, 30, 79, 56, 31] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [82, 57, 30, 79, 87, 31] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [82, 57, 30, 79, 87, 31]⏎ | |
| 5 | print(L[::3], max(L) % 8) | [82, 79] 7⏎ |
Write the output of the following code. Show your working in short.
stock = {'Ink': 85, 'Pen': 60, 'Map': 45, 'Book': 80}
for item in stock:
if stock[item] < 38:
stock[item] += 10
stock["Glue"] = 9
del stock['Ink']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Pen': 60, 'Map': 45, 'Book': 80, 'Glue': 9}
4 194Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Ink': 85, 'Pen': 60, 'Map': 45, 'Book': 80} | stock = {'Ink': 85, 'Pen': 60, 'Map': 45, 'Book': 80} | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 9 | stock = {'Ink': 85, 'Pen': 60, 'Map': 45, 'Book': 80, 'Glue': 9} | |
| 6 | del stock['Ink'] | stock = {'Pen': 60, 'Map': 45, 'Book': 80, 'Glue': 9} | |
| 7 | print(stock) | {'Pen': 60, 'Map': 45, 'Book': 80, 'Glue': 9}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 194⏎ |
Write the output of the following code. Show your working in short.
L = [49, 5, 21, 16, 31, 55]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::4], max(L) % 8)Output:
[54, 26, 37, 47, 86, 55] [54, 86] 6
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [49, 5, 21, 16, 31, 55] | L = [49, 5, 21, 16, 31, 55] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [54, 5, 21, 16, 31, 55] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [54, 26, 21, 16, 31, 55] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [54, 26, 37, 16, 31, 55] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [54, 26, 37, 47, 31, 55] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [54, 26, 37, 47, 86, 55] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [54, 26, 37, 47, 86, 55]⏎ | |
| 5 | print(L[::4], max(L) % 8) | [54, 86] 6⏎ |
Write the output of the following code. Show your working in short.
stock = {'Pen': 80, 'Map': 70, 'Ink': 45, 'Book': 60}
for item in stock:
if stock[item] < 50:
stock[item] += 10
stock["Glue"] = 9
del stock['Map']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Pen': 80, 'Ink': 55, 'Book': 60, 'Glue': 9}
4 204Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Pen': 80, 'Map': 70, 'Ink': 45, 'Book': 60} | stock = {'Pen': 80, 'Map': 70, 'Ink': 45, 'Book': 60} | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 50: | condition is False | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 50: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 50: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Pen': 80, 'Map': 70, 'Ink': 55, 'Book': 60} | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 50: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 9 | stock = {'Pen': 80, 'Map': 70, 'Ink': 55, 'Book': 60, 'Glue': 9} | |
| 6 | del stock['Map'] | stock = {'Pen': 80, 'Ink': 55, 'Book': 60, 'Glue': 9} | |
| 7 | print(stock) | {'Pen': 80, 'Ink': 55, 'Book': 60, 'Glue': 9}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 204⏎ |
Write the output of the following code. Show your working in short.
L = [28, 43, 39, 44, 14, 47]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::2], max(L) % 9)Output:
[71, 82, 83, 58, 61, 47] [71, 83, 61] 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [28, 43, 39, 44, 14, 47] | L = [28, 43, 39, 44, 14, 47] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [71, 43, 39, 44, 14, 47] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [71, 82, 39, 44, 14, 47] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [71, 82, 83, 44, 14, 47] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [71, 82, 83, 58, 14, 47] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [71, 82, 83, 58, 61, 47] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [71, 82, 83, 58, 61, 47]⏎ | |
| 5 | print(L[::2], max(L) % 9) | [71, 83, 61] 2⏎ |
Write the output of the following code. Show your working in short.
stock = {'Ink': 75, 'Book': 55, 'Bag': 45, 'Map': 10}
for item in stock:
if stock[item] < 52:
stock[item] += 10
stock["Glue"] = 12
del stock['Book']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Ink': 75, 'Bag': 55, 'Map': 20, 'Glue': 12}
4 162Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Ink': 75, 'Book': 55, 'Bag': 45, 'Map': 10} | stock = {'Ink': 75, 'Book': 55, 'Bag': 45, 'Map': 10} | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 52: | condition is False | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 52: | condition is False | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 52: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Ink': 75, 'Book': 55, 'Bag': 55, 'Map': 10} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 52: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Ink': 75, 'Book': 55, 'Bag': 55, 'Map': 20} | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 12 | stock = {'Ink': 75, 'Book': 55, 'Bag': 55, 'Map': 20, 'Glue': 12} | |
| 6 | del stock['Book'] | stock = {'Ink': 75, 'Bag': 55, 'Map': 20, 'Glue': 12} | |
| 7 | print(stock) | {'Ink': 75, 'Bag': 55, 'Map': 20, 'Glue': 12}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 162⏎ |
Write the output of the following code. Show your working in short.
stock = {'Bag': 60, 'Pen': 45, 'Map': 40, 'Ink': 70}
for item in stock:
if stock[item] < 33:
stock[item] += 10
stock["Glue"] = 13
del stock['Ink']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Bag': 60, 'Pen': 45, 'Map': 40, 'Glue': 13}
4 158Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 60, 'Pen': 45, 'Map': 40, 'Ink': 70} | stock = {'Bag': 60, 'Pen': 45, 'Map': 40, 'Ink': 70} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 33: | condition is False | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 33: | condition is False | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 33: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 33: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 13 | stock = {'Bag': 60, 'Pen': 45, 'Map': 40, 'Ink': 70, 'Glue': 13} | |
| 6 | del stock['Ink'] | stock = {'Bag': 60, 'Pen': 45, 'Map': 40, 'Glue': 13} | |
| 7 | print(stock) | {'Bag': 60, 'Pen': 45, 'Map': 40, 'Glue': 13}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 158⏎ |
Write the output of the following code. Show your working in short.
L = [51, 34, 6, 37, 15, 33]
A, B = [], []
for x in L:
if x % 2 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[34, 6] [33, 15, 37, 51] [34, 6, 33, 15]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [51, 34, 6, 37, 15, 33] | L = [51, 34, 6, 37, 15, 33] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 51 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [51] | |
| 3 | for x in L: | x = 34 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [34] | |
| 3 | for x in L: | x = 6 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [34, 6] | |
| 3 | for x in L: | x = 37 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [37, 51] | |
| 3 | for x in L: | x = 15 | |
| 4 | if x % 2 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [19, 27, 43, 15, 8, 46]
A, B = [], []
for x in L:
if x % 3 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[27, 15] [46, 8, 43, 19] [27, 15, 46, 8]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [19, 27, 43, 15, 8, 46] | L = [19, 27, 43, 15, 8, 46] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 19 | |
| 4 | if x % 3 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [19] | |
| 3 | for x in L: | x = 27 | |
| 4 | if x % 3 == 0: | condition is True | |
| 5 | A.append(x) | A = [27] | |
| 3 | for x in L: | x = 43 | |
| 4 | if x % 3 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [43, 19] | |
| 3 | for x in L: | x = 15 | |
| 4 | if x % 3 == 0: | condition is True | |
| 5 | A.append(x) | A = [27, 15] | |
| 3 | for x in L: | x = 8 | |
| 4 | if x % 3 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Bag': 35, 'Map': 50, 'Ruler': 40, 'Ink': 80}
for item in stock:
if stock[item] < 31:
stock[item] += 10
stock["Glue"] = 12
del stock['Ruler']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Bag': 35, 'Map': 50, 'Ink': 80, 'Glue': 12}
4 177Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 35, 'Map': 50, 'Ruler': 40, 'Ink': 80} | stock = {'Bag': 35, 'Map': 50, 'Ruler': 40, 'Ink': 80} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 31: | condition is False | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 31: | condition is False | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 31: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 31: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 12 | stock = {'Bag': 35, 'Map': 50, 'Ruler': 40, 'Ink': 80, 'Glue': 12} | |
| 6 | del stock['Ruler'] | stock = {'Bag': 35, 'Map': 50, 'Ink': 80, 'Glue': 12} | |
| 7 | print(stock) | {'Bag': 35, 'Map': 50, 'Ink': 80, 'Glue': 12}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 177⏎ |
Write the output of the following code. Show your working in short.
n = 4
for i in range(1, n + 1):
print(" " * (n - i), end="")
for j in range(1, i + 1):
print(j, end="")
for j in range(i - 1, 0, -1):
print(j, end="")
print()Output:
1 121 12321 1234321
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 4 | n = 4 | |
| 2 | for i in range(1, n + 1): | i = 1 | |
| 3 | print(" " * (n - i), end="") | | |
| 4 | for j in range(1, i + 1): | j = 1 | |
| 5 | print(j, end="") | 1 | |
| 4 | for j in range(1, i + 1): | loop ends (no more values) | |
| 6 | for j in range(i - 1, 0, -1): | loop ends (no more values) | |
| 8 | print() | ⏎ | |
| 2 | for i in range(1, n + 1): | i = 2 | |
| 3 | print(" " * (n - i), end="") | | |
| 4 | for j in range(1, i + 1): | loop ends (no more values) | |
| 5 | print(j, end="") | 1 | |
| 4 | for j in range(1, i + 1): | j = 2 | |
| 5 | print(j, end="") | 2 | |
| 4 | for j in range(1, i + 1): | loop ends (no more values) | |
| 6 | for j in range(i - 1, 0, -1): | j = 1 |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Bag': 85, 'Ruler': 30, 'Map': 25, 'Pen': 70}
for item in stock:
if stock[item] < 42:
stock[item] += 10
stock["Glue"] = 6
del stock['Ruler']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Bag': 85, 'Map': 35, 'Pen': 70, 'Glue': 6}
4 196Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 85, 'Ruler': 30, 'Map': 25, 'Pen': 70} | stock = {'Bag': 85, 'Ruler': 30, 'Map': 25, 'Pen': 70} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 42: | condition is False | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 42: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 85, 'Ruler': 40, 'Map': 25, 'Pen': 70} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 42: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 85, 'Ruler': 40, 'Map': 35, 'Pen': 70} | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 42: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 6 | stock = {'Bag': 85, 'Ruler': 40, 'Map': 35, 'Pen': 70, 'Glue': 6} | |
| 6 | del stock['Ruler'] | stock = {'Bag': 85, 'Map': 35, 'Pen': 70, 'Glue': 6} | |
| 7 | print(stock) | {'Bag': 85, 'Map': 35, 'Pen': 70, 'Glue': 6}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 196⏎ |
Write the output of the following code. Show your working in short.
L = [39, 19, 40, 10, 56, 12]
A, B = [], []
for x in L:
if x % 4 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[40, 56, 12] [10, 19, 39] [40, 56, 12, 10, 19]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [39, 19, 40, 10, 56, 12] | L = [39, 19, 40, 10, 56, 12] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 39 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [39] | |
| 3 | for x in L: | x = 19 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [19, 39] | |
| 3 | for x in L: | x = 40 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [40] | |
| 3 | for x in L: | x = 10 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [10, 19, 39] | |
| 3 | for x in L: | x = 56 | |
| 4 | if x % 4 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Bag': 30, 'Pen': 25, 'Ruler': 50, 'Book': 55}
for item in stock:
if stock[item] < 30:
stock[item] += 10
stock["Glue"] = 16
del stock['Ruler']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Bag': 30, 'Pen': 35, 'Book': 55, 'Glue': 16}
4 136Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 30, 'Pen': 25, 'Ruler': 50, 'Book': 55} | stock = {'Bag': 30, 'Pen': 25, 'Ruler': 50, 'Book': 55} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 30: | condition is False | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 30: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 30, 'Pen': 35, 'Ruler': 50, 'Book': 55} | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 30: | condition is False | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 30: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 16 | stock = {'Bag': 30, 'Pen': 35, 'Ruler': 50, 'Book': 55, 'Glue': 16} | |
| 6 | del stock['Ruler'] | stock = {'Bag': 30, 'Pen': 35, 'Book': 55, 'Glue': 16} | |
| 7 | print(stock) | {'Bag': 30, 'Pen': 35, 'Book': 55, 'Glue': 16}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 136⏎ |
Write the output of the following code. Show your working in short.
L = [46, 33, 29, 10, 44, 36]
A, B = [], []
for x in L:
if x % 2 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[46, 10, 44, 36] [29, 33] [46, 10, 44, 36, 29, 33]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [46, 33, 29, 10, 44, 36] | L = [46, 33, 29, 10, 44, 36] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 46 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [46] | |
| 3 | for x in L: | x = 33 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [33] | |
| 3 | for x in L: | x = 29 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [29, 33] | |
| 3 | for x in L: | x = 10 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [46, 10] | |
| 3 | for x in L: | x = 44 | |
| 4 | if x % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [38, 58, 11, 42, 15, 18]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::3], max(L) % 7)Output:
[96, 69, 53, 57, 33, 18] [96, 57] 5
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [38, 58, 11, 42, 15, 18] | L = [38, 58, 11, 42, 15, 18] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [96, 58, 11, 42, 15, 18] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [96, 69, 11, 42, 15, 18] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [96, 69, 53, 42, 15, 18] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [96, 69, 53, 57, 15, 18] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [96, 69, 53, 57, 33, 18] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [96, 69, 53, 57, 33, 18]⏎ | |
| 5 | print(L[::3], max(L) % 7) | [96, 57] 5⏎ |
Write the output of the following code. Show your working in short.
L = [36, 46, 47, 56, 24, 44]
A, B = [], []
for x in L:
if x % 3 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[36, 24] [44, 56, 47, 46] [36, 24, 44, 56]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [36, 46, 47, 56, 24, 44] | L = [36, 46, 47, 56, 24, 44] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 36 | |
| 4 | if x % 3 == 0: | condition is True | |
| 5 | A.append(x) | A = [36] | |
| 3 | for x in L: | x = 46 | |
| 4 | if x % 3 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [46] | |
| 3 | for x in L: | x = 47 | |
| 4 | if x % 3 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [47, 46] | |
| 3 | for x in L: | x = 56 | |
| 4 | if x % 3 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [56, 47, 46] | |
| 3 | for x in L: | x = 24 | |
| 4 | if x % 3 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Pen': 20, 'Bag': 60, 'Ruler': 55, 'Ink': 75}
for item in stock:
if stock[item] < 35:
stock[item] += 10
stock["Glue"] = 15
del stock['Ruler']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Pen': 30, 'Bag': 60, 'Ink': 75, 'Glue': 15}
4 180Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Pen': 20, 'Bag': 60, 'Ruler': 55, 'Ink': 75} | stock = {'Pen': 20, 'Bag': 60, 'Ruler': 55, 'Ink': 75} | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 35: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Pen': 30, 'Bag': 60, 'Ruler': 55, 'Ink': 75} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 35: | condition is False | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 35: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 35: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 15 | stock = {'Pen': 30, 'Bag': 60, 'Ruler': 55, 'Ink': 75, 'Glue': 15} | |
| 6 | del stock['Ruler'] | stock = {'Pen': 30, 'Bag': 60, 'Ink': 75, 'Glue': 15} | |
| 7 | print(stock) | {'Pen': 30, 'Bag': 60, 'Ink': 75, 'Glue': 15}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 180⏎ |
Write the output of the following code. Show your working in short.
L = [5, 44, 27, 55, 50, 52]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::4], max(L) % 9)Output:
[49, 71, 82, 105, 102, 52] [49, 102] 6
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [5, 44, 27, 55, 50, 52] | L = [5, 44, 27, 55, 50, 52] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [49, 44, 27, 55, 50, 52] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [49, 71, 27, 55, 50, 52] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [49, 71, 82, 55, 50, 52] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [49, 71, 82, 105, 50, 52] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [49, 71, 82, 105, 102, 52] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [49, 71, 82, 105, 102, 52]⏎ | |
| 5 | print(L[::4], max(L) % 9) | [49, 102] 6⏎ |
Write the output of the following code. Show your working in short.
stock = {'Book': 25, 'Map': 10, 'Bag': 85, 'Ink': 75}
for item in stock:
if stock[item] < 47:
stock[item] += 10
stock["Glue"] = 18
del stock['Bag']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Book': 35, 'Map': 20, 'Ink': 75, 'Glue': 18}
4 148Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Book': 25, 'Map': 10, 'Bag': 85, 'Ink': 75} | stock = {'Book': 25, 'Map': 10, 'Bag': 85, 'Ink': 75} | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 47: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Book': 35, 'Map': 10, 'Bag': 85, 'Ink': 75} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 47: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Book': 35, 'Map': 20, 'Bag': 85, 'Ink': 75} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 47: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 47: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 18 | stock = {'Book': 35, 'Map': 20, 'Bag': 85, 'Ink': 75, 'Glue': 18} | |
| 6 | del stock['Bag'] | stock = {'Book': 35, 'Map': 20, 'Ink': 75, 'Glue': 18} | |
| 7 | print(stock) | {'Book': 35, 'Map': 20, 'Ink': 75, 'Glue': 18}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 148⏎ |
Write the output of the following code. Show your working in short.
stock = {'Book': 80, 'Ruler': 35, 'Ink': 85, 'Map': 75}
for item in stock:
if stock[item] < 31:
stock[item] += 10
stock["Glue"] = 18
del stock['Book']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Ruler': 35, 'Ink': 85, 'Map': 75, 'Glue': 18}
4 213Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Book': 80, 'Ruler': 35, 'Ink': 85, 'Map': 75} | stock = {'Book': 80, 'Ruler': 35, 'Ink': 85, 'Map': 75} | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 31: | condition is False | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 31: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 31: | condition is False | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 31: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 18 | stock = {'Book': 80, 'Ruler': 35, 'Ink': 85, 'Map': 75, 'Glue': 18} | |
| 6 | del stock['Book'] | stock = {'Ruler': 35, 'Ink': 85, 'Map': 75, 'Glue': 18} | |
| 7 | print(stock) | {'Ruler': 35, 'Ink': 85, 'Map': 75, 'Glue': 18}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 213⏎ |
Write the output of the following code. Show your working in short.
a, b = 0, 1
for i in range(9):
print(a, end=" ")
a, b = b, a + b
print()
print(a + b)Output:
0 1 1 2 3 5 8 13 21 89
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | a, b = 0, 1 | a = 0, b = 1 | |
| 2 | for i in range(9): | i = 0 | |
| 3 | print(a, end=" ") | 0 | |
| 4 | a, b = b, a + b | a = 1 | |
| 2 | for i in range(9): | i = 1 | |
| 3 | print(a, end=" ") | 1 | |
| 4 | a, b = b, a + b | b = 2 | |
| 2 | for i in range(9): | i = 2 | |
| 3 | print(a, end=" ") | 1 | |
| 4 | a, b = b, a + b | a = 2, b = 3 | |
| 2 | for i in range(9): | i = 3 | |
| 3 | print(a, end=" ") | 2 | |
| 4 | a, b = b, a + b | a = 3, b = 5 | |
| 2 | for i in range(9): | i = 4 | |
| 3 | print(a, end=" ") | 3 | |
| 4 | a, b = b, a + b | a = 5, b = 8 |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [26, 18, 27, 51, 7, 28]
A, B = [], []
for x in L:
if x % 3 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[18, 27, 51] [28, 7, 26] [18, 27, 51, 28, 7]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [26, 18, 27, 51, 7, 28] | L = [26, 18, 27, 51, 7, 28] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 26 | |
| 4 | if x % 3 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [26] | |
| 3 | for x in L: | x = 18 | |
| 4 | if x % 3 == 0: | condition is True | |
| 5 | A.append(x) | A = [18] | |
| 3 | for x in L: | x = 27 | |
| 4 | if x % 3 == 0: | condition is True | |
| 5 | A.append(x) | A = [18, 27] | |
| 3 | for x in L: | x = 51 | |
| 4 | if x % 3 == 0: | condition is True | |
| 5 | A.append(x) | A = [18, 27, 51] | |
| 3 | for x in L: | x = 7 | |
| 4 | if x % 3 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [22, 5, 53, 47, 54, 30]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::2], max(L) % 6)Output:
[27, 58, 100, 101, 84, 30] [27, 100, 84] 5
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [22, 5, 53, 47, 54, 30] | L = [22, 5, 53, 47, 54, 30] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [27, 5, 53, 47, 54, 30] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [27, 58, 53, 47, 54, 30] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [27, 58, 100, 47, 54, 30] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [27, 58, 100, 101, 54, 30] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [27, 58, 100, 101, 84, 30] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [27, 58, 100, 101, 84, 30]⏎ | |
| 5 | print(L[::2], max(L) % 6) | [27, 100, 84] 5⏎ |
Write the output of the following code. Show your working in short.
L = [56, 18, 52, 22, 11, 26]
A, B = [], []
for x in L:
if x % 4 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[56, 52] [26, 11, 22, 18] [56, 52, 26, 11]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [56, 18, 52, 22, 11, 26] | L = [56, 18, 52, 22, 11, 26] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 56 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [56] | |
| 3 | for x in L: | x = 18 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [18] | |
| 3 | for x in L: | x = 52 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [56, 52] | |
| 3 | for x in L: | x = 22 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [22, 18] | |
| 3 | for x in L: | x = 11 | |
| 4 | if x % 4 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Ink': 85, 'Pen': 60, 'Map': 30, 'Ruler': 65}
for item in stock:
if stock[item] < 33:
stock[item] += 10
stock["Glue"] = 9
del stock['Ink']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Pen': 60, 'Map': 40, 'Ruler': 65, 'Glue': 9}
4 174Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Ink': 85, 'Pen': 60, 'Map': 30, 'Ruler': 65} | stock = {'Ink': 85, 'Pen': 60, 'Map': 30, 'Ruler': 65} | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 33: | condition is False | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 33: | condition is False | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 33: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Ink': 85, 'Pen': 60, 'Map': 40, 'Ruler': 65} | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 33: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 9 | stock = {'Ink': 85, 'Pen': 60, 'Map': 40, 'Ruler': 65, 'Glue': 9} | |
| 6 | del stock['Ink'] | stock = {'Pen': 60, 'Map': 40, 'Ruler': 65, 'Glue': 9} | |
| 7 | print(stock) | {'Pen': 60, 'Map': 40, 'Ruler': 65, 'Glue': 9}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 174⏎ |
Write the output of the following code. Show your working in short.
stock = {'Book': 30, 'Bag': 45, 'Map': 35, 'Pen': 15}
for item in stock:
if stock[item] < 56:
stock[item] += 10
stock["Glue"] = 5
del stock['Bag']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Book': 40, 'Map': 45, 'Pen': 25, 'Glue': 5}
4 115Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Book': 30, 'Bag': 45, 'Map': 35, 'Pen': 15} | stock = {'Book': 30, 'Bag': 45, 'Map': 35, 'Pen': 15} | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 56: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Book': 40, 'Bag': 45, 'Map': 35, 'Pen': 15} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 56: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Book': 40, 'Bag': 55, 'Map': 35, 'Pen': 15} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 56: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Book': 40, 'Bag': 55, 'Map': 45, 'Pen': 15} | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 56: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Book': 40, 'Bag': 55, 'Map': 45, 'Pen': 25} | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 5 | stock = {'Book': 40, 'Bag': 55, 'Map': 45, 'Pen': 25, 'Glue': 5} | |
| 6 | del stock['Bag'] | stock = {'Book': 40, 'Map': 45, 'Pen': 25, 'Glue': 5} | |
| 7 | print(stock) | {'Book': 40, 'Map': 45, 'Pen': 25, 'Glue': 5}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 115⏎ |
Write the output of the following code. Show your working in short.
L = [28, 56, 10, 50, 53, 24]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::3], max(L) % 6)Output:
[84, 66, 60, 103, 77, 24] [84, 103] 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [28, 56, 10, 50, 53, 24] | L = [28, 56, 10, 50, 53, 24] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [84, 56, 10, 50, 53, 24] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [84, 66, 10, 50, 53, 24] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [84, 66, 60, 50, 53, 24] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [84, 66, 60, 103, 53, 24] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [84, 66, 60, 103, 77, 24] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [84, 66, 60, 103, 77, 24]⏎ | |
| 5 | print(L[::3], max(L) % 6) | [84, 103] 1⏎ |
Write the output of the following code. Show your working in short.
L = [56, 28, 6, 47, 55, 24]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::4], max(L) % 6)Output:
[84, 34, 53, 102, 79, 24] [84, 79] 0
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [56, 28, 6, 47, 55, 24] | L = [56, 28, 6, 47, 55, 24] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [84, 28, 6, 47, 55, 24] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [84, 34, 6, 47, 55, 24] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [84, 34, 53, 47, 55, 24] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [84, 34, 53, 102, 55, 24] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [84, 34, 53, 102, 79, 24] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [84, 34, 53, 102, 79, 24]⏎ | |
| 5 | print(L[::4], max(L) % 6) | [84, 79] 0⏎ |
Write the output of the following code. Show your working in short.
L = [10, 7, 36, 34, 13, 56]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::2], max(L) % 7)Output:
[17, 43, 70, 47, 69, 56] [17, 70, 69] 0
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [10, 7, 36, 34, 13, 56] | L = [10, 7, 36, 34, 13, 56] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [17, 7, 36, 34, 13, 56] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [17, 43, 36, 34, 13, 56] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [17, 43, 70, 34, 13, 56] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [17, 43, 70, 47, 13, 56] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [17, 43, 70, 47, 69, 56] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [17, 43, 70, 47, 69, 56]⏎ | |
| 5 | print(L[::2], max(L) % 7) | [17, 70, 69] 0⏎ |
Write the output of the following code. Show your working in short.
stock = {'Bag': 15, 'Pen': 35, 'Book': 65, 'Ink': 55}
for item in stock:
if stock[item] < 48:
stock[item] += 10
stock["Glue"] = 8
del stock['Pen']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Bag': 25, 'Book': 65, 'Ink': 55, 'Glue': 8}
4 153Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 15, 'Pen': 35, 'Book': 65, 'Ink': 55} | stock = {'Bag': 15, 'Pen': 35, 'Book': 65, 'Ink': 55} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 48: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 25, 'Pen': 35, 'Book': 65, 'Ink': 55} | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 48: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 25, 'Pen': 45, 'Book': 65, 'Ink': 55} | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 48: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 48: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 8 | stock = {'Bag': 25, 'Pen': 45, 'Book': 65, 'Ink': 55, 'Glue': 8} | |
| 6 | del stock['Pen'] | stock = {'Bag': 25, 'Book': 65, 'Ink': 55, 'Glue': 8} | |
| 7 | print(stock) | {'Bag': 25, 'Book': 65, 'Ink': 55, 'Glue': 8}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 153⏎ |
Write the output of the following code. Show your working in short.
stock = {'Pen': 40, 'Bag': 25, 'Ruler': 50, 'Map': 45}
for item in stock:
if stock[item] < 51:
stock[item] += 10
stock["Glue"] = 17
del stock['Ruler']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Pen': 50, 'Bag': 35, 'Map': 55, 'Glue': 17}
4 157Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Pen': 40, 'Bag': 25, 'Ruler': 50, 'Map': 45} | stock = {'Pen': 40, 'Bag': 25, 'Ruler': 50, 'Map': 45} | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 51: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Pen': 50, 'Bag': 25, 'Ruler': 50, 'Map': 45} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 51: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Pen': 50, 'Bag': 35, 'Ruler': 50, 'Map': 45} | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 51: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Pen': 50, 'Bag': 35, 'Ruler': 60, 'Map': 45} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 51: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Pen': 50, 'Bag': 35, 'Ruler': 60, 'Map': 55} | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 17 | stock = {'Pen': 50, 'Bag': 35, 'Ruler': 60, 'Map': 55, 'Glue': 17} | |
| 6 | del stock['Ruler'] | stock = {'Pen': 50, 'Bag': 35, 'Map': 55, 'Glue': 17} | |
| 7 | print(stock) | {'Pen': 50, 'Bag': 35, 'Map': 55, 'Glue': 17}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 157⏎ |
Write the output of the following code. Show your working in short.
stock = {'Bag': 25, 'Ink': 55, 'Book': 30, 'Ruler': 45}
for item in stock:
if stock[item] < 31:
stock[item] += 10
stock["Glue"] = 15
del stock['Bag']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Ink': 55, 'Book': 40, 'Ruler': 45, 'Glue': 15}
4 155Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 25, 'Ink': 55, 'Book': 30, 'Ruler': 45} | stock = {'Bag': 25, 'Ink': 55, 'Book': 30, 'Ruler': 45} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 31: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 35, 'Ink': 55, 'Book': 30, 'Ruler': 45} | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 31: | condition is False | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 31: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 35, 'Ink': 55, 'Book': 40, 'Ruler': 45} | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 31: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 15 | stock = {'Bag': 35, 'Ink': 55, 'Book': 40, 'Ruler': 45, 'Glue': 15} | |
| 6 | del stock['Bag'] | stock = {'Ink': 55, 'Book': 40, 'Ruler': 45, 'Glue': 15} | |
| 7 | print(stock) | {'Ink': 55, 'Book': 40, 'Ruler': 45, 'Glue': 15}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 155⏎ |
Write the output of the following code. Show your working in short.
stock = {'Map': 25, 'Ruler': 70, 'Bag': 80, 'Ink': 65}
for item in stock:
if stock[item] < 38:
stock[item] += 10
stock["Glue"] = 17
del stock['Map']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Ruler': 70, 'Bag': 80, 'Ink': 65, 'Glue': 17}
4 232Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Map': 25, 'Ruler': 70, 'Bag': 80, 'Ink': 65} | stock = {'Map': 25, 'Ruler': 70, 'Bag': 80, 'Ink': 65} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 38: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Map': 35, 'Ruler': 70, 'Bag': 80, 'Ink': 65} | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 17 | stock = {'Map': 35, 'Ruler': 70, 'Bag': 80, 'Ink': 65, 'Glue': 17} | |
| 6 | del stock['Map'] | stock = {'Ruler': 70, 'Bag': 80, 'Ink': 65, 'Glue': 17} | |
| 7 | print(stock) | {'Ruler': 70, 'Bag': 80, 'Ink': 65, 'Glue': 17}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 232⏎ |
Write the output of the following code. Show your working in short.
L = [5, 30, 44, 9, 12, 50]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::4], max(L) % 7)Output:
[35, 74, 53, 21, 62, 50] [35, 62] 4
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [5, 30, 44, 9, 12, 50] | L = [5, 30, 44, 9, 12, 50] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [35, 30, 44, 9, 12, 50] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [35, 74, 44, 9, 12, 50] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [35, 74, 53, 9, 12, 50] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [35, 74, 53, 21, 12, 50] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [35, 74, 53, 21, 62, 50] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [35, 74, 53, 21, 62, 50]⏎ | |
| 5 | print(L[::4], max(L) % 7) | [35, 62] 4⏎ |
Write the output of the following code. Show your working in short.
L = [36, 10, 29, 49, 16, 21]
A, B = [], []
for x in L:
if x % 4 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[36, 16] [21, 49, 29, 10] [36, 16, 21, 49]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [36, 10, 29, 49, 16, 21] | L = [36, 10, 29, 49, 16, 21] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 36 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [36] | |
| 3 | for x in L: | x = 10 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [10] | |
| 3 | for x in L: | x = 29 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [29, 10] | |
| 3 | for x in L: | x = 49 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [49, 29, 10] | |
| 3 | for x in L: | x = 16 | |
| 4 | if x % 4 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Bag': 50, 'Book': 20, 'Ruler': 15, 'Map': 55}
for item in stock:
if stock[item] < 37:
stock[item] += 10
stock["Glue"] = 14
del stock['Bag']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Book': 30, 'Ruler': 25, 'Map': 55, 'Glue': 14}
4 124Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 50, 'Book': 20, 'Ruler': 15, 'Map': 55} | stock = {'Bag': 50, 'Book': 20, 'Ruler': 15, 'Map': 55} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 37: | condition is False | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 37: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 50, 'Book': 30, 'Ruler': 15, 'Map': 55} | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 37: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 50, 'Book': 30, 'Ruler': 25, 'Map': 55} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 37: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 14 | stock = {'Bag': 50, 'Book': 30, 'Ruler': 25, 'Map': 55, 'Glue': 14} | |
| 6 | del stock['Bag'] | stock = {'Book': 30, 'Ruler': 25, 'Map': 55, 'Glue': 14} | |
| 7 | print(stock) | {'Book': 30, 'Ruler': 25, 'Map': 55, 'Glue': 14}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 124⏎ |
Write the output of the following code. Show your working in short.
stock = {'Bag': 15, 'Map': 40, 'Pen': 30, 'Ink': 75}
for item in stock:
if stock[item] < 32:
stock[item] += 10
stock["Glue"] = 5
del stock['Bag']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Map': 40, 'Pen': 40, 'Ink': 75, 'Glue': 5}
4 160Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 15, 'Map': 40, 'Pen': 30, 'Ink': 75} | stock = {'Bag': 15, 'Map': 40, 'Pen': 30, 'Ink': 75} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 32: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 25, 'Map': 40, 'Pen': 30, 'Ink': 75} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 32: | condition is False | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 32: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 25, 'Map': 40, 'Pen': 40, 'Ink': 75} | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 32: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 5 | stock = {'Bag': 25, 'Map': 40, 'Pen': 40, 'Ink': 75, 'Glue': 5} | |
| 6 | del stock['Bag'] | stock = {'Map': 40, 'Pen': 40, 'Ink': 75, 'Glue': 5} | |
| 7 | print(stock) | {'Map': 40, 'Pen': 40, 'Ink': 75, 'Glue': 5}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 160⏎ |
Write the output of the following code. Show your working in short.
L = [25, 15, 33, 42, 53, 41]
A, B = [], []
for x in L:
if x % 4 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[] [41, 53, 42, 33, 15, 25] [41, 53]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [25, 15, 33, 42, 53, 41] | L = [25, 15, 33, 42, 53, 41] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 25 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [25] | |
| 3 | for x in L: | x = 15 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [15, 25] | |
| 3 | for x in L: | x = 33 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [33, 15, 25] | |
| 3 | for x in L: | x = 42 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [42, 33, 15, 25] | |
| 3 | for x in L: | x = 53 | |
| 4 | if x % 4 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Ruler': 15, 'Pen': 40, 'Map': 75, 'Ink': 65}
for item in stock:
if stock[item] < 45:
stock[item] += 10
stock["Glue"] = 19
del stock['Map']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Ruler': 25, 'Pen': 50, 'Ink': 65, 'Glue': 19}
4 159Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Ruler': 15, 'Pen': 40, 'Map': 75, 'Ink': 65} | stock = {'Ruler': 15, 'Pen': 40, 'Map': 75, 'Ink': 65} | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 45: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Ruler': 25, 'Pen': 40, 'Map': 75, 'Ink': 65} | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 45: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Ruler': 25, 'Pen': 50, 'Map': 75, 'Ink': 65} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 45: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 45: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 19 | stock = {'Ruler': 25, 'Pen': 50, 'Map': 75, 'Ink': 65, 'Glue': 19} | |
| 6 | del stock['Map'] | stock = {'Ruler': 25, 'Pen': 50, 'Ink': 65, 'Glue': 19} | |
| 7 | print(stock) | {'Ruler': 25, 'Pen': 50, 'Ink': 65, 'Glue': 19}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 159⏎ |
Write the output of the following code. Show your working in short.
L = [38, 53, 24, 42, 58, 5]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::4], max(L) % 6)Output:
[91, 77, 66, 100, 63, 5] [91, 63] 4
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [38, 53, 24, 42, 58, 5] | L = [38, 53, 24, 42, 58, 5] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [91, 53, 24, 42, 58, 5] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [91, 77, 24, 42, 58, 5] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [91, 77, 66, 42, 58, 5] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [91, 77, 66, 100, 58, 5] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [91, 77, 66, 100, 63, 5] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [91, 77, 66, 100, 63, 5]⏎ | |
| 5 | print(L[::4], max(L) % 6) | [91, 63] 4⏎ |
Write the output of the following code. Show your working in short.
L = [58, 55, 6, 12, 33, 53]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::3], max(L) % 7)Output:
[113, 61, 18, 45, 86, 53] [113, 45] 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [58, 55, 6, 12, 33, 53] | L = [58, 55, 6, 12, 33, 53] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [113, 55, 6, 12, 33, 53] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [113, 61, 6, 12, 33, 53] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [113, 61, 18, 12, 33, 53] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [113, 61, 18, 45, 33, 53] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [113, 61, 18, 45, 86, 53] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [113, 61, 18, 45, 86, 53]⏎ | |
| 5 | print(L[::3], max(L) % 7) | [113, 45] 1⏎ |
Write the output of the following code. Show your working in short.
L = [50, 46, 14, 42, 15, 58]
A, B = [], []
for x in L:
if x % 2 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[50, 46, 14, 42, 58] [15] [50, 46, 14, 42, 58, 15]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [50, 46, 14, 42, 15, 58] | L = [50, 46, 14, 42, 15, 58] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 50 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [50] | |
| 3 | for x in L: | x = 46 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [50, 46] | |
| 3 | for x in L: | x = 14 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [50, 46, 14] | |
| 3 | for x in L: | x = 42 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [50, 46, 14, 42] | |
| 3 | for x in L: | x = 15 | |
| 4 | if x % 2 == 0: | condition is False |
… the same steps continue for the remaining values.
Write a program to input the marks of five subjects and print the average and the grade (A: 80 and above, B: 60 to 79, C: 40 to 59, D: below 40).
total = 0
for i in range(5):
m = float(input('Marks: '))
total = total + m
avg = total / 5
if avg >= 80:
grade = 'A'
elif avg >= 60:
grade = 'B'
elif avg >= 40:
grade = 'C'
else:
grade = 'D'
print('Average =', avg, 'Grade =', grade)Sample run
Marks: 78 Marks: 85 Marks: 62 Marks: 90 Marks: 71 Average = 77.2 Grade = B
Write a program to find the sale price of an item, given its cost and the discount percentage.
cost = float(input('Cost: '))
disc = float(input('Discount %: '))
sale = cost - cost * disc / 100
print('Sale price =', sale)Sample run
Cost: 1250 Discount %: 12 Sale price = 1100.0
Write a program to find the area and the perimeter of a rectangle.
l = float(input('Length: '))
b = float(input('Breadth: '))
print('Area =', l * b)
print('Perimeter =', 2 * (l + b))Sample run
Length: 12 Breadth: 7.5 Area = 90.0 Perimeter = 39.0
Write a program to find the area and the circumference of a circle.
r = float(input('Radius: '))
print('Area =', round(3.14 * r * r, 2))
print('Circumference =', round(2 * 3.14 * r, 2))Sample run
Radius: 7 Area = 153.86 Circumference = 43.96
Write a program to find the area and the perimeter of a square.
s = float(input('Side: '))
print('Area =', s * s)
print('Perimeter =', 4 * s)Sample run
Side: 9 Area = 81.0 Perimeter = 36.0
Write a program to find the area of a triangle using Heron's formula, and its perimeter.
a = float(input('Side a: '))
b = float(input('Side b: '))
c = float(input('Side c: '))
s = (a + b + c) / 2
area = (s * (s - a) * (s - b) * (s - c)) ** 0.5
print('Perimeter =', a + b + c)
print('Area =', round(area, 2))Sample run
Side a: 3 Side b: 4 Side c: 5 Perimeter = 12.0 Area = 6.0
Write a program to find the simple interest and the compound interest.
p = float(input('Principal: '))
r = float(input('Rate: '))
t = float(input('Time (years): '))
si = p * r * t / 100
ci = p * (1 + r / 100) ** t - p
print('SI =', round(si, 2))
print('CI =', round(ci, 2))Sample run
Principal: 20000 Rate: 7 Time (years): 3 SI = 4200.0 CI = 4500.86
Write a program to find the profit or loss, given the cost price and the selling price.
cp = float(input('Cost price: '))
sp = float(input('Selling price: '))
if sp > cp:
print('Profit =', sp - cp)
elif cp > sp:
print('Loss =', cp - sp)
else:
print('No profit, no loss')Sample run
Cost price: 850 Selling price: 999 Profit = 149.0
Write a program to calculate the EMI, given the amount, the yearly rate of interest and the period in months.
P = float(input('Amount: '))
R = float(input('Rate per year: ')) / 12 / 100
N = int(input('Months: '))
emi = P * R * (1 + R) ** N / ((1 + R) ** N - 1)
print('EMI =', round(emi, 2))Sample run
Amount: 100000 Rate per year: 12 Months: 12 EMI = 8884.88
Write a program to calculate the GST and the total bill amount for a given price and GST rate.
price = float(input('Price: '))
rate = float(input('GST rate %: '))
gst = price * rate / 100
print('GST =', gst)
print('Total =', price + gst)Sample run
Price: 2400 GST rate %: 18 GST = 432.0 Total = 2832.0
Write a program to calculate income tax: no tax up to 3,00,000; 5% on the amount from 3,00,001 to 7,00,000; 10% on the amount above 7,00,000.
inc = float(input('Income: '))
if inc <= 300000:
tax = 0
elif inc <= 700000:
tax = (inc - 300000) * 5 / 100
else:
tax = 400000 * 5 / 100 + (inc - 700000) * 10 / 100
print('Tax =', tax)Sample run
Income: 850000 Tax = 35000.0
Write a program to print the first n multiples of a given number.
x = int(input('Number: '))
n = int(input('How many multiples? '))
for i in range(1, n + 1):
print(x * i, end=' ')Sample run
Number: 7 How many multiples? 6 7 14 21 28 35 42
Write a program to find the sum of the squares of the first 100 natural numbers.
s = 0
for i in range(1, 101):
s = s + i * i
print('Sum of squares =', s)Sample run
Sum of squares = 338350
Write a program to count the vowels in a string entered by the user.
s = input('Enter a string: ')
count = 0
for ch in s:
if ch in 'aeiouAEIOU':
count += 1
print('Vowels =', count)Sample run
Enter a string: Informatics Practices Vowels = 7
Write a program to count how many times a given letter occurs in a string.
s = input('String: ')
c = input('Letter: ')
count = 0
for ch in s:
if ch == c:
count += 1
print(c, 'occurs', count, 'times')Sample run
String: banana bread Letter: a a occurs 4 times
Write a program to print the words of a string that start with a given letter.
s = input('String: ')
c = input('Letter: ')
for w in s.split():
if w[0] == c:
print(w)Sample run
String: python programs print pretty patterns Letter: p python programs print pretty patterns
Write a program to check whether a number is even or odd and positive or negative.
n = int(input('Number: '))
if n % 2 == 0:
print('Even')
else:
print('Odd')
if n >= 0:
print('Positive')
else:
print('Negative')Sample run
Number: -27 Odd Negative
Write a program to print the multiplication table of a number.
n = int(input('Number: '))
for i in range(1, 11):
print(n, 'x', i, '=', n * i)Sample run
Number: 9 9 x 1 = 9 9 x 2 = 18 9 x 3 = 27 9 x 4 = 36 9 x 5 = 45 9 x 6 = 54 9 x 7 = 63 9 x 8 = 72 9 x 9 = 81 9 x 10 = 90
Write a program to find the factorial of a number using a while loop.
n = int(input('Number: '))
f = 1
i = 1
while i <= n:
f = f * i
i = i + 1
print('Factorial =', f)Sample run
Number: 6 Factorial = 720
Write a program to find the sum of the digits of a number.
n = int(input('Number: '))
s = 0
while n > 0:
s = s + n % 10
n = n // 10
print('Sum of digits =', s)Sample run
Number: 4096 Sum of digits = 19
Write a program to convert a temperature from Celsius to Fahrenheit.
c = float(input('Celsius: '))
f = c * 9 / 5 + 32
print('Fahrenheit =', f)Sample run
Celsius: 36.6 Fahrenheit = 97.88000000000001
Write a program to check whether a year is a leap year.
y = int(input('Year: '))
if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0:
print('Leap year')
else:
print('Not a leap year')Sample run
Year: 1900 Not a leap year
Write a program to calculate the electricity bill: Rs 3 per unit for the first 100 units, Rs 5 per unit for the next 100 units, Rs 8 per unit above 200 units.
u = int(input('Units: '))
if u <= 100:
bill = u * 3
elif u <= 200:
bill = 300 + (u - 100) * 5
else:
bill = 300 + 500 + (u - 200) * 8
print('Bill =', bill)Sample run
Units: 260 Bill = 1280
Write a program to find the largest of three numbers.
a = int(input('A: '))
b = int(input('B: '))
c = int(input('C: '))
big = a
if b > big:
big = b
if c > big:
big = c
print('Largest =', big)Sample run
A: 34 B: 91 C: 57 Largest = 91
Write a program to print the sum of all even numbers from 1 to n.
n = int(input('n: '))
s = 0
for i in range(2, n + 1, 2):
s = s + i
print('Sum of even numbers =', s)Sample run
n: 20 Sum of even numbers = 110
Write a program to calculate the BMI (weight in kg / height in m squared) and print 'Underweight' if it is below 18.5, 'Normal' up to 24.9, else 'Overweight'.
w = float(input('Weight (kg): '))
h = float(input('Height (m): '))
bmi = w / (h * h)
print('BMI =', round(bmi, 1))
if bmi < 18.5:
print('Underweight')
elif bmi <= 24.9:
print('Normal')
else:
print('Overweight')Sample run
Weight (kg): 55 Height (m): 1.65 BMI = 20.2 Normal
Write a program to calculate the total fee: tuition fee plus 10% computer fee and Rs 500 transport fee if the student uses the bus.
fee = float(input('Tuition fee: '))
bus = input('Uses bus (y/n): ')
total = fee + fee * 10 / 100
if bus == 'y':
total = total + 500
print('Total fee =', total)Sample run
Tuition fee: 3000 Uses bus (y/n): y Total fee = 3800.0
Write a program to swap two numbers without a third variable.
a = int(input('a: '))
b = int(input('b: '))
a, b = b, a
print('a =', a, 'b =', b)Sample run
a: 15 b: 40 a = 40 b = 15
Write a program to input a number and print its factorial.
n = int(input('Enter a number: '))
f = 1
for i in range(1, n + 1):
f = f * i
print('Factorial =', f)Sample run
Enter a number: 6 Factorial = 720
Write a program to input a number and find the sum of its digits.
n = int(input('Enter a number: '))
s = 0
while n > 0:
s = s + n % 10
n = n // 10
print('Sum of digits =', s)Sample run
Enter a number: 5274 Sum of digits = 18
Write a program to input a number and check whether it is a palindrome.
n = int(input('Enter a number: '))
temp = n
rev = 0
while temp > 0:
rev = rev * 10 + temp % 10
temp = temp // 10
if rev == n:
print(n, 'is a palindrome')
else:
print(n, 'is not a palindrome')Sample run
Enter a number: 12321 12321 is a palindrome
Write a program to input a number and check whether it is prime.
n = int(input('Enter a number: '))
if n < 2:
print(n, 'is not prime')
else:
for i in range(2, n):
if n % i == 0:
print(n, 'is not prime')
break
else:
print(n, 'is prime')Sample run
Enter a number: 29 29 is prime
Write a program to check whether a three-digit number is an Armstrong number.
n = int(input('Enter a 3-digit number: '))
temp = n
s = 0
while temp > 0:
d = temp % 10
s = s + d ** 3
temp = temp // 10
if s == n:
print(n, 'is an Armstrong number')
else:
print(n, 'is not an Armstrong number')Sample run
Enter a 3-digit number: 153 153 is an Armstrong number
Write a program to input two numbers and find their GCD (HCF) and LCM.
a = int(input('First number: '))
b = int(input('Second number: '))
x, y = a, b
while y != 0:
x, y = y, x % y
print('GCD =', x)
print('LCM =', a * b // x)Sample run
First number: 12 Second number: 18 GCD = 6 LCM = 36
Write a program to print the first n terms of the Fibonacci series.
n = int(input('How many terms? '))
a, b = 0, 1
for i in range(n):
print(a, end=' ')
a, b = b, a + bSample run
How many terms? 8 0 1 1 2 3 5 8 13
Write a program to input a number and print its multiplication table up to 10.
n = int(input('Enter a number: '))
for i in range(1, 11):
print(n, 'x', i, '=', n * i)Sample run
Enter a number: 7 7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49 7 x 8 = 56 7 x 9 = 63 7 x 10 = 70
Write a program to input a year and check whether it is a leap year.
y = int(input('Enter a year: '))
if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0:
print(y, 'is a leap year')
else:
print(y, 'is not a leap year')Sample run
Enter a year: 2024 2024 is a leap year
Write a program to input three numbers and print the largest.
a = int(input('A: '))
b = int(input('B: '))
c = int(input('C: '))
if a >= b and a >= c:
big = a
elif b >= c:
big = b
else:
big = c
print('Largest =', big)Sample run
A: 45 B: 72 C: 19 Largest = 72
Write a program to input marks out of 100 and print the grade: A (90 and above), B (75-89), C (50-74), D (33-49), E (below 33).
m = int(input('Marks: '))
if m >= 90:
g = 'A'
elif m >= 75:
g = 'B'
elif m >= 50:
g = 'C'
elif m >= 33:
g = 'D'
else:
g = 'E'
print('Grade', g)Sample run
Marks: 78 Grade B
Write a program to check whether a number is a perfect number (equal to the sum of its factors other than itself).
n = int(input('Enter a number: '))
s = 0
for i in range(1, n):
if n % i == 0:
s = s + i
if s == n:
print(n, 'is a perfect number')
else:
print(n, 'is not a perfect number')Sample run
Enter a number: 28 28 is a perfect number
Write a program to input a number and count its digits.
n = int(input('Enter a number: '))
count = 0
while n > 0:
count += 1
n = n // 10
print('Digits =', count)Sample run
Enter a number: 904512 Digits = 6
Write a program to print all prime numbers between 1 and n.
n = int(input('Up to: '))
for num in range(2, n + 1):
for i in range(2, num):
if num % i == 0:
break
else:
print(num, end=' ')Sample run
Up to: 30 2 3 5 7 11 13 17 19 23 29
Write a program to find the sum of even numbers and the sum of odd numbers from 1 to n.
n = int(input('Enter n: '))
even = odd = 0
for i in range(1, n + 1):
if i % 2 == 0:
even += i
else:
odd += i
print('Sum of even =', even)
print('Sum of odd =', odd)Sample run
Enter n: 10 Sum of even = 30 Sum of odd = 25
Write a program to input a number and print its reverse.
n = int(input('Enter a number: '))
rev = 0
while n > 0:
rev = rev * 10 + n % 10
n = n // 10
print('Reverse =', rev)Sample run
Enter a number: 37081 Reverse = 18073
Write a program to input the principal, rate and time and print the simple interest and compound interest.
p = float(input('Principal: '))
r = float(input('Rate: '))
t = float(input('Time: '))
si = p * r * t / 100
ci = p * (1 + r / 100) ** t - p
print('Simple interest =', round(si, 2))
print('Compound interest =', round(ci, 2))Sample run
Principal: 10000 Rate: 8 Time: 2 Simple interest = 1600.0 Compound interest = 1664.0
Write a program to convert a temperature in Celsius to Fahrenheit and Kelvin.
c = float(input('Celsius: '))
f = c * 9 / 5 + 32
k = c + 273.15
print('Fahrenheit =', f)
print('Kelvin =', k)Sample run
Celsius: 37 Fahrenheit = 98.6 Kelvin = 310.15
Write a program to input the three sides of a triangle and check whether it is equilateral, isosceles or scalene.
a = int(input('Side 1: '))
b = int(input('Side 2: '))
c = int(input('Side 3: '))
if a == b == c:
print('Equilateral')
elif a == b or b == c or a == c:
print('Isosceles')
else:
print('Scalene')Sample run
Side 1: 5 Side 2: 7 Side 3: 5 Isosceles
Write a program to find the sum of the squares of the first n natural numbers.
n = int(input('Enter n: '))
s = 0
for i in range(1, n + 1):
s = s + i * i
print('Sum of squares =', s)Sample run
Enter n: 6 Sum of squares = 91
Write a program to input n numbers and print their average, the largest and the smallest.
n = int(input('How many numbers? '))
total = 0
for i in range(n):
x = int(input('Number: '))
if i == 0:
big = small = x
big = max(big, x)
small = min(small, x)
total += x
print('Average =', total / n)
print('Largest =', big, 'Smallest =', small)Sample run
How many numbers? 4 Number: 15 Number: 42 Number: 8 Number: 23 Average = 22.0 Largest = 42 Smallest = 8
Write a program to print all the factors of a number and their count.
n = int(input('Enter a number: '))
count = 0
for i in range(1, n + 1):
if n % i == 0:
print(i, end=' ')
count += 1
print()
print('Number of factors =', count)Sample run
Enter a number: 36 1 2 3 4 6 9 12 18 36 Number of factors = 9
Write a program to input a number and print whether it is positive, negative or zero, and whether it is even or odd.
n = int(input('Enter a number: '))
if n > 0:
print('Positive')
elif n < 0:
print('Negative')
else:
print('Zero')
if n % 2 == 0:
print('Even')
else:
print('Odd')Sample run
Enter a number: -14 Negative Even
Write a program to print the following pattern for n rows (shown for n = 4):
* * * * * * * * * *
n = int(input('Rows: '))
for i in range(1, n + 1):
print('* ' * i)Sample run
Rows: 4 * * * * * * * * * *
Write a program to print the following pattern for n rows (shown for n = 4):
1 1 2 1 2 3 1 2 3 4
n = int(input('Rows: '))
for i in range(1, n + 1):
for j in range(1, i + 1):
print(j, end=' ')
print()Sample run
Rows: 4 1 1 2 1 2 3 1 2 3 4
Write a program to print the following pattern for n rows (shown for n = 4):
1 2 2 3 3 3 4 4 4 4
n = int(input('Rows: '))
for i in range(1, n + 1):
for j in range(i):
print(i, end=' ')
print()Sample run
Rows: 4 1 2 2 3 3 3 4 4 4 4
Write a program to print the following pattern for n rows (shown for n = 4):
4 3 2 1 4 3 2 4 3 4
n = int(input('Rows: '))
for i in range(1, n + 1):
for j in range(n, i - 1, -1):
print(j, end=' ')
print()Sample run
Rows: 4 4 3 2 1 4 3 2 4 3 4
Write a program to print the following pattern for n rows (shown for n = 4):
* ** *** ****
n = int(input('Rows: '))
for i in range(1, n + 1):
print(' ' * (n - i) + '*' * i)Sample run
Rows: 4 * ** *** ****
Write a program to print the following pattern for n rows (shown for n = 4):
1 2 3 4 5 6 7 8 9 10
n = int(input('Rows: '))
k = 1
for i in range(1, n + 1):
for j in range(i):
print(k, end=' ')
k += 1
print()Sample run
Rows: 4 1 2 3 4 5 6 7 8 9 10
Write a program to print the following pattern for n rows (shown for n = 4):
1 2 3 4 1 2 3 1 2 1
n = int(input('Rows: '))
for i in range(n, 0, -1):
for j in range(1, i + 1):
print(j, end=' ')
print()Sample run
Rows: 4 1 2 3 4 1 2 3 1 2 1
Write a program to input the values needed and find the sum of the series: 1 + x + x² + x³ + ... + xⁿ
x = int(input('x: '))
n = int(input('n: '))
s = 0
for i in range(n + 1):
s = s + x ** i
print('Sum =', s)Sample run
x: 2 n: 5 Sum = 63
Write a program to input the values needed and find the sum of the series: 1 - x + x² - x³ + ... (n terms after 1, up to xⁿ)
x = int(input('x: '))
n = int(input('n: '))
s = 0
for i in range(n + 1):
s = s + (-1) ** i * x ** i
print('Sum =', s)Sample run
x: 3 n: 4 Sum = 61
Write a program to input the values needed and find the sum of the series: x - x²/2 + x³/3 - ... up to n terms
x = float(input('x: '))
n = int(input('n: '))
s = 0
for i in range(1, n + 1):
s = s + (-1) ** (i + 1) * x ** i / i
print('Sum =', round(s, 4))Sample run
x: 2 n: 4 Sum = -1.3333
Write a program to input the values needed and find the sum of the series: 1 + 1/2 + 1/3 + ... + 1/n
n = int(input('n: '))
s = 0
for i in range(1, n + 1):
s = s + 1 / i
print('Sum =', round(s, 4))Sample run
n: 5 Sum = 2.2833
Write a program to input the values needed and find the sum of the series: 1² + 2² + 3² + ... + n² and 1³ + 2³ + ... + n³
n = int(input('n: '))
s2 = s3 = 0
for i in range(1, n + 1):
s2 += i ** 2
s3 += i ** 3
print('Sum of squares =', s2)
print('Sum of cubes =', s3)Sample run
n: 5 Sum of squares = 55 Sum of cubes = 225
Write a program to input the values needed and find the sum of the series: 1 + 2 + 4 + 8 + ... (n terms)
n = int(input('n: '))
term = 1
s = 0
for i in range(n):
s = s + term
term = term * 2
print('Sum =', s)Sample run
n: 6 Sum = 63
Write a program to input the values needed and find the sum of the series: 1 + 3 + 5 + ... (first n odd numbers)
n = int(input('n: '))
s = 0
for i in range(n):
s = s + (2 * i + 1)
print('Sum =', s)Sample run
n: 7 Sum = 49
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL commands for the following:
(i)
UPDATE BOOK SET Price = Price + 10 WHERE Subject = 'Science';
2 rows changed.
Explanation: SET Price = Price + 10 changes the value; WHERE limits the change to the rows where Subject is 'Science': 2 rows (Physics Part 1, Chemistry Part 1). Other rows are not changed.
(ii)
SELECT Title FROM BOOK WHERE Subject = 'Computer' AND Price >= 300;
| Title |
|---|
| Python Basics |
| Learn SQL |
Explanation: WHERE keeps only the rows where Subject is 'Computer' and Price is at least 300: 2 of the 7 rows match (Python Basics, Learn SQL). SELECT then shows only the column Title.
(iii)
SELECT BookID, Title, Price FROM BOOK WHERE Price BETWEEN 200 AND 250;
| BookID | Title | Price |
|---|---|---|
| 201 | Informatics Practices | 210 |
| 206 | The Story of My Experiments | 250 |
Explanation: WHERE keeps only the rows where Price is from 200 to 250 (both included): 2 of the 7 rows match (Informatics Practices, The Story of My Experiments). SELECT then shows only the columns BookID, Title, Price.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL commands for the following:
(i)
SELECT PName, MfgDate FROM PRODUCT WHERE MfgDate BETWEEN '2025-10-01' AND '2026-01-31';
| PName | MfgDate |
|---|---|
| Notebook | 2026-01-10 |
| Geometry Box | 2025-11-02 |
| Lunch Box | 2025-12-18 |
Explanation: WHERE keeps only the rows where MfgDate is from '2025-10-01' to '2026-01-31' (both included): 3 of the 7 rows match (Notebook, Geometry Box, Lunch Box). SELECT then shows only the columns PName, MfgDate.
(ii)
SELECT PName FROM PRODUCT WHERE Brand = 'Camlin' AND Discount IS NOT NULL;
| PName |
|---|
| Geometry Box |
Explanation: WHERE keeps only the rows where Brand is 'Camlin' and Discount has a value (is not NULL): 1 of the 7 rows matches (Geometry Box). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
UPDATE PRODUCT SET Price = Price + 10 WHERE Category = 'Stationery';
2 rows changed.
Explanation: SET Price = Price + 10 changes the value; WHERE limits the change to the rows where Category is 'Stationery': 2 rows (Notebook, Geometry Box). Other rows are not changed.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL commands for the following:
(i)
SELECT PName FROM PRODUCT WHERE Brand = 'Camlin' AND Discount IS NOT NULL;
| PName |
|---|
| Geometry Box |
Explanation: WHERE keeps only the rows where Brand is 'Camlin' and Discount has a value (is not NULL): 1 of the 7 rows matches (Geometry Box). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName, Category FROM PRODUCT WHERE Category = 'Electronics' OR Category = 'Stationery';
| PName | Category |
|---|---|
| Notebook | Stationery |
| Pen Drive | Electronics |
| Geometry Box | Stationery |
| Mouse | Electronics |
| Earphones | Electronics |
Explanation: WHERE keeps only the rows where Category is 'Electronics' or Category is 'Stationery': 5 of the 7 rows match (Notebook, Pen Drive, Geometry Box, Mouse, Earphones). SELECT then shows only the columns PName, Category.
(iii)
SELECT PCode, Price, Price + 10 FROM PRODUCT;
| PCode | Price | Price + 10 |
|---|---|---|
| P01 | 60 | 70 |
| P02 | 450 | 460 |
| P03 | 180 | 190 |
| P04 | 650 | 660 |
| P05 | 320 | 330 |
| P06 | 899 | 909 |
| P07 | 275 | 285 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PCode, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL commands for the following:
(i)
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Mumbai';
| EName | City |
|---|---|
| Ravi | Delhi |
| Seema | Pune |
| Tarun | Delhi |
| Vikas | Pune |
| Wasim | Delhi |
Explanation: WHERE keeps only the rows where City is not 'Mumbai': 5 of the 7 rows match (Ravi, Seema, Tarun, Vikas, Wasim). SELECT then shows only the columns EName, City.
(ii)
SELECT EName FROM EMPLOYEE WHERE City = 'Mumbai' AND Bonus IS NOT NULL;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where City is 'Mumbai' and Bonus has a value (is not NULL). No row satisfies this, so the result is an empty set. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT EName FROM EMPLOYEE WHERE Dept = 'IT' AND Salary >= 70000;
| EName |
|---|
| Tarun |
| Yamini |
Explanation: WHERE keeps only the rows where Dept is 'IT' and Salary is at least 70000: 2 of the 7 rows match (Tarun, Yamini). SELECT then shows only the column EName.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL commands for the following:
(i)
SELECT PName, Doctor FROM PATIENT WHERE Doctor <> 'Dr. Iyer';
| PName | Doctor |
|---|---|
| Mohan | Dr. Rao |
| Nisha | Dr. Sen |
| Om | Dr. Rao |
| Qasim | Dr. Sen |
| Sahil | Dr. Rao |
Explanation: WHERE keeps only the rows where Doctor is not 'Dr. Iyer': 5 of the 7 rows match (Mohan, Nisha, Om, Qasim, Sahil). SELECT then shows only the columns PName, Doctor.
(ii)
SELECT PID, Fee, Fee + 10 FROM PATIENT;
| PID | Fee | Fee + 10 |
|---|---|---|
| 11 | 1500 | 1510 |
| 12 | 8000 | 8010 |
| 13 | 1200 | 1210 |
| 14 | 5000 | 5010 |
| 15 | 9500 | 9510 |
| 16 | 4500 | 4510 |
| 17 | 900 | 910 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PID, Fee, Fee + 10. The expression is calculated for every row; the table itself does not change.
(iii)
SELECT PName, Fee FROM PATIENT WHERE Fee > 4000;
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Pooja | 5000 |
| Qasim | 9500 |
| Rekha | 4500 |
Explanation: WHERE keeps only the rows where Fee is more than 4000: 4 of the 7 rows match (Nisha, Pooja, Qasim, Rekha). SELECT then shows only the columns PName, Fee.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL commands for the following:
(i)
SELECT * FROM BOOK WHERE Subject = 'Computer';
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Explanation: WHERE keeps only the rows where Subject is 'Computer': 3 of the 7 rows match (Informatics Practices, Python Basics, Learn SQL). SELECT then shows all the columns (*).
(ii)
SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'Penguin';
| Title | Publisher |
|---|---|
| Informatics Practices | NCERT |
| Physics Part 1 | NCERT |
| Wings of Fire | Universities |
| Python Basics | BPB |
| Chemistry Part 1 | NCERT |
| Learn SQL | BPB |
Explanation: WHERE keeps only the rows where Publisher is not 'Penguin': 6 of the 7 rows match (Informatics Practices, Physics Part 1, Wings of Fire, Python Basics, Chemistry Part 1, Learn SQL). SELECT then shows only the columns Title, Publisher.
(iii)
SELECT Title, Subject FROM BOOK WHERE NOT Subject = 'Computer';
| Title | Subject |
|---|---|
| Physics Part 1 | Science |
| Wings of Fire | Biography |
| Chemistry Part 1 | Science |
| The Story of My Experiments | Biography |
Explanation: WHERE keeps only the rows where Subject is not 'Computer': 4 of the 7 rows match (Physics Part 1, Wings of Fire, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Subject.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL commands for the following:
(i)
SELECT PName, Fee FROM PATIENT WHERE Fee > 1500;
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Pooja | 5000 |
| Qasim | 9500 |
| Rekha | 4500 |
Explanation: WHERE keeps only the rows where Fee is more than 1500: 4 of the 7 rows match (Nisha, Pooja, Qasim, Rekha). SELECT then shows only the columns PName, Fee.
(ii)
SELECT PName, Ward FROM PATIENT WHERE Ward = 'Maternity' OR Ward = 'General';
| PName | Ward |
|---|---|
| Mohan | General |
| Om | General |
| Pooja | Maternity |
| Rekha | Maternity |
| Sahil | General |
Explanation: WHERE keeps only the rows where Ward is 'Maternity' or Ward is 'General': 5 of the 7 rows match (Mohan, Om, Pooja, Rekha, Sahil). SELECT then shows only the columns PName, Ward.
(iii)
SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
| PName | Insurance |
|---|---|
| Mohan | LIC |
| Om | Star |
| Pooja | LIC |
| Sahil | Star |
Explanation: WHERE keeps only the rows where Insurance has a value (is not NULL): 4 of the 7 rows match (Mohan, Om, Pooja, Sahil). SELECT then shows only the columns PName, Insurance. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL commands for the following:
(i)
SELECT PName FROM PATIENT WHERE Ward = 'General' AND Fee >= 1000;
| PName |
|---|
| Mohan |
| Om |
Explanation: WHERE keeps only the rows where Ward is 'General' and Fee is at least 1000: 2 of the 7 rows match (Mohan, Om). SELECT then shows only the column PName.
(ii)
SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
| PName | Insurance |
|---|---|
| Mohan | LIC |
| Om | Star |
| Pooja | LIC |
| Sahil | Star |
Explanation: WHERE keeps only the rows where Insurance has a value (is not NULL): 4 of the 7 rows match (Mohan, Om, Pooja, Sahil). SELECT then shows only the columns PName, Insurance. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT PName, Doctor FROM PATIENT WHERE Doctor <> 'Dr. Rao';
| PName | Doctor |
|---|---|
| Nisha | Dr. Sen |
| Pooja | Dr. Iyer |
| Qasim | Dr. Sen |
| Rekha | Dr. Iyer |
Explanation: WHERE keeps only the rows where Doctor is not 'Dr. Rao': 4 of the 7 rows match (Nisha, Pooja, Qasim, Rekha). SELECT then shows only the columns PName, Doctor.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL commands for the following:
(i)
SELECT Name, Section FROM STUDENT WHERE NOT Section = 'A';
| Name | Section |
|---|---|
| Bhavya | B |
| Divya | C |
| Eshan | B |
| Gaurav | C |
Explanation: WHERE keeps only the rows where Section is not 'A': 4 of the 7 rows match (Bhavya, Divya, Eshan, Gaurav). SELECT then shows only the columns Name, Section.
(ii)
SELECT Name, Marks FROM STUDENT WHERE Marks < 60 OR Phone IS NULL;
| Name | Marks |
|---|---|
| Bhavya | 92 |
| Chirag | 45 |
| Eshan | 88 |
| Farah | 31 |
| Gaurav | 59 |
Explanation: WHERE keeps only the rows where Marks is less than 60 or Phone is empty (NULL): 5 of the 7 rows match (Bhavya, Chirag, Eshan, Farah, Gaurav). SELECT then shows only the columns Name, Marks. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT * FROM STUDENT WHERE Section = 'A';
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
Explanation: WHERE keeps only the rows where Section is 'A': 3 of the 7 rows match (Aarav, Chirag, Farah). SELECT then shows all the columns (*).
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL commands for the following:
(i)
SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT EName, Bonus FROM EMPLOYEE WHERE Bonus IS NOT NULL;
| EName | Bonus |
|---|---|
| Ravi | 3000 |
| Tarun | 5000 |
| Vikas | 4000 |
| Wasim | 2000 |
Explanation: WHERE keeps only the rows where Bonus has a value (is not NULL): 4 of the 7 rows match (Ravi, Tarun, Vikas, Wasim). SELECT then shows only the columns EName, Bonus. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT EName, Salary FROM EMPLOYEE WHERE Salary < 50000 OR Bonus IS NULL;
| EName | Salary |
|---|---|
| Ravi | 42000 |
| Seema | 58000 |
| Usha | 36000 |
| Wasim | 39000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is less than 50000 or Bonus is empty (NULL): 5 of the 7 rows match (Ravi, Seema, Usha, Wasim, Yamini). SELECT then shows only the columns EName, Salary. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL commands for the following:
(i)
SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
| Name | Phone |
|---|---|
| Aarav | 9810011111 |
| Chirag | 9810033333 |
| Divya | 9810044444 |
| Farah | 9810066666 |
| Gaurav | 9810077777 |
Explanation: WHERE keeps only the rows where Phone has a value (is not NULL): 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Phone. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 70 AND 80;
| RollNo | Name | Marks |
|---|---|---|
| 1 | Aarav | 78 |
Explanation: WHERE keeps only the rows where Marks is from 70 to 80 (both included): 1 of the 7 rows matches (Aarav). SELECT then shows only the columns RollNo, Name, Marks.
(iii)
SELECT Name, Marks FROM STUDENT WHERE Marks > 50;
| Name | Marks |
|---|---|
| Aarav | 78 |
| Bhavya | 92 |
| Divya | 66 |
| Eshan | 88 |
| Gaurav | 59 |
Explanation: WHERE keeps only the rows where Marks is more than 50: 5 of the 7 rows match (Aarav, Bhavya, Divya, Eshan, Gaurav). SELECT then shows only the columns Name, Marks.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL commands for the following:
(i)
SELECT PName, Price FROM PRODUCT WHERE Price > 500;
| PName | Price |
|---|---|
| Mouse | 650 |
| Earphones | 899 |
Explanation: WHERE keeps only the rows where Price is more than 500: 2 of the 7 rows match (Mouse, Earphones). SELECT then shows only the columns PName, Price.
(ii)
SELECT PName FROM PRODUCT WHERE Category = 'Stationery' AND Price >= 500;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Category is 'Stationery' and Price is at least 500. No row satisfies this, so the result is an empty set.
(iii)
SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
| PName | Discount |
|---|---|
| Notebook | 5 |
| Geometry Box | 10 |
| Mouse | 15 |
| Earphones | 20 |
| Lunch Box | 8 |
Explanation: WHERE keeps only the rows where Discount has a value (is not NULL): 5 of the 7 rows match (Notebook, Geometry Box, Mouse, Earphones, Lunch Box). SELECT then shows only the columns PName, Discount. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL commands for the following:
(i)
SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
| Name | DOB |
|---|---|
| Bhavya | 2009-11-30 |
| Divya | 2009-07-21 |
| Farah | 2009-09-09 |
Explanation: WHERE keeps only the rows where DOB is from '2009-06-01' to '2009-12-31' (both included): 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, DOB.
(ii)
SELECT RollNo, Marks, Marks + 10 FROM STUDENT;
| RollNo | Marks | Marks + 10 |
|---|---|---|
| 1 | 78 | 88 |
| 2 | 92 | 102 |
| 3 | 45 | 55 |
| 4 | 66 | 76 |
| 5 | 88 | 98 |
| 6 | 31 | 41 |
| 7 | 59 | 69 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns RollNo, Marks, Marks + 10. The expression is calculated for every row; the table itself does not change.
(iii)
SELECT Name, Marks FROM STUDENT WHERE Marks < 60 OR Phone IS NULL;
| Name | Marks |
|---|---|
| Bhavya | 92 |
| Chirag | 45 |
| Eshan | 88 |
| Farah | 31 |
| Gaurav | 59 |
Explanation: WHERE keeps only the rows where Marks is less than 60 or Phone is empty (NULL): 5 of the 7 rows match (Bhavya, Chirag, Eshan, Farah, Gaurav). SELECT then shows only the columns Name, Marks. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL commands for the following:
(i)
SELECT Name, Gender FROM STUDENT WHERE Gender <> 'F';
| Name | Gender |
|---|---|
| Aarav | M |
| Chirag | M |
| Eshan | M |
| Gaurav | M |
Explanation: WHERE keeps only the rows where Gender is not 'F': 4 of the 7 rows match (Aarav, Chirag, Eshan, Gaurav). SELECT then shows only the columns Name, Gender.
(ii)
SELECT Name FROM STUDENT WHERE Section = 'B' AND Marks >= 60;
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Section is 'B' and Marks is at least 60: 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name.
(iii)
SELECT Name, Marks FROM STUDENT WHERE Marks > 60;
| Name | Marks |
|---|---|
| Aarav | 78 |
| Bhavya | 92 |
| Divya | 66 |
| Eshan | 88 |
Explanation: WHERE keeps only the rows where Marks is more than 60: 4 of the 7 rows match (Aarav, Bhavya, Divya, Eshan). SELECT then shows only the columns Name, Marks.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL commands for the following:
(i)
SELECT Name, Gender FROM STUDENT WHERE Gender <> 'M';
| Name | Gender |
|---|---|
| Bhavya | F |
| Divya | F |
| Farah | F |
Explanation: WHERE keeps only the rows where Gender is not 'M': 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, Gender.
(ii)
SELECT RollNo, Marks, Marks + 10 FROM STUDENT;
| RollNo | Marks | Marks + 10 |
|---|---|---|
| 1 | 78 | 88 |
| 2 | 92 | 102 |
| 3 | 45 | 55 |
| 4 | 66 | 76 |
| 5 | 88 | 98 |
| 6 | 31 | 41 |
| 7 | 59 | 69 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns RollNo, Marks, Marks + 10. The expression is calculated for every row; the table itself does not change.
(iii)
SELECT * FROM STUDENT WHERE Section = 'A';
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
Explanation: WHERE keeps only the rows where Section is 'A': 3 of the 7 rows match (Aarav, Chirag, Farah). SELECT then shows all the columns (*).
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL commands for the following:
(i)
SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
| PName | AdmitDate |
|---|---|
| Nisha | 2026-09-05 |
| Om | 2026-09-10 |
| Pooja | 2026-09-12 |
| Qasim | 2026-09-15 |
Explanation: WHERE keeps only the rows where AdmitDate is from '2026-09-05' to '2026-09-15' (both included): 4 of the 7 rows match (Nisha, Om, Pooja, Qasim). SELECT then shows only the columns PName, AdmitDate.
(ii)
SELECT PName, Fee FROM PATIENT WHERE Fee < 4000 OR Insurance IS NULL;
| PName | Fee |
|---|---|
| Mohan | 1500 |
| Nisha | 8000 |
| Om | 1200 |
| Qasim | 9500 |
| Rekha | 4500 |
| Sahil | 900 |
Explanation: WHERE keeps only the rows where Fee is less than 4000 or Insurance is empty (NULL): 6 of the 7 rows match (Mohan, Nisha, Om, Qasim, Rekha, Sahil). SELECT then shows only the columns PName, Fee. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT PName FROM PATIENT WHERE Ward = 'General' AND Fee >= 1500;
| PName |
|---|
| Mohan |
Explanation: WHERE keeps only the rows where Ward is 'General' and Fee is at least 1500: 1 of the 7 rows matches (Mohan). SELECT then shows only the column PName.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL commands for the following:
(i)
SELECT PID, Fee, Fee + 10 FROM PATIENT;
| PID | Fee | Fee + 10 |
|---|---|---|
| 11 | 1500 | 1510 |
| 12 | 8000 | 8010 |
| 13 | 1200 | 1210 |
| 14 | 5000 | 5010 |
| 15 | 9500 | 9510 |
| 16 | 4500 | 4510 |
| 17 | 900 | 910 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PID, Fee, Fee + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT PName, Ward FROM PATIENT WHERE Ward = 'Maternity' OR Ward = 'ICU';
| PName | Ward |
|---|---|
| Nisha | ICU |
| Pooja | Maternity |
| Qasim | ICU |
| Rekha | Maternity |
Explanation: WHERE keeps only the rows where Ward is 'Maternity' or Ward is 'ICU': 4 of the 7 rows match (Nisha, Pooja, Qasim, Rekha). SELECT then shows only the columns PName, Ward.
(iii)
SELECT PName FROM PATIENT WHERE Insurance IS NULL;
| PName |
|---|
| Nisha |
| Qasim |
| Rekha |
Explanation: WHERE keeps only the rows where Insurance is empty (NULL): 3 of the 7 rows match (Nisha, Qasim, Rekha). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL commands for the following:
(i)
SELECT Name, Section FROM STUDENT WHERE NOT Section = 'A';
| Name | Section |
|---|---|
| Bhavya | B |
| Divya | C |
| Eshan | B |
| Gaurav | C |
Explanation: WHERE keeps only the rows where Section is not 'A': 4 of the 7 rows match (Bhavya, Divya, Eshan, Gaurav). SELECT then shows only the columns Name, Section.
(ii)
SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 60 AND 80;
| RollNo | Name | Marks |
|---|---|---|
| 1 | Aarav | 78 |
| 4 | Divya | 66 |
Explanation: WHERE keeps only the rows where Marks is from 60 to 80 (both included): 2 of the 7 rows match (Aarav, Divya). SELECT then shows only the columns RollNo, Name, Marks.
(iii)
SELECT Name, Marks FROM STUDENT WHERE Marks > 80;
| Name | Marks |
|---|---|
| Bhavya | 92 |
| Eshan | 88 |
Explanation: WHERE keeps only the rows where Marks is more than 80: 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the columns Name, Marks.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL commands for the following:
(i)
SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
| Name | DOB |
|---|---|
| Bhavya | 2009-11-30 |
| Divya | 2009-07-21 |
| Farah | 2009-09-09 |
Explanation: WHERE keeps only the rows where DOB is from '2009-06-01' to '2009-12-31' (both included): 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, DOB.
(ii)
SELECT Name FROM STUDENT WHERE Phone IS NULL;
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Phone is empty (NULL): 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT RollNo, Marks, Marks + 10 FROM STUDENT;
| RollNo | Marks | Marks + 10 |
|---|---|---|
| 1 | 78 | 88 |
| 2 | 92 | 102 |
| 3 | 45 | 55 |
| 4 | 66 | 76 |
| 5 | 88 | 98 |
| 6 | 31 | 41 |
| 7 | 59 | 69 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns RollNo, Marks, Marks + 10. The expression is calculated for every row; the table itself does not change.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL commands for the following:
(i)
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 60000 AND 70000;
| EmpID | EName | Salary |
|---|---|---|
| E105 | Vikas | 64000 |
Explanation: WHERE keeps only the rows where Salary is from 60000 to 70000 (both included): 1 of the 7 rows matches (Vikas). SELECT then shows only the columns EmpID, EName, Salary.
(ii)
SELECT EName, Salary FROM EMPLOYEE WHERE Salary < 60000 OR Bonus IS NULL;
| EName | Salary |
|---|---|
| Ravi | 42000 |
| Seema | 58000 |
| Usha | 36000 |
| Wasim | 39000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is less than 60000 or Bonus is empty (NULL): 5 of the 7 rows match (Ravi, Seema, Usha, Wasim, Yamini). SELECT then shows only the columns EName, Salary. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL commands for the following:
(i)
SELECT PName, Brand FROM PRODUCT WHERE Brand <> 'Camlin';
| PName | Brand |
|---|---|
| Notebook | Classmate |
| Pen Drive | SanDisk |
| Mouse | Logitech |
| Water Bottle | Milton |
| Earphones | Boat |
| Lunch Box | Milton |
Explanation: WHERE keeps only the rows where Brand is not 'Camlin': 6 of the 7 rows match (Notebook, Pen Drive, Mouse, Water Bottle, Earphones, Lunch Box). SELECT then shows only the columns PName, Brand.
(ii)
SELECT PName FROM PRODUCT WHERE Discount IS NULL;
| PName |
|---|
| Pen Drive |
| Water Bottle |
Explanation: WHERE keeps only the rows where Discount is empty (NULL): 2 of the 7 rows match (Pen Drive, Water Bottle). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT PName, Price FROM PRODUCT WHERE Price > 400;
| PName | Price |
|---|---|
| Pen Drive | 450 |
| Mouse | 650 |
| Earphones | 899 |
Explanation: WHERE keeps only the rows where Price is more than 400: 3 of the 7 rows match (Pen Drive, Mouse, Earphones). SELECT then shows only the columns PName, Price.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL commands for the following:
(i)
SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Mumbai';
| EName | City |
|---|---|
| Ravi | Delhi |
| Seema | Pune |
| Tarun | Delhi |
| Vikas | Pune |
| Wasim | Delhi |
Explanation: WHERE keeps only the rows where City is not 'Mumbai': 5 of the 7 rows match (Ravi, Seema, Tarun, Vikas, Wasim). SELECT then shows only the columns EName, City.
(iii)
SELECT EName, Salary FROM EMPLOYEE WHERE Salary < 40000 OR Bonus IS NULL;
| EName | Salary |
|---|---|
| Seema | 58000 |
| Usha | 36000 |
| Wasim | 39000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is less than 40000 or Bonus is empty (NULL): 4 of the 7 rows match (Seema, Usha, Wasim, Yamini). SELECT then shows only the columns EName, Salary. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL commands for the following:
(i)
UPDATE EMPLOYEE SET Salary = Salary + 10 WHERE Dept = 'Sales';
2 rows changed.
Explanation: SET Salary = Salary + 10 changes the value; WHERE limits the change to the rows where Dept is 'Sales': 2 rows (Ravi, Usha). Other rows are not changed.
(ii)
SELECT EName FROM EMPLOYEE WHERE Dept = 'Sales' AND Salary >= 60000;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Dept is 'Sales' and Salary is at least 60000. No row satisfies this, so the result is an empty set.
(iii)
SELECT EName FROM EMPLOYEE WHERE Bonus IS NULL;
| EName |
|---|
| Seema |
| Usha |
| Yamini |
Explanation: WHERE keeps only the rows where Bonus is empty (NULL): 3 of the 7 rows match (Seema, Usha, Yamini). SELECT then shows only the column EName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL commands for the following:
(i)
SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
| Name | DOB |
|---|---|
| Bhavya | 2009-11-30 |
| Divya | 2009-07-21 |
| Farah | 2009-09-09 |
Explanation: WHERE keeps only the rows where DOB is from '2009-06-01' to '2009-12-31' (both included): 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, DOB.
(ii)
SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 50 AND 80;
| RollNo | Name | Marks |
|---|---|---|
| 1 | Aarav | 78 |
| 4 | Divya | 66 |
| 7 | Gaurav | 59 |
Explanation: WHERE keeps only the rows where Marks is from 50 to 80 (both included): 3 of the 7 rows match (Aarav, Divya, Gaurav). SELECT then shows only the columns RollNo, Name, Marks.
(iii)
SELECT Name FROM STUDENT WHERE Section = 'B' AND Marks >= 80;
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Section is 'B' and Marks is at least 80: 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL commands for the following:
(i)
SELECT Name, Marks FROM STUDENT WHERE Marks > 50;
| Name | Marks |
|---|---|
| Aarav | 78 |
| Bhavya | 92 |
| Divya | 66 |
| Eshan | 88 |
| Gaurav | 59 |
Explanation: WHERE keeps only the rows where Marks is more than 50: 5 of the 7 rows match (Aarav, Bhavya, Divya, Eshan, Gaurav). SELECT then shows only the columns Name, Marks.
(ii)
SELECT Name, Marks FROM STUDENT WHERE Marks < 50 OR Phone IS NULL;
| Name | Marks |
|---|---|
| Bhavya | 92 |
| Chirag | 45 |
| Eshan | 88 |
| Farah | 31 |
Explanation: WHERE keeps only the rows where Marks is less than 50 or Phone is empty (NULL): 4 of the 7 rows match (Bhavya, Chirag, Eshan, Farah). SELECT then shows only the columns Name, Marks. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT * FROM STUDENT WHERE Section = 'B';
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
Explanation: WHERE keeps only the rows where Section is 'B': 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows all the columns (*).
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL commands for the following:
(i)
SELECT PName, Category FROM PRODUCT WHERE Category = 'Home' OR Category = 'Stationery';
| PName | Category |
|---|---|
| Notebook | Stationery |
| Geometry Box | Stationery |
| Water Bottle | Home |
| Lunch Box | Home |
Explanation: WHERE keeps only the rows where Category is 'Home' or Category is 'Stationery': 4 of the 7 rows match (Notebook, Geometry Box, Water Bottle, Lunch Box). SELECT then shows only the columns PName, Category.
(ii)
SELECT PName FROM PRODUCT WHERE Brand = 'Milton' AND Discount IS NOT NULL;
| PName |
|---|
| Lunch Box |
Explanation: WHERE keeps only the rows where Brand is 'Milton' and Discount has a value (is not NULL): 1 of the 7 rows matches (Lunch Box). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT * FROM PRODUCT WHERE Category = 'Stationery';
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
Explanation: WHERE keeps only the rows where Category is 'Stationery': 2 of the 7 rows match (Notebook, Geometry Box). SELECT then shows all the columns (*).
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL commands for the following:
(i)
SELECT BookID, Price, Price + 10 FROM BOOK;
| BookID | Price | Price + 10 |
|---|---|---|
| 201 | 210 | 220 |
| 202 | 180 | 190 |
| 203 | 299 | 309 |
| 204 | 350 | 360 |
| 205 | 190 | 200 |
| 206 | 250 | 260 |
| 207 | 400 | 410 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns BookID, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT BookID, Title, Price FROM BOOK WHERE Price BETWEEN 200 AND 250;
| BookID | Title | Price |
|---|---|---|
| 201 | Informatics Practices | 210 |
| 206 | The Story of My Experiments | 250 |
Explanation: WHERE keeps only the rows where Price is from 200 to 250 (both included): 2 of the 7 rows match (Informatics Practices, The Story of My Experiments). SELECT then shows only the columns BookID, Title, Price.
(iii)
SELECT Title, Subject FROM BOOK WHERE Subject = 'Computer' OR Subject = 'Science';
| Title | Subject |
|---|---|
| Informatics Practices | Computer |
| Physics Part 1 | Science |
| Python Basics | Computer |
| Chemistry Part 1 | Science |
| Learn SQL | Computer |
Explanation: WHERE keeps only the rows where Subject is 'Computer' or Subject is 'Science': 5 of the 7 rows match (Informatics Practices, Physics Part 1, Python Basics, Chemistry Part 1, Learn SQL). SELECT then shows only the columns Title, Subject.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL commands for the following:
(i)
SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';
| EName | DOJ |
|---|---|
| Ravi | 2018-06-01 |
| Seema | 2020-01-15 |
| Vikas | 2019-11-05 |
Explanation: WHERE keeps only the rows where DOJ is from '2018-01-01' to '2020-12-31' (both included): 3 of the 7 rows match (Ravi, Seema, Vikas). SELECT then shows only the columns EName, DOJ.
(iii)
SELECT EName, Salary FROM EMPLOYEE WHERE Salary < 40000 OR Bonus IS NULL;
| EName | Salary |
|---|---|
| Seema | 58000 |
| Usha | 36000 |
| Wasim | 39000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is less than 40000 or Bonus is empty (NULL): 4 of the 7 rows match (Seema, Usha, Wasim, Yamini). SELECT then shows only the columns EName, Salary. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL commands for the following:
(i)
SELECT Name FROM STUDENT WHERE Phone IS NULL;
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Phone is empty (NULL): 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
| Name | DOB |
|---|---|
| Bhavya | 2009-11-30 |
| Divya | 2009-07-21 |
| Farah | 2009-09-09 |
Explanation: WHERE keeps only the rows where DOB is from '2009-06-01' to '2009-12-31' (both included): 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, DOB.
(iii)
SELECT Name, Gender FROM STUDENT WHERE Gender <> 'F';
| Name | Gender |
|---|---|
| Aarav | M |
| Chirag | M |
| Eshan | M |
| Gaurav | M |
Explanation: WHERE keeps only the rows where Gender is not 'F': 4 of the 7 rows match (Aarav, Chirag, Eshan, Gaurav). SELECT then shows only the columns Name, Gender.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL commands for the following:
(i)
SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
| PName | Insurance |
|---|---|
| Mohan | LIC |
| Om | Star |
| Pooja | LIC |
| Sahil | Star |
Explanation: WHERE keeps only the rows where Insurance has a value (is not NULL): 4 of the 7 rows match (Mohan, Om, Pooja, Sahil). SELECT then shows only the columns PName, Insurance. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName, Fee FROM PATIENT WHERE Fee < 1500 OR Insurance IS NULL;
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Om | 1200 |
| Qasim | 9500 |
| Rekha | 4500 |
| Sahil | 900 |
Explanation: WHERE keeps only the rows where Fee is less than 1500 or Insurance is empty (NULL): 5 of the 7 rows match (Nisha, Om, Qasim, Rekha, Sahil). SELECT then shows only the columns PName, Fee. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT PName, Fee FROM PATIENT WHERE Fee > 1000;
| PName | Fee |
|---|---|
| Mohan | 1500 |
| Nisha | 8000 |
| Om | 1200 |
| Pooja | 5000 |
| Qasim | 9500 |
| Rekha | 4500 |
Explanation: WHERE keeps only the rows where Fee is more than 1000: 6 of the 7 rows match (Mohan, Nisha, Om, Pooja, Qasim, Rekha). SELECT then shows only the columns PName, Fee.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL commands for the following:
(i)
SELECT PName, Category FROM PRODUCT WHERE Category = 'Electronics' OR Category = 'Home';
| PName | Category |
|---|---|
| Pen Drive | Electronics |
| Mouse | Electronics |
| Water Bottle | Home |
| Earphones | Electronics |
| Lunch Box | Home |
Explanation: WHERE keeps only the rows where Category is 'Electronics' or Category is 'Home': 5 of the 7 rows match (Pen Drive, Mouse, Water Bottle, Earphones, Lunch Box). SELECT then shows only the columns PName, Category.
(ii)
SELECT PName, Price FROM PRODUCT WHERE Price > 100;
| PName | Price |
|---|---|
| Pen Drive | 450 |
| Geometry Box | 180 |
| Mouse | 650 |
| Water Bottle | 320 |
| Earphones | 899 |
| Lunch Box | 275 |
Explanation: WHERE keeps only the rows where Price is more than 100: 6 of the 7 rows match (Pen Drive, Geometry Box, Mouse, Water Bottle, Earphones, Lunch Box). SELECT then shows only the columns PName, Price.
(iii)
SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Electronics';
| PName | Category |
|---|---|
| Notebook | Stationery |
| Geometry Box | Stationery |
| Water Bottle | Home |
| Lunch Box | Home |
Explanation: WHERE keeps only the rows where Category is not 'Electronics': 4 of the 7 rows match (Notebook, Geometry Box, Water Bottle, Lunch Box). SELECT then shows only the columns PName, Category.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL commands for the following:
(i)
SELECT PName FROM PATIENT WHERE Insurance IS NULL;
| PName |
|---|
| Nisha |
| Qasim |
| Rekha |
Explanation: WHERE keeps only the rows where Insurance is empty (NULL): 3 of the 7 rows match (Nisha, Qasim, Rekha). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
| PName | AdmitDate |
|---|---|
| Nisha | 2026-09-05 |
| Om | 2026-09-10 |
| Pooja | 2026-09-12 |
| Qasim | 2026-09-15 |
Explanation: WHERE keeps only the rows where AdmitDate is from '2026-09-05' to '2026-09-15' (both included): 4 of the 7 rows match (Nisha, Om, Pooja, Qasim). SELECT then shows only the columns PName, AdmitDate.
(iii)
SELECT PName FROM PATIENT WHERE Ward = 'Maternity' AND Fee >= 6000;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Ward is 'Maternity' and Fee is at least 6000. No row satisfies this, so the result is an empty set.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL commands for the following:
(i)
SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';
| EName | DOJ |
|---|---|
| Ravi | 2018-06-01 |
| Seema | 2020-01-15 |
| Vikas | 2019-11-05 |
Explanation: WHERE keeps only the rows where DOJ is from '2018-01-01' to '2020-12-31' (both included): 3 of the 7 rows match (Ravi, Seema, Vikas). SELECT then shows only the columns EName, DOJ.
(ii)
SELECT EName, Bonus FROM EMPLOYEE WHERE Bonus IS NOT NULL;
| EName | Bonus |
|---|---|
| Ravi | 3000 |
| Tarun | 5000 |
| Vikas | 4000 |
| Wasim | 2000 |
Explanation: WHERE keeps only the rows where Bonus has a value (is not NULL): 4 of the 7 rows match (Ravi, Tarun, Vikas, Wasim). SELECT then shows only the columns EName, Bonus. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL commands for the following:
(i)
SELECT PName, Price FROM PRODUCT WHERE Price < 100 OR Discount IS NULL;
| PName | Price |
|---|---|
| Notebook | 60 |
| Pen Drive | 450 |
| Water Bottle | 320 |
Explanation: WHERE keeps only the rows where Price is less than 100 or Discount is empty (NULL): 3 of the 7 rows match (Notebook, Pen Drive, Water Bottle). SELECT then shows only the columns PName, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
| PName | Discount |
|---|---|
| Notebook | 5 |
| Geometry Box | 10 |
| Mouse | 15 |
| Earphones | 20 |
| Lunch Box | 8 |
Explanation: WHERE keeps only the rows where Discount has a value (is not NULL): 5 of the 7 rows match (Notebook, Geometry Box, Mouse, Earphones, Lunch Box). SELECT then shows only the columns PName, Discount. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT PName, Price FROM PRODUCT WHERE Price > 400;
| PName | Price |
|---|---|
| Pen Drive | 450 |
| Mouse | 650 |
| Earphones | 899 |
Explanation: WHERE keeps only the rows where Price is more than 400: 3 of the 7 rows match (Pen Drive, Mouse, Earphones). SELECT then shows only the columns PName, Price.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL commands for the following:
(i)
SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 60 AND 70;
| RollNo | Name | Marks |
|---|---|---|
| 4 | Divya | 66 |
Explanation: WHERE keeps only the rows where Marks is from 60 to 70 (both included): 1 of the 7 rows matches (Divya). SELECT then shows only the columns RollNo, Name, Marks.
(ii)
SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
| Name | Phone |
|---|---|
| Aarav | 9810011111 |
| Chirag | 9810033333 |
| Divya | 9810044444 |
| Farah | 9810066666 |
| Gaurav | 9810077777 |
Explanation: WHERE keeps only the rows where Phone has a value (is not NULL): 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Phone. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT Name FROM STUDENT WHERE Gender = 'M' AND Phone IS NOT NULL;
| Name |
|---|
| Aarav |
| Chirag |
| Gaurav |
Explanation: WHERE keeps only the rows where Gender is 'M' and Phone has a value (is not NULL): 3 of the 7 rows match (Aarav, Chirag, Gaurav). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL commands for the following:
(i)
UPDATE PATIENT SET Fee = Fee + 10 WHERE Ward = 'ICU';
2 rows changed.
Explanation: SET Fee = Fee + 10 changes the value; WHERE limits the change to the rows where Ward is 'ICU': 2 rows (Nisha, Qasim). Other rows are not changed.
(ii)
SELECT PName, Doctor FROM PATIENT WHERE Doctor <> 'Dr. Sen';
| PName | Doctor |
|---|---|
| Mohan | Dr. Rao |
| Om | Dr. Rao |
| Pooja | Dr. Iyer |
| Rekha | Dr. Iyer |
| Sahil | Dr. Rao |
Explanation: WHERE keeps only the rows where Doctor is not 'Dr. Sen': 5 of the 7 rows match (Mohan, Om, Pooja, Rekha, Sahil). SELECT then shows only the columns PName, Doctor.
(iii)
SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
| PName | AdmitDate |
|---|---|
| Nisha | 2026-09-05 |
| Om | 2026-09-10 |
| Pooja | 2026-09-12 |
| Qasim | 2026-09-15 |
Explanation: WHERE keeps only the rows where AdmitDate is from '2026-09-05' to '2026-09-15' (both included): 4 of the 7 rows match (Nisha, Om, Pooja, Qasim). SELECT then shows only the columns PName, AdmitDate.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL commands for the following:
(i)
SELECT RollNo, Marks, Marks + 10 FROM STUDENT;
| RollNo | Marks | Marks + 10 |
|---|---|---|
| 1 | 78 | 88 |
| 2 | 92 | 102 |
| 3 | 45 | 55 |
| 4 | 66 | 76 |
| 5 | 88 | 98 |
| 6 | 31 | 41 |
| 7 | 59 | 69 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns RollNo, Marks, Marks + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT Name, Gender FROM STUDENT WHERE Gender <> 'F';
| Name | Gender |
|---|---|
| Aarav | M |
| Chirag | M |
| Eshan | M |
| Gaurav | M |
Explanation: WHERE keeps only the rows where Gender is not 'F': 4 of the 7 rows match (Aarav, Chirag, Eshan, Gaurav). SELECT then shows only the columns Name, Gender.
(iii)
SELECT Name, Section FROM STUDENT WHERE NOT Section = 'B';
| Name | Section |
|---|---|
| Aarav | A |
| Chirag | A |
| Divya | C |
| Farah | A |
| Gaurav | C |
Explanation: WHERE keeps only the rows where Section is not 'B': 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Section.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL commands for the following:
(i)
SELECT PName FROM PRODUCT WHERE Brand = 'Milton' AND Discount IS NOT NULL;
| PName |
|---|
| Lunch Box |
Explanation: WHERE keeps only the rows where Brand is 'Milton' and Discount has a value (is not NULL): 1 of the 7 rows matches (Lunch Box). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName, Brand FROM PRODUCT WHERE Brand <> 'Milton';
| PName | Brand |
|---|---|
| Notebook | Classmate |
| Pen Drive | SanDisk |
| Geometry Box | Camlin |
| Mouse | Logitech |
| Earphones | Boat |
Explanation: WHERE keeps only the rows where Brand is not 'Milton': 5 of the 7 rows match (Notebook, Pen Drive, Geometry Box, Mouse, Earphones). SELECT then shows only the columns PName, Brand.
(iii)
SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Electronics';
| PName | Category |
|---|---|
| Notebook | Stationery |
| Geometry Box | Stationery |
| Water Bottle | Home |
| Lunch Box | Home |
Explanation: WHERE keeps only the rows where Category is not 'Electronics': 4 of the 7 rows match (Notebook, Geometry Box, Water Bottle, Lunch Box). SELECT then shows only the columns PName, Category.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL commands for the following:
(i)
SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 100 AND 500;
| PCode | PName | Price |
|---|---|---|
| P02 | Pen Drive | 450 |
| P03 | Geometry Box | 180 |
| P05 | Water Bottle | 320 |
| P07 | Lunch Box | 275 |
Explanation: WHERE keeps only the rows where Price is from 100 to 500 (both included): 4 of the 7 rows match (Pen Drive, Geometry Box, Water Bottle, Lunch Box). SELECT then shows only the columns PCode, PName, Price.
(ii)
SELECT PName, Price FROM PRODUCT WHERE Price < 100 OR Discount IS NULL;
| PName | Price |
|---|---|
| Notebook | 60 |
| Pen Drive | 450 |
| Water Bottle | 320 |
Explanation: WHERE keeps only the rows where Price is less than 100 or Discount is empty (NULL): 3 of the 7 rows match (Notebook, Pen Drive, Water Bottle). SELECT then shows only the columns PName, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT PName FROM PRODUCT WHERE Discount IS NULL;
| PName |
|---|
| Pen Drive |
| Water Bottle |
Explanation: WHERE keeps only the rows where Discount is empty (NULL): 2 of the 7 rows match (Pen Drive, Water Bottle). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL commands for the following:
(i)
SELECT Title FROM BOOK WHERE Subject = 'Biography' AND Price >= 250;
| Title |
|---|
| Wings of Fire |
| The Story of My Experiments |
Explanation: WHERE keeps only the rows where Subject is 'Biography' and Price is at least 250: 2 of the 7 rows match (Wings of Fire, The Story of My Experiments). SELECT then shows only the column Title.
(ii)
SELECT Title, Price FROM BOOK WHERE Price > 250;
| Title | Price |
|---|---|
| Wings of Fire | 299 |
| Python Basics | 350 |
| Learn SQL | 400 |
Explanation: WHERE keeps only the rows where Price is more than 250: 3 of the 7 rows match (Wings of Fire, Python Basics, Learn SQL). SELECT then shows only the columns Title, Price.
(iii)
SELECT Title, Subject FROM BOOK WHERE Subject = 'Biography' OR Subject = 'Science';
| Title | Subject |
|---|---|
| Physics Part 1 | Science |
| Wings of Fire | Biography |
| Chemistry Part 1 | Science |
| The Story of My Experiments | Biography |
Explanation: WHERE keeps only the rows where Subject is 'Biography' or Subject is 'Science': 4 of the 7 rows match (Physics Part 1, Wings of Fire, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Subject.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL commands for the following:
(i)
SELECT PName, Price FROM PRODUCT WHERE Price < 100 OR Discount IS NULL;
| PName | Price |
|---|---|
| Notebook | 60 |
| Pen Drive | 450 |
| Water Bottle | 320 |
Explanation: WHERE keeps only the rows where Price is less than 100 or Discount is empty (NULL): 3 of the 7 rows match (Notebook, Pen Drive, Water Bottle). SELECT then shows only the columns PName, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
| PName | Discount |
|---|---|
| Notebook | 5 |
| Geometry Box | 10 |
| Mouse | 15 |
| Earphones | 20 |
| Lunch Box | 8 |
Explanation: WHERE keeps only the rows where Discount has a value (is not NULL): 5 of the 7 rows match (Notebook, Geometry Box, Mouse, Earphones, Lunch Box). SELECT then shows only the columns PName, Discount. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT PName FROM PRODUCT WHERE Brand = 'Camlin' AND Discount IS NOT NULL;
| PName |
|---|
| Geometry Box |
Explanation: WHERE keeps only the rows where Brand is 'Camlin' and Discount has a value (is not NULL): 1 of the 7 rows matches (Geometry Box). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
Write SQL commands for the following:
(i)
SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 50000;
| EName | Salary |
|---|---|
| Seema | 58000 |
| Tarun | 75000 |
| Vikas | 64000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is more than 50000: 4 of the 7 rows match (Seema, Tarun, Vikas, Yamini). SELECT then shows only the columns EName, Salary.
(ii)
SELECT EName, Bonus FROM EMPLOYEE WHERE Bonus IS NOT NULL;
| EName | Bonus |
|---|---|
| Ravi | 3000 |
| Tarun | 5000 |
| Vikas | 4000 |
| Wasim | 2000 |
Explanation: WHERE keeps only the rows where Bonus has a value (is not NULL): 4 of the 7 rows match (Ravi, Tarun, Vikas, Wasim). SELECT then shows only the columns EName, Bonus. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT EName FROM EMPLOYEE WHERE Dept = 'Sales' AND Salary >= 50000;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Dept is 'Sales' and Salary is at least 50000. No row satisfies this, so the result is an empty set.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL commands for the following:
(i)
SELECT Name FROM STUDENT WHERE Gender = 'F' AND Phone IS NOT NULL;
| Name |
|---|
| Divya |
| Farah |
Explanation: WHERE keeps only the rows where Gender is 'F' and Phone has a value (is not NULL): 2 of the 7 rows match (Divya, Farah). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT Name, Section FROM STUDENT WHERE NOT Section = 'A';
| Name | Section |
|---|---|
| Bhavya | B |
| Divya | C |
| Eshan | B |
| Gaurav | C |
Explanation: WHERE keeps only the rows where Section is not 'A': 4 of the 7 rows match (Bhavya, Divya, Eshan, Gaurav). SELECT then shows only the columns Name, Section.
(iii)
SELECT Name, Marks FROM STUDENT WHERE Marks < 50 OR Phone IS NULL;
| Name | Marks |
|---|---|
| Bhavya | 92 |
| Chirag | 45 |
| Eshan | 88 |
| Farah | 31 |
Explanation: WHERE keeps only the rows where Marks is less than 50 or Phone is empty (NULL): 4 of the 7 rows match (Bhavya, Chirag, Eshan, Farah). SELECT then shows only the columns Name, Marks. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL commands for the following:
(i)
SELECT PName FROM PATIENT WHERE Ward = 'Maternity' AND Fee >= 1000;
| PName |
|---|
| Pooja |
| Rekha |
Explanation: WHERE keeps only the rows where Ward is 'Maternity' and Fee is at least 1000: 2 of the 7 rows match (Pooja, Rekha). SELECT then shows only the column PName.
(ii)
SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
| PName | Insurance |
|---|---|
| Mohan | LIC |
| Om | Star |
| Pooja | LIC |
| Sahil | Star |
Explanation: WHERE keeps only the rows where Insurance has a value (is not NULL): 4 of the 7 rows match (Mohan, Om, Pooja, Sahil). SELECT then shows only the columns PName, Insurance. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
SELECT PName FROM PATIENT WHERE Insurance IS NULL;
| PName |
|---|
| Nisha |
| Qasim |
| Rekha |
Explanation: WHERE keeps only the rows where Insurance is empty (NULL): 3 of the 7 rows match (Nisha, Qasim, Rekha). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Write SQL commands for the following:
(i)
SELECT PName, Doctor FROM PATIENT WHERE Doctor <> 'Dr. Iyer';
| PName | Doctor |
|---|---|
| Mohan | Dr. Rao |
| Nisha | Dr. Sen |
| Om | Dr. Rao |
| Qasim | Dr. Sen |
| Sahil | Dr. Rao |
Explanation: WHERE keeps only the rows where Doctor is not 'Dr. Iyer': 5 of the 7 rows match (Mohan, Nisha, Om, Qasim, Sahil). SELECT then shows only the columns PName, Doctor.
(ii)
SELECT PName FROM PATIENT WHERE Ward = 'Maternity' AND Fee >= 6000;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Ward is 'Maternity' and Fee is at least 6000. No row satisfies this, so the result is an empty set.
(iii)
SELECT PName, Fee FROM PATIENT WHERE Fee > 6000;
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Qasim | 9500 |
Explanation: WHERE keeps only the rows where Fee is more than 6000: 2 of the 7 rows match (Nisha, Qasim). SELECT then shows only the columns PName, Fee.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL commands for the following:
(i)
SELECT BookID, Price, Price + 10 FROM BOOK;
| BookID | Price | Price + 10 |
|---|---|---|
| 201 | 210 | 220 |
| 202 | 180 | 190 |
| 203 | 299 | 309 |
| 204 | 350 | 360 |
| 205 | 190 | 200 |
| 206 | 250 | 260 |
| 207 | 400 | 410 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns BookID, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
(ii)
SELECT BookID, Title, Price FROM BOOK WHERE Price BETWEEN 300 AND 350;
| BookID | Title | Price |
|---|---|---|
| 204 | Python Basics | 350 |
Explanation: WHERE keeps only the rows where Price is from 300 to 350 (both included): 1 of the 7 rows matches (Python Basics). SELECT then shows only the columns BookID, Title, Price.
(iii)
SELECT Title FROM BOOK WHERE Publisher = 'Penguin' AND Member IS NOT NULL;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Publisher is 'Penguin' and Member has a value (is not NULL). No row satisfies this, so the result is an empty set. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL commands for the following:
(i)
SELECT PName FROM PRODUCT WHERE Category = 'Home' AND Price >= 300;
| PName |
|---|
| Water Bottle |
Explanation: WHERE keeps only the rows where Category is 'Home' and Price is at least 300: 1 of the 7 rows matches (Water Bottle). SELECT then shows only the column PName.
(ii)
UPDATE PRODUCT SET Price = Price + 10 WHERE Category = 'Electronics';
3 rows changed.
Explanation: SET Price = Price + 10 changes the value; WHERE limits the change to the rows where Category is 'Electronics': 3 rows (Pen Drive, Mouse, Earphones). Other rows are not changed.
(iii)
SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 300 AND 500;
| PCode | PName | Price |
|---|---|---|
| P02 | Pen Drive | 450 |
| P05 | Water Bottle | 320 |
Explanation: WHERE keeps only the rows where Price is from 300 to 500 (both included): 2 of the 7 rows match (Pen Drive, Water Bottle). SELECT then shows only the columns PCode, PName, Price.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Write SQL commands for the following:
(i)
SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 50 AND 70;
| RollNo | Name | Marks |
|---|---|---|
| 4 | Divya | 66 |
| 7 | Gaurav | 59 |
Explanation: WHERE keeps only the rows where Marks is from 50 to 70 (both included): 2 of the 7 rows match (Divya, Gaurav). SELECT then shows only the columns RollNo, Name, Marks.
(ii)
SELECT Name, Marks FROM STUDENT WHERE Marks > 70;
| Name | Marks |
|---|---|
| Aarav | 78 |
| Bhavya | 92 |
| Eshan | 88 |
Explanation: WHERE keeps only the rows where Marks is more than 70: 3 of the 7 rows match (Aarav, Bhavya, Eshan). SELECT then shows only the columns Name, Marks.
(iii)
UPDATE STUDENT SET Marks = Marks + 10 WHERE Section = 'B';
2 rows changed.
Explanation: SET Marks = Marks + 10 changes the value; WHERE limits the change to the rows where Section is 'B': 2 rows (Bhavya, Eshan). Other rows are not changed.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Write SQL commands for the following:
(i)
SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'BPB';
| Title | Publisher |
|---|---|
| Informatics Practices | NCERT |
| Physics Part 1 | NCERT |
| Wings of Fire | Universities |
| Chemistry Part 1 | NCERT |
| The Story of My Experiments | Penguin |
Explanation: WHERE keeps only the rows where Publisher is not 'BPB': 5 of the 7 rows match (Informatics Practices, Physics Part 1, Wings of Fire, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Publisher.
(ii)
SELECT Title FROM BOOK WHERE Subject = 'Computer' AND Price >= 300;
| Title |
|---|
| Python Basics |
| Learn SQL |
Explanation: WHERE keeps only the rows where Subject is 'Computer' and Price is at least 300: 2 of the 7 rows match (Python Basics, Learn SQL). SELECT then shows only the column Title.
(iii)
SELECT Title, Subject FROM BOOK WHERE Subject = 'Computer' OR Subject = 'Science';
| Title | Subject |
|---|---|
| Informatics Practices | Computer |
| Physics Part 1 | Science |
| Python Basics | Computer |
| Chemistry Part 1 | Science |
| Learn SQL | Computer |
Explanation: WHERE keeps only the rows where Subject is 'Computer' or Subject is 'Science': 5 of the 7 rows match (Informatics Practices, Physics Part 1, Python Basics, Chemistry Part 1, Learn SQL). SELECT then shows only the columns Title, Subject.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Write SQL commands for the following:
(i)
SELECT PName, Price FROM PRODUCT WHERE Price < 100 OR Discount IS NULL;
| PName | Price |
|---|---|
| Notebook | 60 |
| Pen Drive | 450 |
| Water Bottle | 320 |
Explanation: WHERE keeps only the rows where Price is less than 100 or Discount is empty (NULL): 3 of the 7 rows match (Notebook, Pen Drive, Water Bottle). SELECT then shows only the columns PName, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
SELECT PName, MfgDate FROM PRODUCT WHERE MfgDate BETWEEN '2025-10-01' AND '2026-01-31';
| PName | MfgDate |
|---|---|
| Notebook | 2026-01-10 |
| Geometry Box | 2025-11-02 |
| Lunch Box | 2025-12-18 |
Explanation: WHERE keeps only the rows where MfgDate is from '2025-10-01' to '2026-01-31' (both included): 3 of the 7 rows match (Notebook, Geometry Box, Lunch Box). SELECT then shows only the columns PName, MfgDate.
(iii)
SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
| PName | Discount |
|---|---|
| Notebook | 5 |
| Geometry Box | 10 |
| Mouse | 15 |
| Earphones | 20 |
| Lunch Box | 8 |
Explanation: WHERE keeps only the rows where Discount has a value (is not NULL): 5 of the 7 rows match (Notebook, Geometry Box, Mouse, Earphones, Lunch Box). SELECT then shows only the columns PName, Discount. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Observe the table STUDENT and answer.
Table: STUDENT
| RollNo | AdmNo | Name | Section | DOB | Marks | Phone |
|---|---|---|---|---|---|---|
| 6 | 4556 | Farah | A | 2009-09-09 | 31 | 9810066666 |
| 2 | 4512 | Bhavya | B | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | 2010-01-05 | 45 | 9810033333 |
| 7 | 4567 | Gaurav | C | 2010-02-28 | 59 | 9810077777 |
Observe the table EMPLOYEE and answer.
Table: EMPLOYEE
| EmpID | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|
| E103 | tarun@co.in | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E105 | vikas@co.in | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E101 | ravi@co.in | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E104 | usha@co.in | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
Observe the table PRODUCT and answer.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price |
|---|---|---|---|---|---|---|
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 |
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 |
Observe the table BOOK and answer.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Member |
|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | Karan |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | NULL |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | NULL |
Observe the table PATIENT and answer.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Insurance |
|---|---|---|---|---|---|---|
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | LIC |
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | LIC |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | NULL |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | Star |
Observe the table STUDENT and answer.
Table: STUDENT
| RollNo | AdmNo | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|
| 4 | 4534 | C | F | 2009-07-21 | 66 | 9810044444 |
| 2 | 4512 | B | F | 2009-11-30 | 92 | NULL |
| 7 | 4567 | C | M | 2010-02-28 | 59 | 9810077777 |
| 5 | 4545 | B | M | 2010-03-17 | 88 | NULL |
Observe the table EMPLOYEE and answer.
Table: EMPLOYEE
| EmpID | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|
| E106 | wasim@co.in | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E105 | vikas@co.in | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E102 | seema@co.in | HR | Pune | 2020-01-15 | 58000 | NULL |
| E104 | usha@co.in | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E103 | tarun@co.in | IT | Delhi | 2016-09-20 | 75000 | 5000 |
Observe the table PRODUCT and answer.
Table: PRODUCT
| PCode | Barcode | PName | Category | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|
| P07 | 89010077 | Lunch Box | Home | 2025-12-18 | 275 | 8 |
| P02 | 89010022 | Pen Drive | Electronics | 2025-08-15 | 450 | NULL |
| P04 | 89010044 | Mouse | Electronics | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | 2025-05-30 | 320 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | 2025-11-02 | 180 | 10 |
Observe the table BOOK and answer.
Table: BOOK
| BookID | ISBN | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|
| 202 | 9789352920112 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 201 | 9789352921485 | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 206 | 9780140449136 | Biography | Penguin | 2026-05-30 | 250 | NULL |
Observe the table PATIENT and answer.
Table: PATIENT
| PID | Aadhaar | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|
| 12 | 223422342234 | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 15 | 523452345234 | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 11 | 123412341234 | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
Observe the table STUDENT and answer.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Phone |
|---|---|---|---|---|---|---|
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 9810033333 |
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 9810011111 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 9810077777 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 9810044444 |
Observe the table EMPLOYEE and answer.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Bonus | |
|---|---|---|---|---|---|---|
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | NULL |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 5000 |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 4000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | NULL |
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 3000 |
Observe the table PRODUCT and answer.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price |
|---|---|---|---|---|---|---|
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 |
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 |
Observe the table BOOK and answer.
Table: BOOK
| BookID | ISBN | Title | Subject | IssueDate | Price | Member |
|---|---|---|---|---|---|---|
| 206 | 9780140449136 | The Story of My Experiments | Biography | 2026-05-30 | 250 | NULL |
| 201 | 9789352921485 | Informatics Practices | Computer | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | 2026-07-10 | 180 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | 2026-08-12 | 400 | Karan |
| 203 | 9780143032311 | Wings of Fire | Biography | 2026-06-21 | 299 | Ravi |
| 205 | 9789352925032 | Chemistry Part 1 | Science | 2026-07-15 | 190 | Neha |
Observe the table PATIENT and answer.
Table: PATIENT
| PID | Aadhaar | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|
| 14 | 423442344234 | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 11 | 123412341234 | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 15 | 523452345234 | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
Observe the table STUDENT and answer.
Table: STUDENT
| RollNo | AdmNo | Name | Section | DOB | Marks | Phone |
|---|---|---|---|---|---|---|
| 7 | 4567 | Gaurav | C | 2010-02-28 | 59 | 9810077777 |
| 5 | 4545 | Eshan | B | 2010-03-17 | 88 | NULL |
| 4 | 4534 | Divya | C | 2009-07-21 | 66 | 9810044444 |
| 3 | 4523 | Chirag | A | 2010-01-05 | 45 | 9810033333 |
| 2 | 4512 | Bhavya | B | 2009-11-30 | 92 | NULL |
| 1 | 4501 | Aarav | A | 2009-04-12 | 78 | 9810011111 |
Observe the table EMPLOYEE and answer.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Bonus | |
|---|---|---|---|---|---|---|
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 5000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 4000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | NULL |
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 3000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 2000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | NULL |
Observe the table PRODUCT and answer.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | Price | Discount |
|---|---|---|---|---|---|---|
| P05 | 89010055 | Water Bottle | Home | Milton | 320 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 180 | 10 |
| P07 | 89010077 | Lunch Box | Home | Milton | 275 | 8 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 650 | 15 |
| P01 | 89010011 | Notebook | Stationery | Classmate | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 450 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 899 | 20 |
Observe the table BOOK and answer.
Table: BOOK
| BookID | ISBN | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|
| 205 | 9789352925032 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 202 | 9789352920112 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 201 | 9789352921485 | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 203 | 9780143032311 | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Computer | BPB | 2026-08-01 | 350 | NULL |
Observe the table PATIENT and answer.
Table: PATIENT
| PID | Aadhaar | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|
| 17 | 723472347234 | General | Dr. Rao | 2026-09-20 | 900 | Star |
| 11 | 123412341234 | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 13 | 323432343234 | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 12 | 223422342234 | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 16 | 623462346234 | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 15 | 523452345234 | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
Observe the table STUDENT and answer.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks |
|---|---|---|---|---|---|---|
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 |
Observe the table EMPLOYEE and answer.
Table: EMPLOYEE
| EmpID | EName | Dept | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | 2018-06-01 | 42000 | 3000 |
| E106 | wasim@co.in | Wasim | HR | 2022-07-25 | 39000 | 2000 |
| E103 | tarun@co.in | Tarun | IT | 2016-09-20 | 75000 | 5000 |
| E102 | seema@co.in | Seema | HR | 2020-01-15 | 58000 | NULL |
| E107 | yamini@co.in | Yamini | IT | 2017-12-12 | 81000 | NULL |
| E104 | usha@co.in | Usha | Sales | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | 2019-11-05 | 64000 | 4000 |
Observe the table PRODUCT and answer.
Table: PRODUCT
| PCode | Barcode | PName | Category | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|
| P03 | 89010033 | Geometry Box | Stationery | 2025-11-02 | 180 | 10 |
| P06 | 89010066 | Earphones | Electronics | 2026-03-05 | 899 | 20 |
| P02 | 89010022 | Pen Drive | Electronics | 2025-08-15 | 450 | NULL |
| P05 | 89010055 | Water Bottle | Home | 2025-05-30 | 320 | NULL |
| P07 | 89010077 | Lunch Box | Home | 2025-12-18 | 275 | 8 |
Observe the table BOOK and answer.
Table: BOOK
| BookID | ISBN | Title | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|
| 206 | 9780140449136 | The Story of My Experiments | Penguin | 2026-05-30 | 250 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | NCERT | 2026-07-15 | 190 | Neha |
| 202 | 9789352920112 | Physics Part 1 | NCERT | 2026-07-10 | 180 | NULL |
| 201 | 9789352921485 | Informatics Practices | NCERT | 2026-07-03 | 210 | Asha |
| 204 | 9789386551009 | Python Basics | BPB | 2026-08-01 | 350 | NULL |
Observe the table PATIENT and answer.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee |
|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 |
Observe the table STUDENT and answer.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks |
|---|---|---|---|---|---|---|
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 |
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 |
Observe the table EMPLOYEE and answer.
Table: EMPLOYEE
| EmpID | EName | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|
| E106 | wasim@co.in | Wasim | Delhi | 2022-07-25 | 39000 | 2000 |
| E104 | usha@co.in | Usha | Mumbai | 2021-03-10 | 36000 | NULL |
| E101 | ravi@co.in | Ravi | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | Delhi | 2016-09-20 | 75000 | 5000 |
| E105 | vikas@co.in | Vikas | Pune | 2019-11-05 | 64000 | 4000 |
| E107 | yamini@co.in | Yamini | Mumbai | 2017-12-12 | 81000 | NULL |
Observe the table PRODUCT and answer.
Table: PRODUCT
| PCode | Barcode | PName | Category | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | 2026-01-10 | 60 | 5 |
| P04 | 89010044 | Mouse | Electronics | 2026-02-20 | 650 | 15 |
| P02 | 89010022 | Pen Drive | Electronics | 2025-08-15 | 450 | NULL |
| P06 | 89010066 | Earphones | Electronics | 2026-03-05 | 899 | 20 |
Observe the table BOOK and answer.
Table: BOOK
| BookID | ISBN | Title | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|
| 205 | 9789352925032 | Chemistry Part 1 | NCERT | 2026-07-15 | 190 | Neha |
| 202 | 9789352920112 | Physics Part 1 | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | BPB | 2026-08-01 | 350 | NULL |
| 201 | 9789352921485 | Informatics Practices | NCERT | 2026-07-03 | 210 | Asha |
Observe the table PATIENT and answer.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | Fee | Insurance |
|---|---|---|---|---|---|---|
| 17 | 723472347234 | Sahil | General | Dr. Rao | 900 | Star |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 4500 | NULL |
| 11 | 123412341234 | Mohan | General | Dr. Rao | 1500 | LIC |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 5000 | LIC |
Observe the table STUDENT and answer.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | Marks | Phone |
|---|---|---|---|---|---|---|
| 7 | 4567 | Gaurav | C | M | 59 | 9810077777 |
| 4 | 4534 | Divya | C | F | 66 | 9810044444 |
| 3 | 4523 | Chirag | A | M | 45 | 9810033333 |
| 6 | 4556 | Farah | A | F | 31 | 9810066666 |
| 2 | 4512 | Bhavya | B | F | 92 | NULL |
Observe the table EMPLOYEE and answer.
Table: EMPLOYEE
| EmpID | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|
| E102 | seema@co.in | HR | Pune | 2020-01-15 | 58000 | NULL |
| E106 | wasim@co.in | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | IT | Mumbai | 2017-12-12 | 81000 | NULL |
| E101 | ravi@co.in | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
Observe the table PRODUCT and answer.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | Price | Discount |
|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 60 | 5 |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 650 | 15 |
| P07 | 89010077 | Lunch Box | Home | Milton | 275 | 8 |
| P06 | 89010066 | Earphones | Electronics | Boat | 899 | 20 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 450 | NULL |
Observe the table BOOK and answer.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price |
|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 |
Observe the table PATIENT and answer.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Insurance |
|---|---|---|---|---|---|---|
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | NULL |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | NULL |
Observe the table STUDENT and answer.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks |
|---|---|---|---|---|---|---|
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 |
Observe the table EMPLOYEE and answer.
Table: EMPLOYEE
| EmpID | EName | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|
| E102 | seema@co.in | Seema | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | Pune | 2019-11-05 | 64000 | 4000 |
Observe the table PRODUCT and answer.
Table: PRODUCT
| PCode | Barcode | PName | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|
| P02 | 89010022 | Pen Drive | SanDisk | 2025-08-15 | 450 | NULL |
| P06 | 89010066 | Earphones | Boat | 2026-03-05 | 899 | 20 |
| P01 | 89010011 | Notebook | Classmate | 2026-01-10 | 60 | 5 |
| P03 | 89010033 | Geometry Box | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Milton | 2025-05-30 | 320 | NULL |
Observe the table BOOK and answer.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price |
|---|---|---|---|---|---|---|
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 |
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 |
Observe the table PATIENT and answer.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Insurance |
|---|---|---|---|---|---|---|
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | NULL |
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | LIC |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | NULL |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | Star |
Observe the table STUDENT and answer.
Table: STUDENT
| RollNo | AdmNo | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|
| 4 | 4534 | C | F | 2009-07-21 | 66 | 9810044444 |
| 2 | 4512 | B | F | 2009-11-30 | 92 | NULL |
| 7 | 4567 | C | M | 2010-02-28 | 59 | 9810077777 |
| 6 | 4556 | A | F | 2009-09-09 | 31 | 9810066666 |
| 1 | 4501 | A | M | 2009-04-12 | 78 | 9810011111 |
| 3 | 4523 | A | M | 2010-01-05 | 45 | 9810033333 |
| 5 | 4545 | B | M | 2010-03-17 | 88 | NULL |
Observe the table EMPLOYEE and answer.
Table: EMPLOYEE
| EmpID | EName | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|
| E105 | vikas@co.in | Vikas | Pune | 2019-11-05 | 64000 | 4000 |
| E107 | yamini@co.in | Yamini | Mumbai | 2017-12-12 | 81000 | NULL |
| E104 | usha@co.in | Usha | Mumbai | 2021-03-10 | 36000 | NULL |
| E101 | ravi@co.in | Ravi | Delhi | 2018-06-01 | 42000 | 3000 |
| E106 | wasim@co.in | Wasim | Delhi | 2022-07-25 | 39000 | 2000 |
| E103 | tarun@co.in | Tarun | Delhi | 2016-09-20 | 75000 | 5000 |
| E102 | seema@co.in | Seema | Pune | 2020-01-15 | 58000 | NULL |
Observe the table PRODUCT and answer.
Table: PRODUCT
| PCode | Barcode | PName | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|
| P07 | 89010077 | Lunch Box | Milton | 2025-12-18 | 275 | 8 |
| P01 | 89010011 | Notebook | Classmate | 2026-01-10 | 60 | 5 |
| P03 | 89010033 | Geometry Box | Camlin | 2025-11-02 | 180 | 10 |
| P06 | 89010066 | Earphones | Boat | 2026-03-05 | 899 | 20 |
| P02 | 89010022 | Pen Drive | SanDisk | 2025-08-15 | 450 | NULL |
| P05 | 89010055 | Water Bottle | Milton | 2025-05-30 | 320 | NULL |
Observe the table BOOK and answer.
Table: BOOK
| BookID | ISBN | Title | Subject | IssueDate | Price | Member |
|---|---|---|---|---|---|---|
| 203 | 9780143032311 | Wings of Fire | Biography | 2026-06-21 | 299 | Ravi |
| 202 | 9789352920112 | Physics Part 1 | Science | 2026-07-10 | 180 | NULL |
| 206 | 9780140449136 | The Story of My Experiments | Biography | 2026-05-30 | 250 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | 2026-07-15 | 190 | Neha |
| 204 | 9789386551009 | Python Basics | Computer | 2026-08-01 | 350 | NULL |
Observe the table PATIENT and answer.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | Fee | Insurance |
|---|---|---|---|---|---|---|
| 17 | 723472347234 | Sahil | General | Dr. Rao | 900 | Star |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 9500 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 5000 | LIC |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 4500 | NULL |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 8000 | NULL |
A school buys new computers for its lab. Each has 8 GB RAM, a 512 GB SSD, a keyboard, a mouse, a webcam and a monitor. The lab also has a printer and a scanner.
Riya deleted some project files from her laptop and also emptied the Recycle Bin. Later she needs them. She is also planning to sell her old phone.
A railway company uses reservation software made only for it, runs it on Linux servers, uses an antivirus, and its staff write letters in a word processor.
The history of computing goes from the abacus and Pascaline to Babbage's Analytical Engine, then ENIAC, and today's laptops and smartphones.
A hospital wants a computer system: doctors type patient details, X-ray images are stored for years, reports are printed, and a large screen shows the queue.
Aman's computer is slow. It has 4 GB RAM and a nearly full 1 TB hard disk. He wants to make it faster.
A company is choosing software: an operating system, an office suite and a payroll system made by a local firm only for it.
A computer runs a Python program. The program and data are first in the SSD, then loaded, and the CPU processes them before the result is shown.
A pen drive of 32 GB has 12,000 photos of 2 MB each.
In a bank, cheques are read by a machine, customers' fingerprints are scanned, and passbooks are printed.
A student lists: registers, RAM, ROM, cache, hard disk, pen drive, cloud storage.
Your school is replacing old CRT monitors and printers.
Answer the following about a computer lab.
Answer the following about a computer lab.
Answer the following about a computer lab.
Answer the following about a computer lab.
Answer the following about a computer lab.
Answer the following about a computer lab.
Answer the following about a computer lab.
Answer the following about a computer lab.
Answer the following about a computer lab.
Answer the following about a computer lab.
Write a program to find the largest and the smallest numbers in a list.
L = eval(input('Enter a list: '))
print('Largest =', max(L))
print('Smallest =', min(L))Sample run
Enter a list: [45, 12, 78, 3, 56] Largest = 78 Smallest = 3
Write a program to find the third largest and the third smallest numbers in a list.
L = eval(input('Enter a list: '))
L.sort()
print('Third smallest =', L[2])
print('Third largest =', L[-3])Sample run
Enter a list: [34, 7, 91, 15, 62, 48, 23] Third smallest = 23 Third largest = 48
Write a program to find the third largest and the third smallest numbers in a list without sort().
L = eval(input('Enter a list: '))
A = L.copy()
for i in range(2):
A.remove(max(A))
B = L.copy()
for i in range(2):
B.remove(min(B))
print('Third largest =', max(A))
print('Third smallest =', min(B))Sample run
Enter a list: [34, 7, 91, 15, 62, 48, 23] Third largest = 48 Third smallest = 23
Write a program to create a list of n numbers entered by the user and print their sum and average.
n = int(input('How many numbers? '))
L = []
for i in range(n):
L.append(int(input('Number: ')))
print(L)
print('Sum =', sum(L), 'Average =', sum(L) / n)Sample run
How many numbers? 4 Number: 25 Number: 40 Number: 15 Number: 60 [25, 40, 15, 60] Sum = 140 Average = 35.0
Write a program to search for a number in a list and print its position (index) or 'Not found'.
L = eval(input('Enter a list: '))
x = int(input('Search: '))
if x in L:
print('Found at index', L.index(x))
else:
print('Not found')Sample run
Enter a list: [12, 45, 7, 30, 18] Search: 30 Found at index 3
Write a program to count the even and the odd numbers in a list.
L = eval(input('Enter a list: '))
e = o = 0
for x in L:
if x % 2 == 0:
e += 1
else:
o += 1
print('Even:', e, 'Odd:', o)Sample run
Enter a list: [3, 8, 15, 22, 7, 10] Even: 3 Odd: 3
Write a program to make a new list with only the numbers greater than 50 from a given list.
L = eval(input('Enter a list: '))
N = []
for x in L:
if x > 50:
N.append(x)
print(N)Sample run
Enter a list: [45, 67, 12, 89, 50, 73] [67, 89, 73]
Write a program to remove all the occurrences of a number from a list.
L = eval(input('Enter a list: '))
x = int(input('Number to remove: '))
while x in L:
L.remove(x)
print(L)Sample run
Enter a list: [5, 9, 5, 2, 5, 7] Number to remove: 5 [9, 2, 7]
Write a program to create a dictionary of states and their capitals, and print the capital of a state given by the user.
D = {'Rajasthan': 'Jaipur', 'Kerala': 'Thiruvananthapuram', 'Bihar': 'Patna', 'Punjab': 'Chandigarh'}
s = input('State: ')
if s in D:
print('Capital:', D[s])
else:
print('Not in the dictionary')Sample run
State: Kerala Capital: Thiruvananthapuram
Write a program to store the names and marks of students in a dictionary and print the highest and the lowest marks with the names.
D = eval(input('Enter dictionary: '))
hi = lo = None
for k in D:
if hi is None or D[k] > D[hi]:
hi = k
if lo is None or D[k] < D[lo]:
lo = k
print('Highest:', hi, D[hi])
print('Lowest:', lo, D[lo])Sample run
Enter dictionary: {'Anu': 78, 'Ben': 92, 'Charu': 64, 'Dev': 85}
Highest: Ben 92
Lowest: Charu 64Write a program to count the frequency of each element of a list using a dictionary.
L = eval(input('Enter a list: '))
F = {}
for x in L:
if x in F:
F[x] = F[x] + 1
else:
F[x] = 1
print(F)Sample run
Enter a list: [2, 5, 2, 8, 5, 2]
{2: 3, 5: 2, 8: 1}Write a program to create a NumPy array from a list of marks and print the marks increased by 5, and the number of elements.
import numpy as np
L = eval(input('Enter marks: '))
a = np.array(L)
print(a + 5)
print('Number of marks =', a.size)Sample run
Enter marks: [56, 72, 81, 64] [61 77 86 69] Number of marks = 4
Write a program to create a 2-D NumPy array from a nested list and print its shape, number of dimensions and number of elements.
import numpy as np
L = eval(input('Enter a nested list: '))
a = np.array(L)
print(a)
print('Shape:', a.shape)
print('Dimensions:', a.ndim)
print('Elements:', a.size)Sample run
Enter a nested list: [[1, 2, 3], [4, 5, 6]] [[1 2 3] [4 5 6]] Shape: (2, 3) Dimensions: 2 Elements: 6
Write a program to update the price of an item in a dictionary of items and prices, and then delete one item.
D = {'pen': 20, 'book': 120, 'bag': 650}
k = input('Item to update: ')
D[k] = int(input('New price: '))
d = input('Item to delete: ')
del D[d]
print(D)Sample run
Item to update: book
New price: 135
Item to delete: pen
{'book': 135, 'bag': 650}Write a program to print the keys, the values and the items of a dictionary of fruits and their prices, and the total price.
D = {'apple': 120, 'mango': 90, 'banana': 50}
print(list(D.keys()))
print(list(D.values()))
print(list(D.items()))
print('Total =', sum(D.values()))Sample run
['apple', 'mango', 'banana']
[120, 90, 50]
[('apple', 120), ('mango', 90), ('banana', 50)]
Total = 260Write a program to input a list and print it in reverse order without reverse().
L = eval(input('Enter a list: '))
for i in range(len(L) - 1, -1, -1):
print(L[i], end=' ')Sample run
Enter a list: [10, 20, 30, 40] 40 30 20 10
Write a program to find the sum of the numbers at even positions (indices) of a list.
L = eval(input('Enter a list: '))
s = 0
for i in range(0, len(L), 2):
s = s + L[i]
print('Sum =', s)Sample run
Enter a list: [5, 9, 12, 4, 8, 3] Sum = 25
Write a program to insert an element at a given position in a list and then sort the list.
L = eval(input('Enter a list: '))
x = int(input('Element: '))
p = int(input('Position: '))
L.insert(p, x)
print('After insert:', L)
L.sort()
print('Sorted:', L)Sample run
Enter a list: [40, 10, 30] Element: 25 Position: 1 After insert: [40, 25, 10, 30] Sorted: [10, 25, 30, 40]
Write a program to merge two dictionaries using update() and print the number of keys.
D1 = {'a': 1, 'b': 2}
D2 = {'b': 20, 'c': 30}
D1.update(D2)
print(D1)
print('Keys:', len(D1))Sample run
{'a': 1, 'b': 20, 'c': 30}
Keys: 3Write a program to create a NumPy array of the prices of five items and print the prices after a 10% discount.
import numpy as np price = np.array([200, 450, 120, 999, 75]) new = price - price * 10 / 100 print(new)
Sample run
[180. 405. 108. 899.1 67.5]
Write a program to input the marks of n students in a list and print how many students scored above the class average.
n = int(input('How many students? '))
M = []
for i in range(n):
M.append(int(input('Marks: ')))
avg = sum(M) / n
c = 0
for m in M:
if m > avg:
c += 1
print('Average =', avg)
print('Above average:', c)Sample run
How many students? 5 Marks: 67 Marks: 82 Marks: 45 Marks: 90 Marks: 71 Average = 71.0 Above average: 2
Write a program to create a dictionary of item names and quantities and print the items whose quantity is less than 10 (to be re-ordered).
stock = {'pen': 40, 'pencil': 6, 'eraser': 12, 'ruler': 3}
for item in stock:
if stock[item] < 10:
print('Re-order', item, stock[item])Sample run
Re-order pencil 6 Re-order ruler 3
Write a program to create two NumPy arrays of the marks in two tests and print the total and the average of the two tests for each student.
import numpy as np
t1 = np.array([18, 22, 15, 25])
t2 = np.array([20, 19, 24, 21])
print('Total:', t1 + t2)
print('Average:', (t1 + t2) / 2)Sample run
Total: [38 41 39 46] Average: [19. 20.5 19.5 23. ]
Write a program to input a list of numbers and create a new list with each number squared, then print the new list and its sum.
L = eval(input('Enter a list: '))
S = []
for x in L:
S.append(x * x)
print(S)
print('Sum =', sum(S))Sample run
Enter a list: [3, 5, 2, 7] [9, 25, 4, 49] Sum = 87
Write a program to input a list of numbers and search for a number (linear search). Print its position or 'not found'.
L = eval(input('Enter a list: '))
x = int(input('Number to search: '))
for i in range(len(L)):
if L[i] == x:
print(x, 'found at index', i)
break
else:
print(x, 'not found')Sample run
Enter a list: [12, 45, 7, 30, 18] Number to search: 30 30 found at index 3
Write a program to input a list and swap the elements at even positions with the elements at odd positions: [1, 2, 3, 4] becomes [2, 1, 4, 3].
L = eval(input('Enter a list: '))
for i in range(0, len(L) - 1, 2):
L[i], L[i + 1] = L[i + 1], L[i]
print(L)Sample run
Enter a list: [10, 20, 30, 40, 50, 60] [20, 10, 40, 30, 60, 50]
Write a program to find the largest and the second largest element of a list without sorting.
L = eval(input('Enter a list: '))
first = second = None
for x in L:
if first is None or x > first:
second = first
first = x
elif x != first and (second is None or x > second):
second = x
print('Largest =', first)
print('Second largest =', second)Sample run
Enter a list: [34, 78, 12, 90, 56, 90] Largest = 90 Second largest = 78
Write a program to rotate the elements of a list one place to the left: [1, 2, 3, 4] becomes [2, 3, 4, 1].
L = eval(input('Enter a list: '))
first = L[0]
for i in range(len(L) - 1):
L[i] = L[i + 1]
L[-1] = first
print(L)Sample run
Enter a list: [5, 10, 15, 20, 25] [10, 15, 20, 25, 5]
Write a program to rotate the elements of a list one place to the right.
L = eval(input('Enter a list: '))
last = L[-1]
for i in range(len(L) - 1, 0, -1):
L[i] = L[i - 1]
L[0] = last
print(L)Sample run
Enter a list: [5, 10, 15, 20, 25] [25, 5, 10, 15, 20]
Write a program to remove the duplicate elements from a list.
L = eval(input('Enter a list: '))
new = []
for x in L:
if x not in new:
new.append(x)
print('Without duplicates:', new)Sample run
Enter a list: [3, 5, 3, 8, 5, 9, 3] Without duplicates: [3, 5, 8, 9]
Write a program to input a list and put the positive and the negative numbers into two separate lists.
L = eval(input('Enter a list: '))
pos, neg = [], []
for x in L:
if x >= 0:
pos.append(x)
else:
neg.append(x)
print('Positive:', pos)
print('Negative:', neg)Sample run
Enter a list: [12, -5, 0, 8, -17, 25] Positive: [12, 0, 8, 25] Negative: [-5, -17]
Write a program to find the frequency of each element of a list using a dictionary.
L = eval(input('Enter a list: '))
freq = {}
for x in L:
freq[x] = freq.get(x, 0) + 1
for k in freq:
print(k, 'occurs', freq[k], 'times')Sample run
Enter a list: [2, 7, 2, 9, 7, 2] 2 occurs 3 times 7 occurs 2 times 9 occurs 1 times
Write a program to input a list and replace every even element by its half and every odd element by its double.
L = eval(input('Enter a list: '))
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] = L[i] // 2
else:
L[i] = L[i] * 2
print(L)Sample run
Enter a list: [10, 7, 24, 3, 15] [5, 14, 12, 6, 30]
Write a program to print the cumulative sum of a list: [1, 2, 3] gives [1, 3, 6].
L = eval(input('Enter a list: '))
C = []
s = 0
for x in L:
s = s + x
C.append(s)
print(C)Sample run
Enter a list: [4, 6, 1, 9, 5] [4, 10, 11, 20, 25]
Write a program to create a dictionary of n students' roll numbers and names, and search for a roll number.
n = int(input('How many students? '))
D = {}
for i in range(n):
r = int(input('Roll no: '))
name = input('Name: ')
D[r] = name
r = int(input('Roll no to search: '))
if r in D:
print('Name:', D[r])
else:
print('Not found')Sample run
How many students? 3 Roll no: 1 Name: Asha Roll no: 2 Name: Bilal Roll no: 3 Name: Charu Roll no to search: 2 Name: Bilal
Write a program to create a dictionary of country names and their capitals, and print the capital of a country given by the user.
D = {'India': 'New Delhi', 'Japan': 'Tokyo', 'France': 'Paris', 'Kenya': 'Nairobi'}
c = input('Country: ')
print('Capital:', D.get(c, 'not in the list'))Sample run
Country: Japan Capital: Tokyo
Write a program to find the key with the largest value in a dictionary of items and prices.
D = eval(input('Enter a dictionary: '))
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Costliest item:', best, D[best])Sample run
Enter a dictionary: {'pen': 20, 'bag': 650, 'book': 280}
Costliest item: bag 650Write a program to input a list of numbers and print the numbers that are divisible by 3 but not by 5.
L = eval(input('Enter a list: '))
for x in L:
if x % 3 == 0 and x % 5 != 0:
print(x, end=' ')Sample run
Enter a list: [9, 15, 21, 30, 33, 40, 42] 9 21 33 42
Write a program to merge two lists and print the merged list in ascending order, without using + or extend().
A = eval(input('First list: '))
B = eval(input('Second list: '))
C = []
for x in A:
C.append(x)
for x in B:
C.append(x)
C.sort()
print(C)Sample run
First list: [8, 3, 5] Second list: [7, 1, 9] [1, 3, 5, 7, 8, 9]
Write a program to create a dictionary from two lists: one of names and one of marks. Print the names of the students who scored above 80.
names = eval(input('Names: '))
marks = eval(input('Marks: '))
D = {}
for i in range(len(names)):
D[names[i]] = marks[i]
print(D)
for k in D:
if D[k] > 80:
print(k)Sample run
Names: ['Anu', 'Bhanu', 'Chetan', 'Divya']
Marks: [78, 92, 85, 64]
{'Anu': 78, 'Bhanu': 92, 'Chetan': 85, 'Divya': 64}
Bhanu
ChetanWrite a program to input a list of numbers and create a new list that has the square of each odd number.
L = eval(input('Enter a list: '))
S = []
for x in L:
if x % 2 != 0:
S.append(x * x)
print(S)Sample run
Enter a list: [3, 8, 5, 10, 7] [9, 25, 49]
Write a program to find the sum of the elements at even indices and at odd indices of a list.
L = eval(input('Enter a list: '))
e = o = 0
for i in range(len(L)):
if i % 2 == 0:
e += L[i]
else:
o += L[i]
print('Sum at even indices =', e)
print('Sum at odd indices =', o)Sample run
Enter a list: [10, 3, 20, 7, 30, 1] Sum at even indices = 60 Sum at odd indices = 11
Write a menu-driven program for a list of numbers with these options: 1. Append a number, 2. Delete a number, 3. Display the list, 4. Sort the list, 5. Exit.
L = []
while True:
print('1.Append 2.Delete 3.Display 4.Sort 5.Exit')
ch = int(input('Choice: '))
if ch == 1:
L.append(int(input('Number: ')))
elif ch == 2:
x = int(input('Number to delete: '))
if x in L:
L.remove(x)
else:
print('Not in list')
elif ch == 3:
print(L)
elif ch == 4:
L.sort()
print('Sorted:', L)
elif ch == 5:
break
else:
print('Wrong choice')Sample run
1.Append 2.Delete 3.Display 4.Sort 5.Exit Choice: 1 Number: 30 1.Append 2.Delete 3.Display 4.Sort 5.Exit Choice: 1 Number: 10 1.Append 2.Delete 3.Display 4.Sort 5.Exit Choice: 1 Number: 20 1.Append 2.Delete 3.Display 4.Sort 5.Exit Choice: 3 [30, 10, 20] 1.Append 2.Delete 3.Display 4.Sort 5.Exit Choice: 2 Number to delete: 10 1.Append 2.Delete 3.Display 4.Sort 5.Exit Choice: 4 Sorted: [20, 30] 1.Append 2.Delete 3.Display 4.Sort 5.Exit Choice: 5
Write a menu-driven program to maintain a phone book (dictionary of name: phone) with options: 1. Add, 2. Search, 3. Delete, 4. Display all, 5. Exit.
book = {}
while True:
print('1.Add 2.Search 3.Delete 4.Display 5.Exit')
ch = int(input('Choice: '))
if ch == 1:
n = input('Name: ')
book[n] = input('Phone: ')
elif ch == 2:
n = input('Name: ')
print(book.get(n, 'Not found'))
elif ch == 3:
n = input('Name: ')
if n in book:
del book[n]
print('Deleted')
else:
print('Not found')
elif ch == 4:
for n in book:
print(n, book[n])
elif ch == 5:
breakSample run
1.Add 2.Search 3.Delete 4.Display 5.Exit Choice: 1 Name: Asha Phone: 98110 22334 1.Add 2.Search 3.Delete 4.Display 5.Exit Choice: 1 Name: Ravi Phone: 98990 55667 1.Add 2.Search 3.Delete 4.Display 5.Exit Choice: 2 Name: Ravi 98990 55667 1.Add 2.Search 3.Delete 4.Display 5.Exit Choice: 3 Name: Asha Deleted 1.Add 2.Search 3.Delete 4.Display 5.Exit Choice: 4 Ravi 98990 55667 1.Add 2.Search 3.Delete 4.Display 5.Exit Choice: 5
Write a menu-driven program for a stock dictionary (item: quantity): 1. Add or update an item, 2. Sell an item (reduce its quantity), 3. Show items with quantity below 5, 4. Exit.
stock = {'pen': 40, 'pencil': 3, 'eraser': 12}
while True:
print('1.Add/Update 2.Sell 3.Low stock 4.Exit')
ch = int(input('Choice: '))
if ch == 1:
it = input('Item: ')
stock[it] = stock.get(it, 0) + int(input('Quantity: '))
elif ch == 2:
it = input('Item: ')
q = int(input('Quantity: '))
if stock.get(it, 0) >= q:
stock[it] -= q
else:
print('Not enough stock')
elif ch == 3:
for it in stock:
if stock[it] < 5:
print(it, stock[it])
elif ch == 4:
break
print(stock)Sample run
1.Add/Update 2.Sell 3.Low stock 4.Exit
Choice: 1
Item: sharpener
Quantity: 6
{'pen': 40, 'pencil': 3, 'eraser': 12, 'sharpener': 6}
1.Add/Update 2.Sell 3.Low stock 4.Exit
Choice: 2
Item: pen
Quantity: 38
{'pen': 2, 'pencil': 3, 'eraser': 12, 'sharpener': 6}
1.Add/Update 2.Sell 3.Low stock 4.Exit
Choice: 3
pen 2
pencil 3
{'pen': 2, 'pencil': 3, 'eraser': 12, 'sharpener': 6}
1.Add/Update 2.Sell 3.Low stock 4.Exit
Choice: 4Write a program to input the name and marks of 4 students and store them in a dictionary. Then:
n = int(input('How many students? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Marks: '))
# (i)
print('Names with marks more than 75:')
for k in D:
if D[k] > 75:
print(k, D[k])
# (ii)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest marks:', best, D[best])Sample run
How many students? 4 Name: Asha Marks: 88 Name: Bilal Marks: 64 Name: Charu Marks: 92 Name: Dev Marks: 47 Names with marks more than 75: Asha 88 Charu 92 Highest marks: Charu 92
Write a program to input the name and marks of 4 students and store them in a dictionary. Then:
n = int(input('How many students? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Marks: '))
# (i)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest marks:', best, D[best])
# (ii)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))Sample run
How many students? 4 Name: Asha Marks: 88 Name: Bilal Marks: 64 Name: Charu Marks: 92 Name: Dev Marks: 47 Highest marks: Charu 92 Total = 291 Average = 72.75
Write a program to input the name and marks of 4 students and store them in a dictionary. Then:
n = int(input('How many students? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Marks: '))
# (i)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))
# (ii)
for k in sorted(D):
print(k, D[k])Sample run
How many students? 4 Name: Asha Marks: 88 Name: Bilal Marks: 64 Name: Charu Marks: 92 Name: Dev Marks: 47 Total = 291 Average = 72.75 Asha 88 Bilal 64 Charu 92 Dev 47
Write a program to input the name and marks of 4 students and store them in a dictionary. Then:
n = int(input('How many students? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Marks: '))
# (i)
for k in sorted(D):
print(k, D[k])
# (ii)
c = 0
for k in D:
if D[k] < 75:
c += 1
print('Count with marks less than 75:', c)Sample run
How many students? 4 Name: Asha Marks: 88 Name: Bilal Marks: 64 Name: Charu Marks: 92 Name: Dev Marks: 47 Asha 88 Bilal 64 Charu 92 Dev 47 Count with marks less than 75: 2
Write a program to input the name and marks of 4 students and store them in a dictionary. Then:
n = int(input('How many students? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Marks: '))
# (i)
c = 0
for k in D:
if D[k] < 75:
c += 1
print('Count with marks less than 75:', c)
# (ii)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)Sample run
How many students? 4
Name: Asha
Marks: 88
Name: Bilal
Marks: 64
Name: Charu
Marks: 92
Name: Dev
Marks: 47
Count with marks less than 75: 2
{'Asha': 96.8, 'Bilal': 70.4, 'Charu': 101.2, 'Dev': 51.7}Write a program to input the name and salary of 4 employees and store them in a dictionary. Then:
n = int(input('How many employees? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Salary: '))
# (i)
print('Names with salary more than 50000:')
for k in D:
if D[k] > 50000:
print(k, D[k])
# (ii)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))Sample run
How many employees? 4 Name: Ravi Salary: 42000 Name: Seema Salary: 58000 Name: Tarun Salary: 36000 Name: Usha Salary: 61000 Names with salary more than 50000: Seema 58000 Usha 61000 Total = 197000 Average = 49250.0
Write a program to input the name and salary of 4 employees and store them in a dictionary. Then:
n = int(input('How many employees? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Salary: '))
# (i)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest salary:', best, D[best])
# (ii)
for k in sorted(D):
print(k, D[k])Sample run
How many employees? 4 Name: Ravi Salary: 42000 Name: Seema Salary: 58000 Name: Tarun Salary: 36000 Name: Usha Salary: 61000 Highest salary: Usha 61000 Ravi 42000 Seema 58000 Tarun 36000 Usha 61000
Write a program to input the name and salary of 4 employees and store them in a dictionary. Then:
n = int(input('How many employees? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Salary: '))
# (i)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))
# (ii)
c = 0
for k in D:
if D[k] < 50000:
c += 1
print('Count with salary less than 50000:', c)Sample run
How many employees? 4 Name: Ravi Salary: 42000 Name: Seema Salary: 58000 Name: Tarun Salary: 36000 Name: Usha Salary: 61000 Total = 197000 Average = 49250.0 Count with salary less than 50000: 2
Write a program to input the name and salary of 4 employees and store them in a dictionary. Then:
n = int(input('How many employees? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Salary: '))
# (i)
for k in sorted(D):
print(k, D[k])
# (ii)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)Sample run
How many employees? 4
Name: Ravi
Salary: 42000
Name: Seema
Salary: 58000
Name: Tarun
Salary: 36000
Name: Usha
Salary: 61000
Ravi 42000
Seema 58000
Tarun 36000
Usha 61000
{'Ravi': 46200.0, 'Seema': 63800.0, 'Tarun': 39600.0, 'Usha': 67100.0}Write a program to input the name and salary of 4 employees and store them in a dictionary. Then:
n = int(input('How many employees? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Salary: '))
# (i)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)
# (ii)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest salary:', best, D[best])Sample run
How many employees? 4
Name: Ravi
Salary: 42000
Name: Seema
Salary: 58000
Name: Tarun
Salary: 36000
Name: Usha
Salary: 61000
{'Ravi': 46200.0, 'Seema': 63800.0, 'Tarun': 39600.0, 'Usha': 67100.0}
Highest salary: Usha 67100.0Write a program to input the item and price of 4 items and store them in a dictionary. Then:
n = int(input('How many items? '))
D = {}
for i in range(n):
k = input('Item: ')
D[k] = int(input('Price: '))
# (i)
print('Items with price more than 300:')
for k in D:
if D[k] > 300:
print(k, D[k])
# (ii)
for k in sorted(D):
print(k, D[k])Sample run
How many items? 4 Item: Pen Price: 20 Item: Bag Price: 650 Item: Book Price: 280 Item: Lamp Price: 450 Items with price more than 300: Bag 650 Lamp 450 Bag 650 Book 280 Lamp 450 Pen 20
Write a program to input the item and price of 4 items and store them in a dictionary. Then:
n = int(input('How many items? '))
D = {}
for i in range(n):
k = input('Item: ')
D[k] = int(input('Price: '))
# (i)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest price:', best, D[best])
# (ii)
c = 0
for k in D:
if D[k] < 300:
c += 1
print('Count with price less than 300:', c)Sample run
How many items? 4 Item: Pen Price: 20 Item: Bag Price: 650 Item: Book Price: 280 Item: Lamp Price: 450 Highest price: Bag 650 Count with price less than 300: 2
Write a program to input the item and price of 4 items and store them in a dictionary. Then:
n = int(input('How many items? '))
D = {}
for i in range(n):
k = input('Item: ')
D[k] = int(input('Price: '))
# (i)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))
# (ii)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)Sample run
How many items? 4
Item: Pen
Price: 20
Item: Bag
Price: 650
Item: Book
Price: 280
Item: Lamp
Price: 450
Total = 1400
Average = 350.0
{'Pen': 22.0, 'Bag': 715.0, 'Book': 308.0, 'Lamp': 495.0}Write a program to input the item and price of 4 items and store them in a dictionary. Then:
n = int(input('How many items? '))
D = {}
for i in range(n):
k = input('Item: ')
D[k] = int(input('Price: '))
# (i)
for k in sorted(D):
print(k, D[k])
# (ii)
print('Items with price more than 300:')
for k in D:
if D[k] > 300:
print(k, D[k])Sample run
How many items? 4 Item: Pen Price: 20 Item: Bag Price: 650 Item: Book Price: 280 Item: Lamp Price: 450 Bag 650 Book 280 Lamp 450 Pen 20 Items with price more than 300: Bag 650 Lamp 450
Write a program to input the item and price of 4 items and store them in a dictionary. Then:
n = int(input('How many items? '))
D = {}
for i in range(n):
k = input('Item: ')
D[k] = int(input('Price: '))
# (i)
c = 0
for k in D:
if D[k] < 300:
c += 1
print('Count with price less than 300:', c)
# (ii)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest price:', best, D[best])Sample run
How many items? 4 Item: Pen Price: 20 Item: Bag Price: 650 Item: Book Price: 280 Item: Lamp Price: 450 Count with price less than 300: 2 Highest price: Bag 650
Write a program to input the player and runs of 4 players and store them in a dictionary. Then:
n = int(input('How many players? '))
D = {}
for i in range(n):
k = input('Player: ')
D[k] = int(input('Runs: '))
# (i)
print('Players with runs more than 50:')
for k in D:
if D[k] > 50:
print(k, D[k])
# (ii)
c = 0
for k in D:
if D[k] < 50:
c += 1
print('Count with runs less than 50:', c)Sample run
How many players? 4 Player: Rohit Runs: 74 Player: Virat Runs: 101 Player: Gill Runs: 38 Player: Pant Runs: 55 Players with runs more than 50: Rohit 74 Virat 101 Pant 55 Count with runs less than 50: 1
Write a program to input the player and runs of 4 players and store them in a dictionary. Then:
n = int(input('How many players? '))
D = {}
for i in range(n):
k = input('Player: ')
D[k] = int(input('Runs: '))
# (i)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest runs:', best, D[best])
# (ii)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)Sample run
How many players? 4
Player: Rohit
Runs: 74
Player: Virat
Runs: 101
Player: Gill
Runs: 38
Player: Pant
Runs: 55
Highest runs: Virat 101
{'Rohit': 81.4, 'Virat': 111.1, 'Gill': 41.8, 'Pant': 60.5}Write a program to input the player and runs of 4 players and store them in a dictionary. Then:
n = int(input('How many players? '))
D = {}
for i in range(n):
k = input('Player: ')
D[k] = int(input('Runs: '))
# (i)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))
# (ii)
print('Players with runs more than 50:')
for k in D:
if D[k] > 50:
print(k, D[k])Sample run
How many players? 4 Player: Rohit Runs: 74 Player: Virat Runs: 101 Player: Gill Runs: 38 Player: Pant Runs: 55 Total = 268 Average = 67.0 Players with runs more than 50: Rohit 74 Virat 101 Pant 55
Write a program to input the player and runs of 4 players and store them in a dictionary. Then:
n = int(input('How many players? '))
D = {}
for i in range(n):
k = input('Player: ')
D[k] = int(input('Runs: '))
# (i)
for k in sorted(D):
print(k, D[k])
# (ii)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest runs:', best, D[best])Sample run
How many players? 4 Player: Rohit Runs: 74 Player: Virat Runs: 101 Player: Gill Runs: 38 Player: Pant Runs: 55 Gill 38 Pant 55 Rohit 74 Virat 101 Highest runs: Virat 101
Write a program to input the player and runs of 4 players and store them in a dictionary. Then:
n = int(input('How many players? '))
D = {}
for i in range(n):
k = input('Player: ')
D[k] = int(input('Runs: '))
# (i)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)
# (ii)
for k in sorted(D):
print(k, D[k])Sample run
How many players? 4
Player: Rohit
Runs: 74
Player: Virat
Runs: 101
Player: Gill
Runs: 38
Player: Pant
Runs: 55
{'Rohit': 81.4, 'Virat': 111.1, 'Gill': 41.8, 'Pant': 60.5}
Gill 41.8
Pant 60.5
Rohit 81.4
Virat 111.1Write a program to input the title and copies of 4 books and store them in a dictionary. Then:
n = int(input('How many books? '))
D = {}
for i in range(n):
k = input('Title: ')
D[k] = int(input('Copies: '))
# (i)
print('Titles with copies more than 10:')
for k in D:
if D[k] > 10:
print(k, D[k])
# (ii)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)Sample run
How many books? 4
Title: Gitanjali
Copies: 12
Title: Godan
Copies: 5
Title: Malgudi Days
Copies: 9
Title: Wings of Fire
Copies: 15
Titles with copies more than 10:
Gitanjali 12
Wings of Fire 15
{'Gitanjali': 13.2, 'Godan': 5.5, 'Malgudi Days': 9.9, 'Wings of Fire': 16.5}Write a program to input the title and copies of 4 books and store them in a dictionary. Then:
n = int(input('How many books? '))
D = {}
for i in range(n):
k = input('Title: ')
D[k] = int(input('Copies: '))
# (i)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest copies:', best, D[best])
# (ii)
print('Titles with copies more than 10:')
for k in D:
if D[k] > 10:
print(k, D[k])Sample run
How many books? 4 Title: Gitanjali Copies: 12 Title: Godan Copies: 5 Title: Malgudi Days Copies: 9 Title: Wings of Fire Copies: 15 Highest copies: Wings of Fire 15 Titles with copies more than 10: Gitanjali 12 Wings of Fire 15
Write a program to input the title and copies of 4 books and store them in a dictionary. Then:
n = int(input('How many books? '))
D = {}
for i in range(n):
k = input('Title: ')
D[k] = int(input('Copies: '))
# (i)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))
# (ii)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest copies:', best, D[best])Sample run
How many books? 4 Title: Gitanjali Copies: 12 Title: Godan Copies: 5 Title: Malgudi Days Copies: 9 Title: Wings of Fire Copies: 15 Total = 41 Average = 10.25 Highest copies: Wings of Fire 15
Write a program to input the title and copies of 4 books and store them in a dictionary. Then:
n = int(input('How many books? '))
D = {}
for i in range(n):
k = input('Title: ')
D[k] = int(input('Copies: '))
# (i)
for k in sorted(D):
print(k, D[k])
# (ii)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))Sample run
How many books? 4 Title: Gitanjali Copies: 12 Title: Godan Copies: 5 Title: Malgudi Days Copies: 9 Title: Wings of Fire Copies: 15 Gitanjali 12 Godan 5 Malgudi Days 9 Wings of Fire 15 Total = 41 Average = 10.25
Write a program to input the title and copies of 4 books and store them in a dictionary. Then:
n = int(input('How many books? '))
D = {}
for i in range(n):
k = input('Title: ')
D[k] = int(input('Copies: '))
# (i)
c = 0
for k in D:
if D[k] < 10:
c += 1
print('Count with copies less than 10:', c)
# (ii)
for k in sorted(D):
print(k, D[k])Sample run
How many books? 4 Title: Gitanjali Copies: 12 Title: Godan Copies: 5 Title: Malgudi Days Copies: 9 Title: Wings of Fire Copies: 15 Count with copies less than 10: 2 Gitanjali 12 Godan 5 Malgudi Days 9 Wings of Fire 15
Write a program to input the city and population (lakh) of 4 cities and store them in a dictionary. Then:
n = int(input('How many cities? '))
D = {}
for i in range(n):
k = input('City: ')
D[k] = int(input('Population (lakh): '))
# (i)
print('Citys with population (lakh) more than 50:')
for k in D:
if D[k] > 50:
print(k, D[k])
# (ii)
print('Citys with population (lakh) more than 50:')
for k in D:
if D[k] > 50:
print(k, D[k])Sample run
How many cities? 4 City: Delhi Population (lakh): 190 City: Pune Population (lakh): 70 City: Jaipur Population (lakh): 40 City: Patna Population (lakh): 25 Citys with population (lakh) more than 50: Delhi 190 Pune 70 Citys with population (lakh) more than 50: Delhi 190 Pune 70
Write a program to input the city and population (lakh) of 4 cities and store them in a dictionary. Then:
n = int(input('How many cities? '))
D = {}
for i in range(n):
k = input('City: ')
D[k] = int(input('Population (lakh): '))
# (i)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest population (lakh):', best, D[best])
# (ii)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest population (lakh):', best, D[best])Sample run
How many cities? 4 City: Delhi Population (lakh): 190 City: Pune Population (lakh): 70 City: Jaipur Population (lakh): 40 City: Patna Population (lakh): 25 Highest population (lakh): Delhi 190 Highest population (lakh): Delhi 190
Write a program to input the city and population (lakh) of 4 cities and store them in a dictionary. Then:
n = int(input('How many cities? '))
D = {}
for i in range(n):
k = input('City: ')
D[k] = int(input('Population (lakh): '))
# (i)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))
# (ii)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))Sample run
How many cities? 4 City: Delhi Population (lakh): 190 City: Pune Population (lakh): 70 City: Jaipur Population (lakh): 40 City: Patna Population (lakh): 25 Total = 325 Average = 81.25 Total = 325 Average = 81.25
Write a program to input the city and population (lakh) of 4 cities and store them in a dictionary. Then:
n = int(input('How many cities? '))
D = {}
for i in range(n):
k = input('City: ')
D[k] = int(input('Population (lakh): '))
# (i)
for k in sorted(D):
print(k, D[k])
# (ii)
for k in sorted(D):
print(k, D[k])Sample run
How many cities? 4 City: Delhi Population (lakh): 190 City: Pune Population (lakh): 70 City: Jaipur Population (lakh): 40 City: Patna Population (lakh): 25 Delhi 190 Jaipur 40 Patna 25 Pune 70 Delhi 190 Jaipur 40 Patna 25 Pune 70
Write a program to input the city and population (lakh) of 4 cities and store them in a dictionary. Then:
n = int(input('How many cities? '))
D = {}
for i in range(n):
k = input('City: ')
D[k] = int(input('Population (lakh): '))
# (i)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)
# (ii)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)Sample run
How many cities? 4
City: Delhi
Population (lakh): 190
City: Pune
Population (lakh): 70
City: Jaipur
Population (lakh): 40
City: Patna
Population (lakh): 25
{'Delhi': 209.0, 'Pune': 77.0, 'Jaipur': 44.0, 'Patna': 27.5}
{'Delhi': 229.9, 'Pune': 84.7, 'Jaipur': 48.4, 'Patna': 30.3}Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
R = []
for i in range(len(L) - 1, -1, -1):
R.append(L[i])
print('Reversed:', R)Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11] Sum = 111 Average = 15.857142857142858 Reversed: [11, 40, 9, 7, 22, 7, 15]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)Sample run
Enter a list of numbers: [5, 18, 29, 18, 3, 60, 13] Sum = 146 Average = 20.857142857142858 Even: 3 Odd: 4
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2] Sum = 134 Average = 19.142857142857142 Largest: 41 Smallest: 2
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
avg = sum(L) / len(L)
print('Above average:', end=' ')
for x in L:
if x > avg:
print(x, end=' ')
print()Sample run
Enter a list of numbers: [23, 8, 17, 42, 8, 31, 12] Sum = 141 Average = 20.142857142857142 Above average: 23 42 31
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
print('Primes:', end=' ')
for x in L:
if x > 1:
for i in range(2, x):
if x % i == 0:
break
else:
print(x, end=' ')
print()Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11] Sum = 111 Average = 15.857142857142858 Primes: 7 7 11
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
E = L[::2]
print('Even-index elements:', E)Sample run
Enter a list of numbers: [5, 18, 29, 18, 3, 60, 13] Sum = 146 Average = 20.857142857142858 Even-index elements: [5, 29, 3, 13]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print('Frequency:', F)Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2]
Sum = 134 Average = 19.142857142857142
Frequency: {41: 1, 6: 2, 19: 1, 33: 1, 27: 1, 2: 1}Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
S = sorted(L, reverse=True)
print('Top three:', S[:3])Sample run
Enter a list of numbers: [23, 8, 17, 42, 8, 31, 12] Sum = 141 Average = 20.142857142857142 Top three: [42, 31, 23]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
x = L[0]
while x in L:
L.remove(x)
print('After removing', x, ':', L)Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11] Sum = 111 Average = 15.857142857142858 After removing 15 : [7, 22, 7, 9, 40, 11]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)
# (ii)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11] Even: 2 Odd: 5 Largest: 40 Smallest: 7
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)
# (ii)
avg = sum(L) / len(L)
print('Above average:', end=' ')
for x in L:
if x > avg:
print(x, end=' ')
print()Sample run
Enter a list of numbers: [5, 18, 29, 18, 3, 60, 13] Even: 3 Odd: 4 Above average: 29 60
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)
# (ii)
print('Primes:', end=' ')
for x in L:
if x > 1:
for i in range(2, x):
if x % i == 0:
break
else:
print(x, end=' ')
print()Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2] Even: 3 Odd: 4 Primes: 41 19 2
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)
# (ii)
E = L[::2]
print('Even-index elements:', E)Sample run
Enter a list of numbers: [23, 8, 17, 42, 8, 31, 12] Even: 4 Odd: 3 Even-index elements: [23, 17, 8, 12]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)
# (ii)
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print('Frequency:', F)Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11]
Even: 2 Odd: 5
Frequency: {15: 1, 7: 2, 22: 1, 9: 1, 40: 1, 11: 1}Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)
# (ii)
S = sorted(L, reverse=True)
print('Top three:', S[:3])Sample run
Enter a list of numbers: [5, 18, 29, 18, 3, 60, 13] Even: 3 Odd: 4 Top three: [60, 29, 18]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)
# (ii)
x = L[0]
while x in L:
L.remove(x)
print('After removing', x, ':', L)Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2] Even: 3 Odd: 4 After removing 41 : [6, 19, 33, 6, 27, 2]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)
# (ii)
avg = sum(L) / len(L)
print('Above average:', end=' ')
for x in L:
if x > avg:
print(x, end=' ')
print()Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2] Largest: 41 Smallest: 2 Above average: 41 33 27
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)
# (ii)
print('Primes:', end=' ')
for x in L:
if x > 1:
for i in range(2, x):
if x % i == 0:
break
else:
print(x, end=' ')
print()Sample run
Enter a list of numbers: [23, 8, 17, 42, 8, 31, 12] Largest: 42 Smallest: 8 Primes: 23 17 31
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)
# (ii)
E = L[::2]
print('Even-index elements:', E)Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11] Largest: 40 Smallest: 7 Even-index elements: [15, 22, 9, 11]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)
# (ii)
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print('Frequency:', F)Sample run
Enter a list of numbers: [5, 18, 29, 18, 3, 60, 13]
Largest: 60 Smallest: 3
Frequency: {5: 1, 18: 2, 29: 1, 3: 1, 60: 1, 13: 1}Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)
# (ii)
S = sorted(L, reverse=True)
print('Top three:', S[:3])Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2] Largest: 41 Smallest: 2 Top three: [41, 33, 27]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)
# (ii)
x = L[0]
while x in L:
L.remove(x)
print('After removing', x, ':', L)Sample run
Enter a list of numbers: [23, 8, 17, 42, 8, 31, 12] Largest: 42 Smallest: 8 After removing 23 : [8, 17, 42, 8, 31, 12]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Primes:', end=' ')
for x in L:
if x > 1:
for i in range(2, x):
if x % i == 0:
break
else:
print(x, end=' ')
print()
# (ii)
E = L[::2]
print('Even-index elements:', E)Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2] Primes: 41 19 2 Even-index elements: [41, 19, 6, 2]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Primes:', end=' ')
for x in L:
if x > 1:
for i in range(2, x):
if x % i == 0:
break
else:
print(x, end=' ')
print()
# (ii)
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print('Frequency:', F)Sample run
Enter a list of numbers: [23, 8, 17, 42, 8, 31, 12]
Primes: 23 17 31
Frequency: {23: 1, 8: 2, 17: 1, 42: 1, 31: 1, 12: 1}Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Primes:', end=' ')
for x in L:
if x > 1:
for i in range(2, x):
if x % i == 0:
break
else:
print(x, end=' ')
print()
# (ii)
S = sorted(L, reverse=True)
print('Top three:', S[:3])Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11] Primes: 7 7 11 Top three: [40, 22, 15]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Primes:', end=' ')
for x in L:
if x > 1:
for i in range(2, x):
if x % i == 0:
break
else:
print(x, end=' ')
print()
# (ii)
x = L[0]
while x in L:
L.remove(x)
print('After removing', x, ':', L)Sample run
Enter a list of numbers: [5, 18, 29, 18, 3, 60, 13] Primes: 5 29 3 13 After removing 5 : [18, 29, 18, 3, 60, 13]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
E = L[::2]
print('Even-index elements:', E)
# (ii)
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print('Frequency:', F)Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11]
Even-index elements: [15, 22, 9, 11]
Frequency: {15: 1, 7: 2, 22: 1, 9: 1, 40: 1, 11: 1}Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
E = L[::2]
print('Even-index elements:', E)
# (ii)
S = sorted(L, reverse=True)
print('Top three:', S[:3])Sample run
Enter a list of numbers: [5, 18, 29, 18, 3, 60, 13] Even-index elements: [5, 29, 3, 13] Top three: [60, 29, 18]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
E = L[::2]
print('Even-index elements:', E)
# (ii)
x = L[0]
while x in L:
L.remove(x)
print('After removing', x, ':', L)Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2] Even-index elements: [41, 19, 6, 2] After removing 41 : [6, 19, 33, 6, 27, 2]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
S = sorted(L, reverse=True)
print('Top three:', S[:3])
# (ii)
x = L[0]
while x in L:
L.remove(x)
print('After removing', x, ':', L)Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11] Top three: [40, 22, 15] After removing 15 : [7, 22, 7, 9, 40, 11]
Write a program to store the names of students and their marks in five subjects in a dictionary (name: list of marks). Print each name with the total and the percentage, and the name of the topper.
n = int(input('How many students? '))
D = {}
for i in range(n):
name = input('Name: ')
marks = eval(input('Marks in 5 subjects: '))
D[name] = marks
top = ''
best = -1
for name in D:
t = sum(D[name])
print(name, 'Total =', t, 'Percent =', t / 5)
if t > best:
best = t
top = name
print('Topper:', top)Sample run
How many students? 3 Name: Asha Marks in 5 subjects: [78, 85, 90, 72, 88] Name: Bilal Marks in 5 subjects: [65, 70, 58, 80, 75] Name: Charu Marks in 5 subjects: [92, 88, 95, 90, 89] Asha Total = 413 Percent = 82.6 Bilal Total = 348 Percent = 69.6 Charu Total = 454 Percent = 90.8 Topper: Charu
Write a program to create a dictionary of n states and their capitals entered by the user. Then:
n = int(input('How many states? '))
D = {}
for i in range(n):
s = input('State: ')
D[s] = input('Capital: ')
for s in D:
print(s, '-', D[s])
x = input('Search state: ')
print('Capital:', D.get(x, 'not found'))Sample run
How many states? 3 State: Assam Capital: Dispur State: Goa Capital: Panaji State: Odisha Capital: Bhubaneswar Assam - Dispur Goa - Panaji Odisha - Bhubaneswar Search state: Goa Capital: Panaji
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
(a) Write the output of the following queries:
SELECT Name, Section FROM STUDENT WHERE Section = 'C' OR Section = 'B';SELECT Name, Marks FROM STUDENT WHERE Marks > 80;SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;(b) Write SQL queries for the following:
(i)
| Name | Section |
|---|---|
| Bhavya | B |
| Divya | C |
| Eshan | B |
| Gaurav | C |
Explanation: WHERE keeps only the rows where Section is 'C' or Section is 'B': 4 of the 7 rows match (Bhavya, Divya, Eshan, Gaurav). SELECT then shows only the columns Name, Section.
(ii)
| Name | Marks |
|---|---|
| Bhavya | 92 |
| Eshan | 88 |
Explanation: WHERE keeps only the rows where Marks is more than 80: 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the columns Name, Marks.
(iii)
| Name | Phone |
|---|---|
| Aarav | 9810011111 |
| Chirag | 9810033333 |
| Divya | 9810044444 |
| Farah | 9810066666 |
| Gaurav | 9810077777 |
Explanation: WHERE keeps only the rows where Phone has a value (is not NULL): 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Phone. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT Name, Section FROM STUDENT WHERE NOT Section = 'B';
| Name | Section |
|---|---|
| Aarav | A |
| Chirag | A |
| Divya | C |
| Farah | A |
| Gaurav | C |
Explanation: WHERE keeps only the rows where Section is not 'B': 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Section.
(v)
SELECT Name FROM STUDENT WHERE Section = 'B' AND Marks >= 80;
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Section is 'B' and Marks is at least 80: 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
(a) Write the output of the following queries:
SELECT Title, IssueDate FROM BOOK WHERE IssueDate BETWEEN '2026-07-01' AND '2026-07-31';SELECT Title FROM BOOK WHERE Publisher = 'Penguin' AND Member IS NOT NULL;SELECT Title, Price FROM BOOK WHERE Price < 250 OR Member IS NULL;(b) Write SQL queries for the following:
(i)
| Title | IssueDate |
|---|---|
| Informatics Practices | 2026-07-03 |
| Physics Part 1 | 2026-07-10 |
| Chemistry Part 1 | 2026-07-15 |
Explanation: WHERE keeps only the rows where IssueDate is from '2026-07-01' to '2026-07-31' (both included): 3 of the 7 rows match (Informatics Practices, Physics Part 1, Chemistry Part 1). SELECT then shows only the columns Title, IssueDate.
(ii)
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Publisher is 'Penguin' and Member has a value (is not NULL). No row satisfies this, so the result is an empty set. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| Title | Price |
|---|---|
| Informatics Practices | 210 |
| Physics Part 1 | 180 |
| Python Basics | 350 |
| Chemistry Part 1 | 190 |
| The Story of My Experiments | 250 |
Explanation: WHERE keeps only the rows where Price is less than 250 or Member is empty (NULL): 5 of the 7 rows match (Informatics Practices, Physics Part 1, Python Basics, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT Title, Member FROM BOOK WHERE Member IS NOT NULL;
| Title | Member |
|---|---|
| Informatics Practices | Asha |
| Wings of Fire | Ravi |
| Chemistry Part 1 | Neha |
| Learn SQL | Karan |
Explanation: WHERE keeps only the rows where Member has a value (is not NULL): 4 of the 7 rows match (Informatics Practices, Wings of Fire, Chemistry Part 1, Learn SQL). SELECT then shows only the columns Title, Member. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(v)
SELECT Title FROM BOOK WHERE Subject = 'Computer' AND Price >= 200;
| Title |
|---|
| Informatics Practices |
| Python Basics |
| Learn SQL |
Explanation: WHERE keeps only the rows where Subject is 'Computer' and Price is at least 200: 3 of the 7 rows match (Informatics Practices, Python Basics, Learn SQL). SELECT then shows only the column Title.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
(a) Write the output of the following queries:
SELECT Name FROM STUDENT WHERE Gender = 'M' AND Phone IS NOT NULL;SELECT Name FROM STUDENT WHERE Phone IS NULL;SELECT Name FROM STUDENT WHERE Section = 'A' AND Marks >= 50;(b) Write SQL queries for the following:
(i)
| Name |
|---|
| Aarav |
| Chirag |
| Gaurav |
Explanation: WHERE keeps only the rows where Gender is 'M' and Phone has a value (is not NULL): 3 of the 7 rows match (Aarav, Chirag, Gaurav). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Phone is empty (NULL): 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| Name |
|---|
| Aarav |
Explanation: WHERE keeps only the rows where Section is 'A' and Marks is at least 50: 1 of the 7 rows matches (Aarav). SELECT then shows only the column Name.
(iv)
SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
| Name | DOB |
|---|---|
| Bhavya | 2009-11-30 |
| Divya | 2009-07-21 |
| Farah | 2009-09-09 |
Explanation: WHERE keeps only the rows where DOB is from '2009-06-01' to '2009-12-31' (both included): 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, DOB.
(v)
SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 70 AND 80;
| RollNo | Name | Marks |
|---|---|---|
| 1 | Aarav | 78 |
Explanation: WHERE keeps only the rows where Marks is from 70 to 80 (both included): 1 of the 7 rows matches (Aarav). SELECT then shows only the columns RollNo, Name, Marks.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
(a) Write the output of the following queries:
SELECT EName FROM EMPLOYEE WHERE Bonus IS NULL;SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 50000;SELECT EName FROM EMPLOYEE WHERE Dept = 'IT' AND Salary >= 40000;(b) Write SQL queries for the following:
(i)
| EName |
|---|
| Seema |
| Usha |
| Yamini |
Explanation: WHERE keeps only the rows where Bonus is empty (NULL): 3 of the 7 rows match (Seema, Usha, Yamini). SELECT then shows only the column EName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
| EmpID | EName | Salary |
|---|---|---|
| E101 | Ravi | 42000 |
Explanation: WHERE keeps only the rows where Salary is from 40000 to 50000 (both included): 1 of the 7 rows matches (Ravi). SELECT then shows only the columns EmpID, EName, Salary.
(iii)
| EName |
|---|
| Tarun |
| Vikas |
| Yamini |
Explanation: WHERE keeps only the rows where Dept is 'IT' and Salary is at least 40000: 3 of the 7 rows match (Tarun, Vikas, Yamini). SELECT then shows only the column EName.
(iv)
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Delhi';
| EName | City |
|---|---|
| Seema | Pune |
| Usha | Mumbai |
| Vikas | Pune |
| Yamini | Mumbai |
Explanation: WHERE keeps only the rows where City is not 'Delhi': 4 of the 7 rows match (Seema, Usha, Vikas, Yamini). SELECT then shows only the columns EName, City.
(v)
SELECT EName, Salary FROM EMPLOYEE WHERE Salary < 40000 OR Bonus IS NULL;
| EName | Salary |
|---|---|
| Seema | 58000 |
| Usha | 36000 |
| Wasim | 39000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is less than 40000 or Bonus is empty (NULL): 4 of the 7 rows match (Seema, Usha, Wasim, Yamini). SELECT then shows only the columns EName, Salary. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
(a) Write the output of the following queries:
SELECT EName FROM EMPLOYEE WHERE Dept = 'HR' AND Salary >= 70000;SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 70000;SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 60000 AND 70000;(b) Write SQL queries for the following:
(i)
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Dept is 'HR' and Salary is at least 70000. No row satisfies this, so the result is an empty set.
(ii)
| EName | Salary |
|---|---|
| Tarun | 75000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is more than 70000: 2 of the 7 rows match (Tarun, Yamini). SELECT then shows only the columns EName, Salary.
(iii)
| EmpID | EName | Salary |
|---|---|---|
| E105 | Vikas | 64000 |
Explanation: WHERE keeps only the rows where Salary is from 60000 to 70000 (both included): 1 of the 7 rows matches (Vikas). SELECT then shows only the columns EmpID, EName, Salary.
(iv)
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Delhi';
| EName | City |
|---|---|
| Seema | Pune |
| Usha | Mumbai |
| Vikas | Pune |
| Yamini | Mumbai |
Explanation: WHERE keeps only the rows where City is not 'Delhi': 4 of the 7 rows match (Seema, Usha, Vikas, Yamini). SELECT then shows only the columns EName, City.
(v)
SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
(a) Write the output of the following queries:
SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 100 AND 300;SELECT PName, Brand FROM PRODUCT WHERE Brand <> 'Camlin';SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;(b) Write SQL queries for the following:
(i)
| PCode | PName | Price |
|---|---|---|
| P03 | Geometry Box | 180 |
| P07 | Lunch Box | 275 |
Explanation: WHERE keeps only the rows where Price is from 100 to 300 (both included): 2 of the 7 rows match (Geometry Box, Lunch Box). SELECT then shows only the columns PCode, PName, Price.
(ii)
| PName | Brand |
|---|---|
| Notebook | Classmate |
| Pen Drive | SanDisk |
| Mouse | Logitech |
| Water Bottle | Milton |
| Earphones | Boat |
| Lunch Box | Milton |
Explanation: WHERE keeps only the rows where Brand is not 'Camlin': 6 of the 7 rows match (Notebook, Pen Drive, Mouse, Water Bottle, Earphones, Lunch Box). SELECT then shows only the columns PName, Brand.
(iii)
| PName | Discount |
|---|---|
| Notebook | 5 |
| Geometry Box | 10 |
| Mouse | 15 |
| Earphones | 20 |
| Lunch Box | 8 |
Explanation: WHERE keeps only the rows where Discount has a value (is not NULL): 5 of the 7 rows match (Notebook, Geometry Box, Mouse, Earphones, Lunch Box). SELECT then shows only the columns PName, Discount. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT PName, Category FROM PRODUCT WHERE Category = 'Stationery' OR Category = 'Home';
| PName | Category |
|---|---|
| Notebook | Stationery |
| Geometry Box | Stationery |
| Water Bottle | Home |
| Lunch Box | Home |
Explanation: WHERE keeps only the rows where Category is 'Stationery' or Category is 'Home': 4 of the 7 rows match (Notebook, Geometry Box, Water Bottle, Lunch Box). SELECT then shows only the columns PName, Category.
(v)
SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Home';
| PName | Category |
|---|---|
| Notebook | Stationery |
| Pen Drive | Electronics |
| Geometry Box | Stationery |
| Mouse | Electronics |
| Earphones | Electronics |
Explanation: WHERE keeps only the rows where Category is not 'Home': 5 of the 7 rows match (Notebook, Pen Drive, Geometry Box, Mouse, Earphones). SELECT then shows only the columns PName, Category.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
(a) Write the output of the following queries:
SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'Penguin';SELECT Title, Subject FROM BOOK WHERE NOT Subject = 'Biography';SELECT * FROM BOOK WHERE Subject = 'Biography';(b) Write SQL queries for the following:
(i)
| Title | Publisher |
|---|---|
| Informatics Practices | NCERT |
| Physics Part 1 | NCERT |
| Wings of Fire | Universities |
| Python Basics | BPB |
| Chemistry Part 1 | NCERT |
| Learn SQL | BPB |
Explanation: WHERE keeps only the rows where Publisher is not 'Penguin': 6 of the 7 rows match (Informatics Practices, Physics Part 1, Wings of Fire, Python Basics, Chemistry Part 1, Learn SQL). SELECT then shows only the columns Title, Publisher.
(ii)
| Title | Subject |
|---|---|
| Informatics Practices | Computer |
| Physics Part 1 | Science |
| Python Basics | Computer |
| Chemistry Part 1 | Science |
| Learn SQL | Computer |
Explanation: WHERE keeps only the rows where Subject is not 'Biography': 5 of the 7 rows match (Informatics Practices, Physics Part 1, Python Basics, Chemistry Part 1, Learn SQL). SELECT then shows only the columns Title, Subject.
(iii)
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
Explanation: WHERE keeps only the rows where Subject is 'Biography': 2 of the 7 rows match (Wings of Fire, The Story of My Experiments). SELECT then shows all the columns (*).
(iv)
SELECT BookID, Title, Price FROM BOOK WHERE Price BETWEEN 200 AND 250;
| BookID | Title | Price |
|---|---|---|
| 201 | Informatics Practices | 210 |
| 206 | The Story of My Experiments | 250 |
Explanation: WHERE keeps only the rows where Price is from 200 to 250 (both included): 2 of the 7 rows match (Informatics Practices, The Story of My Experiments). SELECT then shows only the columns BookID, Title, Price.
(v)
SELECT Title FROM BOOK WHERE Publisher = 'Penguin' AND Member IS NOT NULL;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Publisher is 'Penguin' and Member has a value (is not NULL). No row satisfies this, so the result is an empty set. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
(a) Write the output of the following queries:
SELECT PID, Fee, Fee + 10 FROM PATIENT;SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;(b) Write SQL queries for the following:
(i)
| PID | Fee | Fee + 10 |
|---|---|---|
| 11 | 1500 | 1510 |
| 12 | 8000 | 8010 |
| 13 | 1200 | 1210 |
| 14 | 5000 | 5010 |
| 15 | 9500 | 9510 |
| 16 | 4500 | 4510 |
| 17 | 900 | 910 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PID, Fee, Fee + 10. The expression is calculated for every row; the table itself does not change.
(ii)
| PName | AdmitDate |
|---|---|
| Nisha | 2026-09-05 |
| Om | 2026-09-10 |
| Pooja | 2026-09-12 |
| Qasim | 2026-09-15 |
Explanation: WHERE keeps only the rows where AdmitDate is from '2026-09-05' to '2026-09-15' (both included): 4 of the 7 rows match (Nisha, Om, Pooja, Qasim). SELECT then shows only the columns PName, AdmitDate.
(iii)
| PName | Insurance |
|---|---|
| Mohan | LIC |
| Om | Star |
| Pooja | LIC |
| Sahil | Star |
Explanation: WHERE keeps only the rows where Insurance has a value (is not NULL): 4 of the 7 rows match (Mohan, Om, Pooja, Sahil). SELECT then shows only the columns PName, Insurance. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT PName, Fee FROM PATIENT WHERE Fee < 1000 OR Insurance IS NULL;
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Qasim | 9500 |
| Rekha | 4500 |
| Sahil | 900 |
Explanation: WHERE keeps only the rows where Fee is less than 1000 or Insurance is empty (NULL): 4 of the 7 rows match (Nisha, Qasim, Rekha, Sahil). SELECT then shows only the columns PName, Fee. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(v)
SELECT PName FROM PATIENT WHERE Insurance IS NULL;
| PName |
|---|
| Nisha |
| Qasim |
| Rekha |
Explanation: WHERE keeps only the rows where Insurance is empty (NULL): 3 of the 7 rows match (Nisha, Qasim, Rekha). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
(a) Write the output of the following queries:
SELECT PName, Ward FROM PATIENT WHERE NOT Ward = 'Maternity';SELECT PName FROM PATIENT WHERE Doctor = 'Dr. Sen' AND Insurance IS NOT NULL;SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';(b) Write SQL queries for the following:
(i)
| PName | Ward |
|---|---|
| Mohan | General |
| Nisha | ICU |
| Om | General |
| Qasim | ICU |
| Sahil | General |
Explanation: WHERE keeps only the rows where Ward is not 'Maternity': 5 of the 7 rows match (Mohan, Nisha, Om, Qasim, Sahil). SELECT then shows only the columns PName, Ward.
(ii)
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Doctor is 'Dr. Sen' and Insurance has a value (is not NULL). No row satisfies this, so the result is an empty set. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| PName | AdmitDate |
|---|---|
| Nisha | 2026-09-05 |
| Om | 2026-09-10 |
| Pooja | 2026-09-12 |
| Qasim | 2026-09-15 |
Explanation: WHERE keeps only the rows where AdmitDate is from '2026-09-05' to '2026-09-15' (both included): 4 of the 7 rows match (Nisha, Om, Pooja, Qasim). SELECT then shows only the columns PName, AdmitDate.
(iv)
SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
| PName | Insurance |
|---|---|
| Mohan | LIC |
| Om | Star |
| Pooja | LIC |
| Sahil | Star |
Explanation: WHERE keeps only the rows where Insurance has a value (is not NULL): 4 of the 7 rows match (Mohan, Om, Pooja, Sahil). SELECT then shows only the columns PName, Insurance. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(v)
SELECT PName FROM PATIENT WHERE Insurance IS NULL;
| PName |
|---|
| Nisha |
| Qasim |
| Rekha |
Explanation: WHERE keeps only the rows where Insurance is empty (NULL): 3 of the 7 rows match (Nisha, Qasim, Rekha). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
(a) Write the output of the following queries:
SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 40000;SELECT EName, Dept FROM EMPLOYEE WHERE NOT Dept = 'IT';(b) Write SQL queries for the following:
(i)
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
(ii)
| EName | Salary |
|---|---|
| Ravi | 42000 |
| Seema | 58000 |
| Tarun | 75000 |
| Vikas | 64000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is more than 40000: 5 of the 7 rows match (Ravi, Seema, Tarun, Vikas, Yamini). SELECT then shows only the columns EName, Salary.
(iii)
| EName | Dept |
|---|---|
| Ravi | Sales |
| Seema | HR |
| Usha | Sales |
| Wasim | HR |
Explanation: WHERE keeps only the rows where Dept is not 'IT': 4 of the 7 rows match (Ravi, Seema, Usha, Wasim). SELECT then shows only the columns EName, Dept.
(iv)
SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';
| EName | DOJ |
|---|---|
| Ravi | 2018-06-01 |
| Seema | 2020-01-15 |
| Vikas | 2019-11-05 |
Explanation: WHERE keeps only the rows where DOJ is from '2018-01-01' to '2020-12-31' (both included): 3 of the 7 rows match (Ravi, Seema, Vikas). SELECT then shows only the columns EName, DOJ.
(v)
SELECT EName FROM EMPLOYEE WHERE Dept = 'IT' AND Salary >= 40000;
| EName |
|---|
| Tarun |
| Vikas |
| Yamini |
Explanation: WHERE keeps only the rows where Dept is 'IT' and Salary is at least 40000: 3 of the 7 rows match (Tarun, Vikas, Yamini). SELECT then shows only the column EName.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
(a) Write the output of the following queries:
SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';SELECT PName, Fee FROM PATIENT WHERE Fee < 4000 OR Insurance IS NULL;SELECT PName, Ward FROM PATIENT WHERE Ward = 'ICU' OR Ward = 'General';(b) Write SQL queries for the following:
(i)
| PName | AdmitDate |
|---|---|
| Nisha | 2026-09-05 |
| Om | 2026-09-10 |
| Pooja | 2026-09-12 |
| Qasim | 2026-09-15 |
Explanation: WHERE keeps only the rows where AdmitDate is from '2026-09-05' to '2026-09-15' (both included): 4 of the 7 rows match (Nisha, Om, Pooja, Qasim). SELECT then shows only the columns PName, AdmitDate.
(ii)
| PName | Fee |
|---|---|
| Mohan | 1500 |
| Nisha | 8000 |
| Om | 1200 |
| Qasim | 9500 |
| Rekha | 4500 |
| Sahil | 900 |
Explanation: WHERE keeps only the rows where Fee is less than 4000 or Insurance is empty (NULL): 6 of the 7 rows match (Mohan, Nisha, Om, Qasim, Rekha, Sahil). SELECT then shows only the columns PName, Fee. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| PName | Ward |
|---|---|
| Mohan | General |
| Nisha | ICU |
| Om | General |
| Qasim | ICU |
| Sahil | General |
Explanation: WHERE keeps only the rows where Ward is 'ICU' or Ward is 'General': 5 of the 7 rows match (Mohan, Nisha, Om, Qasim, Sahil). SELECT then shows only the columns PName, Ward.
(iv)
SELECT PID, PName, Fee FROM PATIENT WHERE Fee BETWEEN 4000 AND 6000;
| PID | PName | Fee |
|---|---|---|
| 14 | Pooja | 5000 |
| 16 | Rekha | 4500 |
Explanation: WHERE keeps only the rows where Fee is from 4000 to 6000 (both included): 2 of the 7 rows match (Pooja, Rekha). SELECT then shows only the columns PID, PName, Fee.
(v)
SELECT PName, Fee FROM PATIENT WHERE Fee > 4000;
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Pooja | 5000 |
| Qasim | 9500 |
| Rekha | 4500 |
Explanation: WHERE keeps only the rows where Fee is more than 4000: 4 of the 7 rows match (Nisha, Pooja, Qasim, Rekha). SELECT then shows only the columns PName, Fee.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
(a) Write the output of the following queries:
SELECT Title FROM BOOK WHERE Publisher = 'NCERT' AND Member IS NOT NULL;SELECT Title, Subject FROM BOOK WHERE NOT Subject = 'Biography';SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'NCERT';(b) Write SQL queries for the following:
(i)
| Title |
|---|
| Informatics Practices |
| Chemistry Part 1 |
Explanation: WHERE keeps only the rows where Publisher is 'NCERT' and Member has a value (is not NULL): 2 of the 7 rows match (Informatics Practices, Chemistry Part 1). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
| Title | Subject |
|---|---|
| Informatics Practices | Computer |
| Physics Part 1 | Science |
| Python Basics | Computer |
| Chemistry Part 1 | Science |
| Learn SQL | Computer |
Explanation: WHERE keeps only the rows where Subject is not 'Biography': 5 of the 7 rows match (Informatics Practices, Physics Part 1, Python Basics, Chemistry Part 1, Learn SQL). SELECT then shows only the columns Title, Subject.
(iii)
| Title | Publisher |
|---|---|
| Wings of Fire | Universities |
| Python Basics | BPB |
| The Story of My Experiments | Penguin |
| Learn SQL | BPB |
Explanation: WHERE keeps only the rows where Publisher is not 'NCERT': 4 of the 7 rows match (Wings of Fire, Python Basics, The Story of My Experiments, Learn SQL). SELECT then shows only the columns Title, Publisher.
(iv)
SELECT Title FROM BOOK WHERE Subject = 'Biography' AND Price >= 250;
| Title |
|---|
| Wings of Fire |
| The Story of My Experiments |
Explanation: WHERE keeps only the rows where Subject is 'Biography' and Price is at least 250: 2 of the 7 rows match (Wings of Fire, The Story of My Experiments). SELECT then shows only the column Title.
(v)
SELECT Title FROM BOOK WHERE Member IS NULL;
| Title |
|---|
| Physics Part 1 |
| Python Basics |
| The Story of My Experiments |
Explanation: WHERE keeps only the rows where Member is empty (NULL): 3 of the 7 rows match (Physics Part 1, Python Basics, The Story of My Experiments). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
(a) Write the output of the following queries:
SELECT PName FROM PATIENT WHERE Insurance IS NULL;SELECT PName FROM PATIENT WHERE Ward = 'Maternity' AND Fee >= 6000;SELECT PName, Fee FROM PATIENT WHERE Fee < 1000 OR Insurance IS NULL;(b) Write SQL queries for the following:
(i)
| PName |
|---|
| Nisha |
| Qasim |
| Rekha |
Explanation: WHERE keeps only the rows where Insurance is empty (NULL): 3 of the 7 rows match (Nisha, Qasim, Rekha). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Ward is 'Maternity' and Fee is at least 6000. No row satisfies this, so the result is an empty set.
(iii)
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Qasim | 9500 |
| Rekha | 4500 |
| Sahil | 900 |
Explanation: WHERE keeps only the rows where Fee is less than 1000 or Insurance is empty (NULL): 4 of the 7 rows match (Nisha, Qasim, Rekha, Sahil). SELECT then shows only the columns PName, Fee. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT PName FROM PATIENT WHERE Doctor = 'Dr. Iyer' AND Insurance IS NOT NULL;
| PName |
|---|
| Pooja |
Explanation: WHERE keeps only the rows where Doctor is 'Dr. Iyer' and Insurance has a value (is not NULL): 1 of the 7 rows matches (Pooja). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(v)
SELECT * FROM PATIENT WHERE Ward = 'Maternity';
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
Explanation: WHERE keeps only the rows where Ward is 'Maternity': 2 of the 7 rows match (Pooja, Rekha). SELECT then shows all the columns (*).
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
(a) Write the output of the following queries:
SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 70000;SELECT EName, Bonus FROM EMPLOYEE WHERE Bonus IS NOT NULL;(b) Write SQL queries for the following:
(i)
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
(ii)
| EName | Salary |
|---|---|
| Tarun | 75000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is more than 70000: 2 of the 7 rows match (Tarun, Yamini). SELECT then shows only the columns EName, Salary.
(iii)
| EName | Bonus |
|---|---|
| Ravi | 3000 |
| Tarun | 5000 |
| Vikas | 4000 |
| Wasim | 2000 |
Explanation: WHERE keeps only the rows where Bonus has a value (is not NULL): 4 of the 7 rows match (Ravi, Tarun, Vikas, Wasim). SELECT then shows only the columns EName, Bonus. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'IT' OR Dept = 'Sales';
| EName | Dept |
|---|---|
| Ravi | Sales |
| Tarun | IT |
| Usha | Sales |
| Vikas | IT |
| Yamini | IT |
Explanation: WHERE keeps only the rows where Dept is 'IT' or Dept is 'Sales': 5 of the 7 rows match (Ravi, Tarun, Usha, Vikas, Yamini). SELECT then shows only the columns EName, Dept.
(v)
SELECT EName FROM EMPLOYEE WHERE Bonus IS NULL;
| EName |
|---|
| Seema |
| Usha |
| Yamini |
Explanation: WHERE keeps only the rows where Bonus is empty (NULL): 3 of the 7 rows match (Seema, Usha, Yamini). SELECT then shows only the column EName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
(a) Write the output of the following queries:
SELECT PName FROM PRODUCT WHERE Brand = 'Camlin' AND Discount IS NOT NULL;SELECT PName FROM PRODUCT WHERE Discount IS NULL;SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 400 AND 500;(b) Write SQL queries for the following:
(i)
| PName |
|---|
| Geometry Box |
Explanation: WHERE keeps only the rows where Brand is 'Camlin' and Discount has a value (is not NULL): 1 of the 7 rows matches (Geometry Box). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
| PName |
|---|
| Pen Drive |
| Water Bottle |
Explanation: WHERE keeps only the rows where Discount is empty (NULL): 2 of the 7 rows match (Pen Drive, Water Bottle). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| PCode | PName | Price |
|---|---|---|
| P02 | Pen Drive | 450 |
Explanation: WHERE keeps only the rows where Price is from 400 to 500 (both included): 1 of the 7 rows matches (Pen Drive). SELECT then shows only the columns PCode, PName, Price.
(iv)
SELECT PCode, Price, Price + 10 FROM PRODUCT;
| PCode | Price | Price + 10 |
|---|---|---|
| P01 | 60 | 70 |
| P02 | 450 | 460 |
| P03 | 180 | 190 |
| P04 | 650 | 660 |
| P05 | 320 | 330 |
| P06 | 899 | 909 |
| P07 | 275 | 285 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PCode, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
(v)
SELECT PName, MfgDate FROM PRODUCT WHERE MfgDate BETWEEN '2025-10-01' AND '2026-01-31';
| PName | MfgDate |
|---|---|
| Notebook | 2026-01-10 |
| Geometry Box | 2025-11-02 |
| Lunch Box | 2025-12-18 |
Explanation: WHERE keeps only the rows where MfgDate is from '2025-10-01' to '2026-01-31' (both included): 3 of the 7 rows match (Notebook, Geometry Box, Lunch Box). SELECT then shows only the columns PName, MfgDate.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
(a) Write the output of the following queries:
SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'Sales' OR Dept = 'IT';SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 60000;SELECT EName FROM EMPLOYEE WHERE Dept = 'HR' AND Salary >= 60000;(b) Write SQL queries for the following:
(i)
| EName | Dept |
|---|---|
| Ravi | Sales |
| Tarun | IT |
| Usha | Sales |
| Vikas | IT |
| Yamini | IT |
Explanation: WHERE keeps only the rows where Dept is 'Sales' or Dept is 'IT': 5 of the 7 rows match (Ravi, Tarun, Usha, Vikas, Yamini). SELECT then shows only the columns EName, Dept.
(ii)
| EName | Salary |
|---|---|
| Tarun | 75000 |
| Vikas | 64000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is more than 60000: 3 of the 7 rows match (Tarun, Vikas, Yamini). SELECT then shows only the columns EName, Salary.
(iii)
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Dept is 'HR' and Salary is at least 60000. No row satisfies this, so the result is an empty set.
(iv)
SELECT EName, Dept FROM EMPLOYEE WHERE NOT Dept = 'HR';
| EName | Dept |
|---|---|
| Ravi | Sales |
| Tarun | IT |
| Usha | Sales |
| Vikas | IT |
| Yamini | IT |
Explanation: WHERE keeps only the rows where Dept is not 'HR': 5 of the 7 rows match (Ravi, Tarun, Usha, Vikas, Yamini). SELECT then shows only the columns EName, Dept.
(v)
SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';
| EName | DOJ |
|---|---|
| Ravi | 2018-06-01 |
| Seema | 2020-01-15 |
| Vikas | 2019-11-05 |
Explanation: WHERE keeps only the rows where DOJ is from '2018-01-01' to '2020-12-31' (both included): 3 of the 7 rows match (Ravi, Seema, Vikas). SELECT then shows only the columns EName, DOJ.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
(a) Write the output of the following queries:
SELECT Name FROM STUDENT WHERE Gender = 'F' AND Phone IS NOT NULL;SELECT Name, Marks FROM STUDENT WHERE Marks > 80;SELECT Name, Section FROM STUDENT WHERE NOT Section = 'A';(b) Write SQL queries for the following:
(i)
| Name |
|---|
| Divya |
| Farah |
Explanation: WHERE keeps only the rows where Gender is 'F' and Phone has a value (is not NULL): 2 of the 7 rows match (Divya, Farah). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
| Name | Marks |
|---|---|
| Bhavya | 92 |
| Eshan | 88 |
Explanation: WHERE keeps only the rows where Marks is more than 80: 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the columns Name, Marks.
(iii)
| Name | Section |
|---|---|
| Bhavya | B |
| Divya | C |
| Eshan | B |
| Gaurav | C |
Explanation: WHERE keeps only the rows where Section is not 'A': 4 of the 7 rows match (Bhavya, Divya, Eshan, Gaurav). SELECT then shows only the columns Name, Section.
(iv)
SELECT * FROM STUDENT WHERE Section = 'A';
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
Explanation: WHERE keeps only the rows where Section is 'A': 3 of the 7 rows match (Aarav, Chirag, Farah). SELECT then shows all the columns (*).
(v)
SELECT Name, Gender FROM STUDENT WHERE Gender <> 'F';
| Name | Gender |
|---|---|
| Aarav | M |
| Chirag | M |
| Eshan | M |
| Gaurav | M |
Explanation: WHERE keeps only the rows where Gender is not 'F': 4 of the 7 rows match (Aarav, Chirag, Eshan, Gaurav). SELECT then shows only the columns Name, Gender.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
(a) Write the output of the following queries:
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Delhi';SELECT * FROM EMPLOYEE WHERE Dept = 'Sales';SELECT EName FROM EMPLOYEE WHERE City = 'Delhi' AND Bonus IS NOT NULL;(b) Write SQL queries for the following:
(i)
| EName | City |
|---|---|
| Seema | Pune |
| Usha | Mumbai |
| Vikas | Pune |
| Yamini | Mumbai |
Explanation: WHERE keeps only the rows where City is not 'Delhi': 4 of the 7 rows match (Seema, Usha, Vikas, Yamini). SELECT then shows only the columns EName, City.
(ii)
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
Explanation: WHERE keeps only the rows where Dept is 'Sales': 2 of the 7 rows match (Ravi, Usha). SELECT then shows all the columns (*).
(iii)
| EName |
|---|
| Ravi |
| Tarun |
| Wasim |
Explanation: WHERE keeps only the rows where City is 'Delhi' and Bonus has a value (is not NULL): 3 of the 7 rows match (Ravi, Tarun, Wasim). SELECT then shows only the column EName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 60000 AND 70000;
| EmpID | EName | Salary |
|---|---|---|
| E105 | Vikas | 64000 |
Explanation: WHERE keeps only the rows where Salary is from 60000 to 70000 (both included): 1 of the 7 rows matches (Vikas). SELECT then shows only the columns EmpID, EName, Salary.
(v)
SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'HR' OR Dept = 'Sales';
| EName | Dept |
|---|---|
| Ravi | Sales |
| Seema | HR |
| Usha | Sales |
| Wasim | HR |
Explanation: WHERE keeps only the rows where Dept is 'HR' or Dept is 'Sales': 4 of the 7 rows match (Ravi, Seema, Usha, Wasim). SELECT then shows only the columns EName, Dept.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
(a) Write the output of the following queries:
SELECT PName FROM PRODUCT WHERE Category = 'Electronics' AND Price >= 300;SELECT PName FROM PRODUCT WHERE Discount IS NULL;SELECT * FROM PRODUCT WHERE Category = 'Electronics';(b) Write SQL queries for the following:
(i)
| PName |
|---|
| Pen Drive |
| Mouse |
| Earphones |
Explanation: WHERE keeps only the rows where Category is 'Electronics' and Price is at least 300: 3 of the 7 rows match (Pen Drive, Mouse, Earphones). SELECT then shows only the column PName.
(ii)
| PName |
|---|
| Pen Drive |
| Water Bottle |
Explanation: WHERE keeps only the rows where Discount is empty (NULL): 2 of the 7 rows match (Pen Drive, Water Bottle). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
Explanation: WHERE keeps only the rows where Category is 'Electronics': 3 of the 7 rows match (Pen Drive, Mouse, Earphones). SELECT then shows all the columns (*).
(iv)
SELECT PName, Brand FROM PRODUCT WHERE Brand <> 'Boat';
| PName | Brand |
|---|---|
| Notebook | Classmate |
| Pen Drive | SanDisk |
| Geometry Box | Camlin |
| Mouse | Logitech |
| Water Bottle | Milton |
| Lunch Box | Milton |
Explanation: WHERE keeps only the rows where Brand is not 'Boat': 6 of the 7 rows match (Notebook, Pen Drive, Geometry Box, Mouse, Water Bottle, Lunch Box). SELECT then shows only the columns PName, Brand.
(v)
SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
| PName | Discount |
|---|---|
| Notebook | 5 |
| Geometry Box | 10 |
| Mouse | 15 |
| Earphones | 20 |
| Lunch Box | 8 |
Explanation: WHERE keeps only the rows where Discount has a value (is not NULL): 5 of the 7 rows match (Notebook, Geometry Box, Mouse, Earphones, Lunch Box). SELECT then shows only the columns PName, Discount. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
(a) Write the output of the following queries:
SELECT PCode, Price, Price + 10 FROM PRODUCT;SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Home';SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 400 AND 500;(b) Write SQL queries for the following:
(i)
| PCode | Price | Price + 10 |
|---|---|---|
| P01 | 60 | 70 |
| P02 | 450 | 460 |
| P03 | 180 | 190 |
| P04 | 650 | 660 |
| P05 | 320 | 330 |
| P06 | 899 | 909 |
| P07 | 275 | 285 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PCode, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
(ii)
| PName | Category |
|---|---|
| Notebook | Stationery |
| Pen Drive | Electronics |
| Geometry Box | Stationery |
| Mouse | Electronics |
| Earphones | Electronics |
Explanation: WHERE keeps only the rows where Category is not 'Home': 5 of the 7 rows match (Notebook, Pen Drive, Geometry Box, Mouse, Earphones). SELECT then shows only the columns PName, Category.
(iii)
| PCode | PName | Price |
|---|---|---|
| P02 | Pen Drive | 450 |
Explanation: WHERE keeps only the rows where Price is from 400 to 500 (both included): 1 of the 7 rows matches (Pen Drive). SELECT then shows only the columns PCode, PName, Price.
(iv)
SELECT PName FROM PRODUCT WHERE Discount IS NULL;
| PName |
|---|
| Pen Drive |
| Water Bottle |
Explanation: WHERE keeps only the rows where Discount is empty (NULL): 2 of the 7 rows match (Pen Drive, Water Bottle). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(v)
SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
| PName | Discount |
|---|---|
| Notebook | 5 |
| Geometry Box | 10 |
| Mouse | 15 |
| Earphones | 20 |
| Lunch Box | 8 |
Explanation: WHERE keeps only the rows where Discount has a value (is not NULL): 5 of the 7 rows match (Notebook, Geometry Box, Mouse, Earphones, Lunch Box). SELECT then shows only the columns PName, Discount. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
(a) Write the output of the following queries:
SELECT Title, Subject FROM BOOK WHERE Subject = 'Computer' OR Subject = 'Science';SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'NCERT';SELECT Title, Price FROM BOOK WHERE Price < 250 OR Member IS NULL;(b) Write SQL queries for the following:
(i)
| Title | Subject |
|---|---|
| Informatics Practices | Computer |
| Physics Part 1 | Science |
| Python Basics | Computer |
| Chemistry Part 1 | Science |
| Learn SQL | Computer |
Explanation: WHERE keeps only the rows where Subject is 'Computer' or Subject is 'Science': 5 of the 7 rows match (Informatics Practices, Physics Part 1, Python Basics, Chemistry Part 1, Learn SQL). SELECT then shows only the columns Title, Subject.
(ii)
| Title | Publisher |
|---|---|
| Wings of Fire | Universities |
| Python Basics | BPB |
| The Story of My Experiments | Penguin |
| Learn SQL | BPB |
Explanation: WHERE keeps only the rows where Publisher is not 'NCERT': 4 of the 7 rows match (Wings of Fire, Python Basics, The Story of My Experiments, Learn SQL). SELECT then shows only the columns Title, Publisher.
(iii)
| Title | Price |
|---|---|
| Informatics Practices | 210 |
| Physics Part 1 | 180 |
| Python Basics | 350 |
| Chemistry Part 1 | 190 |
| The Story of My Experiments | 250 |
Explanation: WHERE keeps only the rows where Price is less than 250 or Member is empty (NULL): 5 of the 7 rows match (Informatics Practices, Physics Part 1, Python Basics, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT Title FROM BOOK WHERE Publisher = 'NCERT' AND Member IS NOT NULL;
| Title |
|---|
| Informatics Practices |
| Chemistry Part 1 |
Explanation: WHERE keeps only the rows where Publisher is 'NCERT' and Member has a value (is not NULL): 2 of the 7 rows match (Informatics Practices, Chemistry Part 1). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(v)
SELECT Title, Member FROM BOOK WHERE Member IS NOT NULL;
| Title | Member |
|---|---|
| Informatics Practices | Asha |
| Wings of Fire | Ravi |
| Chemistry Part 1 | Neha |
| Learn SQL | Karan |
Explanation: WHERE keeps only the rows where Member has a value (is not NULL): 4 of the 7 rows match (Informatics Practices, Wings of Fire, Chemistry Part 1, Learn SQL). SELECT then shows only the columns Title, Member. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
(a) Write the output of the following queries:
SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';SELECT * FROM STUDENT WHERE Section = 'C';SELECT Name FROM STUDENT WHERE Phone IS NULL;(b) Write SQL queries for the following:
(i)
| Name | DOB |
|---|---|
| Bhavya | 2009-11-30 |
| Divya | 2009-07-21 |
| Farah | 2009-09-09 |
Explanation: WHERE keeps only the rows where DOB is from '2009-06-01' to '2009-12-31' (both included): 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, DOB.
(ii)
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Explanation: WHERE keeps only the rows where Section is 'C': 2 of the 7 rows match (Divya, Gaurav). SELECT then shows all the columns (*).
(iii)
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Phone is empty (NULL): 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT Name, Marks FROM STUDENT WHERE Marks > 60;
| Name | Marks |
|---|---|
| Aarav | 78 |
| Bhavya | 92 |
| Divya | 66 |
| Eshan | 88 |
Explanation: WHERE keeps only the rows where Marks is more than 60: 4 of the 7 rows match (Aarav, Bhavya, Divya, Eshan). SELECT then shows only the columns Name, Marks.
(v)
SELECT Name FROM STUDENT WHERE Gender = 'F' AND Phone IS NOT NULL;
| Name |
|---|
| Divya |
| Farah |
Explanation: WHERE keeps only the rows where Gender is 'F' and Phone has a value (is not NULL): 2 of the 7 rows match (Divya, Farah). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
(a) Write the output of the following queries:
SELECT EName, Salary FROM EMPLOYEE WHERE Salary < 50000 OR Bonus IS NULL;SELECT EName FROM EMPLOYEE WHERE Dept = 'IT' AND Salary >= 40000;SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';(b) Write SQL queries for the following:
(i)
| EName | Salary |
|---|---|
| Ravi | 42000 |
| Seema | 58000 |
| Usha | 36000 |
| Wasim | 39000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is less than 50000 or Bonus is empty (NULL): 5 of the 7 rows match (Ravi, Seema, Usha, Wasim, Yamini). SELECT then shows only the columns EName, Salary. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
| EName |
|---|
| Tarun |
| Vikas |
| Yamini |
Explanation: WHERE keeps only the rows where Dept is 'IT' and Salary is at least 40000: 3 of the 7 rows match (Tarun, Vikas, Yamini). SELECT then shows only the column EName.
(iii)
| EName | DOJ |
|---|---|
| Ravi | 2018-06-01 |
| Seema | 2020-01-15 |
| Vikas | 2019-11-05 |
Explanation: WHERE keeps only the rows where DOJ is from '2018-01-01' to '2020-12-31' (both included): 3 of the 7 rows match (Ravi, Seema, Vikas). SELECT then shows only the columns EName, DOJ.
(iv)
SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
(v)
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Mumbai';
| EName | City |
|---|---|
| Ravi | Delhi |
| Seema | Pune |
| Tarun | Delhi |
| Vikas | Pune |
| Wasim | Delhi |
Explanation: WHERE keeps only the rows where City is not 'Mumbai': 5 of the 7 rows match (Ravi, Seema, Tarun, Vikas, Wasim). SELECT then shows only the columns EName, City.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
(a) Write the output of the following queries:
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Delhi';SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 70000;SELECT EName, Bonus FROM EMPLOYEE WHERE Bonus IS NOT NULL;(b) Write SQL queries for the following:
(i)
| EName | City |
|---|---|
| Seema | Pune |
| Usha | Mumbai |
| Vikas | Pune |
| Yamini | Mumbai |
Explanation: WHERE keeps only the rows where City is not 'Delhi': 4 of the 7 rows match (Seema, Usha, Vikas, Yamini). SELECT then shows only the columns EName, City.
(ii)
| EmpID | EName | Salary |
|---|---|---|
| E101 | Ravi | 42000 |
| E102 | Seema | 58000 |
| E105 | Vikas | 64000 |
Explanation: WHERE keeps only the rows where Salary is from 40000 to 70000 (both included): 3 of the 7 rows match (Ravi, Seema, Vikas). SELECT then shows only the columns EmpID, EName, Salary.
(iii)
| EName | Bonus |
|---|---|
| Ravi | 3000 |
| Tarun | 5000 |
| Vikas | 4000 |
| Wasim | 2000 |
Explanation: WHERE keeps only the rows where Bonus has a value (is not NULL): 4 of the 7 rows match (Ravi, Tarun, Vikas, Wasim). SELECT then shows only the columns EName, Bonus. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 50000;
| EName | Salary |
|---|---|
| Seema | 58000 |
| Tarun | 75000 |
| Vikas | 64000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is more than 50000: 4 of the 7 rows match (Seema, Tarun, Vikas, Yamini). SELECT then shows only the columns EName, Salary.
(v)
SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'IT' OR Dept = 'Sales';
| EName | Dept |
|---|---|
| Ravi | Sales |
| Tarun | IT |
| Usha | Sales |
| Vikas | IT |
| Yamini | IT |
Explanation: WHERE keeps only the rows where Dept is 'IT' or Dept is 'Sales': 5 of the 7 rows match (Ravi, Tarun, Usha, Vikas, Yamini). SELECT then shows only the columns EName, Dept.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
(a) Write the output of the following queries:
SELECT PName, Fee FROM PATIENT WHERE Fee < 1000 OR Insurance IS NULL;SELECT PName FROM PATIENT WHERE Insurance IS NULL;SELECT * FROM PATIENT WHERE Ward = 'General';(b) Write SQL queries for the following:
(i)
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Qasim | 9500 |
| Rekha | 4500 |
| Sahil | 900 |
Explanation: WHERE keeps only the rows where Fee is less than 1000 or Insurance is empty (NULL): 4 of the 7 rows match (Nisha, Qasim, Rekha, Sahil). SELECT then shows only the columns PName, Fee. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
| PName |
|---|
| Nisha |
| Qasim |
| Rekha |
Explanation: WHERE keeps only the rows where Insurance is empty (NULL): 3 of the 7 rows match (Nisha, Qasim, Rekha). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
Explanation: WHERE keeps only the rows where Ward is 'General': 3 of the 7 rows match (Mohan, Om, Sahil). SELECT then shows all the columns (*).
(iv)
SELECT PName, Ward FROM PATIENT WHERE NOT Ward = 'General';
| PName | Ward |
|---|---|
| Nisha | ICU |
| Pooja | Maternity |
| Qasim | ICU |
| Rekha | Maternity |
Explanation: WHERE keeps only the rows where Ward is not 'General': 4 of the 7 rows match (Nisha, Pooja, Qasim, Rekha). SELECT then shows only the columns PName, Ward.
(v)
SELECT PName, Fee FROM PATIENT WHERE Fee > 1000;
| PName | Fee |
|---|---|
| Mohan | 1500 |
| Nisha | 8000 |
| Om | 1200 |
| Pooja | 5000 |
| Qasim | 9500 |
| Rekha | 4500 |
Explanation: WHERE keeps only the rows where Fee is more than 1000: 6 of the 7 rows match (Mohan, Nisha, Om, Pooja, Qasim, Rekha). SELECT then shows only the columns PName, Fee.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
(a) Write the output of the following queries:
SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'Sales' OR Dept = 'IT';SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 60000;SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 60000;(b) Write SQL queries for the following:
(i)
| EName | Dept |
|---|---|
| Ravi | Sales |
| Tarun | IT |
| Usha | Sales |
| Vikas | IT |
| Yamini | IT |
Explanation: WHERE keeps only the rows where Dept is 'Sales' or Dept is 'IT': 5 of the 7 rows match (Ravi, Tarun, Usha, Vikas, Yamini). SELECT then shows only the columns EName, Dept.
(ii)
| EName | Salary |
|---|---|
| Tarun | 75000 |
| Vikas | 64000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is more than 60000: 3 of the 7 rows match (Tarun, Vikas, Yamini). SELECT then shows only the columns EName, Salary.
(iii)
| EmpID | EName | Salary |
|---|---|---|
| E101 | Ravi | 42000 |
| E102 | Seema | 58000 |
Explanation: WHERE keeps only the rows where Salary is from 40000 to 60000 (both included): 2 of the 7 rows match (Ravi, Seema). SELECT then shows only the columns EmpID, EName, Salary.
(iv)
SELECT EName FROM EMPLOYEE WHERE City = 'Mumbai' AND Bonus IS NOT NULL;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where City is 'Mumbai' and Bonus has a value (is not NULL). No row satisfies this, so the result is an empty set. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(v)
SELECT * FROM EMPLOYEE WHERE Dept = 'Sales';
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
Explanation: WHERE keeps only the rows where Dept is 'Sales': 2 of the 7 rows match (Ravi, Usha). SELECT then shows all the columns (*).
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
(a) Write the output of the following queries:
SELECT Name FROM STUDENT WHERE Gender = 'F' AND Phone IS NOT NULL;SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 60 AND 80;SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';(b) Write SQL queries for the following:
(i)
| Name |
|---|
| Divya |
| Farah |
Explanation: WHERE keeps only the rows where Gender is 'F' and Phone has a value (is not NULL): 2 of the 7 rows match (Divya, Farah). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
| RollNo | Name | Marks |
|---|---|---|
| 1 | Aarav | 78 |
| 4 | Divya | 66 |
Explanation: WHERE keeps only the rows where Marks is from 60 to 80 (both included): 2 of the 7 rows match (Aarav, Divya). SELECT then shows only the columns RollNo, Name, Marks.
(iii)
| Name | DOB |
|---|---|
| Bhavya | 2009-11-30 |
| Divya | 2009-07-21 |
| Farah | 2009-09-09 |
Explanation: WHERE keeps only the rows where DOB is from '2009-06-01' to '2009-12-31' (both included): 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, DOB.
(iv)
SELECT Name, Section FROM STUDENT WHERE Section = 'A' OR Section = 'B';
| Name | Section |
|---|---|
| Aarav | A |
| Bhavya | B |
| Chirag | A |
| Eshan | B |
| Farah | A |
Explanation: WHERE keeps only the rows where Section is 'A' or Section is 'B': 5 of the 7 rows match (Aarav, Bhavya, Chirag, Eshan, Farah). SELECT then shows only the columns Name, Section.
(v)
SELECT RollNo, Marks, Marks + 10 FROM STUDENT;
| RollNo | Marks | Marks + 10 |
|---|---|---|
| 1 | 78 | 88 |
| 2 | 92 | 102 |
| 3 | 45 | 55 |
| 4 | 66 | 76 |
| 5 | 88 | 98 |
| 6 | 31 | 41 |
| 7 | 59 | 69 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns RollNo, Marks, Marks + 10. The expression is calculated for every row; the table itself does not change.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
(a) Write the output of the following queries:
SELECT Name, Section FROM STUDENT WHERE NOT Section = 'A';SELECT RollNo, Marks, Marks + 10 FROM STUDENT;SELECT Name FROM STUDENT WHERE Gender = 'F' AND Phone IS NOT NULL;(b) Write SQL queries for the following:
(i)
| Name | Section |
|---|---|
| Bhavya | B |
| Divya | C |
| Eshan | B |
| Gaurav | C |
Explanation: WHERE keeps only the rows where Section is not 'A': 4 of the 7 rows match (Bhavya, Divya, Eshan, Gaurav). SELECT then shows only the columns Name, Section.
(ii)
| RollNo | Marks | Marks + 10 |
|---|---|---|
| 1 | 78 | 88 |
| 2 | 92 | 102 |
| 3 | 45 | 55 |
| 4 | 66 | 76 |
| 5 | 88 | 98 |
| 6 | 31 | 41 |
| 7 | 59 | 69 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns RollNo, Marks, Marks + 10. The expression is calculated for every row; the table itself does not change.
(iii)
| Name |
|---|
| Divya |
| Farah |
Explanation: WHERE keeps only the rows where Gender is 'F' and Phone has a value (is not NULL): 2 of the 7 rows match (Divya, Farah). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 70 AND 80;
| RollNo | Name | Marks |
|---|---|---|
| 1 | Aarav | 78 |
Explanation: WHERE keeps only the rows where Marks is from 70 to 80 (both included): 1 of the 7 rows matches (Aarav). SELECT then shows only the columns RollNo, Name, Marks.
(v)
SELECT * FROM STUDENT WHERE Section = 'A';
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
Explanation: WHERE keeps only the rows where Section is 'A': 3 of the 7 rows match (Aarav, Chirag, Farah). SELECT then shows all the columns (*).
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
(a) Write the output of the following queries:
SELECT PName FROM PATIENT WHERE Insurance IS NULL;SELECT PID, Fee, Fee + 10 FROM PATIENT;SELECT PName FROM PATIENT WHERE Doctor = 'Dr. Sen' AND Insurance IS NOT NULL;(b) Write SQL queries for the following:
(i)
| PName |
|---|
| Nisha |
| Qasim |
| Rekha |
Explanation: WHERE keeps only the rows where Insurance is empty (NULL): 3 of the 7 rows match (Nisha, Qasim, Rekha). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
| PID | Fee | Fee + 10 |
|---|---|---|
| 11 | 1500 | 1510 |
| 12 | 8000 | 8010 |
| 13 | 1200 | 1210 |
| 14 | 5000 | 5010 |
| 15 | 9500 | 9510 |
| 16 | 4500 | 4510 |
| 17 | 900 | 910 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PID, Fee, Fee + 10. The expression is calculated for every row; the table itself does not change.
(iii)
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Doctor is 'Dr. Sen' and Insurance has a value (is not NULL). No row satisfies this, so the result is an empty set. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT PName, Fee FROM PATIENT WHERE Fee < 1000 OR Insurance IS NULL;
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Qasim | 9500 |
| Rekha | 4500 |
| Sahil | 900 |
Explanation: WHERE keeps only the rows where Fee is less than 1000 or Insurance is empty (NULL): 4 of the 7 rows match (Nisha, Qasim, Rekha, Sahil). SELECT then shows only the columns PName, Fee. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(v)
SELECT PID, PName, Fee FROM PATIENT WHERE Fee BETWEEN 1000 AND 4000;
| PID | PName | Fee |
|---|---|---|
| 11 | Mohan | 1500 |
| 13 | Om | 1200 |
Explanation: WHERE keeps only the rows where Fee is from 1000 to 4000 (both included): 2 of the 7 rows match (Mohan, Om). SELECT then shows only the columns PID, PName, Fee.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
(a) Write the output of the following queries:
SELECT BookID, Price, Price + 10 FROM BOOK;SELECT Title FROM BOOK WHERE Member IS NULL;SELECT Title FROM BOOK WHERE Publisher = 'BPB' AND Member IS NOT NULL;(b) Write SQL queries for the following:
(i)
| BookID | Price | Price + 10 |
|---|---|---|
| 201 | 210 | 220 |
| 202 | 180 | 190 |
| 203 | 299 | 309 |
| 204 | 350 | 360 |
| 205 | 190 | 200 |
| 206 | 250 | 260 |
| 207 | 400 | 410 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns BookID, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
(ii)
| Title |
|---|
| Physics Part 1 |
| Python Basics |
| The Story of My Experiments |
Explanation: WHERE keeps only the rows where Member is empty (NULL): 3 of the 7 rows match (Physics Part 1, Python Basics, The Story of My Experiments). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| Title |
|---|
| Learn SQL |
Explanation: WHERE keeps only the rows where Publisher is 'BPB' and Member has a value (is not NULL): 1 of the 7 rows matches (Learn SQL). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT Title, Subject FROM BOOK WHERE Subject = 'Biography' OR Subject = 'Computer';
| Title | Subject |
|---|---|
| Informatics Practices | Computer |
| Wings of Fire | Biography |
| Python Basics | Computer |
| The Story of My Experiments | Biography |
| Learn SQL | Computer |
Explanation: WHERE keeps only the rows where Subject is 'Biography' or Subject is 'Computer': 5 of the 7 rows match (Informatics Practices, Wings of Fire, Python Basics, The Story of My Experiments, Learn SQL). SELECT then shows only the columns Title, Subject.
(v)
SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'BPB';
| Title | Publisher |
|---|---|
| Informatics Practices | NCERT |
| Physics Part 1 | NCERT |
| Wings of Fire | Universities |
| Chemistry Part 1 | NCERT |
| The Story of My Experiments | Penguin |
Explanation: WHERE keeps only the rows where Publisher is not 'BPB': 5 of the 7 rows match (Informatics Practices, Physics Part 1, Wings of Fire, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Publisher.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
(a) Write the output of the following queries:
SELECT Title FROM BOOK WHERE Publisher = 'Penguin' AND Member IS NOT NULL;SELECT Title, Member FROM BOOK WHERE Member IS NOT NULL;SELECT BookID, Price, Price + 10 FROM BOOK;(b) Write SQL queries for the following:
(i)
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Publisher is 'Penguin' and Member has a value (is not NULL). No row satisfies this, so the result is an empty set. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
| Title | Member |
|---|---|
| Informatics Practices | Asha |
| Wings of Fire | Ravi |
| Chemistry Part 1 | Neha |
| Learn SQL | Karan |
Explanation: WHERE keeps only the rows where Member has a value (is not NULL): 4 of the 7 rows match (Informatics Practices, Wings of Fire, Chemistry Part 1, Learn SQL). SELECT then shows only the columns Title, Member. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| BookID | Price | Price + 10 |
|---|---|---|
| 201 | 210 | 220 |
| 202 | 180 | 190 |
| 203 | 299 | 309 |
| 204 | 350 | 360 |
| 205 | 190 | 200 |
| 206 | 250 | 260 |
| 207 | 400 | 410 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns BookID, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
(iv)
SELECT Title FROM BOOK WHERE Member IS NULL;
| Title |
|---|
| Physics Part 1 |
| Python Basics |
| The Story of My Experiments |
Explanation: WHERE keeps only the rows where Member is empty (NULL): 3 of the 7 rows match (Physics Part 1, Python Basics, The Story of My Experiments). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(v)
SELECT BookID, Title, Price FROM BOOK WHERE Price BETWEEN 200 AND 350;
| BookID | Title | Price |
|---|---|---|
| 201 | Informatics Practices | 210 |
| 203 | Wings of Fire | 299 |
| 204 | Python Basics | 350 |
| 206 | The Story of My Experiments | 250 |
Explanation: WHERE keeps only the rows where Price is from 200 to 350 (both included): 4 of the 7 rows match (Informatics Practices, Wings of Fire, Python Basics, The Story of My Experiments). SELECT then shows only the columns BookID, Title, Price.
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
(a) Write the output of the following queries:
SELECT PName, Category FROM PRODUCT WHERE Category = 'Home' OR Category = 'Electronics';SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Home';(b) Write SQL queries for the following:
(i)
| PName | Category |
|---|---|
| Pen Drive | Electronics |
| Mouse | Electronics |
| Water Bottle | Home |
| Earphones | Electronics |
| Lunch Box | Home |
Explanation: WHERE keeps only the rows where Category is 'Home' or Category is 'Electronics': 5 of the 7 rows match (Pen Drive, Mouse, Water Bottle, Earphones, Lunch Box). SELECT then shows only the columns PName, Category.
(ii)
| PName | Discount |
|---|---|
| Notebook | 5 |
| Geometry Box | 10 |
| Mouse | 15 |
| Earphones | 20 |
| Lunch Box | 8 |
Explanation: WHERE keeps only the rows where Discount has a value (is not NULL): 5 of the 7 rows match (Notebook, Geometry Box, Mouse, Earphones, Lunch Box). SELECT then shows only the columns PName, Discount. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| PName | Category |
|---|---|
| Notebook | Stationery |
| Pen Drive | Electronics |
| Geometry Box | Stationery |
| Mouse | Electronics |
| Earphones | Electronics |
Explanation: WHERE keeps only the rows where Category is not 'Home': 5 of the 7 rows match (Notebook, Pen Drive, Geometry Box, Mouse, Earphones). SELECT then shows only the columns PName, Category.
(iv)
SELECT * FROM PRODUCT WHERE Category = 'Home';
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
Explanation: WHERE keeps only the rows where Category is 'Home': 2 of the 7 rows match (Water Bottle, Lunch Box). SELECT then shows all the columns (*).
(v)
SELECT PName FROM PRODUCT WHERE Category = 'Home' AND Price >= 400;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Category is 'Home' and Price is at least 400. No row satisfies this, so the result is an empty set.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
(a) Write the output of the following queries:
SELECT Title, Subject FROM BOOK WHERE Subject = 'Science' OR Subject = 'Biography';SELECT Title, Member FROM BOOK WHERE Member IS NOT NULL;SELECT Title FROM BOOK WHERE Member IS NULL;(b) Write SQL queries for the following:
(i)
| Title | Subject |
|---|---|
| Physics Part 1 | Science |
| Wings of Fire | Biography |
| Chemistry Part 1 | Science |
| The Story of My Experiments | Biography |
Explanation: WHERE keeps only the rows where Subject is 'Science' or Subject is 'Biography': 4 of the 7 rows match (Physics Part 1, Wings of Fire, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Subject.
(ii)
| Title | Member |
|---|---|
| Informatics Practices | Asha |
| Wings of Fire | Ravi |
| Chemistry Part 1 | Neha |
| Learn SQL | Karan |
Explanation: WHERE keeps only the rows where Member has a value (is not NULL): 4 of the 7 rows match (Informatics Practices, Wings of Fire, Chemistry Part 1, Learn SQL). SELECT then shows only the columns Title, Member. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| Title |
|---|
| Physics Part 1 |
| Python Basics |
| The Story of My Experiments |
Explanation: WHERE keeps only the rows where Member is empty (NULL): 3 of the 7 rows match (Physics Part 1, Python Basics, The Story of My Experiments). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT Title FROM BOOK WHERE Publisher = 'Penguin' AND Member IS NOT NULL;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Publisher is 'Penguin' and Member has a value (is not NULL). No row satisfies this, so the result is an empty set. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(v)
SELECT Title, Price FROM BOOK WHERE Price > 300;
| Title | Price |
|---|---|
| Python Basics | 350 |
| Learn SQL | 400 |
Explanation: WHERE keeps only the rows where Price is more than 300: 2 of the 7 rows match (Python Basics, Learn SQL). SELECT then shows only the columns Title, Price.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
(a) Write the output of the following queries:
SELECT Title FROM BOOK WHERE Publisher = 'NCERT' AND Member IS NOT NULL;SELECT Title FROM BOOK WHERE Member IS NULL;SELECT Title FROM BOOK WHERE Subject = 'Computer' AND Price >= 300;(b) Write SQL queries for the following:
(i)
| Title |
|---|
| Informatics Practices |
| Chemistry Part 1 |
Explanation: WHERE keeps only the rows where Publisher is 'NCERT' and Member has a value (is not NULL): 2 of the 7 rows match (Informatics Practices, Chemistry Part 1). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
| Title |
|---|
| Physics Part 1 |
| Python Basics |
| The Story of My Experiments |
Explanation: WHERE keeps only the rows where Member is empty (NULL): 3 of the 7 rows match (Physics Part 1, Python Basics, The Story of My Experiments). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| Title |
|---|
| Python Basics |
| Learn SQL |
Explanation: WHERE keeps only the rows where Subject is 'Computer' and Price is at least 300: 2 of the 7 rows match (Python Basics, Learn SQL). SELECT then shows only the column Title.
(iv)
SELECT * FROM BOOK WHERE Subject = 'Computer';
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Explanation: WHERE keeps only the rows where Subject is 'Computer': 3 of the 7 rows match (Informatics Practices, Python Basics, Learn SQL). SELECT then shows all the columns (*).
(v)
SELECT Title, IssueDate FROM BOOK WHERE IssueDate BETWEEN '2026-07-01' AND '2026-07-31';
| Title | IssueDate |
|---|---|
| Informatics Practices | 2026-07-03 |
| Physics Part 1 | 2026-07-10 |
| Chemistry Part 1 | 2026-07-15 |
Explanation: WHERE keeps only the rows where IssueDate is from '2026-07-01' to '2026-07-31' (both included): 3 of the 7 rows match (Informatics Practices, Physics Part 1, Chemistry Part 1). SELECT then shows only the columns Title, IssueDate.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
(a) Write the output of the following queries:
SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;SELECT RollNo, Marks, Marks + 10 FROM STUDENT;SELECT * FROM STUDENT WHERE Section = 'C';(b) Write SQL queries for the following:
(i)
| Name | Phone |
|---|---|
| Aarav | 9810011111 |
| Chirag | 9810033333 |
| Divya | 9810044444 |
| Farah | 9810066666 |
| Gaurav | 9810077777 |
Explanation: WHERE keeps only the rows where Phone has a value (is not NULL): 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Phone. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
| RollNo | Marks | Marks + 10 |
|---|---|---|
| 1 | 78 | 88 |
| 2 | 92 | 102 |
| 3 | 45 | 55 |
| 4 | 66 | 76 |
| 5 | 88 | 98 |
| 6 | 31 | 41 |
| 7 | 59 | 69 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns RollNo, Marks, Marks + 10. The expression is calculated for every row; the table itself does not change.
(iii)
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
Explanation: WHERE keeps only the rows where Section is 'C': 2 of the 7 rows match (Divya, Gaurav). SELECT then shows all the columns (*).
(iv)
SELECT Name, Section FROM STUDENT WHERE Section = 'A' OR Section = 'C';
| Name | Section |
|---|---|
| Aarav | A |
| Chirag | A |
| Divya | C |
| Farah | A |
| Gaurav | C |
Explanation: WHERE keeps only the rows where Section is 'A' or Section is 'C': 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Section.
(v)
SELECT Name FROM STUDENT WHERE Gender = 'M' AND Phone IS NOT NULL;
| Name |
|---|
| Aarav |
| Chirag |
| Gaurav |
Explanation: WHERE keeps only the rows where Gender is 'M' and Phone has a value (is not NULL): 3 of the 7 rows match (Aarav, Chirag, Gaurav). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table PRODUCT given below.
Table: PRODUCT
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P02 | 89010022 | Pen Drive | Electronics | SanDisk | 2025-08-15 | 450 | NULL |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
| P04 | 89010044 | Mouse | Electronics | Logitech | 2026-02-20 | 650 | 15 |
| P05 | 89010055 | Water Bottle | Home | Milton | 2025-05-30 | 320 | NULL |
| P06 | 89010066 | Earphones | Electronics | Boat | 2026-03-05 | 899 | 20 |
| P07 | 89010077 | Lunch Box | Home | Milton | 2025-12-18 | 275 | 8 |
(a) Write the output of the following queries:
SELECT PName, Category FROM PRODUCT WHERE Category = 'Electronics' OR Category = 'Home';SELECT * FROM PRODUCT WHERE Category = 'Stationery';SELECT PName FROM PRODUCT WHERE Discount IS NULL;(b) Write SQL queries for the following:
(i)
| PName | Category |
|---|---|
| Pen Drive | Electronics |
| Mouse | Electronics |
| Water Bottle | Home |
| Earphones | Electronics |
| Lunch Box | Home |
Explanation: WHERE keeps only the rows where Category is 'Electronics' or Category is 'Home': 5 of the 7 rows match (Pen Drive, Mouse, Water Bottle, Earphones, Lunch Box). SELECT then shows only the columns PName, Category.
(ii)
| PCode | Barcode | PName | Category | Brand | MfgDate | Price | Discount |
|---|---|---|---|---|---|---|---|
| P01 | 89010011 | Notebook | Stationery | Classmate | 2026-01-10 | 60 | 5 |
| P03 | 89010033 | Geometry Box | Stationery | Camlin | 2025-11-02 | 180 | 10 |
Explanation: WHERE keeps only the rows where Category is 'Stationery': 2 of the 7 rows match (Notebook, Geometry Box). SELECT then shows all the columns (*).
(iii)
| PName |
|---|
| Pen Drive |
| Water Bottle |
Explanation: WHERE keeps only the rows where Discount is empty (NULL): 2 of the 7 rows match (Pen Drive, Water Bottle). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT PName FROM PRODUCT WHERE Brand = 'Boat' AND Discount IS NOT NULL;
| PName |
|---|
| Earphones |
Explanation: WHERE keeps only the rows where Brand is 'Boat' and Discount has a value (is not NULL): 1 of the 7 rows matches (Earphones). SELECT then shows only the column PName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(v)
SELECT PCode, Price, Price + 10 FROM PRODUCT;
| PCode | Price | Price + 10 |
|---|---|---|
| P01 | 60 | 70 |
| P02 | 450 | 460 |
| P03 | 180 | 190 |
| P04 | 650 | 660 |
| P05 | 320 | 330 |
| P06 | 899 | 909 |
| P07 | 275 | 285 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PCode, Price, Price + 10. The expression is calculated for every row; the table itself does not change.
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
(a) Write the output of the following queries:
SELECT Title, Subject FROM BOOK WHERE NOT Subject = 'Computer';SELECT * FROM BOOK WHERE Subject = 'Computer';SELECT Title FROM BOOK WHERE Subject = 'Computer' AND Price >= 250;(b) Write SQL queries for the following:
(i)
| Title | Subject |
|---|---|
| Physics Part 1 | Science |
| Wings of Fire | Biography |
| Chemistry Part 1 | Science |
| The Story of My Experiments | Biography |
Explanation: WHERE keeps only the rows where Subject is not 'Computer': 4 of the 7 rows match (Physics Part 1, Wings of Fire, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Subject.
(ii)
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
Explanation: WHERE keeps only the rows where Subject is 'Computer': 3 of the 7 rows match (Informatics Practices, Python Basics, Learn SQL). SELECT then shows all the columns (*).
(iii)
| Title |
|---|
| Python Basics |
| Learn SQL |
Explanation: WHERE keeps only the rows where Subject is 'Computer' and Price is at least 250: 2 of the 7 rows match (Python Basics, Learn SQL). SELECT then shows only the column Title.
(iv)
SELECT Title FROM BOOK WHERE Publisher = 'BPB' AND Member IS NOT NULL;
| Title |
|---|
| Learn SQL |
Explanation: WHERE keeps only the rows where Publisher is 'BPB' and Member has a value (is not NULL): 1 of the 7 rows matches (Learn SQL). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(v)
SELECT BookID, Title, Price FROM BOOK WHERE Price BETWEEN 250 AND 300;
| BookID | Title | Price |
|---|---|---|
| 203 | Wings of Fire | 299 |
| 206 | The Story of My Experiments | 250 |
Explanation: WHERE keeps only the rows where Price is from 250 to 300 (both included): 2 of the 7 rows match (Wings of Fire, The Story of My Experiments). SELECT then shows only the columns BookID, Title, Price.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
(a) Write the output of the following queries:
SELECT Name, Gender FROM STUDENT WHERE Gender <> 'F';SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;SELECT Name FROM STUDENT WHERE Phone IS NULL;(b) Write SQL queries for the following:
(i)
| Name | Gender |
|---|---|
| Aarav | M |
| Chirag | M |
| Eshan | M |
| Gaurav | M |
Explanation: WHERE keeps only the rows where Gender is not 'F': 4 of the 7 rows match (Aarav, Chirag, Eshan, Gaurav). SELECT then shows only the columns Name, Gender.
(ii)
| Name | Phone |
|---|---|
| Aarav | 9810011111 |
| Chirag | 9810033333 |
| Divya | 9810044444 |
| Farah | 9810066666 |
| Gaurav | 9810077777 |
Explanation: WHERE keeps only the rows where Phone has a value (is not NULL): 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Phone. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Phone is empty (NULL): 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
| Name | DOB |
|---|---|
| Bhavya | 2009-11-30 |
| Divya | 2009-07-21 |
| Farah | 2009-09-09 |
Explanation: WHERE keeps only the rows where DOB is from '2009-06-01' to '2009-12-31' (both included): 3 of the 7 rows match (Bhavya, Divya, Farah). SELECT then shows only the columns Name, DOB.
(v)
SELECT Name, Marks FROM STUDENT WHERE Marks < 60 OR Phone IS NULL;
| Name | Marks |
|---|---|
| Bhavya | 92 |
| Chirag | 45 |
| Eshan | 88 |
| Farah | 31 |
| Gaurav | 59 |
Explanation: WHERE keeps only the rows where Marks is less than 60 or Phone is empty (NULL): 5 of the 7 rows match (Bhavya, Chirag, Eshan, Farah, Gaurav). SELECT then shows only the columns Name, Marks. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
(a) Write the output of the following queries:
SELECT RollNo, Marks, Marks + 10 FROM STUDENT;SELECT Name FROM STUDENT WHERE Phone IS NULL;SELECT Name, Marks FROM STUDENT WHERE Marks > 70;(b) Write SQL queries for the following:
(i)
| RollNo | Marks | Marks + 10 |
|---|---|---|
| 1 | 78 | 88 |
| 2 | 92 | 102 |
| 3 | 45 | 55 |
| 4 | 66 | 76 |
| 5 | 88 | 98 |
| 6 | 31 | 41 |
| 7 | 59 | 69 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns RollNo, Marks, Marks + 10. The expression is calculated for every row; the table itself does not change.
(ii)
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Phone is empty (NULL): 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| Name | Marks |
|---|---|
| Aarav | 78 |
| Bhavya | 92 |
| Eshan | 88 |
Explanation: WHERE keeps only the rows where Marks is more than 70: 3 of the 7 rows match (Aarav, Bhavya, Eshan). SELECT then shows only the columns Name, Marks.
(iv)
SELECT Name FROM STUDENT WHERE Section = 'C' AND Marks >= 70;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Section is 'C' and Marks is at least 70. No row satisfies this, so the result is an empty set.
(v)
SELECT Name, Section FROM STUDENT WHERE Section = 'B' OR Section = 'A';
| Name | Section |
|---|---|
| Aarav | A |
| Bhavya | B |
| Chirag | A |
| Eshan | B |
| Farah | A |
Explanation: WHERE keeps only the rows where Section is 'B' or Section is 'A': 5 of the 7 rows match (Aarav, Bhavya, Chirag, Eshan, Farah). SELECT then shows only the columns Name, Section.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
(a) Write the output of the following queries:
SELECT Name, Marks FROM STUDENT WHERE Marks < 50 OR Phone IS NULL;SELECT Name FROM STUDENT WHERE Gender = 'F' AND Phone IS NOT NULL;SELECT Name FROM STUDENT WHERE Phone IS NULL;(b) Write SQL queries for the following:
(i)
| Name | Marks |
|---|---|
| Bhavya | 92 |
| Chirag | 45 |
| Eshan | 88 |
| Farah | 31 |
Explanation: WHERE keeps only the rows where Marks is less than 50 or Phone is empty (NULL): 4 of the 7 rows match (Bhavya, Chirag, Eshan, Farah). SELECT then shows only the columns Name, Marks. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
| Name |
|---|
| Divya |
| Farah |
Explanation: WHERE keeps only the rows where Gender is 'F' and Phone has a value (is not NULL): 2 of the 7 rows match (Divya, Farah). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Phone is empty (NULL): 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 50 AND 60;
| RollNo | Name | Marks |
|---|---|---|
| 7 | Gaurav | 59 |
Explanation: WHERE keeps only the rows where Marks is from 50 to 60 (both included): 1 of the 7 rows matches (Gaurav). SELECT then shows only the columns RollNo, Name, Marks.
(v)
SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
| Name | Phone |
|---|---|
| Aarav | 9810011111 |
| Chirag | 9810033333 |
| Divya | 9810044444 |
| Farah | 9810066666 |
| Gaurav | 9810077777 |
Explanation: WHERE keeps only the rows where Phone has a value (is not NULL): 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Phone. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
Consider the table BOOK given below.
Table: BOOK
| BookID | ISBN | Title | Subject | Publisher | IssueDate | Price | Member |
|---|---|---|---|---|---|---|---|
| 201 | 9789352921485 | Informatics Practices | Computer | NCERT | 2026-07-03 | 210 | Asha |
| 202 | 9789352920112 | Physics Part 1 | Science | NCERT | 2026-07-10 | 180 | NULL |
| 203 | 9780143032311 | Wings of Fire | Biography | Universities | 2026-06-21 | 299 | Ravi |
| 204 | 9789386551009 | Python Basics | Computer | BPB | 2026-08-01 | 350 | NULL |
| 205 | 9789352925032 | Chemistry Part 1 | Science | NCERT | 2026-07-15 | 190 | Neha |
| 206 | 9780140449136 | The Story of My Experiments | Biography | Penguin | 2026-05-30 | 250 | NULL |
| 207 | 9789386551023 | Learn SQL | Computer | BPB | 2026-08-12 | 400 | Karan |
(a) Write the output of the following queries:
SELECT Title, Subject FROM BOOK WHERE NOT Subject = 'Biography';SELECT Title, Price FROM BOOK WHERE Price < 200 OR Member IS NULL;SELECT Title, IssueDate FROM BOOK WHERE IssueDate BETWEEN '2026-07-01' AND '2026-07-31';(b) Write SQL queries for the following:
(i)
| Title | Subject |
|---|---|
| Informatics Practices | Computer |
| Physics Part 1 | Science |
| Python Basics | Computer |
| Chemistry Part 1 | Science |
| Learn SQL | Computer |
Explanation: WHERE keeps only the rows where Subject is not 'Biography': 5 of the 7 rows match (Informatics Practices, Physics Part 1, Python Basics, Chemistry Part 1, Learn SQL). SELECT then shows only the columns Title, Subject.
(ii)
| Title | Price |
|---|---|
| Physics Part 1 | 180 |
| Python Basics | 350 |
| Chemistry Part 1 | 190 |
| The Story of My Experiments | 250 |
Explanation: WHERE keeps only the rows where Price is less than 200 or Member is empty (NULL): 4 of the 7 rows match (Physics Part 1, Python Basics, Chemistry Part 1, The Story of My Experiments). SELECT then shows only the columns Title, Price. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| Title | IssueDate |
|---|---|
| Informatics Practices | 2026-07-03 |
| Physics Part 1 | 2026-07-10 |
| Chemistry Part 1 | 2026-07-15 |
Explanation: WHERE keeps only the rows where IssueDate is from '2026-07-01' to '2026-07-31' (both included): 3 of the 7 rows match (Informatics Practices, Physics Part 1, Chemistry Part 1). SELECT then shows only the columns Title, IssueDate.
(iv)
SELECT Title FROM BOOK WHERE Member IS NULL;
| Title |
|---|
| Physics Part 1 |
| Python Basics |
| The Story of My Experiments |
Explanation: WHERE keeps only the rows where Member is empty (NULL): 3 of the 7 rows match (Physics Part 1, Python Basics, The Story of My Experiments). SELECT then shows only the column Title. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(v)
SELECT Title FROM BOOK WHERE Subject = 'Biography' AND Price >= 300;
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where Subject is 'Biography' and Price is at least 300. No row satisfies this, so the result is an empty set.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
(a) Write the output of the following queries:
SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;SELECT EName FROM EMPLOYEE WHERE City = 'Mumbai' AND Bonus IS NOT NULL;SELECT EName FROM EMPLOYEE WHERE Bonus IS NULL;(b) Write SQL queries for the following:
(i)
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
(ii)
Output: no rows (empty set).
Explanation: WHERE keeps only the rows where City is 'Mumbai' and Bonus has a value (is not NULL). No row satisfies this, so the result is an empty set. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| EName |
|---|
| Seema |
| Usha |
| Yamini |
Explanation: WHERE keeps only the rows where Bonus is empty (NULL): 3 of the 7 rows match (Seema, Usha, Yamini). SELECT then shows only the column EName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';
| EName | DOJ |
|---|---|
| Ravi | 2018-06-01 |
| Seema | 2020-01-15 |
| Vikas | 2019-11-05 |
Explanation: WHERE keeps only the rows where DOJ is from '2018-01-01' to '2020-12-31' (both included): 3 of the 7 rows match (Ravi, Seema, Vikas). SELECT then shows only the columns EName, DOJ.
(v)
SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 60000;
| EName | Salary |
|---|---|
| Tarun | 75000 |
| Vikas | 64000 |
| Yamini | 81000 |
Explanation: WHERE keeps only the rows where Salary is more than 60000: 3 of the 7 rows match (Tarun, Vikas, Yamini). SELECT then shows only the columns EName, Salary.
Consider the table PATIENT given below.
Table: PATIENT
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 11 | 123412341234 | Mohan | General | Dr. Rao | 2026-09-02 | 1500 | LIC |
| 12 | 223422342234 | Nisha | ICU | Dr. Sen | 2026-09-05 | 8000 | NULL |
| 13 | 323432343234 | Om | General | Dr. Rao | 2026-09-10 | 1200 | Star |
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 15 | 523452345234 | Qasim | ICU | Dr. Sen | 2026-09-15 | 9500 | NULL |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
| 17 | 723472347234 | Sahil | General | Dr. Rao | 2026-09-20 | 900 | Star |
(a) Write the output of the following queries:
SELECT PName, Fee FROM PATIENT WHERE Fee > 4000;SELECT PName, Ward FROM PATIENT WHERE NOT Ward = 'Maternity';SELECT PID, Fee, Fee + 10 FROM PATIENT;(b) Write SQL queries for the following:
(i)
| PName | Fee |
|---|---|
| Nisha | 8000 |
| Pooja | 5000 |
| Qasim | 9500 |
| Rekha | 4500 |
Explanation: WHERE keeps only the rows where Fee is more than 4000: 4 of the 7 rows match (Nisha, Pooja, Qasim, Rekha). SELECT then shows only the columns PName, Fee.
(ii)
| PName | Ward |
|---|---|
| Mohan | General |
| Nisha | ICU |
| Om | General |
| Qasim | ICU |
| Sahil | General |
Explanation: WHERE keeps only the rows where Ward is not 'Maternity': 5 of the 7 rows match (Mohan, Nisha, Om, Qasim, Sahil). SELECT then shows only the columns PName, Ward.
(iii)
| PID | Fee | Fee + 10 |
|---|---|---|
| 11 | 1500 | 1510 |
| 12 | 8000 | 8010 |
| 13 | 1200 | 1210 |
| 14 | 5000 | 5010 |
| 15 | 9500 | 9510 |
| 16 | 4500 | 4510 |
| 17 | 900 | 910 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns PID, Fee, Fee + 10. The expression is calculated for every row; the table itself does not change.
(iv)
SELECT * FROM PATIENT WHERE Ward = 'Maternity';
| PID | Aadhaar | PName | Ward | Doctor | AdmitDate | Fee | Insurance |
|---|---|---|---|---|---|---|---|
| 14 | 423442344234 | Pooja | Maternity | Dr. Iyer | 2026-09-12 | 5000 | LIC |
| 16 | 623462346234 | Rekha | Maternity | Dr. Iyer | 2026-09-18 | 4500 | NULL |
Explanation: WHERE keeps only the rows where Ward is 'Maternity': 2 of the 7 rows match (Pooja, Rekha). SELECT then shows all the columns (*).
(v)
SELECT PName FROM PATIENT WHERE Ward = 'Maternity' AND Fee >= 4000;
| PName |
|---|
| Pooja |
| Rekha |
Explanation: WHERE keeps only the rows where Ward is 'Maternity' and Fee is at least 4000: 2 of the 7 rows match (Pooja, Rekha). SELECT then shows only the column PName.
Consider the table EMPLOYEE given below.
Table: EMPLOYEE
| EmpID | EName | Dept | City | DOJ | Salary | Bonus | |
|---|---|---|---|---|---|---|---|
| E101 | ravi@co.in | Ravi | Sales | Delhi | 2018-06-01 | 42000 | 3000 |
| E102 | seema@co.in | Seema | HR | Pune | 2020-01-15 | 58000 | NULL |
| E103 | tarun@co.in | Tarun | IT | Delhi | 2016-09-20 | 75000 | 5000 |
| E104 | usha@co.in | Usha | Sales | Mumbai | 2021-03-10 | 36000 | NULL |
| E105 | vikas@co.in | Vikas | IT | Pune | 2019-11-05 | 64000 | 4000 |
| E106 | wasim@co.in | Wasim | HR | Delhi | 2022-07-25 | 39000 | 2000 |
| E107 | yamini@co.in | Yamini | IT | Mumbai | 2017-12-12 | 81000 | NULL |
(a) Write the output of the following queries:
SELECT EName FROM EMPLOYEE WHERE Bonus IS NULL;SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;SELECT EName, Bonus FROM EMPLOYEE WHERE Bonus IS NOT NULL;(b) Write SQL queries for the following:
(i)
| EName |
|---|
| Seema |
| Usha |
| Yamini |
Explanation: WHERE keeps only the rows where Bonus is empty (NULL): 3 of the 7 rows match (Seema, Usha, Yamini). SELECT then shows only the column EName. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(ii)
| EmpID | Salary | Salary + 10 |
|---|---|---|
| E101 | 42000 | 42010 |
| E102 | 58000 | 58010 |
| E103 | 75000 | 75010 |
| E104 | 36000 | 36010 |
| E105 | 64000 | 64010 |
| E106 | 39000 | 39010 |
| E107 | 81000 | 81010 |
Explanation: There is no WHERE clause, so all 7 rows are shown, with only the columns EmpID, Salary, Salary + 10. The expression is calculated for every row; the table itself does not change.
(iii)
| EName | Bonus |
|---|---|
| Ravi | 3000 |
| Tarun | 5000 |
| Vikas | 4000 |
| Wasim | 2000 |
Explanation: WHERE keeps only the rows where Bonus has a value (is not NULL): 4 of the 7 rows match (Ravi, Tarun, Vikas, Wasim). SELECT then shows only the columns EName, Bonus. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iv)
SELECT EName, Dept FROM EMPLOYEE WHERE NOT Dept = 'IT';
| EName | Dept |
|---|---|
| Ravi | Sales |
| Seema | HR |
| Usha | Sales |
| Wasim | HR |
Explanation: WHERE keeps only the rows where Dept is not 'IT': 4 of the 7 rows match (Ravi, Seema, Usha, Wasim). SELECT then shows only the columns EName, Dept.
(v)
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 70000;
| EmpID | EName | Salary |
|---|---|---|
| E101 | Ravi | 42000 |
| E102 | Seema | 58000 |
| E105 | Vikas | 64000 |
Explanation: WHERE keeps only the rows where Salary is from 40000 to 70000 (both included): 3 of the 7 rows match (Ravi, Seema, Vikas). SELECT then shows only the columns EmpID, EName, Salary.
Consider the table STUDENT given below.
Table: STUDENT
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 1 | 4501 | Aarav | A | M | 2009-04-12 | 78 | 9810011111 |
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 3 | 4523 | Chirag | A | M | 2010-01-05 | 45 | 9810033333 |
| 4 | 4534 | Divya | C | F | 2009-07-21 | 66 | 9810044444 |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
| 6 | 4556 | Farah | A | F | 2009-09-09 | 31 | 9810066666 |
| 7 | 4567 | Gaurav | C | M | 2010-02-28 | 59 | 9810077777 |
(a) Write the output of the following queries:
SELECT * FROM STUDENT WHERE Section = 'B';SELECT Name FROM STUDENT WHERE Gender = 'M' AND Phone IS NOT NULL;SELECT Name FROM STUDENT WHERE Section = 'B' AND Marks >= 50;(b) Write SQL queries for the following:
(i)
| RollNo | AdmNo | Name | Section | Gender | DOB | Marks | Phone |
|---|---|---|---|---|---|---|---|
| 2 | 4512 | Bhavya | B | F | 2009-11-30 | 92 | NULL |
| 5 | 4545 | Eshan | B | M | 2010-03-17 | 88 | NULL |
Explanation: WHERE keeps only the rows where Section is 'B': 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows all the columns (*).
(ii)
| Name |
|---|
| Aarav |
| Chirag |
| Gaurav |
Explanation: WHERE keeps only the rows where Gender is 'M' and Phone has a value (is not NULL): 3 of the 7 rows match (Aarav, Chirag, Gaurav). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(iii)
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Section is 'B' and Marks is at least 50: 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name.
(iv)
SELECT Name FROM STUDENT WHERE Phone IS NULL;
| Name |
|---|
| Bhavya |
| Eshan |
Explanation: WHERE keeps only the rows where Phone is empty (NULL): 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows only the column Name. (NULL is checked with IS NULL / IS NOT NULL, never with =.)
(v)
SELECT Name, Section FROM STUDENT WHERE NOT Section = 'B';
| Name | Section |
|---|---|
| Aarav | A |
| Chirag | A |
| Divya | C |
| Farah | A |
| Gaurav | C |
Explanation: WHERE keeps only the rows where Section is not 'B': 5 of the 7 rows match (Aarav, Chirag, Divya, Farah, Gaurav). SELECT then shows only the columns Name, Section.
Write SQL commands for the following:
(i)
CREATE TABLE STUDENT (
RollNo INT PRIMARY KEY,
Name VARCHAR(25) NOT NULL,
Section CHAR(1),
Gender CHAR(1),
DOB DATE,
Marks INT,
Phone VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes RollNo unique and not empty; NOT NULL makes Name compulsory.
(ii)
INSERT INTO STUDENT VALUES (105, 'Eshan', 'B', 'M', '2010-03-17', 88, NULL);
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE STUDENT ADD Grade CHAR(1);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE STUDENT SET Marks = Marks + 5 WHERE Section = 'B';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Section = 'B' change.
(v)
DELETE FROM STUDENT WHERE Marks < 50;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE EMPLOYEE (
EmpID CHAR(4) PRIMARY KEY,
EName VARCHAR(25) NOT NULL,
Dept VARCHAR(10),
City VARCHAR(15),
DOJ DATE,
Salary INT,
Bonus INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes EmpID unique and not empty; NOT NULL makes EName compulsory.
(ii)
INSERT INTO EMPLOYEE VALUES ('E153', 'Tarun', 'IT', 'Delhi', '2016-09-20', 75000, 5000);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE EMPLOYEE ADD Grade CHAR(1);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE EMPLOYEE SET Salary = Salary + 5 WHERE Dept = 'Sales';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Dept = 'Sales' change.
(v)
DELETE FROM EMPLOYEE WHERE Salary < 70000;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE PRODUCT (
PCode CHAR(4) PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Category VARCHAR(12),
Brand VARCHAR(12),
MfgDate DATE,
Price INT,
Discount INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PCode unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PRODUCT VALUES ('P51', 'Notebook', 'Stationery', 'Classmate', '2026-01-10', 60, 5);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PRODUCT ADD Grade CHAR(1);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PRODUCT SET Price = Price + 5 WHERE Category = 'Stationery';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Category = 'Stationery' change.
(v)
DELETE FROM PRODUCT WHERE Price < 100;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE BOOK (
BookID INT PRIMARY KEY,
Title VARCHAR(30) NOT NULL,
Subject VARCHAR(12),
Publisher VARCHAR(12),
IssueDate DATE,
Price INT,
Member VARCHAR(15)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes BookID unique and not empty; NOT NULL makes Title compulsory.
(ii)
INSERT INTO BOOK VALUES (302, 'Physics Part 1', 'Science', 'NCERT', '2026-07-10', 180, NULL);
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE BOOK ADD Grade CHAR(1);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE BOOK SET Price = Price + 5 WHERE Subject = 'Biography';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Subject = 'Biography' change.
(v)
DROP TABLE BOOK;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE PATIENT (
PID INT PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Ward VARCHAR(12),
Doctor VARCHAR(15),
AdmitDate DATE,
Fee INT,
Insurance VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PID unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PATIENT VALUES (113, 'Om', 'General', 'Dr. Rao', '2026-09-10', 1200, 'Star');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PATIENT ADD Remarks VARCHAR(30);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PATIENT SET Fee = Fee + 5 WHERE Ward = 'General';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Ward = 'General' change.
(v)
DROP TABLE PATIENT;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE STUDENT (
RollNo INT PRIMARY KEY,
Name VARCHAR(25) NOT NULL,
Section CHAR(1),
Gender CHAR(1),
DOB DATE,
Marks INT,
Phone VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes RollNo unique and not empty; NOT NULL makes Name compulsory.
(ii)
INSERT INTO STUDENT VALUES (101, 'Aarav', 'A', 'M', '2009-04-12', 78, '9810011111');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE STUDENT ADD Rating INT;
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE STUDENT SET Marks = Marks + 5 WHERE Section = 'B';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Section = 'B' change.
(v)
DELETE FROM STUDENT WHERE Marks < 50;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE EMPLOYEE (
EmpID CHAR(4) PRIMARY KEY,
EName VARCHAR(25) NOT NULL,
Dept VARCHAR(10),
City VARCHAR(15),
DOJ DATE,
Salary INT,
Bonus INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes EmpID unique and not empty; NOT NULL makes EName compulsory.
(ii)
INSERT INTO EMPLOYEE VALUES ('E153', 'Tarun', 'IT', 'Delhi', '2016-09-20', 75000, 5000);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE EMPLOYEE ADD Remarks VARCHAR(30);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE EMPLOYEE SET Salary = Salary + 5 WHERE Dept = 'HR';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Dept = 'HR' change.
(v)
DROP TABLE EMPLOYEE;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE PRODUCT (
PCode CHAR(4) PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Category VARCHAR(12),
Brand VARCHAR(12),
MfgDate DATE,
Price INT,
Discount INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PCode unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PRODUCT VALUES ('P57', 'Lunch Box', 'Home', 'Milton', '2025-12-18', 275, 8);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PRODUCT ADD Status VARCHAR(10);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PRODUCT SET Price = Price + 5 WHERE Category = 'Electronics';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Category = 'Electronics' change.
(v)
DELETE FROM PRODUCT WHERE Price < 400;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE BOOK (
BookID INT PRIMARY KEY,
Title VARCHAR(30) NOT NULL,
Subject VARCHAR(12),
Publisher VARCHAR(12),
IssueDate DATE,
Price INT,
Member VARCHAR(15)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes BookID unique and not empty; NOT NULL makes Title compulsory.
(ii)
INSERT INTO BOOK VALUES (303, 'Wings of Fire', 'Biography', 'Universities', '2026-06-21', 299, 'Ravi');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE BOOK ADD Remarks VARCHAR(30);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE BOOK SET Price = Price + 5 WHERE Subject = 'Computer';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Subject = 'Computer' change.
(v)
DROP TABLE BOOK;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE PATIENT (
PID INT PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Ward VARCHAR(12),
Doctor VARCHAR(15),
AdmitDate DATE,
Fee INT,
Insurance VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PID unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PATIENT VALUES (111, 'Mohan', 'General', 'Dr. Rao', '2026-09-02', 1500, 'LIC');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PATIENT ADD Status VARCHAR(10);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PATIENT SET Fee = Fee + 5 WHERE Ward = 'Maternity';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Ward = 'Maternity' change.
(v)
DELETE FROM PATIENT WHERE Fee < 6000;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE STUDENT (
RollNo INT PRIMARY KEY,
Name VARCHAR(25) NOT NULL,
Section CHAR(1),
Gender CHAR(1),
DOB DATE,
Marks INT,
Phone VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes RollNo unique and not empty; NOT NULL makes Name compulsory.
(ii)
INSERT INTO STUDENT VALUES (105, 'Eshan', 'B', 'M', '2010-03-17', 88, NULL);
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE STUDENT ADD Rating INT;
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE STUDENT SET Marks = Marks + 5 WHERE Section = 'B';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Section = 'B' change.
(v)
DELETE FROM STUDENT WHERE Marks < 50;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE EMPLOYEE (
EmpID CHAR(4) PRIMARY KEY,
EName VARCHAR(25) NOT NULL,
Dept VARCHAR(10),
City VARCHAR(15),
DOJ DATE,
Salary INT,
Bonus INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes EmpID unique and not empty; NOT NULL makes EName compulsory.
(ii)
INSERT INTO EMPLOYEE VALUES ('E151', 'Ravi', 'Sales', 'Delhi', '2018-06-01', 42000, 3000);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE EMPLOYEE ADD Grade CHAR(1);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE EMPLOYEE SET Salary = Salary + 5 WHERE Dept = 'IT';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Dept = 'IT' change.
(v)
DROP TABLE EMPLOYEE;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE PRODUCT (
PCode CHAR(4) PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Category VARCHAR(12),
Brand VARCHAR(12),
MfgDate DATE,
Price INT,
Discount INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PCode unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PRODUCT VALUES ('P56', 'Earphones', 'Electronics', 'Boat', '2026-03-05', 899, 20);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PRODUCT ADD Grade CHAR(1);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PRODUCT SET Price = Price + 5 WHERE Category = 'Electronics';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Category = 'Electronics' change.
(v)
DELETE FROM PRODUCT WHERE Price < 100;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE BOOK (
BookID INT PRIMARY KEY,
Title VARCHAR(30) NOT NULL,
Subject VARCHAR(12),
Publisher VARCHAR(12),
IssueDate DATE,
Price INT,
Member VARCHAR(15)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes BookID unique and not empty; NOT NULL makes Title compulsory.
(ii)
INSERT INTO BOOK VALUES (305, 'Chemistry Part 1', 'Science', 'NCERT', '2026-07-15', 190, 'Neha');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE BOOK ADD Status VARCHAR(10);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE BOOK SET Price = Price + 5 WHERE Subject = 'Biography';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Subject = 'Biography' change.
(v)
DELETE FROM BOOK WHERE Price < 300;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE PATIENT (
PID INT PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Ward VARCHAR(12),
Doctor VARCHAR(15),
AdmitDate DATE,
Fee INT,
Insurance VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PID unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PATIENT VALUES (114, 'Pooja', 'Maternity', 'Dr. Iyer', '2026-09-12', 5000, 'LIC');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PATIENT ADD Status VARCHAR(10);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PATIENT SET Fee = Fee + 5 WHERE Ward = 'Maternity';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Ward = 'Maternity' change.
(v)
DELETE FROM PATIENT WHERE Fee < 1500;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE STUDENT (
RollNo INT PRIMARY KEY,
Name VARCHAR(25) NOT NULL,
Section CHAR(1),
Gender CHAR(1),
DOB DATE,
Marks INT,
Phone VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes RollNo unique and not empty; NOT NULL makes Name compulsory.
(ii)
INSERT INTO STUDENT VALUES (101, 'Aarav', 'A', 'M', '2009-04-12', 78, '9810011111');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE STUDENT ADD Status VARCHAR(10);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE STUDENT SET Marks = Marks + 5 WHERE Section = 'A';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Section = 'A' change.
(v)
DROP TABLE STUDENT;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE EMPLOYEE (
EmpID CHAR(4) PRIMARY KEY,
EName VARCHAR(25) NOT NULL,
Dept VARCHAR(10),
City VARCHAR(15),
DOJ DATE,
Salary INT,
Bonus INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes EmpID unique and not empty; NOT NULL makes EName compulsory.
(ii)
INSERT INTO EMPLOYEE VALUES ('E156', 'Wasim', 'HR', 'Delhi', '2022-07-25', 39000, 2000);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE EMPLOYEE ADD Remarks VARCHAR(30);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE EMPLOYEE SET Salary = Salary + 5 WHERE Dept = 'Sales';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Dept = 'Sales' change.
(v)
DROP TABLE EMPLOYEE;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE PRODUCT (
PCode CHAR(4) PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Category VARCHAR(12),
Brand VARCHAR(12),
MfgDate DATE,
Price INT,
Discount INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PCode unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PRODUCT VALUES ('P52', 'Pen Drive', 'Electronics', 'SanDisk', '2025-08-15', 450, NULL);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PRODUCT ADD Grade CHAR(1);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PRODUCT SET Price = Price + 5 WHERE Category = 'Stationery';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Category = 'Stationery' change.
(v)
DROP TABLE PRODUCT;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE BOOK (
BookID INT PRIMARY KEY,
Title VARCHAR(30) NOT NULL,
Subject VARCHAR(12),
Publisher VARCHAR(12),
IssueDate DATE,
Price INT,
Member VARCHAR(15)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes BookID unique and not empty; NOT NULL makes Title compulsory.
(ii)
INSERT INTO BOOK VALUES (305, 'Chemistry Part 1', 'Science', 'NCERT', '2026-07-15', 190, 'Neha');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE BOOK ADD Remarks VARCHAR(30);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE BOOK SET Price = Price + 5 WHERE Subject = 'Computer';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Subject = 'Computer' change.
(v)
DELETE FROM BOOK WHERE Price < 200;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE PATIENT (
PID INT PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Ward VARCHAR(12),
Doctor VARCHAR(15),
AdmitDate DATE,
Fee INT,
Insurance VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PID unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PATIENT VALUES (115, 'Qasim', 'ICU', 'Dr. Sen', '2026-09-15', 9500, NULL);
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PATIENT ADD Status VARCHAR(10);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PATIENT SET Fee = Fee + 5 WHERE Ward = 'Maternity';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Ward = 'Maternity' change.
(v)
DELETE FROM PATIENT WHERE Fee < 1500;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE STUDENT (
RollNo INT PRIMARY KEY,
Name VARCHAR(25) NOT NULL,
Section CHAR(1),
Gender CHAR(1),
DOB DATE,
Marks INT,
Phone VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes RollNo unique and not empty; NOT NULL makes Name compulsory.
(ii)
INSERT INTO STUDENT VALUES (105, 'Eshan', 'B', 'M', '2010-03-17', 88, NULL);
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE STUDENT ADD Remarks VARCHAR(30);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE STUDENT SET Marks = Marks + 5 WHERE Section = 'A';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Section = 'A' change.
(v)
DROP TABLE STUDENT;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE EMPLOYEE (
EmpID CHAR(4) PRIMARY KEY,
EName VARCHAR(25) NOT NULL,
Dept VARCHAR(10),
City VARCHAR(15),
DOJ DATE,
Salary INT,
Bonus INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes EmpID unique and not empty; NOT NULL makes EName compulsory.
(ii)
INSERT INTO EMPLOYEE VALUES ('E156', 'Wasim', 'HR', 'Delhi', '2022-07-25', 39000, 2000);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE EMPLOYEE ADD Status VARCHAR(10);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE EMPLOYEE SET Salary = Salary + 5 WHERE Dept = 'IT';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Dept = 'IT' change.
(v)
DROP TABLE EMPLOYEE;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE PRODUCT (
PCode CHAR(4) PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Category VARCHAR(12),
Brand VARCHAR(12),
MfgDate DATE,
Price INT,
Discount INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PCode unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PRODUCT VALUES ('P56', 'Earphones', 'Electronics', 'Boat', '2026-03-05', 899, 20);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PRODUCT ADD Rating INT;
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PRODUCT SET Price = Price + 5 WHERE Category = 'Home';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Category = 'Home' change.
(v)
DROP TABLE PRODUCT;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE BOOK (
BookID INT PRIMARY KEY,
Title VARCHAR(30) NOT NULL,
Subject VARCHAR(12),
Publisher VARCHAR(12),
IssueDate DATE,
Price INT,
Member VARCHAR(15)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes BookID unique and not empty; NOT NULL makes Title compulsory.
(ii)
INSERT INTO BOOK VALUES (306, 'The Story of My Experiments', 'Biography', 'Penguin', '2026-05-30', 250, NULL);
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE BOOK ADD Remarks VARCHAR(30);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE BOOK SET Price = Price + 5 WHERE Subject = 'Biography';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Subject = 'Biography' change.
(v)
DELETE FROM BOOK WHERE Price < 250;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE PATIENT (
PID INT PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Ward VARCHAR(12),
Doctor VARCHAR(15),
AdmitDate DATE,
Fee INT,
Insurance VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PID unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PATIENT VALUES (115, 'Qasim', 'ICU', 'Dr. Sen', '2026-09-15', 9500, NULL);
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PATIENT ADD Rating INT;
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PATIENT SET Fee = Fee + 5 WHERE Ward = 'Maternity';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Ward = 'Maternity' change.
(v)
DELETE FROM PATIENT WHERE Fee < 1500;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE STUDENT (
RollNo INT PRIMARY KEY,
Name VARCHAR(25) NOT NULL,
Section CHAR(1),
Gender CHAR(1),
DOB DATE,
Marks INT,
Phone VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes RollNo unique and not empty; NOT NULL makes Name compulsory.
(ii)
INSERT INTO STUDENT VALUES (101, 'Aarav', 'A', 'M', '2009-04-12', 78, '9810011111');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE STUDENT ADD Remarks VARCHAR(30);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE STUDENT SET Marks = Marks + 5 WHERE Section = 'A';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Section = 'A' change.
(v)
DROP TABLE STUDENT;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE EMPLOYEE (
EmpID CHAR(4) PRIMARY KEY,
EName VARCHAR(25) NOT NULL,
Dept VARCHAR(10),
City VARCHAR(15),
DOJ DATE,
Salary INT,
Bonus INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes EmpID unique and not empty; NOT NULL makes EName compulsory.
(ii)
INSERT INTO EMPLOYEE VALUES ('E151', 'Ravi', 'Sales', 'Delhi', '2018-06-01', 42000, 3000);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE EMPLOYEE ADD Remarks VARCHAR(30);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE EMPLOYEE SET Salary = Salary + 5 WHERE Dept = 'HR';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Dept = 'HR' change.
(v)
DROP TABLE EMPLOYEE;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE PRODUCT (
PCode CHAR(4) PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Category VARCHAR(12),
Brand VARCHAR(12),
MfgDate DATE,
Price INT,
Discount INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PCode unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PRODUCT VALUES ('P52', 'Pen Drive', 'Electronics', 'SanDisk', '2025-08-15', 450, NULL);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PRODUCT ADD Remarks VARCHAR(30);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PRODUCT SET Price = Price + 5 WHERE Category = 'Electronics';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Category = 'Electronics' change.
(v)
DELETE FROM PRODUCT WHERE Price < 400;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE BOOK (
BookID INT PRIMARY KEY,
Title VARCHAR(30) NOT NULL,
Subject VARCHAR(12),
Publisher VARCHAR(12),
IssueDate DATE,
Price INT,
Member VARCHAR(15)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes BookID unique and not empty; NOT NULL makes Title compulsory.
(ii)
INSERT INTO BOOK VALUES (302, 'Physics Part 1', 'Science', 'NCERT', '2026-07-10', 180, NULL);
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE BOOK ADD Remarks VARCHAR(30);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE BOOK SET Price = Price + 5 WHERE Subject = 'Computer';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Subject = 'Computer' change.
(v)
DELETE FROM BOOK WHERE Price < 250;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE PATIENT (
PID INT PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Ward VARCHAR(12),
Doctor VARCHAR(15),
AdmitDate DATE,
Fee INT,
Insurance VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PID unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PATIENT VALUES (117, 'Sahil', 'General', 'Dr. Rao', '2026-09-20', 900, 'Star');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PATIENT ADD Status VARCHAR(10);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PATIENT SET Fee = Fee + 5 WHERE Ward = 'Maternity';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Ward = 'Maternity' change.
(v)
DELETE FROM PATIENT WHERE Fee < 1000;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE STUDENT (
RollNo INT PRIMARY KEY,
Name VARCHAR(25) NOT NULL,
Section CHAR(1),
Gender CHAR(1),
DOB DATE,
Marks INT,
Phone VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes RollNo unique and not empty; NOT NULL makes Name compulsory.
(ii)
INSERT INTO STUDENT VALUES (106, 'Farah', 'A', 'F', '2009-09-09', 31, '9810066666');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE STUDENT ADD Rating INT;
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE STUDENT SET Marks = Marks + 5 WHERE Section = 'A';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Section = 'A' change.
(v)
DROP TABLE STUDENT;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE EMPLOYEE (
EmpID CHAR(4) PRIMARY KEY,
EName VARCHAR(25) NOT NULL,
Dept VARCHAR(10),
City VARCHAR(15),
DOJ DATE,
Salary INT,
Bonus INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes EmpID unique and not empty; NOT NULL makes EName compulsory.
(ii)
INSERT INTO EMPLOYEE VALUES ('E152', 'Seema', 'HR', 'Pune', '2020-01-15', 58000, NULL);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE EMPLOYEE ADD Rating INT;
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE EMPLOYEE SET Salary = Salary + 5 WHERE Dept = 'IT';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Dept = 'IT' change.
(v)
DROP TABLE EMPLOYEE;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE PRODUCT (
PCode CHAR(4) PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Category VARCHAR(12),
Brand VARCHAR(12),
MfgDate DATE,
Price INT,
Discount INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PCode unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PRODUCT VALUES ('P52', 'Pen Drive', 'Electronics', 'SanDisk', '2025-08-15', 450, NULL);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PRODUCT ADD Grade CHAR(1);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PRODUCT SET Price = Price + 5 WHERE Category = 'Stationery';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Category = 'Stationery' change.
(v)
DROP TABLE PRODUCT;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE BOOK (
BookID INT PRIMARY KEY,
Title VARCHAR(30) NOT NULL,
Subject VARCHAR(12),
Publisher VARCHAR(12),
IssueDate DATE,
Price INT,
Member VARCHAR(15)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes BookID unique and not empty; NOT NULL makes Title compulsory.
(ii)
INSERT INTO BOOK VALUES (301, 'Informatics Practices', 'Computer', 'NCERT', '2026-07-03', 210, 'Asha');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE BOOK ADD Rating INT;
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE BOOK SET Price = Price + 5 WHERE Subject = 'Computer';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Subject = 'Computer' change.
(v)
DELETE FROM BOOK WHERE Price < 250;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE PATIENT (
PID INT PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Ward VARCHAR(12),
Doctor VARCHAR(15),
AdmitDate DATE,
Fee INT,
Insurance VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PID unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PATIENT VALUES (112, 'Nisha', 'ICU', 'Dr. Sen', '2026-09-05', 8000, NULL);
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PATIENT ADD Remarks VARCHAR(30);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PATIENT SET Fee = Fee + 5 WHERE Ward = 'ICU';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Ward = 'ICU' change.
(v)
DELETE FROM PATIENT WHERE Fee < 1500;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE STUDENT (
RollNo INT PRIMARY KEY,
Name VARCHAR(25) NOT NULL,
Section CHAR(1),
Gender CHAR(1),
DOB DATE,
Marks INT,
Phone VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes RollNo unique and not empty; NOT NULL makes Name compulsory.
(ii)
INSERT INTO STUDENT VALUES (105, 'Eshan', 'B', 'M', '2010-03-17', 88, NULL);
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE STUDENT ADD Remarks VARCHAR(30);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE STUDENT SET Marks = Marks + 5 WHERE Section = 'C';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Section = 'C' change.
(v)
DROP TABLE STUDENT;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE EMPLOYEE (
EmpID CHAR(4) PRIMARY KEY,
EName VARCHAR(25) NOT NULL,
Dept VARCHAR(10),
City VARCHAR(15),
DOJ DATE,
Salary INT,
Bonus INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes EmpID unique and not empty; NOT NULL makes EName compulsory.
(ii)
INSERT INTO EMPLOYEE VALUES ('E154', 'Usha', 'Sales', 'Mumbai', '2021-03-10', 36000, NULL);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE EMPLOYEE ADD Status VARCHAR(10);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE EMPLOYEE SET Salary = Salary + 5 WHERE Dept = 'IT';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Dept = 'IT' change.
(v)
DELETE FROM EMPLOYEE WHERE Salary < 50000;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE PRODUCT (
PCode CHAR(4) PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Category VARCHAR(12),
Brand VARCHAR(12),
MfgDate DATE,
Price INT,
Discount INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PCode unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PRODUCT VALUES ('P51', 'Notebook', 'Stationery', 'Classmate', '2026-01-10', 60, 5);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PRODUCT ADD Grade CHAR(1);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PRODUCT SET Price = Price + 5 WHERE Category = 'Home';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Category = 'Home' change.
(v)
DROP TABLE PRODUCT;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE BOOK (
BookID INT PRIMARY KEY,
Title VARCHAR(30) NOT NULL,
Subject VARCHAR(12),
Publisher VARCHAR(12),
IssueDate DATE,
Price INT,
Member VARCHAR(15)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes BookID unique and not empty; NOT NULL makes Title compulsory.
(ii)
INSERT INTO BOOK VALUES (301, 'Informatics Practices', 'Computer', 'NCERT', '2026-07-03', 210, 'Asha');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE BOOK ADD Grade CHAR(1);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE BOOK SET Price = Price + 5 WHERE Subject = 'Science';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Subject = 'Science' change.
(v)
DELETE FROM BOOK WHERE Price < 350;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE PATIENT (
PID INT PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Ward VARCHAR(12),
Doctor VARCHAR(15),
AdmitDate DATE,
Fee INT,
Insurance VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PID unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PATIENT VALUES (114, 'Pooja', 'Maternity', 'Dr. Iyer', '2026-09-12', 5000, 'LIC');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PATIENT ADD Grade CHAR(1);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PATIENT SET Fee = Fee + 5 WHERE Ward = 'ICU';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Ward = 'ICU' change.
(v)
DELETE FROM PATIENT WHERE Fee < 4000;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE STUDENT (
RollNo INT PRIMARY KEY,
Name VARCHAR(25) NOT NULL,
Section CHAR(1),
Gender CHAR(1),
DOB DATE,
Marks INT,
Phone VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes RollNo unique and not empty; NOT NULL makes Name compulsory.
(ii)
INSERT INTO STUDENT VALUES (103, 'Chirag', 'A', 'M', '2010-01-05', 45, '9810033333');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE STUDENT ADD Remarks VARCHAR(30);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE STUDENT SET Marks = Marks + 5 WHERE Section = 'A';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Section = 'A' change.
(v)
DROP TABLE STUDENT;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE EMPLOYEE (
EmpID CHAR(4) PRIMARY KEY,
EName VARCHAR(25) NOT NULL,
Dept VARCHAR(10),
City VARCHAR(15),
DOJ DATE,
Salary INT,
Bonus INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes EmpID unique and not empty; NOT NULL makes EName compulsory.
(ii)
INSERT INTO EMPLOYEE VALUES ('E154', 'Usha', 'Sales', 'Mumbai', '2021-03-10', 36000, NULL);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE EMPLOYEE ADD Rating INT;
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE EMPLOYEE SET Salary = Salary + 5 WHERE Dept = 'HR';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Dept = 'HR' change.
(v)
DELETE FROM EMPLOYEE WHERE Salary < 70000;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Write SQL commands for the following:
(i)
CREATE TABLE PRODUCT (
PCode CHAR(4) PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Category VARCHAR(12),
Brand VARCHAR(12),
MfgDate DATE,
Price INT,
Discount INT
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PCode unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PRODUCT VALUES ('P57', 'Lunch Box', 'Home', 'Milton', '2025-12-18', 275, 8);Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PRODUCT ADD Rating INT;
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PRODUCT SET Price = Price + 5 WHERE Category = 'Electronics';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Category = 'Electronics' change.
(v)
DROP TABLE PRODUCT;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE BOOK (
BookID INT PRIMARY KEY,
Title VARCHAR(30) NOT NULL,
Subject VARCHAR(12),
Publisher VARCHAR(12),
IssueDate DATE,
Price INT,
Member VARCHAR(15)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes BookID unique and not empty; NOT NULL makes Title compulsory.
(ii)
INSERT INTO BOOK VALUES (304, 'Python Basics', 'Computer', 'BPB', '2026-08-01', 350, NULL);
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE BOOK ADD Status VARCHAR(10);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE BOOK SET Price = Price + 5 WHERE Subject = 'Computer';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Subject = 'Computer' change.
(v)
DROP TABLE BOOK;
Explanation: DROP TABLE removes the whole table: its structure and all its rows.
Write SQL commands for the following:
(i)
CREATE TABLE PATIENT (
PID INT PRIMARY KEY,
PName VARCHAR(20) NOT NULL,
Ward VARCHAR(12),
Doctor VARCHAR(15),
AdmitDate DATE,
Fee INT,
Insurance VARCHAR(10)
);Explanation: CREATE TABLE is a DDL command that makes the structure: each column gets a data type; PRIMARY KEY makes PID unique and not empty; NOT NULL makes PName compulsory.
(ii)
INSERT INTO PATIENT VALUES (113, 'Om', 'General', 'Dr. Rao', '2026-09-10', 1200, 'Star');
Explanation: INSERT INTO ... VALUES adds one new row. Values are given in the same order as the columns; text and dates go in quotes, NULL without quotes.
(iii)
ALTER TABLE PATIENT ADD Remarks VARCHAR(30);
Explanation: ALTER TABLE ... ADD changes the structure by adding a new column; it is NULL in the existing rows.
(iv)
UPDATE PATIENT SET Fee = Fee + 5 WHERE Ward = 'General';
Explanation: UPDATE ... SET changes the data; WHERE makes sure only the rows with Ward = 'General' change.
(v)
DELETE FROM PATIENT WHERE Fee < 1000;
Explanation: DELETE removes only the rows that satisfy WHERE; the table structure remains.
Tap an option to check your answer at once; your score is saved
Ten multiple-choice questions picked at random. Tap an option to answer. You get your score at the end.
Twenty ready papers with blueprints and a random paper maker, all on the CBSE paper design (Class XI unit marks)
Each paper has 37 questions for 70 marks in Sections A to E, with internal choices (OR) in Q24, Q25, Q26, Q28, Q29, Q30, Q32, Q34, Q35 and Q37. Unit marks are kept as in the syllabus: Unit 1 10, Unit 2 25, Unit 3 30, Unit 4 5. Every paper opens with its chapter-wise blueprint. No question is repeated: the twenty papers use 940 different questions.
Downloads and printing work when this page is opened as an HTML file in a browser.
Choose Paper 1 to Paper 20, or make a random paper. The blueprint and the paper open here.
Read this the evening before and at the exam centre gate
= NULL instead of IS NULLint() with input()L = L.sort()