Class XI Informatics Practices (065)

Minimum Learning Support Material · CBSE 2026-27

Notes · Infographics · Labs · 1682 solved questions · Flashcards · Quiz · Practice Paper Maker

Designed by NareN, PGT (Computer Science), PM SHRI K V Shalimar Bagh, Delhi-88 (Shift-I) ✨ Click Here For Your Valuable Feedback ✨
1

Know the paper first

Theory 70 marks, 3 hours, 37 questions in five sections

SectionQuestionsMarks eachTotalWhat comes
AQ1 to Q21121MCQ and True/False on all units; Q20 and Q21 are Assertion-Reason
BQ22 to Q28214Computer system, emerging trends, Python, database, SQL
CQ29 to Q32312Python output and program, SQL commands, keys
DQ33, Q3448Computer system case, Python program
EQ35 to Q37515Long Python program, SQL outputs and SQL commands

Unit-wise marks (theory 70)

Blueprint of the paper

One common blueprint for all twenty practice papers. Each cell shows the number of questions, with their marks in brackets.

UnitSec A1 mark each1 mSec B2 marks each2 mSec C3 marks each3 mSec D4 marks each4 mSec E5 marks each5 mTotalmarks
Unit 1Introduction to Computer System4 (4)1 (2)-1 (4)-10
Unit 2Introduction to Python6 (6)2 (4)2 (6)1 (4)1 (5)25
Unit 3Database Concepts and SQL8 (8)3 (6)2 (6)-2 (10)30
Unit 4Introduction to Emerging Trends3 (3)1 (2)---5
Total21 (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.

The fixed slots

Q22Computer system2 marks
Q23Emerging trends2 marks
Q27, Q28Write SQL queries2 marks
Q29Output of a Python program3 marks
Q30Python program3 marks
Q31Three SQL commands3 marks
Q32Keys, degree, cardinality3 marks
Q33Computer system case4 marks
Q34List / dictionary / NumPy program4 marks
Q35Long Python program5 marks
Q36, Q37SQL: outputs and commands5 marks

Internal choice (OR) is given in Q24, Q25, Q26, Q28, Q29, Q30, Q32, Q34, Q35 and Q37.

Practical: 30 marks

Practical file: at least 14 Python programs and 14 SQL queries.

2

Pass plan in three steps

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.

Step 1 · 15 marksUnits 1 and 4: computer parts, memory units, software types and the emerging trends. Pure learning, with the infographics here.
Step 2 · 30 marksSQL: CREATE, INSERT, SELECT with WHERE, BETWEEN, IS NULL, UPDATE, DELETE, ALTER, DROP; keys, degree and cardinality. Practise on the tables of this kit.
Step 3 · 25 marksPython: operators, if and loops, lists, dictionaries, NumPy arrays; output questions and the suggested practical programs.
Marks milne wali baat
  • In SQL, end every command with a semicolon and put text and dates in single quotes.
  • In Python output questions, write each printed line exactly, with brackets and commas.
  • Draw a neat table for degree and cardinality questions.
Common mistake
  • WHERE Phone = NULL is wrong; use IS NULL.
  • DELETE removes rows; DROP removes the table.
  • input() gives a string: use int().
  • L.sort() returns None.
3

Computer system

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.

Evolution of computing devices

c. 2500 BCAbacuscounting with beads
1642PascalineBlaise Pascal: adds and subtracts
1834Analytical EngineCharles Babbage: input, mill, store, output
1890Tabulating machineHerman Hollerith: punched cards for the US census
1945Von Neumann ideastored program concept
1946ENIACvacuum tubes; filled a room
1947Transistorsmaller, faster, cooler
1958Integrated circuitmany transistors on one chip
1971MicroprocessorIntel 4004: CPU on a chip
1981Personal computerIBM PC; computers at home
2007Smartphonea computer in your pocket
TodayCloud, AI, IoTcomputing everywhere

Picture: block diagram of a computer

Central Processing Unit (CPU)Control Unit (CU)fetch · decode · executeALUarithmetic, logicRegistersfastestPrimary memoryRAM · ROM · cacheInput unitkeyboard, mouseOutput unitmonitor, printerSecondary storageHDD · SSD · pen driveData and instructions flow between the unitsdata / instructionscontrol signals from the CU
Block diagram of a computer. The CU controls every unit (dashed lines); data moves along the solid arrows.

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 and learnParts of a computer

Tap each part.

Input unit

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.

Central Processing Unit

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.

Arithmetic Logic Unit

Does: arithmetic (+, -, ×, ÷) and logical work (comparisons).

Control Unit

Does: fetches, decodes and runs instructions; directs all the other units.

Primary memory

Does: holds the program and data being used; RAM, ROM, cache, registers.

Output unit

Does: gives the result to the user.

Devices: monitor, printer, speaker, projector, plotter, 3D printer.

System bus

Data bus: carries data.

Address bus: carries memory addresses.

Control bus: carries control signals.

Picture: the machine cycle

Fetchread from memoryDecodeCU understands itExecuteALU does the work
The CPU repeats the fetch, decode, execute cycle for every instruction.

Input and output devices

Input deviceUseOutput deviceUse
Keyboardtype textMonitorshows soft copy
Scannercopies paper to imagePrintergives hard copy
OMRreads filled bubblesSpeakersound output
MICRreads cheque numbersPlotterlarge drawings, maps
Barcode readerreads product codesProjectorshows on a big screen
Biometric scannerfingerprint, face3D printermakes solid objects

GameInput or output?

Tap the right box.

GamePut the computing devices in order of invention

Tap from the oldest to the newest.

More in detail

Generations of computers

GenerationTechnologyExampleFeature
1st (1940s-50s)vacuum tubesENIAC, UNIVAChuge, hot, costly
2nd (1950s-60s)transistorsIBM 1401smaller, faster
3rd (1960s-70s)integrated circuitsIBM 360keyboards and monitors
4th (1970s-now)microprocessorsPCs, laptopssmall, cheap, personal
5th (now)AI, parallel processingsmart assistantslearning machines

Easy example: making tea is like a computer

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 and learnSpecial input devices

Tap a device.

Optical Mark Reader

Reads: pencil or pen marks in bubbles.

Where: answer sheets of NEET, JEE, school tests.

Magnetic Ink Character Recognition

Reads: numbers printed with magnetic ink.

Where: the bottom line of a bank cheque.

Optical Character Recognition

Reads: printed text from an image and makes it editable.

Where: scanning a book page into a Word file.

Barcode / QR reader

Reads: black-and-white bar or square codes.

Where: shop billing, UPI payments.

Biometric scanner

Reads: fingerprint, face or iris.

Where: Aadhaar, school attendance, phone unlock.

Remember

Remember the order: vacuum tube → transistor → IC → microprocessor. Each made computers smaller, faster and cheaper.

Common mistake

The CPU is not the cabinet (box). The CPU is the chip inside it.

Open its questions
4

Memory and data recovery

Units, primary and secondary memory, deletion, recovery, security

Memory stores data and instructions. The smallest unit is a bit (0 or 1).

bit>nibble = 4 bits>byte = 8 bits>KB = 1024 B>MB>GB>TB>PB>EB>ZB>YB

Try it Memory unit converter

Type a value and choose units.

Computer memory
Primary memory
  • RAM: volatile, read-write (SRAM, DRAM)
  • ROM: non-volatile, start-up program (PROM, EPROM, EEPROM)
  • Cache: very fast, between CPU and RAM
  • Registers: inside the CPU, fastest
Secondary memory
  • HDD: magnetic, spinning disk
  • SSD: flash chips, no moving parts
  • Pen drive, memory card
  • CD / DVD: optical
  • Cloud storage: over the Internet

Picture: the memory pyramid

RegistersCacheRAM (main memory)SSD / Hard diskPen drive, DVD, cloudspeed
Higher in the pyramid: faster, smaller and costlier. Lower: slower, bigger and cheaper.
Primary memorySecondary memory
Accessed by CPUdirectlythrough primary memory
Speedfastslower
Cost per GBhighlow
Sizesmall (GB)large (TB)
Volatile?RAM yes, ROM nono

Data deletion, recovery and security

Deletefile goes to the Recycle Bin
→
Empty bin / Shift+Delonly the entry is removed; space is marked free
→
Still on diskdata stays until new data overwrites it
→
Recoveryrecovery software can bring it back

Security concern

  • Old phones, disks and pen drives may still hold our deleted data
  • Others can recover photos, messages, passwords and misuse them

Safe practice

  • Securely wipe or shred data before selling or giving away
  • Encrypt devices; use factory reset with encryption
  • Physically destroy disks that held secret data
  • Keep backups so recovery is not needed

More in detail

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

SizeAbout as much as
1 byteone letter, such as A
1 KBa short paragraph
1 MBa small book or a photo
1 GBa full-length movie (low quality)
1 TBabout 2.5 lakh photos
HDDSSDPen drive
Works byspinning magnetic diskflash chipsflash chips
Speedslowervery fastmedium
Moving partsyesnono
Usecheap large storagefast laptopscarrying files
Remember

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.

Common mistake

Formatting or deleting is not enough before selling a phone. Use encryption and a secure wipe.

Open its questions
5

Software

System and application, generic and specific, translators, OS

Software is a set of programs that tells the hardware what to do.

Software
System software
  • Operating system: Windows, Linux, Android, iOS
  • Device drivers: printer driver
  • Utilities: antivirus, disk cleanup, backup, compression
  • Language translators: compiler, interpreter, assembler
Application software
  • General purpose (generic): word processor, spreadsheet, browser, presentation
  • Specific purpose (customised): school fee system, railway reservation, hospital management

Language translators

Source codehigh-level (Python)Translatorcompiler / interpreterMachine code0s and 1s
AssemblerCompilerInterpreter
Fromassembly languagehigh-level, whole programhigh-level, line by line
Errors-all listed togetherstops at the first error
ExampleNASMC, C++Python

Operating system: functions

  • Process management
  • Memory management
  • File management
  • Device management
  • Security and user interface (CLI, GUI)

Open source and proprietary

  • Open source: code available; free to use and change (Linux, LibreOffice, Python, MySQL)
  • Proprietary: owned; licence needed (Windows, MS Office, Tally)

GameSort the software

Tap the type.

More in detail

Easy example: hardware and software

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.

SoftwareTypeWhy
Windows 11System (OS)runs the computer
Printer driverSystem (driver)lets the OS use the printer
AntivirusSystem (utility)protects the computer
Python interpreterSystem (translator)runs Python programs
LibreOffice WriterApplication, general purposeanyone can type letters
School fee softwareApplication, specific purposemade for one school

GameOrder the translation of a Python program

Tap in order.

Open its questions
6

Python basics

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.

Two modes

  • Interactive mode: type at >>>, see the result at once; not saved
  • Script mode: write a program in a .py file, save and run it (F5 in IDLE)

Character set

  • Letters A-Z, a-z; digits 0-9
  • Special symbols + - * / ( ) [ ] { } : , # = < >
  • White space: space, tab, new line

Tokens: the smallest units

TokenMeaningExamples
Keywordreserved wordif, else, for, while, True, False, None, and
Identifiername given by the usermarks, total_1, Name
Literalfixed value25, 3.5, 'KV', True, None
Operatordoes an operation+ - * / // % ** == and in
Punctuatorseparates parts( ) [ ] { } , : ' #
Data types
Numbers
  • int: 25
  • float: 3.5
  • complex: 3 + 4j
  • bool: True, False
Sequences
  • str: 'KV'
  • list: [1, 2, 3]
Mapping
  • dict: {'a': 1}
None
  • NoneType: None
MutableImmutable
Meaningcan be changed in placecannot be changed; a change makes a new object
Typeslist, dictint, 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

Operators

KindOperatorsExampleResult
Arithmetic+ - * / // % **17 // 5, 17 % 5, 2 ** 33, 2, 8
Relational== != > < >= <=7 != 4True
Logicaland or not5 > 3 and 2 > 4False
Assignment=x = 5x gets 5
Augmented+= -= *= /= //= %= **=x += 2x = x + 2
Identityis, is nota is bsame object?
Membershipin, not in3 in [1, 3]True
( )>**>* / // %>+ ->relational>not>and>or
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 conversionExplicit conversion
Done byPython itselfthe programmer
Example5 + 2.5 gives 7.5 (int to float)int('25'), float(7), str(10)

Errors and debugging

ErrorWhenExample
Syntax errorgrammar is wrong; found before runningif x > 5 print(x) (no colon)
Logical errorruns but gives a wrong answeravg = a + b / 2
Runtime errorwhile running10 / 0 (ZeroDivisionError), int("ten") (ValueError)

GameMutable or immutable?

Tap the box.

More in detail

Easy example: a variable is a labelled box

marks78
name'Riya'
passedTrue

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
'''
Open its questions
7

Flow of control

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.

if - elif - else

marks = 72
if marks >= 80:
    print('A')
elif marks >= 60:
    print('B')
else:
    print('C')

for with range()

for i in range(1, 6):
    print(i * i, end=' ')

Try it range() explorer

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
nn % 10sn // 10
472888472
47221047
477174
44210
forwhile
Usenumber of rounds knownrepeat while a condition is True
Examplefor i in range(5):while n > 0:
Risk-infinite loop if the condition never becomes False
Remember

range(a, b) gives a, a+1, ... b-1. It runs b - a times.

Common mistake

Forgetting the colon or the indentation is the most common syntax error.

More in detail

Picture: if-else as a flowchart

Startmarks >= 33 ?print('Pass')print('Fail')StopTrueFalse
The diamond asks a question; one of the two paths runs.

Picture: while loop as a flowchart

Starti = 1i <= 5 ?print(i); i += 1StopTrueFalse
The condition is checked before every round; the arrow goes back up.

Easy examples

Real lifePython idea
If it rains, take an umbrella, else wear sunglassesif ... else
Do 10 push-upsfor i in range(10):
Keep filling the bottle until it is fullwhile not full:
Traffic light: red, yellow or greenif ... 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
Open its questions
8

Lists

Operations, traversing, methods, built-in functions

A list is an ordered, mutable collection in [ ]: L = [10, 'KV', 3.5].

Picture: list indexing

010-5
120-4
230-3
340-2
450-1

L[0] is 10, L[-1] is 50, L[1:4] is [20, 30, 40].

OperationExampleResult
Concatenation[1, 2] + [3][1, 2, 3]
Repetition[0] * 3[0, 0, 0]
Membership3 in [1, 3]True
Slicing[5, 6, 7, 8][1:3][6, 7]
Traversingfor x in L: print(x)each element

Try it List method lab

Type a value, tap a method, watch the list change.

Method / functionDoesExample (L = [30, 10, 20])
len(L)number of elements3
list(x)makes a listlist('ab') gives ['a', 'b']
L.append(x)adds x at the end[30, 10, 20, 5]
L.insert(i, x)adds x at index iL.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 occursL.count(10) gives 1
L.index(x)position of xL.index(20) gives 2
L.remove(x)deletes the first x[30, 20]
L.pop(i)deletes and returnsL.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, sumsmallest, largest, total10, 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

More in detail

Easy example: a list is like a train

0Engine1Coach A2Coach B3Coach C

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
Open its questions
9

Dictionaries

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}

'Amit'→85
'Bela'→92
'Charu'→78

key → value. Keys are unique; marks['Bela'] gives 92.

Try it Dictionary lab

D = {'Amit': 85, 'Bela': 92}. Add, change, get or delete.

Method / functionDoesExample (D = {"a": 1, "b": 2})
dict()makes a dictionarydict(a=1) gives {"a": 1}
len(D)number of pairs2
D[k] = vadds or updatesD["c"] = 3
del D[k]deletes a pairdel D["a"]
D.get(k)value, or None if absentD.get("z") gives None
D.keys()all keysdict_keys(["a", "b"])
D.values()all valuesdict_values([1, 2])
D.items()all pairsdict_items([("a", 1), ("b", 2)])
D.update(E)adds / changes pairs of ED.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

More in detail

Easy example: a dictionary is like a phone book

'Mummy'→'98110 11111'
'Papa'→'98110 22222'
'School'→'011 2747 1234'

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
Open its questions
10

Introduction to NumPy

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])

01214527330

ndim 1 · shape (4,) · size 4

2-D array: np.array([[1, 2, 3], [4, 5, 6]])

123
456

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

Try it Array shape lab

Type a list or a nested list (rows of equal length). See ndim, shape and size.

Python listNumPy array
Typesmixed allowedone type only
+joins: [1, 2] + [3, 4] = [1, 2, 3, 4]adds: [4 6]
* 2repeats the listdoubles each element
Speed and memoryslower, more memoryfaster, less memory
Remember

Remember: ndim = number of dimensions, shape = (rows, columns), size = total elements, dtype = type of the elements.

Common mistake

Print shows arrays without commas: [2 4 6], not [2, 4, 6].

More in detail

Picture: element-by-element work

102030
+
123
=
112233

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.

Open its questions
11

Database concepts

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.

Problems of file systems

  • Data redundancy (repeated data)
  • Data inconsistency (copies differ)
  • Difficult access and sharing
  • Poor security

Advantages of a DBMS

  • Less redundancy and inconsistency
  • Easy sharing and fast search
  • Security and access control
  • Backup and recovery

Picture: parts of a relation

RollNoNameSectionMarks1AaravA782BhavyaB923ChiragA45Attribute (column)Tuple(row)Primary keyDegree = 4 columnsCardinality = 3 rowsDomain of Section:{A, B, C}
Relation STUDENT: attributes, tuples, primary key, degree, cardinality and domain.
TermMeaningIn the picture
Relationa tableSTUDENT
Attributea columnRollNo, Name, Section, Marks
Tuplea row(2, Bhavya, B, 92)
Degreenumber of attributes4
Cardinalitynumber of tuples3
Domainset of allowed valuesSection: {A, B, C}

Keys

All attributesRollNo, AdmNo, Name, Section, Marks
Candidate keyscan identify every row: RollNo, AdmNo
Primary keythe one chosen: RollNo
Alternate keythe rest: AdmNo
KeyMeaningExample
Candidate keycan uniquely identify each rowRollNo, AdmNo
Primary keythe candidate key chosen; no NULL, no repeatsRollNo
Alternate keycandidate key not chosenAdmNo

GameDegree or cardinality?

Tap the term that changes.

More in detail

Easy example: file system versus database

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

AdmNoRollNoNameAadhaarCity
45011Aarav1111 2222 3333Delhi
45122Bhavya4444 5555 6666Delhi
45233Aarav7777 8888 9999Pune

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.

Open its questions
12

Structured Query Language

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.

DDL

Data Definition Language

defines the structure

  • CREATE DATABASE / TABLE
  • ALTER TABLE (add, drop column / primary key)
  • DROP TABLE / DATABASE
DML

Data Manipulation Language

changes the data

  • INSERT INTO ... VALUES
  • UPDATE ... SET ... WHERE
  • DELETE FROM ... WHERE
DQL

Data Query Language

reads the data

  • SELECT ... FROM ... WHERE
  • with relational and logical operators
  • BETWEEN, IS NULL, IS NOT NULL

Data types and constraints

Data typeStoresExample
INTwhole numbers45
FLOAT / DECIMAL(8,2)numbers with decimals45.75
CHAR(n)fixed-length textCHAR(1): 'A'
VARCHAR(n)variable-length textVARCHAR(25): 'Bhavya'
DATEdate as 'YYYY-MM-DD''2009-11-30'
ConstraintRule
NOT NULLa value must be given
UNIQUEno two rows have the same value
PRIMARY KEYNOT 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;

DQL: SELECT

SELECT Name, Markswhich columns
FROM STUDENTwhich table
WHERE Marks BETWEEN 60 AND 80which rows
; end of the statement

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Query 1

SELECT Name, Marks FROM STUDENT WHERE Marks > 70;
NameMarks
Aarav78
Bhavya92
Eshan88

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.

Query 2

SELECT * FROM STUDENT WHERE Section = 'A' AND Gender = 'F';
RollNoAdmNoNameSectionGenderDOBMarksPhone
64556FarahAF2009-09-09319810066666

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 (*).

Query 3

SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
NameDOB
Bhavya2009-11-30
Divya2009-07-21
Farah2009-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.

Query 4

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 =.)

Query 5

SELECT Name, Marks, Marks + 5 FROM STUDENT WHERE Section <> 'A' OR Marks >= 85;
NameMarksMarks + 5
Bhavya9297
Divya6671
Eshan8893
Gaurav5964

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.

Try it SELECT builder

Build a query on the STUDENT table above and see its result at once.

Remember

Text and dates go in single quotes; numbers do not. BETWEEN a AND b includes both a and b.

Common mistake

= NULL never matches. Use IS NULL / IS NOT NULL.

GameDDL, DML or DQL?

Tap the family of the command.

More in detail

Picture: UPDATE changes values

UPDATE STUDENT SET Marks = Marks + 5 WHERE Section = 'A';

Before

RollNoNameSectionMarksPhone
1AaravA7898100
2BhavyaB92NULL
3ChiragA4598101
4DivyaC6698102
➜

After

RollNoNameSectionMarksPhone
1AaravA8398100
2BhavyaB92NULL
3ChiragA5098101
4DivyaC6698102

Picture: DELETE removes rows

DELETE FROM STUDENT WHERE Marks < 50;

Before

RollNoNameSectionMarksPhone
1AaravA7898100
2BhavyaB92NULL
3ChiragA4598101
4DivyaC6698102
➜

After

RollNoNameSectionMarksPhone
1AaravA7898100
2BhavyaB92NULL
4DivyaC6698102

Picture: INSERT adds a row

INSERT INTO STUDENT VALUES (5, 'Esha', 'B', 81, NULL);

Before

RollNoNameSectionMarksPhone
1AaravA7898100
2BhavyaB92NULL
3ChiragA4598101
4DivyaC6698102
➜

After

RollNoNameSectionMarksPhone
1AaravA7898100
2BhavyaB92NULL
3ChiragA4598101
4DivyaC6698102
5EshaB81NULL

Picture: ALTER ADD adds a column

ALTER TABLE STUDENT ADD Grade CHAR(1);

Before

RollNoNameSectionMarksPhone
1AaravA7898100
2BhavyaB92NULL
3ChiragA4598101
4DivyaC6698102
➜

After

RollNoNameSectionMarksPhoneGrade
1AaravA7898100NULL
2BhavyaB92NULLNULL
3ChiragA4598101NULL
4DivyaC6698102NULL

Easy example: SQL in daily life

You want toSQL
see the students of Section ASELECT * FROM STUDENT WHERE Section = 'A';
give 5 grace marks to Section AUPDATE STUDENT SET Marks = Marks + 5 WHERE Section = 'A';
find who has not given a phone numberSELECT Name FROM STUDENT WHERE Phone IS NULL;
remove a student who leftDELETE FROM STUDENT WHERE RollNo = 4;
Open its questions
14

Question bank: every type, with answers

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.

Section A · 1 mark each

A1Unit 1: computer system, memory, software1 mark · 135 questions
A1.1Practice1 mark

Which of these is application software?

Answer

(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.

A1.2Practice1 mark

Which of these is an output device?

Answer

(b) Monitor A projector shows the computer's output on a big screen.

A1.3Practice1 mark

Which of these is an input device?

Answer

(d) MICR A barcode reader sends the product code into the computer, so it is an input device.

A1.4Practice1 mark

Software that manages the hardware and gives a platform to other programs is

Answer

(a) an operating system The operating system manages the hardware and runs all other programs, e.g. Windows, Linux.

A1.5Practice1 mark

State True or False: Python uses an interpreter.

Answer

(a) True Python code is run line by line by the Python interpreter.

A1.6Practice1 mark

Which of these is an output device?

Answer

(b) Monitor A projector shows the computer's output on a big screen.

A1.7Practice1 mark

Which of these is an output device?

Answer

(b) Plotter A projector shows the computer's output on a big screen.

A1.8Practice1 mark

Which of these is an output device?

Answer

(b) Headphones A projector shows the computer's output on a big screen.

A1.9Practice1 mark

Which of these is an input device?

Answer

(d) OMR A barcode reader sends the product code into the computer, so it is an input device.

A1.10Practice1 mark

How many bits are there in 15 bytes?

Answer

(d) 120 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.11Practice1 mark

The part of the CPU that does calculations and comparisons is the

Answer

(c) ALU The Arithmetic Logic Unit does arithmetic (+, -, *, /) and logical comparisons (>, <, ==).

A1.12Practice1 mark

Antivirus and disk cleanup are examples of

Answer

(d) utility software Utilities maintain and protect the computer; they are a kind of system software.

A1.13Practice1 mark

Which of these is an input device?

Answer

(d) Microphone A barcode reader sends the product code into the computer, so it is an input device.

A1.14Practice1 mark

Which of these is application software?

Answer

(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.

A1.15Practice1 mark

How many GB are there in 4 TB?

Answer

(d) 4096 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.16Practice1 mark

Which invention replaced vacuum tubes and made computers smaller?

Answer

(c) Transistor The transistor (1947) is small, cheap and cool, so second-generation computers became smaller and faster.

A1.17Practice1 mark

Which of these is free and open source software?

Answer

(d) LibreOffice LibreOffice is free and its source code is open; the others are proprietary.

A1.18Practice1 mark

Which of these is an output device?

Answer

(b) 3D printer A projector shows the computer's output on a big screen.

A1.19Practice1 mark

Which of these is an output device?

Answer

(b) Monitor A projector shows the computer's output on a big screen.

A1.20Practice1 mark

Which of these is an output device?

Answer

(b) Plotter A projector shows the computer's output on a big screen.

A1.21Practice1 mark

1 GB is equal to

Answer

(a) 1024 MB Each bigger unit is 1024 times the smaller: 1 GB = 1024 MB.

A1.22Practice1 mark

Which of these is an example of specific purpose software?

Answer

(b) Railway reservation software Railway reservation software is made only for the railways' own work.

A1.23Practice1 mark

Which of these is an input device?

Answer

(d) Graphics tablet A barcode reader sends the product code into the computer, so it is an input device.

A1.24Practice1 mark

Which of these is an input device?

Answer

(d) Barcode reader A barcode reader sends the product code into the computer, so it is an input device.

A1.25Practice1 mark

Which of these is system software?

Answer

(a) Antivirus A device driver helps the operating system use a device, so it is system software.

A1.26Practice1 mark

A device that reads the answer sheets of competitive exams is

Answer

(b) OMR (Optical Mark Reader) OMR reads the marks (filled bubbles) on special sheets, as in competitive exams.

A1.27Practice1 mark

Which of these is system software?

Answer

(a) Python interpreter A device driver helps the operating system use a device, so it is system software.

A1.28Practice1 mark

How many TB are there in 12 PB?

Answer

(a) 12288 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.29Practice1 mark

Which of these is system software?

Answer

(a) Compiler A device driver helps the operating system use a device, so it is system software.

A1.30Practice1 mark

How many bytes are there in 15 KB?

Answer

(b) 15360 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.31Practice1 mark

How many KB are there in 16 MB?

Answer

(d) 16384 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.32Practice1 mark

The part of the CPU that controls the order of operations is the

Answer

(d) control unit The control unit fetches and decodes instructions and directs the other parts, like a traffic police officer.

A1.33Practice1 mark

How many bits are there in 4 nibbles?

Answer

(b) 16 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.34Practice1 mark

An assembler translates

Answer

(c) assembly language into machine language An assembler converts assembly language (mnemonics like ADD, MOV) into machine code.

A1.35Practice1 mark

How many bytes are there in 6 KB?

Answer

(c) 6144 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.36Practice1 mark

Which of these is non-volatile?

Answer

(a) ROM ROM keeps its contents even without power; it stores the start-up program.

A1.37Practice1 mark

The idea of storing a program in memory along with data is called the

Answer

(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.

A1.38Practice1 mark

Which of these is an output device?

Answer

(b) Monitor A projector shows the computer's output on a big screen.

A1.39Practice1 mark

Which of these is application software?

Answer

(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.

A1.40Practice1 mark

How many bytes are there in 12 KB?

Answer

(a) 12288 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.41Practice1 mark

Which of these is an input device?

Answer

(d) Microphone A barcode reader sends the product code into the computer, so it is an input device.

A1.42Practice1 mark

Which of these is an input device?

Answer

(d) Barcode reader A barcode reader sends the product code into the computer, so it is an input device.

A1.43Practice1 mark

Which of these is an input device?

Answer

(d) Graphics tablet A barcode reader sends the product code into the computer, so it is an input device.

A1.44Practice1 mark

Which of these is an input device?

Answer

(d) Biometric scanner A barcode reader sends the product code into the computer, so it is an input device.

A1.45Practice1 mark

Which memory holds the BIOS / start-up program?

Answer

(b) ROM The BIOS (start-up program) is kept in ROM because ROM does not lose data without power.

A1.46Practice1 mark

State True or False: A deleted file is always lost for ever.

Answer

(b) False It can often be recovered until it is overwritten.

A1.47Practice1 mark

Which of these is an output device?

Answer

(b) Monitor A projector shows the computer's output on a big screen.

A1.48Practice1 mark

Which of these is system software?

Answer

(d) Device driver A device driver helps the operating system use a device, so it is system software.

A1.49Practice1 mark

Which law says that the number of transistors on a chip doubles about every two years?

Answer

(c) Moore's law Gordon Moore observed that the number of transistors on a chip doubles about every two years.

A1.50Practice1 mark

How many bits are there in 7 bytes?

Answer

(b) 56 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.51Practice1 mark

Which of these is system software?

Answer

(a) Compiler A device driver helps the operating system use a device, so it is system software.

A1.52Practice1 mark

ENIAC was built using

Answer

(a) vacuum tubes ENIAC (1946) used about 18,000 vacuum tubes, filled a large room and used a lot of power.

A1.53Practice1 mark

Which of these is application software?

Answer

(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.

A1.54Practice1 mark

How many bits are there in 2 bytes?

Answer

(c) 16 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.55Practice1 mark

Which of these is an input device?

Answer

(d) OMR A barcode reader sends the product code into the computer, so it is an input device.

A1.56Practice1 mark

Which of these is an output device?

Answer

(b) Printer A projector shows the computer's output on a big screen.

A1.57Practice1 mark

Which memory loses its contents when the power is switched off?

Answer

(c) RAM RAM is volatile: its contents are lost when the power is switched off.

A1.58Practice1 mark

Which of these is an output device?

Answer

(b) Projector A projector shows the computer's output on a big screen.

A1.59Practice1 mark

Which of these is system software?

Answer

(a) Disk cleanup A device driver helps the operating system use a device, so it is system software.

A1.60Practice1 mark

The abacus was used mainly for

Answer

(a) counting and simple calculation It has beads on rods that are moved to count, add and subtract; it is the oldest calculating device.

A1.61Practice1 mark

The wires that carry data between the parts of a computer are called

Answer

(c) buses Buses (data, address and control bus) connect the CPU, memory and devices.

A1.62Practice1 mark

Which of these is an output device?

Answer

(b) Projector A projector shows the computer's output on a big screen.

A1.63Practice1 mark

A 3D printer is an example of

Answer

(a) an output device It takes a design from the computer and makes a solid object, so it gives output.

A1.64Practice1 mark

1 nibble is equal to

Answer

(b) 4 bits A nibble is half a byte, that is 4 bits.

A1.65Practice1 mark

Which of these is an output device?

Answer

(b) Headphones A projector shows the computer's output on a big screen.

A1.66Practice1 mark

When a file is deleted, the operating system usually

Answer

(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.

A1.67Practice1 mark

Which of these is an output device?

Answer

(b) Printer A projector shows the computer's output on a big screen.

A1.68Practice1 mark

How many GB are there in 11 TB?

Answer

(d) 11264 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.69Practice1 mark

Which of these is an output device?

Answer

(b) Speaker A projector shows the computer's output on a big screen.

A1.70Practice1 mark

How many GB are there in 6 TB?

Answer

(a) 6144 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.71Practice1 mark

Which of these is application software?

Answer

(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.

A1.72Practice1 mark

Which of these is an output device?

Answer

(b) Plotter A projector shows the computer's output on a big screen.

A1.73Practice1 mark

The Intel 4004 (1971) was the first

Answer

(a) microprocessor Intel 4004, made in 1971, was the first microprocessor (a 4-bit CPU on one chip).

A1.74Practice1 mark

The operating system of most smartphones is

Answer

(c) Android or iOS Android (Google) and iOS (Apple) are mobile operating systems.

A1.75Practice1 mark

How many TB are there in 2 PB?

Answer

(b) 2048 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.76Practice1 mark

Software used to bring back deleted files is called

Answer

(d) data recovery software Data recovery software scans the disk for data that is marked free but not yet overwritten.

A1.77Practice1 mark

How many MB are there in 5 GB?

Answer

(c) 5120 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.78Practice1 mark

How many GB are there in 9 TB?

Answer

(c) 9216 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.79Practice1 mark

Which of these is an input device?

Answer

(d) Mouse A barcode reader sends the product code into the computer, so it is an input device.

A1.80Practice1 mark

Registers are

Answer

(c) the fastest memory, inside the CPU Registers are tiny storage places inside the CPU; they are the fastest memory.

A1.81Practice1 mark

Which memory is between the CPU and RAM and is very fast?

Answer

(d) Cache memory Cache keeps the most-used data close to the CPU so the CPU does not wait for slower RAM.

A1.82Practice1 mark

The Pascaline, made by Blaise Pascal, could

Answer

(b) add and subtract Pascal's machine (1642) used gears and wheels and could only add and subtract numbers.

A1.83Practice1 mark

Which of these is an output device?

Answer

(a) Projector A projector shows the computer's output on a big screen.

A1.84Practice1 mark

A word processor used by everyone is an example of

Answer

(b) general purpose (generic) software It is made for many users and common tasks, so it is general purpose software.

A1.85Practice1 mark

Which of these is application software?

Answer

(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.

A1.86Practice1 mark

1 byte is equal to

Answer

(b) 8 bits 8 bits make 1 byte; one byte can store one English character.

A1.87Practice1 mark

Many transistors on one silicon chip is called an

Answer

(c) integrated circuit (IC) An integrated circuit puts thousands of transistors on one chip; it started the third generation.

A1.88Practice1 mark

Software made for a particular user or organisation, such as a school's fee system, is

Answer

(b) specific purpose (customised) software It is made to order for one organisation, so it is specific purpose (customised) software.

A1.89Practice1 mark

Which of these is application software?

Answer

(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.

A1.90Practice1 mark

State True or False: Cache memory is faster than RAM.

Answer

(a) True Cache is made of fast SRAM and sits close to the CPU, so it is faster than RAM.

A1.91Practice1 mark

Which of these is system software?

Answer

(a) Compiler A device driver helps the operating system use a device, so it is system software.

A1.92Practice1 mark

How many bits are there in 14 bytes?

Answer

(c) 112 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.93Practice1 mark

Which of these is an input device?

Answer

(d) Barcode reader A barcode reader sends the product code into the computer, so it is an input device.

A1.94Practice1 mark

Which of these is secondary storage?

Answer

(d) Hard disk drive A hard disk stores data permanently; cache, registers and RAM are primary memory.

A1.95Practice1 mark

Which of these is an input device?

Answer

(d) OMR A barcode reader sends the product code into the computer, so it is an input device.

A1.96Practice1 mark

How many bytes are there in 10 KB?

Answer

(c) 10240 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.97Practice1 mark

Which of these is an input device?

Answer

(d) Graphics tablet A barcode reader sends the product code into the computer, so it is an input device.

A1.98Practice1 mark

How many bits are there in 10 nibbles?

Answer

(d) 40 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.99Practice1 mark

Which of these is system software?

Answer

(a) Disk cleanup A device driver helps the operating system use a device, so it is system software.

A1.100Practice1 mark

How many bits are there in 13 bytes?

Answer

(a) 104 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.101Practice1 mark

Which device converts text on paper into editable text?

Answer

(c) Scanner with OCR The scanner makes an image of the page; OCR software then recognises the characters as text.

A1.102Practice1 mark

State True or False: The microprocessor was invented before the transistor.

Answer

(b) False Transistor (1947) came before the IC and the microprocessor (1971).

A1.103Practice1 mark

Which of these is an output device?

Answer

(b) Monitor A projector shows the computer's output on a big screen.

A1.104Practice1 mark

Which of these is application software?

Answer

(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.

A1.105Practice1 mark

A complete CPU on a single chip is a

Answer

(d) microprocessor A microprocessor has the ALU, control unit and registers on one chip; it made personal computers possible.

A1.106Practice1 mark

Deleted files from the hard disk first go to the

Answer

(c) Recycle Bin (Trash) In Windows a deleted file first goes to the Recycle Bin, from where it can be restored.

A1.107Practice1 mark

The device used by banks to read the numbers printed on cheques is

Answer

(d) MICR MICR reads the numbers printed in magnetic ink at the bottom of a cheque.

A1.108Practice1 mark

An SSD stores data on

Answer

(a) flash memory chips An SSD uses flash memory chips and has no moving parts, so it is faster than a hard disk.

A1.109Practice1 mark

Which of these is an input device?

Answer

(d) OMR A barcode reader sends the product code into the computer, so it is an input device.

A1.110Practice1 mark

Which of these is an output device?

Answer

(b) Speaker A projector shows the computer's output on a big screen.

A1.111Practice1 mark

Herman Hollerith's tabulating machine used

Answer

(b) punched cards Hollerith used punched cards to read and count the census data of the USA (1890).

A1.112Practice1 mark

A program that translates the whole high-level program at once is a

Answer

(d) compiler A compiler translates the whole program at once and reports all errors together.

A1.113Practice1 mark

Who designed the Analytical Engine, the first idea of a general-purpose computer?

Answer

(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.

A1.114Practice1 mark

How many TB are there in 13 PB?

Answer

(c) 13312 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.115Practice1 mark

Which of these is an output device?

Answer

(b) Plotter A projector shows the computer's output on a big screen.

A1.116Practice1 mark

Which of these is system software?

Answer

(a) Compiler A device driver helps the operating system use a device, so it is system software.

A1.117Practice1 mark

How many KB are there in 12 MB?

Answer

(c) 12288 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.118Practice1 mark

Which is the largest unit?

Answer

(d) Petabyte Order: MB < GB < TB < PB, so the petabyte is the largest of these.

A1.119Practice1 mark

The three main parts of a computer system are

Answer

(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.

A1.120Practice1 mark

Software owned by a company whose source code is not shared is

Answer

(c) proprietary software Proprietary software is owned by a company; the user buys a licence but cannot see or change the code.

A1.121Practice1 mark

How many bits are there in 11 bytes?

Answer

(c) 88 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.122Practice1 mark

Which of these is an output device?

Answer

(b) 3D printer A projector shows the computer's output on a big screen.

A1.123Practice1 mark

Which device works both as input and output?

Answer

(c) Touch screen A touch screen shows output and also takes our touch as input.

A1.124Practice1 mark

Which of these is an output device?

Answer

(b) Plotter A projector shows the computer's output on a big screen.

A1.125Practice1 mark

How many bytes are there in 3 KB?

Answer

(d) 3072 1 byte = 8 bits; each larger unit is 1024 times the smaller one.

A1.126Practice1 mark

Which of these is system software?

Answer

(a) Compiler A device driver helps the operating system use a device, so it is system software.

A1.127Practice1 mark

The best way to prevent misuse of data on an old hard disk before selling it is to

Answer

(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.

A1.128Practice1 mark

Recovering deleted files is possible because

Answer

(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.

A1.129Practice1 mark

State True or False: A compiler shows all the errors of a program together.

Answer

(a) True The compiler checks the whole program first and lists all the errors together.

A1.130Practice1 mark

Which of these is an input device?

Answer

(d) Keyboard A barcode reader sends the product code into the computer, so it is an input device.

A1.131Practice1 mark

Which of these is an output device?

Answer

(b) 3D printer A projector shows the computer's output on a big screen.

A1.132Practice1 mark

Which of these is an output device?

Answer

(b) Speaker A projector shows the computer's output on a big screen.

A1.133Practice1 mark

Which of these is an input device?

Answer

(d) MICR A barcode reader sends the product code into the computer, so it is an input device.

A1.134Practice1 mark

A program that translates a high-level program line by line is an

Answer

(d) interpreter An interpreter translates and runs one line at a time and stops at the first error.

A1.135Practice1 mark

Which of these is an input device?

Answer

(d) Scanner A barcode reader sends the product code into the computer, so it is an input device.

A2Python and NumPy concepts1 mark · 69 questions
A2.1Practice1 mark

What is the result of 9 % 4 ** 2?

Answer

(c) 9 4 ** 2 = 16 first; 9 % 16 = 9.

A2.2Practice1 mark

All the elements of a NumPy array must be of

Answer

(b) the same data type An array stores elements of one type; mixed values are converted to one type.

A2.3Practice1 mark

The number of dimensions of a NumPy array is given by

Answer

(a) ndim ndim gives the number of dimensions: 1 for a simple list, 2 for rows and columns.

A2.4Practice1 mark

Which method returns all the key-value pairs of a dictionary?

Answer

(d) items() D.items() gives (key, value) pairs.

A2.5Practice1 mark

Which operator is used for exponent (power)?

Answer

(a) ** 2 ** 3 gives 8; ^ is not power in Python.

A2.6Practice1 mark

input() always returns a value of type

Answer

(c) str input() returns a string; use int() or float() to get a number.

A2.7Practice1 mark

The default value of end in print() is

Answer

(b) a new line (\n) After printing, print() goes to a new line unless end is changed.

A2.8Practice1 mark

The value of 5 > 3 and 3 > 1 is

Answer

(c) True Both conditions are True, so and gives True.

A2.9Practice1 mark

Which method returns the value of a key, and None if the key is not present?

Answer

(d) get() D.get('x') returns None instead of giving KeyError.

A2.10Practice1 mark

The default separator (sep) in print() is

Answer

(d) a space print(1, 2) prints 1 2 with a space between.

A2.11Practice1 mark

bool(0) and bool('') give

Answer

(d) False and False 0 and the empty string are treated as False.

A2.12Practice1 mark

The total number of elements of a NumPy array is given by

Answer

(b) size size gives the total number of elements: rows x columns for a 2-D array.

A2.13Practice1 mark

Which method makes a dictionary from a list of keys, with the same value for every key?

Answer

(c) dict.fromkeys() dict.fromkeys(['a', 'b'], 0) gives {'a': 0, 'b': 0}.

A2.14Practice1 mark

Which function makes a NumPy array from a list?

Answer

(a) np.array() np.array([1, 2, 3]) makes an array from the list.

A2.15Practice1 mark

The smallest individual unit of a Python program is a

Answer

(d) token Tokens: keywords, identifiers, literals, operators and punctuators.

A2.16Practice1 mark

For an array made from [[1, 2, 3], [4, 5, 6]], shape is

Answer

(d) (2, 3) 2 rows and 3 columns, so shape is (2, 3).

A2.17Practice1 mark

The correct way to import NumPy with its usual short name is

Answer

(d) import numpy as np np is the usual short name: import numpy as np.

A2.18Practice1 mark

The else part of a loop runs when

Answer

(d) the loop ends normally, without break The loop's else runs only if the loop was not stopped by break.

A2.19Practice1 mark

Which statement does nothing and is used as a placeholder?

Answer

(b) pass pass is used where a statement is needed but nothing is to be done.

A2.20Practice1 mark

The value None belongs to the data type

Answer

(d) NoneType None is the only value of the NoneType type.

A2.21Practice1 mark

Which of these names is NOT valid?

Answer

(c) my-name A hyphen is not allowed in a name; Python reads it as minus.

A2.22Practice1 mark

Which operator gives the remainder?

Answer

(d) % 17 % 5 gives 2, the remainder.

A2.23Practice1 mark

Which method adds one element at the end of a list?

Answer

(d) append() L.append(5) adds 5 as the last element.

A2.24Practice1 mark

In Python, complex numbers are written as

Answer

(d) 3 + 4j Python uses j for the imaginary part: 3 + 4j.

A2.25Practice1 mark

The output of print(10, 20, sep='-') is

Answer

(c) 10-20 sep='-' puts - between the values instead of a space.

A2.26Practice1 mark

In 5 + 2.0, Python converts 5 to a float on its own. This is

Answer

(c) implicit type conversion Python converts it automatically, so it is implicit conversion.

A2.27Practice1 mark

Which operator checks whether two names refer to the same object?

Answer

(a) is is checks identity (same object); == checks equal values.

A2.28Practice1 mark

An error in the grammar of the code, such as a missing colon, is a

Answer

(c) syntax error Wrong grammar (syntax) is caught before the program runs.

A2.29Practice1 mark

Which of these is a membership operator?

Answer

(a) in in checks whether a value is present: 3 in [1, 3] is True.

A2.30Practice1 mark

State True or False: Adding two NumPy arrays of the same size adds their elements one by one.

Answer

(a) True NumPy adds element by element: [1, 2] + [3, 4] gives [4 6].

A2.31Practice1 mark

Accessing a key that is not in the dictionary with d[key] gives

Answer

(a) KeyError D['x'] for a missing key gives KeyError.

A2.32Practice1 mark

Searching a list element by element from the start is called

Answer

(a) linear search Checking every element one after another is linear search.

A2.33Practice1 mark

Python program files are saved with the extension

Answer

(a) .py Python scripts are saved as name.py.

A2.34Practice1 mark

Which method removes the first occurrence of a given value?

Answer

(a) remove() L.remove(10) deletes the first 10 in the list.

A2.35Practice1 mark

Which loop is best when the number of repetitions is known?

Answer

(c) for for i in range(n) runs exactly n times.

A2.36Practice1 mark

Which statement deletes the elements from index 1 to 2 of L?

Answer

(b) del L[1:3] del L[1:3] deletes index 1 and 2 (the stop index 3 is not included).

A2.37Practice1 mark

np.array([1, 2.5, 3]) has the data type

Answer

(d) float64 One value is a float, so all elements become float64.

A2.38Practice1 mark

How many times does 'for i in range(3, 15, 4)' run?

Answer

(b) 3 i takes 3, 7 and 11.

A2.39Practice1 mark

NumPy is a Python library used mainly for

Answer

(b) working with arrays and numbers NumPy (Numerical Python) works with arrays of numbers quickly.

A2.40Practice1 mark

Dividing a number by zero while the program runs gives a

Answer

(c) runtime error (ZeroDivisionError) The program starts but stops with ZeroDivisionError while running.

A2.41Practice1 mark

State True or False: L[1] = 10 is allowed on a list L of 3 elements.

Answer

(a) True Lists are mutable and index 1 exists in a 3-element list.

A2.42Practice1 mark

Which method removes an element by index and returns it?

Answer

(c) pop() L.pop(2) removes and returns the element at index 2.

A2.43Practice1 mark

State True or False: A NumPy array can be made from a Python list.

Answer

(a) True np.array(list) does exactly this.

A2.44Practice1 mark

Which statement skips the rest of the current loop round and goes to the next round?

Answer

(d) continue continue jumps to the next round of the loop.

A2.45Practice1 mark

list('KV') gives

Answer

(c) ['K', 'V'] list() makes one element from each character.

A2.46Practice1 mark

A loop that never ends is called

Answer

(c) an infinite loop If the condition never becomes False, the loop runs for ever.

A2.47Practice1 mark

State True or False: Dictionary keys can be repeated.

Answer

(b) False A new value for an existing key replaces the old value.

A2.48Practice1 mark

range(5) gives the numbers

Answer

(c) 0, 1, 2, 3, 4 range(5) starts at 0 and stops before 5.

A2.49Practice1 mark

np.array([1, 2, 3]) * 2 gives

Answer

(d) [2 4 6] NumPy multiplies every element by 2; arrays print without commas.

A2.50Practice1 mark

Which mode of Python runs one statement at a time with the >>> prompt?

Answer

(b) Interactive mode Interactive mode shows the >>> prompt and gives the result of each statement at once.

A2.51Practice1 mark

A while loop is called

Answer

(b) entry-controlled The condition is checked before each round (at the entry).

A2.52Practice1 mark

Which statement is used to write an empty if block?

Answer

(d) pass An empty block gives an error, so pass is written inside it.

A2.53Practice1 mark

A comment in Python starts with

Answer

(a) # Everything after # on a line is ignored by Python.

A2.54Practice1 mark

Converting the type of a value by a function such as int() or float() is called

Answer

(c) explicit type conversion The programmer converts it on purpose, so it is explicit conversion.

A2.55Practice1 mark

Which attribute gives the data type of the elements of an array?

Answer

(d) dtype dtype tells the type, such as int64 or float64.

A2.56Practice1 mark

Which method adds all the elements of another list at the end?

Answer

(b) extend() L.extend([4, 5]) adds 4 and 5 one by one.

A2.57Practice1 mark

State True or False: A while loop may not run even once.

Answer

(a) True If the condition is False at the start, the body is skipped.

A2.58Practice1 mark

State True or False: The = operator compares two values.

Answer

(b) False = assigns; == compares.

A2.59Practice1 mark

Which statement ends the loop at once?

Answer

(a) break break stops the loop immediately.

A2.60Practice1 mark

Which of these can be a dictionary key?

Answer

(a) (1, 2) A key must be immutable: numbers, strings and tuples can be keys; lists and dictionaries cannot.

A2.61Practice1 mark

Which function gives the memory address (identity) of an object?

Answer

(b) id() id(x) gives the identity of the object x.

A2.62Practice1 mark

State True or False: In Python, a variable must be declared with its type before use.

Answer

(b) False Python finds the type from the value given.

A2.63Practice1 mark

d.update(e)

Answer

(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.

A2.64Practice1 mark

What is the length of [1, [2, 3], 4]?

Answer

(d) 3 The inner list counts as one element: 1, [2, 3], 4.

A2.65Practice1 mark

A loop inside another loop is called

Answer

(c) a nested loop The inner loop runs fully for every round of the outer loop.

A2.66Practice1 mark

Which of these is a valid identifier?

Answer

(c) total_marks It has letters and an underscore; it does not start with a digit, has no hyphen and is not a keyword.

A2.67Practice1 mark

Which method removes all the elements of a list?

Answer

(b) clear() L.clear() leaves an empty list [].

A2.68Practice1 mark

len({'a': 1, 'b': 2}) is

Answer

(c) 2 There are two key-value pairs.

A2.69Practice1 mark

Python is a

Answer

(b) high-level, interpreted language Python is close to English (high level) and is run by an interpreter.

A3Python and NumPy output1 mark · 298 questions
A3.1Practice1 mark

What is the output of the following code?

D = {'Dev': 65, 'Gita': 50, 'Bela': 41, 'Esha': 77}
D["Zoya"] = 99
print(len(D))
Answer

(b) 5 A dictionary keeps key: value pairs; keys are unique.

A3.2Practice1 mark

What is the output of the following code?

L = [25, 36, 6, 2, 27, 31]
L.sort(reverse=True)
print(L)
Answer

(c) [36, 31, 27, 25, 6, 2] sort(reverse=True) arranges the same list in descending order (largest first).

A3.3Practice1 mark

What is the output of the following code?

L = [23, 3, 17, 28, 9]
L.insert(4, 60)
print(L)
Answer

(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.

A3.4Practice1 mark

What is the output of the following code?

for i in range(6, -6, -1):
    print(i, end=" ")
Answer

(d) 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 range(start, stop, step) starts at start and stops before stop.

A3.5Practice1 mark

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)
Answer

(a) [21 16 26 30] NumPy works element by element on arrays of one type.

A3.6Practice1 mark

What is the output of the following code?

print(-14 // 4, -14 % 4)
Answer

(d) -4 2 // rounds down towards minus infinity, so -14 // 4 is -4; the remainder takes the sign of the divisor.

A3.7Practice1 mark

What is the output of the following code?

for i in range(0, 4, 1):
    print(i, end=" ")
Answer

(d) 0 1 2 3 range(start, stop, step) starts at start and stops before stop.

A3.8Practice1 mark

What is the output of the following code?

D = {'Esha': 48, 'Charu': 52, 'Gita': 76, 'Dev': 43}
print(D.get("Zoya"))
Answer

(d) None A dictionary keeps key: value pairs; keys are unique.

A3.9Practice1 mark

What is the output of the following code?

L = [8, 9, 36, 6]
L[0] = 44
print(L)
Answer

(a) [44, 9, 36, 6] Lists are mutable, so L[0] = 44 replaces the element at index 0 (8) with 44.

A3.10Practice1 mark

What is the output of the following code?

print(24 - 5 // 5 % 2)
Answer

(b) 23 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.11Practice1 mark

What is the output of the following code?

print(-21 // 6, -21 % 6)
Answer

(d) -4 3 // rounds down towards minus infinity, so -21 // 6 is -4; the remainder takes the sign of the divisor.

A3.12Practice1 mark

What is the output of the following code?

L = [24, 36, 14, 17, 4]
print(L[1:6])
Answer

(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.

A3.13Practice1 mark

What is the output of the following code?

for i in range(1, -6, -1):
    print(i, end=" ")
Answer

(a) 1 0 -1 -2 -3 -4 -5 range(start, stop, step) starts at start and stops before stop.

A3.14Practice1 mark

What is the output of the following code?

print(8 - 3 % 5 * 2)
Answer

(a) 2 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.15Practice1 mark

What is the output of the following code?

for i in range(0, -11, -2):
    print(i, end=" ")
Answer

(b) 0 -2 -4 -6 -8 -10 range(start, stop, step) starts at start and stops before stop.

A3.16Practice1 mark

What is the output of the following code?

a = 4
b = a * 2
a = b - a
b //= 3
print(a, b)
Answer

(d) 4 2 In a, b = b, a + b the right side is worked out first, with the old values.

A3.17Practice1 mark

What is the output of the following code?

import numpy as np
a = np.array([1.5, 2, 3])
print(a.dtype)
Answer

(b) float64 NumPy works element by element on arrays of one type.

A3.18Practice1 mark

What is the output of the following code?

D = {'Bela': 59, 'Dev': 68, 'Farid': 81, 'Charu': 60}
print(D.get("Zoya", 0))
Answer

(a) 0 A dictionary keeps key: value pairs; keys are unique.

A3.19Practice1 mark

What is the output of the following code?

print(str(9) * 2)
Answer

(a) 99 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.

A3.20Practice1 mark

What is the output of the following code?

n = 36
count = 0
while n > 5:
    n = n - 5
    count += 1
print(count, n)
Answer

(b) 7 1 Trace the loop: the condition is checked before every round.

A3.21Practice1 mark

What is the output of the following code?

print(type('7' * 2))
Answer

(a) <class 'str'> The type of the result decides the class.

A3.22Practice1 mark

What is the output of the following code?

D = {'Esha': 94, 'Charu': 80, 'Dev': 73, 'Amit': 48}
print(list(D.values())[1])
Answer

(d) 80 A dictionary keeps key: value pairs; keys are unique.

A3.23Practice1 mark

What is the output of the following code?

L = [32, 17, 25, 23]
print(sorted(L)[1])
Answer

(b) 23 sorted(L) gives a new list in ascending order: [17, 23, 25, 32]. Its element at index 1 is 23.

A3.24Practice1 mark

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")
Answer

(d) Fail Only the first true condition of an if-elif chain runs.

A3.25Practice1 mark

What is the output of the following code?

n = 47
count = 0
while n > 3:
    n = n - 9
    count += 1
print(count, n)
Answer

(c) 5 2 Trace the loop: the condition is checked before every round.

A3.26Practice1 mark

What is the output of the following code?

print(7 + 5 * 3 % 3)
Answer

(d) 7 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.27Practice1 mark

What is the output of the following code?

D = {'Bela': 55, 'Dev': 67, 'Esha': 89, 'Charu': 56}
print(D.get("Zoya", 0))
Answer

(b) 0 A dictionary keeps key: value pairs; keys are unique.

A3.28Practice1 mark

What is the output of the following code?

D = {'Amit': 42, 'Gita': 49, 'Dev': 92, 'Charu': 67}
print(list(D.keys()))
Answer

(b) ['Amit', 'Gita', 'Dev', 'Charu'] A dictionary keeps key: value pairs; keys are unique.

A3.29Practice1 mark

What is the output of the following code?

L = [18, 12, 16, 2]
print(L * 2)
Answer

(c) [18, 12, 16, 2, 18, 12, 16, 2] The * operator repeats the list, so the elements appear 2 times one after another.

A3.30Practice1 mark

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])
Answer

(d) 29 6 [16 29] NumPy works element by element on arrays of one type.

A3.31Practice1 mark

What is the output of the following code?

L = [38, 8, 10, 15, 39, 31]
L.append([60, 61])
print(L)
Answer

(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).

A3.32Practice1 mark

What is the output of the following code?

for i in range(2, 12, 2):
    print(i, end=" ")
Answer

(c) 2 4 6 8 10 range(start, stop, step) starts at start and stops before stop.

A3.33Practice1 mark

What is the output of the following code?

print(not 1)
Answer

(b) False not is applied first, then and, then or. and/or return one of the operands.

A3.34Practice1 mark

What is the output of the following code?

a = 9
b = 8
a += b
b = a - b
a = a - b
print(a, b)
Answer

(c) 8 9 In a, b = b, a + b the right side is worked out first, with the old values.

A3.35Practice1 mark

What is the output of the following code?

c = 0
for i in range(4):
    for j in range(4):
        c += 1
print(c)
Answer

(d) 16 The inner loop runs fully for every round of the outer loop.

A3.36Practice1 mark

What is the output of the following code?

D = {'Gita': 46, 'Charu': 76, 'Bela': 52, 'Dev': 74}
print(sorted(D))
Answer

(b) ['Bela', 'Charu', 'Dev', 'Gita'] A dictionary keeps key: value pairs; keys are unique.

A3.37Practice1 mark

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)
Answer

(d) 2 (2, 3) 6 NumPy works element by element on arrays of one type.

A3.38Practice1 mark

What is the output of the following code?

D = {'Charu': 80, 'Farid': 49, 'Bela': 62, 'Dev': 68}
print(max(D))
Answer

(c) Farid A dictionary keeps key: value pairs; keys are unique.

A3.39Practice1 mark

What is the output of the following code?

D = {'Gita': 85, 'Dev': 80, 'Amit': 53, 'Farid': 75}
print(D["Farid"])
Answer

(c) 75 A dictionary keeps key: value pairs; keys are unique.

A3.40Practice1 mark

What is the output of the following code?

L = [13, 1, 9, 29, 25]
L.extend([46, 47])
print(L)
Answer

(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.

A3.41Practice1 mark

What is the output of the following code?

L = [20, 6, 16, 10, 22]
print(16 in L, 52 not in L)
Answer

(d) True True 16 is in the list, so "in" gives True; 52 is not in the list, so "not in" gives True.

A3.42Practice1 mark

What is the output of the following code?

for i in range(3, 12):
    if i % 2 == 0:
        continue
    print(i, end=" ")
Answer

(a) 3 5 7 9 11 break leaves the loop; continue skips only the rest of that round.

A3.43Practice1 mark

What is the output of the following code?

for i in range(5, 12, 3):
    print(i, end=" ")
Answer

(d) 5 8 11 range(start, stop, step) starts at start and stops before stop.

A3.44Practice1 mark

What is the output of the following code?

print(28 / 3, 28 // 3, 28 % 3)
Answer

(c) 9.333333333333334 9 1 / always gives a float; // gives the quotient rounded down; % gives the remainder.

A3.45Practice1 mark

What is the output of the following code?

print(type(7 // 2))
Answer

(b) <class 'int'> The type of the result decides the class.

A3.46Practice1 mark

What is the output of the following code?

print(57 / 9, 57 // 9, 57 % 9)
Answer

(c) 6.333333333333333 6 3 / always gives a float; // gives the quotient rounded down; % gives the remainder.

A3.47Practice1 mark

What is the output of the following code?

n = 34
count = 0
while n > 7:
    n = n - 6
    count += 1
print(count, n)
Answer

(d) 5 4 Trace the loop: the condition is checked before every round.

A3.48Practice1 mark

What is the output of the following code?

D = {'Dev': 53, 'Charu': 90, 'Amit': 72, 'Farid': 97}
print(max(D.values()))
Answer

(a) 97 A dictionary keeps key: value pairs; keys are unique.

A3.49Practice1 mark

What is the output of the following code?

L = [27, 1, 35, 36]
print(L.index(1))
Answer

(c) 1 index(1) returns the position of the first 1; counting from 0, it is at index 1.

A3.50Practice1 mark

What is the output of the following code?

L = [9, 34, 19, 7, 25]
L.append(41)
print(L)
Answer

(c) [9, 34, 19, 7, 25, 41] append(41) adds 41 as the last element.

A3.51Practice1 mark

What is the output of the following code?

for i in range(3, -8, -2):
    print(i, end=" ")
Answer

(b) 3 1 -1 -3 -5 -7 range(start, stop, step) starts at start and stops before stop.

A3.52Practice1 mark

What is the output of the following code?

D = {'Esha': 88, 'Bela': 77, 'Charu': 89, 'Gita': 49}
print(D.get("Zoya"))
Answer

(d) None A dictionary keeps key: value pairs; keys are unique.

A3.53Practice1 mark

What is the output of the following code?

c = 0
for i in range(2):
    for j in range(4):
        c += 1
print(c)
Answer

(b) 8 The inner loop runs fully for every round of the outer loop.

A3.54Practice1 mark

What is the output of the following code?

print(8 + 2 * 2 % 4)
Answer

(c) 8 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.55Practice1 mark

What is the output of the following code?

L = [35, 19, 8, 24]
L.insert(2, 51)
print(L)
Answer

(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.

A3.56Practice1 mark

What is the output of the following code?

for i in range(1, 14):
    if i % 3 == 0:
        continue
    print(i, end=" ")
Answer

(d) 1 2 4 5 7 8 10 11 13 break leaves the loop; continue skips only the rest of that round.

A3.57Practice1 mark

What is the output of the following code?

L = [14, 38, 27, 19, 32]
del L[1]
print(L)
Answer

(a) [14, 27, 19, 32] del L[1] removes the element at index 1, which is 38.

A3.58Practice1 mark

What is the output of the following code?

L = [36, 25, 14, 27]
L[0] = 52
print(L)
Answer

(b) [52, 25, 14, 27] Lists are mutable, so L[0] = 52 replaces the element at index 0 (36) with 52.

A3.59Practice1 mark

What is the output of the following code?

L = [38, 33, 27, 32]
print(sum(L) // len(L))
Answer

(a) 32 sum(L) is 130 and len(L) is 4; // gives the floor quotient 130 // 4 = 32.

A3.60Practice1 mark

What is the output of the following code?

D = {'Farid': 83, 'Amit': 60, 'Dev': 91, 'Esha': 51}
print(max(D))
Answer

(a) Farid A dictionary keeps key: value pairs; keys are unique.

A3.61Practice1 mark

What is the output of the following code?

D = {'Charu': 84, 'Bela': 96, 'Esha': 88, 'Dev': 92}
print(D.get("Zoya"))
Answer

(d) None A dictionary keeps key: value pairs; keys are unique.

A3.62Practice1 mark

What is the output of the following code?

D = {'Esha': 41, 'Charu': 62, 'Bela': 79, 'Gita': 53}
print("Esha" in D, 41 in D)
Answer

(d) True False A dictionary keeps key: value pairs; keys are unique.

A3.63Practice1 mark

What is the output of the following code?

L = [12, 20, 3, 10]
print(max(L) - min(L))
Answer

(b) 17 max(L) is 20 and min(L) is 3, so 20 - 3 = 17.

A3.64Practice1 mark

What is the output of the following code?

for i in range(4, 13):
    if i % 3 == 0:
        continue
    print(i, end=" ")
Answer

(a) 4 5 7 8 10 11 break leaves the loop; continue skips only the rest of that round.

A3.65Practice1 mark

What is the output of the following code?

D = {'Gita': 80, 'Charu': 60, 'Farid': 98, 'Esha': 55}
D["Charu"] = 99
print(D)
Answer

(c) {'Gita': 80, 'Charu': 99, 'Farid': 98, 'Esha': 55} A dictionary keeps key: value pairs; keys are unique.

A3.66Practice1 mark

What is the output of the following code?

L = [30, 4, 31, 35, 23, 37]
del L[3]
print(L)
Answer

(d) [30, 4, 31, 23, 37] del L[3] removes the element at index 3, which is 35.

A3.67Practice1 mark

What is the output of the following code?

L = [8, 32, 2, 4, 16]
print(L.pop(3), L)
Answer

(c) 4 [8, 32, 2, 16] pop(3) removes and returns the element at index 3 (4); then the changed list is printed.

A3.68Practice1 mark

What is the output of the following code?

a, b = 9, 6
a, b = b, a + b
print(a, b)
Answer

(b) 6 15 In a, b = b, a + b the right side is worked out first, with the old values.

A3.69Practice1 mark

What is the output of the following code?

L = [34, 36, 39, 1, 32]
print(max(L) - min(L))
Answer

(a) 38 max(L) is 39 and min(L) is 1, so 39 - 1 = 38.

A3.70Practice1 mark

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")
Answer

(a) A Only the first true condition of an if-elif chain runs.

A3.71Practice1 mark

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)
Answer

(b) 1 (4,) 4 NumPy works element by element on arrays of one type.

A3.72Practice1 mark

What is the output of the following code?

L = [18, 24, 33, 19, 7, 20]
print(7 in L, 45 not in L)
Answer

(a) True True 7 is in the list, so "in" gives True; 45 is not in the list, so "not in" gives True.

A3.73Practice1 mark

What is the output of the following code?

L = [30, 39, 5, 33, 8]
print(len(L + [53]))
Answer

(d) 6 L + [..] makes a new list with one more element: 5 + 1 = 6. L itself does not change.

A3.74Practice1 mark

What is the output of the following code?

print(type(float(7)))
Answer

(a) <class 'float'> The type of the result decides the class.

A3.75Practice1 mark

What is the output of the following code?

D = {'Esha': 76, 'Amit': 77, 'Bela': 71, 'Dev': 78}
print(sorted(D))
Answer

(d) ['Amit', 'Bela', 'Dev', 'Esha'] A dictionary keeps key: value pairs; keys are unique.

A3.76Practice1 mark

What is the output of the following code?

for i in range(2, 9, 2):
    print(i, end=" ")
Answer

(b) 2 4 6 8 range(start, stop, step) starts at start and stops before stop.

A3.77Practice1 mark

What is the output of the following code?

for i in range(2, 13):
    if i % 8 == 0:
        break
    print(i, end=" ")
Answer

(a) 2 3 4 5 6 7 break leaves the loop; continue skips only the rest of that round.

A3.78Practice1 mark

What is the output of the following code?

x = 6
x -= 2
x **= 2
print(x)
Answer

(c) 16 In a, b = b, a + b the right side is worked out first, with the old values.

A3.79Practice1 mark

What is the output of the following code?

print(13 + 6 * 2 ** 2)
Answer

(a) 37 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.80Practice1 mark

What is the output of the following code?

for i in range(1, 7, 3):
    print(i, end=" ")
Answer

(b) 1 4 range(start, stop, step) starts at start and stops before stop.

A3.81Practice1 mark

What is the output of the following code?

for i in range(6, 10, 2):
    print(i, end=" ")
Answer

(a) 6 8 range(start, stop, step) starts at start and stops before stop.

A3.82Practice1 mark

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)
Answer

(d) [28 33 34 34] NumPy works element by element on arrays of one type.

A3.83Practice1 mark

What is the output of the following code?

print(20 / 4, 20 // 4, 20 % 4)
Answer

(a) 5.0 5 0 / always gives a float; // gives the quotient rounded down; % gives the remainder.

A3.84Practice1 mark

What is the output of the following code?

D = {'Dev': 58, 'Farid': 96, 'Amit': 90, 'Gita': 77}
D["Gita"] = 99
print(D)
Answer

(d) {'Dev': 58, 'Farid': 96, 'Amit': 90, 'Gita': 99} A dictionary keeps key: value pairs; keys are unique.

A3.85Practice1 mark

What is the output of the following code?

L = [4, 33, 11, 24, 25]
print(L[::-2])
Answer

(c) [25, 11, 4] A step of -2 starts from the last element and moves left, taking every second element: [25, 11, 4].

A3.86Practice1 mark

What is the output of the following code?

L = [14, 5, 11, 2, 25]
print(14 in L, 48 not in L)
Answer

(c) True True 14 is in the list, so "in" gives True; 48 is not in the list, so "not in" gives True.

A3.87Practice1 mark

What is the output of the following code?

n = 25
count = 0
while n > 6:
    n = n - 3
    count += 1
print(count, n)
Answer

(c) 7 4 Trace the loop: the condition is checked before every round.

A3.88Practice1 mark

What is the output of the following code?

D = {'Esha': 97, 'Bela': 43, 'Dev': 54, 'Gita': 45}
D["Zoya"] = 99
print(len(D))
Answer

(c) 5 A dictionary keeps key: value pairs; keys are unique.

A3.89Practice1 mark

What is the output of the following code?

print(13 - 3 // 3 % 4)
Answer

(c) 12 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.90Practice1 mark

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])
Answer

(d) 2 7 NumPy works element by element on arrays of one type.

A3.91Practice1 mark

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")
Answer

(a) C Only the first true condition of an if-elif chain runs.

A3.92Practice1 mark

What is the output of the following code?

n = 39
count = 0
while n > 7:
    n = n - 4
    count += 1
print(count, n)
Answer

(a) 8 7 Trace the loop: the condition is checked before every round.

A3.93Practice1 mark

What is the output of the following code?

print(not 5 > 3 or 5 == 3 and 0)
Answer

(a) False not is applied first, then and, then or. and/or return one of the operands.

A3.94Practice1 mark

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])
Answer

(d) 18 16 NumPy works element by element on arrays of one type.

A3.95Practice1 mark

What is the output of the following code?

print(21 + 4 * 3 * 2)
Answer

(a) 45 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.96Practice1 mark

What is the output of the following code?

for i in range(6, 12, 1):
    print(i, end=" ")
Answer

(a) 6 7 8 9 10 11 range(start, stop, step) starts at start and stops before stop.

A3.97Practice1 mark

What is the output of the following code?

print(29 / 8, 29 // 8, 29 % 8)
Answer

(a) 3.625 3 5 / always gives a float; // gives the quotient rounded down; % gives the remainder.

A3.98Practice1 mark

What is the output of the following code?

L = [7, 3, 22, 28, 29, 5]
L.append([50, 51])
print(L)
Answer

(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).

A3.99Practice1 mark

What is the output of the following code?

L = [32, 23, 15, 14]
print(sorted(L)[1])
Answer

(a) 15 sorted(L) gives a new list in ascending order: [14, 15, 23, 32]. Its element at index 1 is 15.

A3.100Practice1 mark

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])
Answer

(d) 1 13 NumPy works element by element on arrays of one type.

A3.101Practice1 mark

What is the output of the following code?

print(17 + 5 * 4 // 2)
Answer

(b) 27 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.102Practice1 mark

What is the output of the following code?

D = {'Farid': 63, 'Amit': 66, 'Dev': 48, 'Gita': 90}
print(sorted(D))
Answer

(b) ['Amit', 'Dev', 'Farid', 'Gita'] A dictionary keeps key: value pairs; keys are unique.

A3.103Practice1 mark

What is the output of the following code?

D = {'Gita': 48, 'Amit': 74, 'Bela': 41, 'Esha': 68}
print(max(D))
Answer

(c) Gita A dictionary keeps key: value pairs; keys are unique.

A3.104Practice1 mark

What is the output of the following code?

L = [6, 36, 38, 31, 33, 25]
L.append(47)
print(L)
Answer

(a) [6, 36, 38, 31, 33, 25, 47] append(47) adds 47 as the last element.

A3.105Practice1 mark

What is the output of the following code?

D = {'Farid': 86, 'Charu': 47, 'Esha': 50, 'Gita': 62}
print(D.pop("Esha"), len(D))
Answer

(d) 50 3 A dictionary keeps key: value pairs; keys are unique.

A3.106Practice1 mark

What is the output of the following code?

print(30 + 4 // 2 ** 2)
Answer

(d) 31 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.107Practice1 mark

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")
Answer

(d) Fail Only the first true condition of an if-elif chain runs.

A3.108Practice1 mark

What is the output of the following code?

D = {'Bela': 70, 'Gita': 64, 'Farid': 42, 'Charu': 67}
print(D.get("Zoya", 0))
Answer

(c) 0 A dictionary keeps key: value pairs; keys are unique.

A3.109Practice1 mark

What is the output of the following code?

print(-13 // 6, -13 % 6)
Answer

(d) -3 5 // rounds down towards minus infinity, so -13 // 6 is -3; the remainder takes the sign of the divisor.

A3.110Practice1 mark

What is the output of the following code?

print(0 or 5)
Answer

(c) 5 not is applied first, then and, then or. and/or return one of the operands.

A3.111Practice1 mark

What is the output of the following code?

print(-23 // 4, -23 % 4)
Answer

(b) -6 1 // rounds down towards minus infinity, so -23 // 4 is -6; the remainder takes the sign of the divisor.

A3.112Practice1 mark

What is the output of the following code?

n = 27
count = 0
while n > 6:
    n = n - 9
    count += 1
print(count, n)
Answer

(a) 3 0 Trace the loop: the condition is checked before every round.

A3.113Practice1 mark

What is the output of the following code?

print(float('8') * 2)
Answer

(d) 16.0 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.

A3.114Practice1 mark

What is the output of the following code?

x = 8
x -= 2
x **= 2
print(x)
Answer

(a) 36 In a, b = b, a + b the right side is worked out first, with the old values.

A3.115Practice1 mark

What is the output of the following code?

L = [22, 20, 9, 35, 7, 34]
print(L.pop(), L)
Answer

(d) 34 [22, 20, 9, 35, 7] pop() without an index removes and returns the last element (34); then the changed list is printed.

A3.116Practice1 mark

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])
Answer

(b) 18 27 [18 8] NumPy works element by element on arrays of one type.

A3.117Practice1 mark

What is the output of the following code?

D = {'Esha': 82, 'Farid': 67, 'Bela': 94, 'Charu': 60}
D["Esha"] = 99
print(D)
Answer

(d) {'Esha': 99, 'Farid': 67, 'Bela': 94, 'Charu': 60} A dictionary keeps key: value pairs; keys are unique.

A3.118Practice1 mark

What is the output of the following code?

L = [24, 16, 22, 5, 21]
L.insert(0, 53)
print(L)
Answer

(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.

A3.119Practice1 mark

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)
Answer

(a) 2 (2, 3) 6 NumPy works element by element on arrays of one type.

A3.120Practice1 mark

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")
Answer

(b) C Only the first true condition of an if-elif chain runs.

A3.121Practice1 mark

What is the output of the following code?

print(str(3) * 2)
Answer

(d) 33 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.

A3.122Practice1 mark

What is the output of the following code?

L = [5, 32, 16, 30]
L[0] = 53
print(L)
Answer

(a) [53, 32, 16, 30] Lists are mutable, so L[0] = 53 replaces the element at index 0 (5) with 53.

A3.123Practice1 mark

What is the output of the following code?

print(32 / 3, 32 // 3, 32 % 3)
Answer

(b) 10.666666666666666 10 2 / always gives a float; // gives the quotient rounded down; % gives the remainder.

A3.124Practice1 mark

What is the output of the following code?

print(9 and 8)
Answer

(a) 8 not is applied first, then and, then or. and/or return one of the operands.

A3.125Practice1 mark

What is the output of the following code?

for i in range(3, 15):
    if i % 7 == 0:
        break
    print(i, end=" ")
Answer

(d) 3 4 5 6 break leaves the loop; continue skips only the rest of that round.

A3.126Practice1 mark

What is the output of the following code?

print(type(2 ** 3))
Answer

(d) <class 'int'> The type of the result decides the class.

A3.127Practice1 mark

What is the output of the following code?

L = [23, 28, 15, 32]
print(L.index(28))
Answer

(c) 1 index(28) returns the position of the first 28; counting from 0, it is at index 1.

A3.128Practice1 mark

What is the output of the following code?

print(30 + 5 * 4 // 4)
Answer

(a) 35 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.129Practice1 mark

What is the output of the following code?

D = {'Charu': 78, 'Amit': 56, 'Gita': 45, 'Dev': 48}
print(D.get("Zoya"))
Answer

(a) None A dictionary keeps key: value pairs; keys are unique.

A3.130Practice1 mark

What is the output of the following code?

L = [12, 1, 26, 6]
print(L.pop(1), L)
Answer

(d) 1 [12, 26, 6] pop(1) removes and returns the element at index 1 (1); then the changed list is printed.

A3.131Practice1 mark

What is the output of the following code?

L = [27, 9, 7, 24, 1, 37]
print(sorted(L)[1])
Answer

(c) 7 sorted(L) gives a new list in ascending order: [1, 7, 9, 24, 27, 37]. Its element at index 1 is 7.

A3.132Practice1 mark

What is the output of the following code?

for i in range(1, -8, -2):
    print(i, end=" ")
Answer

(d) 1 -1 -3 -5 -7 range(start, stop, step) starts at start and stops before stop.

A3.133Practice1 mark

What is the output of the following code?

for i in range(1, -6, -2):
    print(i, end=" ")
Answer

(c) 1 -1 -3 -5 range(start, stop, step) starts at start and stops before stop.

A3.134Practice1 mark

What is the output of the following code?

x = 9
x *= 2 + 3
print(x)
Answer

(a) 45 In a, b = b, a + b the right side is worked out first, with the old values.

A3.135Practice1 mark

What is the output of the following code?

D = {'Esha': 78, 'Dev': 53, 'Bela': 52, 'Gita': 70}
print(D.pop("Bela"), len(D))
Answer

(c) 52 3 A dictionary keeps key: value pairs; keys are unique.

A3.136Practice1 mark

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])
Answer

(a) 1 19 NumPy works element by element on arrays of one type.

A3.137Practice1 mark

What is the output of the following code?

L = [35, 27, 31, 2]
print(L[1:4])
Answer

(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.

A3.138Practice1 mark

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)
Answer

(a) 10 The inner loop runs fully for every round of the outer loop.

A3.139Practice1 mark

What is the output of the following code?

print(42 / 3, 42 // 3, 42 % 3)
Answer

(c) 14.0 14 0 / always gives a float; // gives the quotient rounded down; % gives the remainder.

A3.140Practice1 mark

What is the output of the following code?

print(float('2') * 2)
Answer

(d) 4.0 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.

A3.141Practice1 mark

What is the output of the following code?

L = [31, 29, 18, 24, 6]
print(L * 2)
Answer

(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.

A3.142Practice1 mark

What is the output of the following code?

for i in range(5, 12, 1):
    print(i, end=" ")
Answer

(b) 5 6 7 8 9 10 11 range(start, stop, step) starts at start and stops before stop.

A3.143Practice1 mark

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)
Answer

(c) [11 14 34 33] NumPy works element by element on arrays of one type.

A3.144Practice1 mark

What is the output of the following code?

print(26 + 2 * 5 * 4)
Answer

(c) 66 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.145Practice1 mark

What is the output of the following code?

n = 35
count = 0
while n > 6:
    n = n - 5
    count += 1
print(count, n)
Answer

(c) 6 5 Trace the loop: the condition is checked before every round.

A3.146Practice1 mark

What is the output of the following code?

D = {'Charu': 86, 'Gita': 47, 'Bela': 84, 'Farid': 80}
print(sorted(D))
Answer

(c) ['Bela', 'Charu', 'Farid', 'Gita'] A dictionary keeps key: value pairs; keys are unique.

A3.147Practice1 mark

What is the output of the following code?

print(7 + 3 % 3 // 4)
Answer

(b) 7 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.148Practice1 mark

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())
Answer

(d) 46 23 2 NumPy works element by element on arrays of one type.

A3.149Practice1 mark

What is the output of the following code?

for i in range(1, 13, 1):
    print(i, end=" ")
Answer

(c) 1 2 3 4 5 6 7 8 9 10 11 12 range(start, stop, step) starts at start and stops before stop.

A3.150Practice1 mark

What is the output of the following code?

print(28 - 5 // 2 % 2)
Answer

(b) 28 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.151Practice1 mark

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])
Answer

(d) 4 4 NumPy works element by element on arrays of one type.

A3.152Practice1 mark

What is the output of the following code?

for i in range(1, 11, 2):
    print(i, end=" ")
Answer

(a) 1 3 5 7 9 range(start, stop, step) starts at start and stops before stop.

A3.153Practice1 mark

What is the output of the following code?

for i in range(1, -11, -2):
    print(i, end=" ")
Answer

(a) 1 -1 -3 -5 -7 -9 range(start, stop, step) starts at start and stops before stop.

A3.154Practice1 mark

What is the output of the following code?

import numpy as np
a = np.array([18, 21, 23, 29])
print(a * 2)
Answer

(d) [36 42 46 58] NumPy works element by element on arrays of one type.

A3.155Practice1 mark

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)
Answer

(b) [54 21 41 34] NumPy works element by element on arrays of one type.

A3.156Practice1 mark

What is the output of the following code?

for i in range(2, -10, -2):
    print(i, end=" ")
Answer

(a) 2 0 -2 -4 -6 -8 range(start, stop, step) starts at start and stops before stop.

A3.157Practice1 mark

What is the output of the following code?

D = {'Amit': 82, 'Esha': 62, 'Bela': 53, 'Dev': 42}
print(list(D.keys()))
Answer

(b) ['Amit', 'Esha', 'Bela', 'Dev'] A dictionary keeps key: value pairs; keys are unique.

A3.158Practice1 mark

What is the output of the following code?

print(16 / 5, 16 // 5, 16 % 5)
Answer

(d) 3.2 3 1 / always gives a float; // gives the quotient rounded down; % gives the remainder.

A3.159Practice1 mark

What is the output of the following code?

for i in range(3, 15):
    if i % 6 == 0:
        break
    print(i, end=" ")
Answer

(d) 3 4 5 break leaves the loop; continue skips only the rest of that round.

A3.160Practice1 mark

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)
Answer

(d) [18 29 45 6] NumPy works element by element on arrays of one type.

A3.161Practice1 mark

What is the output of the following code?

for i in range(2, 7, 2):
    print(i, end=" ")
Answer

(c) 2 4 6 range(start, stop, step) starts at start and stops before stop.

A3.162Practice1 mark

What is the output of the following code?

n = 34
count = 0
while n > 2:
    n = n - 9
    count += 1
print(count, n)
Answer

(c) 4 -2 Trace the loop: the condition is checked before every round.

A3.163Practice1 mark

What is the output of the following code?

print(type(7 / 2))
Answer

(b) <class 'float'> The type of the result decides the class.

A3.164Practice1 mark

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")
Answer

(c) B Only the first true condition of an if-elif chain runs.

A3.165Practice1 mark

What is the output of the following code?

L = [1, 15, 11, 17, 24, 5]
L.reverse()
print(L)
Answer

(d) [5, 24, 17, 11, 15, 1] reverse() reverses the order of the elements in the same list (it does not sort).

A3.166Practice1 mark

What is the output of the following code?

print(6 and 9)
Answer

(a) 9 not is applied first, then and, then or. and/or return one of the operands.

A3.167Practice1 mark

What is the output of the following code?

print(type((7)))
Answer

(b) <class 'int'> The type of the result decides the class.

A3.168Practice1 mark

What is the output of the following code?

n = 38
count = 0
while n > 1:
    n = n - 9
    count += 1
print(count, n)
Answer

(d) 5 -7 Trace the loop: the condition is checked before every round.

A3.169Practice1 mark

What is the output of the following code?

D = {'Esha': 77, 'Charu': 47, 'Amit': 84, 'Bela': 70}
print(sorted(D))
Answer

(b) ['Amit', 'Bela', 'Charu', 'Esha'] A dictionary keeps key: value pairs; keys are unique.

A3.170Practice1 mark

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)
Answer

(a) [21 22 29 42] NumPy works element by element on arrays of one type.

A3.171Practice1 mark

What is the output of the following code?

import numpy as np
a = np.array([1, 18, 27, 9])
print(a * 2)
Answer

(c) [ 2 36 54 18] NumPy works element by element on arrays of one type.

A3.172Practice1 mark

What is the output of the following code?

D = {'Dev': 67, 'Esha': 69, 'Gita': 87, 'Farid': 88}
print(max(D))
Answer

(d) Gita A dictionary keeps key: value pairs; keys are unique.

A3.173Practice1 mark

What is the output of the following code?

n = 54
count = 0
while n > 7:
    n = n - 6
    count += 1
print(count, n)
Answer

(b) 8 6 Trace the loop: the condition is checked before every round.

A3.174Practice1 mark

What is the output of the following code?

L = [30, 14, 36, 33, 13, 1]
L.remove(14)
print(L)
Answer

(a) [30, 36, 33, 13, 1] remove(14) deletes the first occurrence of the value 14 (not the index).

A3.175Practice1 mark

What is the output of the following code?

L = [15, 8, 22, 5]
L.sort()
print(L)
Answer

(a) [5, 8, 15, 22] sort() arranges the same list in ascending order (smallest first).

A3.176Practice1 mark

What is the output of the following code?

print(13 + 5 % 5 ** 2)
Answer

(c) 18 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.177Practice1 mark

What is the output of the following code?

D = {'Farid': 83, 'Charu': 44, 'Esha': 94, 'Gita': 82}
print(D.get("Zoya", 0))
Answer

(a) 0 A dictionary keeps key: value pairs; keys are unique.

A3.178Practice1 mark

What is the output of the following code?

print(-19 // 5, -19 % 5)
Answer

(a) -4 1 // rounds down towards minus infinity, so -19 // 5 is -4; the remainder takes the sign of the divisor.

A3.179Practice1 mark

What is the output of the following code?

print(56 / 9, 56 // 9, 56 % 9)
Answer

(d) 6.222222222222222 6 2 / always gives a float; // gives the quotient rounded down; % gives the remainder.

A3.180Practice1 mark

What is the output of the following code?

print(not 0)
Answer

(a) True not is applied first, then and, then or. and/or return one of the operands.

A3.181Practice1 mark

What is the output of the following code?

D = {'Charu': 89, 'Esha': 65, 'Farid': 94, 'Dev': 71}
print(len(D))
Answer

(c) 4 A dictionary keeps key: value pairs; keys are unique.

A3.182Practice1 mark

What is the output of the following code?

D = {'Bela': 90, 'Gita': 54, 'Amit': 82, 'Dev': 76}
print("Gita" in D, 54 in D)
Answer

(d) True False A dictionary keeps key: value pairs; keys are unique.

A3.183Practice1 mark

What is the output of the following code?

L = [19, 33, 5, 3, 15]
print(max(L) - min(L))
Answer

(a) 30 max(L) is 33 and min(L) is 3, so 33 - 3 = 30.

A3.184Practice1 mark

What is the output of the following code?

print(7 > 5 and 12 < 10 or not 0)
Answer

(d) True not is applied first, then and, then or. and/or return one of the operands.

A3.185Practice1 mark

What is the output of the following code?

print(16 - 6 % 4 * 3)
Answer

(a) 10 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.186Practice1 mark

What is the output of the following code?

print(-19 // 6, -19 % 6)
Answer

(a) -4 5 // rounds down towards minus infinity, so -19 // 6 is -4; the remainder takes the sign of the divisor.

A3.187Practice1 mark

What is the output of the following code?

L = [6, 7, 37, 29]
L.insert(0, 44)
print(L)
Answer

(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.

A3.188Practice1 mark

What is the output of the following code?

print(27 - 6 * 2 ** 2)
Answer

(b) 3 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.189Practice1 mark

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])
Answer

(a) 20 26 [19 9] NumPy works element by element on arrays of one type.

A3.190Practice1 mark

What is the output of the following code?

D = {'Amit': 87, 'Bela': 49, 'Dev': 66, 'Gita': 63}
print(D["Amit"])
Answer

(d) 87 A dictionary keeps key: value pairs; keys are unique.

A3.191Practice1 mark

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])
Answer

(c) 6 20 [16 6] NumPy works element by element on arrays of one type.

A3.192Practice1 mark

What is the output of the following code?

L = [34, 14, 23, 24]
print(L * 2)
Answer

(a) [34, 14, 23, 24, 34, 14, 23, 24] The * operator repeats the list, so the elements appear 2 times one after another.

A3.193Practice1 mark

What is the output of the following code?

n = 49
count = 0
while n > 7:
    n = n - 4
    count += 1
print(count, n)
Answer

(a) 11 5 Trace the loop: the condition is checked before every round.

A3.194Practice1 mark

What is the output of the following code?

L = [18, 33, 28, 16, 25]
L.extend([57, 58])
print(L)
Answer

(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.

A3.195Practice1 mark

What is the output of the following code?

import numpy as np
a = np.array([True, False])
print(a.dtype)
Answer

(b) bool NumPy works element by element on arrays of one type.

A3.196Practice1 mark

What is the output of the following code?

for i in range(2, 14):
    if i % 3 == 0:
        continue
    print(i, end=" ")
Answer

(d) 2 4 5 7 8 10 11 13 break leaves the loop; continue skips only the rest of that round.

A3.197Practice1 mark

What is the output of the following code?

n = 52
count = 0
while n > 4:
    n = n - 9
    count += 1
print(count, n)
Answer

(b) 6 -2 Trace the loop: the condition is checked before every round.

A3.198Practice1 mark

What is the output of the following code?

print(int(8.5), round(8.5))
Answer

(a) 8 8 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.

A3.199Practice1 mark

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")
Answer

(b) C Only the first true condition of an if-elif chain runs.

A3.200Practice1 mark

What is the output of the following code?

D = {'Esha': 72, 'Bela': 80, 'Amit': 85, 'Farid': 74}
print(list(D.values())[1])
Answer

(a) 80 A dictionary keeps key: value pairs; keys are unique.

A3.201Practice1 mark

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)
Answer

(d) {'Charu': 76, 'Dev': 53, 'Esha': 73, 'Bela': 50, 'Zoya': 60} A dictionary keeps key: value pairs; keys are unique.

A3.202Practice1 mark

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)
Answer

(d) [36 24 23 28] NumPy works element by element on arrays of one type.

A3.203Practice1 mark

What is the output of the following code?

print(7 + 6 // 5 * 3)
Answer

(d) 10 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.204Practice1 mark

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])
Answer

(b) 8 11 NumPy works element by element on arrays of one type.

A3.205Practice1 mark

What is the output of the following code?

print(-22 // 4, -22 % 4)
Answer

(d) -6 2 // rounds down towards minus infinity, so -22 // 4 is -6; the remainder takes the sign of the divisor.

A3.206Practice1 mark

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)
Answer

(b) 1 (4,) 4 NumPy works element by element on arrays of one type.

A3.207Practice1 mark

What is the output of the following code?

print(10 - 2 // 3 % 3)
Answer

(d) 10 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.208Practice1 mark

What is the output of the following code?

L = [2, 27, 22, 7, 38]
L.extend([43, 44])
print(L)
Answer

(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.

A3.209Practice1 mark

What is the output of the following code?

a = 7
b = 6
a += b
b = a - b
a = a - b
print(a, b)
Answer

(c) 6 7 In a, b = b, a + b the right side is worked out first, with the old values.

A3.210Practice1 mark

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())
Answer

(a) 48 20 5 NumPy works element by element on arrays of one type.

A3.211Practice1 mark

What is the output of the following code?

print(22 + 6 * 4 ** 2)
Answer

(d) 118 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.212Practice1 mark

What is the output of the following code?

for i in range(0, 5, 1):
    print(i, end=" ")
Answer

(a) 0 1 2 3 4 range(start, stop, step) starts at start and stops before stop.

A3.213Practice1 mark

What is the output of the following code?

L = [8, 37, 20, 36, 1]
L.remove(20)
print(L)
Answer

(c) [8, 37, 36, 1] remove(20) deletes the first occurrence of the value 20 (not the index).

A3.214Practice1 mark

What is the output of the following code?

L = [24, 17, 10, 11, 19]
print(L[1:2])
Answer

(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.

A3.215Practice1 mark

What is the output of the following code?

D = {'Dev': 50, 'Gita': 81, 'Bela': 82, 'Amit': 45}
print(len(D))
Answer

(c) 4 A dictionary keeps key: value pairs; keys are unique.

A3.216Practice1 mark

What is the output of the following code?

c = 0
for i in range(2):
    for j in range(3):
        c += 1
print(c)
Answer

(d) 6 The inner loop runs fully for every round of the outer loop.

A3.217Practice1 mark

What is the output of the following code?

D = {'Dev': 49, 'Charu': 81, 'Esha': 52, 'Farid': 67}
print(D.get("Zoya"))
Answer

(a) None A dictionary keeps key: value pairs; keys are unique.

A3.218Practice1 mark

What is the output of the following code?

print(int(7.5), round(7.5))
Answer

(b) 7 8 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.

A3.219Practice1 mark

What is the output of the following code?

L = [8, 19, 20, 23, 16, 10]
print(len(L + [51]))
Answer

(c) 7 L + [..] makes a new list with one more element: 6 + 1 = 7. L itself does not change.

A3.220Practice1 mark

What is the output of the following code?

D = {'Dev': 67, 'Farid': 83, 'Esha': 78, 'Charu': 48}
print(list(D.items())[0])
Answer

(d) ('Dev', 67) A dictionary keeps key: value pairs; keys are unique.

A3.221Practice1 mark

What is the output of the following code?

print(str(8) * 2)
Answer

(d) 88 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.

A3.222Practice1 mark

What is the output of the following code?

for i in range(1, 16):
    if i % 3 == 0:
        continue
    print(i, end=" ")
Answer

(c) 1 2 4 5 7 8 10 11 13 14 break leaves the loop; continue skips only the rest of that round.

A3.223Practice1 mark

What is the output of the following code?

print(int('7') + 7, '7' + '7')
Answer

(c) 14 77 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.

A3.224Practice1 mark

What is the output of the following code?

a = 10
b = 8
a += b
b = a - b
a = a - b
print(a, b)
Answer

(c) 8 10 In a, b = b, a + b the right side is worked out first, with the old values.

A3.225Practice1 mark

What is the output of the following code?

D = {'Dev': 88, 'Bela': 82, 'Esha': 44, 'Gita': 81}
print(D["Gita"])
Answer

(d) 81 A dictionary keeps key: value pairs; keys are unique.

A3.226Practice1 mark

What is the output of the following code?

L = [5, 12, 21, 39]
print(L[1:4])
Answer

(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.

A3.227Practice1 mark

What is the output of the following code?

D = {'Amit': 50, 'Dev': 42, 'Charu': 51, 'Esha': 47}
del D["Dev"]
print(D)
Answer

(a) {'Amit': 50, 'Charu': 51, 'Esha': 47} A dictionary keeps key: value pairs; keys are unique.

A3.228Practice1 mark

What is the output of the following code?

L = [26, 1, 33, 6]
print(sum(L) // len(L))
Answer

(c) 16 sum(L) is 66 and len(L) is 4; // gives the floor quotient 66 // 4 = 16.

A3.229Practice1 mark

What is the output of the following code?

print(9 < 6 < 15)
Answer

(a) False not is applied first, then and, then or. and/or return one of the operands.

A3.230Practice1 mark

What is the output of the following code?

L = [23, 39, 5, 4, 7]
L.reverse()
print(L)
Answer

(c) [7, 4, 5, 39, 23] reverse() reverses the order of the elements in the same list (it does not sort).

A3.231Practice1 mark

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")
Answer

(c) Fail Only the first true condition of an if-elif chain runs.

A3.232Practice1 mark

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")
Answer

(d) A Only the first true condition of an if-elif chain runs.

A3.233Practice1 mark

What is the output of the following code?

for i in range(1, 13, 2):
    print(i, end=" ")
Answer

(c) 1 3 5 7 9 11 range(start, stop, step) starts at start and stops before stop.

A3.234Practice1 mark

What is the output of the following code?

print(float('9') * 2)
Answer

(d) 18.0 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.

A3.235Practice1 mark

What is the output of the following code?

x = 3
x -= 2
x **= 2
print(x)
Answer

(c) 1 In a, b = b, a + b the right side is worked out first, with the old values.

A3.236Practice1 mark

What is the output of the following code?

for i in range(2, 12):
    if i % 6 == 0:
        break
    print(i, end=" ")
Answer

(a) 2 3 4 5 break leaves the loop; continue skips only the rest of that round.

A3.237Practice1 mark

What is the output of the following code?

print(20 - 4 % 3 % 3)
Answer

(d) 19 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.238Practice1 mark

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])
Answer

(d) 29 17 [29 11] NumPy works element by element on arrays of one type.

A3.239Practice1 mark

What is the output of the following code?

print(20 / 8, 20 // 8, 20 % 8)
Answer

(b) 2.5 2 4 / always gives a float; // gives the quotient rounded down; % gives the remainder.

A3.240Practice1 mark

What is the output of the following code?

print(22 / 6, 22 // 6, 22 % 6)
Answer

(a) 3.6666666666666665 3 4 / always gives a float; // gives the quotient rounded down; % gives the remainder.

A3.241Practice1 mark

What is the output of the following code?

for i in range(0, -8, -1):
    print(i, end=" ")
Answer

(a) 0 -1 -2 -3 -4 -5 -6 -7 range(start, stop, step) starts at start and stops before stop.

A3.242Practice1 mark

What is the output of the following code?

print(27 - 3 % 4 ** 3)
Answer

(b) 24 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.243Practice1 mark

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)
Answer

(a) [31 12 42 29] NumPy works element by element on arrays of one type.

A3.244Practice1 mark

What is the output of the following code?

for i in range(0, 12, 3):
    print(i, end=" ")
Answer

(d) 0 3 6 9 range(start, stop, step) starts at start and stops before stop.

A3.245Practice1 mark

What is the output of the following code?

D = {'Esha': 60, 'Bela': 69, 'Charu': 94, 'Amit': 42}
print(list(D.items())[0])
Answer

(b) ('Esha', 60) A dictionary keeps key: value pairs; keys are unique.

A3.246Practice1 mark

What is the output of the following code?

D = {'Dev': 78, 'Farid': 86, 'Amit': 74, 'Bela': 50}
D["Dev"] = 99
print(D)
Answer

(a) {'Dev': 99, 'Farid': 86, 'Amit': 74, 'Bela': 50} A dictionary keeps key: value pairs; keys are unique.

A3.247Practice1 mark

What is the output of the following code?

D = {'Amit': 45, 'Charu': 85, 'Gita': 52, 'Bela': 67}
print(max(D.values()))
Answer

(a) 85 A dictionary keeps key: value pairs; keys are unique.

A3.248Practice1 mark

What is the output of the following code?

for i in range(5, -7, -2):
    print(i, end=" ")
Answer

(c) 5 3 1 -1 -3 -5 range(start, stop, step) starts at start and stops before stop.

A3.249Practice1 mark

What is the output of the following code?

L = [10, 39, 12, 7]
L[2] = 52
print(L)
Answer

(a) [10, 39, 52, 7] Lists are mutable, so L[2] = 52 replaces the element at index 2 (12) with 52.

A3.250Practice1 mark

What is the output of the following code?

print(type(2 ** -1))
Answer

(b) <class 'float'> The type of the result decides the class.

A3.251Practice1 mark

What is the output of the following code?

L = [34, 36, 14, 12, 11]
print(L[::-2])
Answer

(b) [11, 14, 34] A step of -2 starts from the last element and moves left, taking every second element: [11, 14, 34].

A3.252Practice1 mark

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)
Answer

(d) 2 (2, 3) 6 NumPy works element by element on arrays of one type.

A3.253Practice1 mark

What is the output of the following code?

for i in range(2, 12):
    if i % 8 == 0:
        break
    print(i, end=" ")
Answer

(b) 2 3 4 5 6 7 break leaves the loop; continue skips only the rest of that round.

A3.254Practice1 mark

What is the output of the following code?

print(14 - 5 // 2 ** 3)
Answer

(c) 14 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.255Practice1 mark

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])
Answer

(b) 2 15 NumPy works element by element on arrays of one type.

A3.256Practice1 mark

What is the output of the following code?

D = {'Gita': 84, 'Farid': 47, 'Charu': 64, 'Dev': 78}
print(sorted(D))
Answer

(d) ['Charu', 'Dev', 'Farid', 'Gita'] A dictionary keeps key: value pairs; keys are unique.

A3.257Practice1 mark

What is the output of the following code?

print(0 or 9)
Answer

(a) 9 not is applied first, then and, then or. and/or return one of the operands.

A3.258Practice1 mark

What is the output of the following code?

import numpy as np
a = np.array([18, 14, 25, 29])
print(a * 2)
Answer

(c) [36 28 50 58] NumPy works element by element on arrays of one type.

A3.259Practice1 mark

What is the output of the following code?

D = {'Esha': 83, 'Farid': 44, 'Bela': 86, 'Amit': 55}
D["Farid"] = 99
print(D)
Answer

(b) {'Esha': 83, 'Farid': 99, 'Bela': 86, 'Amit': 55} A dictionary keeps key: value pairs; keys are unique.

A3.260Practice1 mark

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])
Answer

(a) 7 7 NumPy works element by element on arrays of one type.

A3.261Practice1 mark

What is the output of the following code?

D = {'Esha': 51, 'Dev': 54, 'Amit': 56, 'Charu': 64}
print(list(D.values())[1])
Answer

(a) 54 A dictionary keeps key: value pairs; keys are unique.

A3.262Practice1 mark

What is the output of the following code?

L = [24, 22, 9, 33, 30, 13]
L.sort(reverse=True)
print(L)
Answer

(c) [33, 30, 24, 22, 13, 9] sort(reverse=True) arranges the same list in descending order (largest first).

A3.263Practice1 mark

What is the output of the following code?

print(8 + 6 % 3 % 3)
Answer

(c) 8 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.264Practice1 mark

What is the output of the following code?

for i in range(3, 12):
    if i % 6 == 0:
        break
    print(i, end=" ")
Answer

(c) 3 4 5 break leaves the loop; continue skips only the rest of that round.

A3.265Practice1 mark

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)
Answer

(c) 20 The inner loop runs fully for every round of the outer loop.

A3.266Practice1 mark

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)
Answer

(a) [30 36 12 13] NumPy works element by element on arrays of one type.

A3.267Practice1 mark

What is the output of the following code?

D = {'Bela': 74, 'Dev': 77, 'Charu': 94, 'Esha': 84}
print(D.pop("Esha"), len(D))
Answer

(d) 84 3 A dictionary keeps key: value pairs; keys are unique.

A3.268Practice1 mark

What is the output of the following code?

for i in range(3, 10):
    if i % 2 == 0:
        continue
    print(i, end=" ")
Answer

(c) 3 5 7 9 break leaves the loop; continue skips only the rest of that round.

A3.269Practice1 mark

What is the output of the following code?

x = 10
x *= 2 + 3
print(x)
Answer

(b) 50 In a, b = b, a + b the right side is worked out first, with the old values.

A3.270Practice1 mark

What is the output of the following code?

a, b = 8, 10
a, b = b, a + b
print(a, b)
Answer

(c) 10 18 In a, b = b, a + b the right side is worked out first, with the old values.

A3.271Practice1 mark

What is the output of the following code?

D = {'Dev': 40, 'Charu': 70, 'Amit': 67, 'Farid': 60}
del D["Charu"]
print(D)
Answer

(a) {'Dev': 40, 'Amit': 67, 'Farid': 60} A dictionary keeps key: value pairs; keys are unique.

A3.272Practice1 mark

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")
Answer

(a) Fail Only the first true condition of an if-elif chain runs.

A3.273Practice1 mark

What is the output of the following code?

L = [9, 30, 37, 6, 34]
print(max(L) - min(L))
Answer

(b) 31 max(L) is 37 and min(L) is 6, so 37 - 6 = 31.

A3.274Practice1 mark

What is the output of the following code?

print(34 / 6, 34 // 6, 34 % 6)
Answer

(d) 5.666666666666667 5 4 / always gives a float; // gives the quotient rounded down; % gives the remainder.

A3.275Practice1 mark

What is the output of the following code?

print(23 - 5 // 3 ** 2)
Answer

(d) 23 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.276Practice1 mark

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])
Answer

(d) 3 2 NumPy works element by element on arrays of one type.

A3.277Practice1 mark

What is the output of the following code?

L = [25, 32, 27, 22]
L.append(46)
print(L)
Answer

(b) [25, 32, 27, 22, 46] append(46) adds 46 as the last element.

A3.278Practice1 mark

What is the output of the following code?

L = [32, 11, 15, 1, 29]
print(11 in L, 45 not in L)
Answer

(d) True True 11 is in the list, so "in" gives True; 45 is not in the list, so "not in" gives True.

A3.279Practice1 mark

What is the output of the following code?

print(47 / 7, 47 // 7, 47 % 7)
Answer

(c) 6.714285714285714 6 5 / always gives a float; // gives the quotient rounded down; % gives the remainder.

A3.280Practice1 mark

What is the output of the following code?

print(type('3' + '4'))
Answer

(d) <class 'str'> The type of the result decides the class.

A3.281Practice1 mark

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)
Answer

(a) [26 53 31 28] NumPy works element by element on arrays of one type.

A3.282Practice1 mark

What is the output of the following code?

D = {'Esha': 66, 'Amit': 76, 'Dev': 61, 'Gita': 75}
print(D.pop("Esha"), len(D))
Answer

(b) 66 3 A dictionary keeps key: value pairs; keys are unique.

A3.283Practice1 mark

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)
Answer

(a) [40 24 22 19] NumPy works element by element on arrays of one type.

A3.284Practice1 mark

What is the output of the following code?

D = {'Esha': 52, 'Amit': 84, 'Dev': 80, 'Charu': 48}
print(D.get("Zoya", 0))
Answer

(a) 0 A dictionary keeps key: value pairs; keys are unique.

A3.285Practice1 mark

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")
Answer

(c) Fail Only the first true condition of an if-elif chain runs.

A3.286Practice1 mark

What is the output of the following code?

print(-25 // 4, -25 % 4)
Answer

(d) -7 3 // rounds down towards minus infinity, so -25 // 4 is -7; the remainder takes the sign of the divisor.

A3.287Practice1 mark

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)
Answer

(a) 1 (4,) 4 NumPy works element by element on arrays of one type.

A3.288Practice1 mark

What is the output of the following code?

D = {'Dev': 73, 'Charu': 59, 'Gita': 45, 'Bela': 55}
print(sorted(D))
Answer

(d) ['Bela', 'Charu', 'Dev', 'Gita'] A dictionary keeps key: value pairs; keys are unique.

A3.289Practice1 mark

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])
Answer

(d) 15 10 NumPy works element by element on arrays of one type.

A3.290Practice1 mark

What is the output of the following code?

import numpy as np
a = np.array([1, 2, 3])
print(a.dtype)
Answer

(b) int64 NumPy works element by element on arrays of one type.

A3.291Practice1 mark

What is the output of the following code?

n = 43
count = 0
while n > 1:
    n = n - 3
    count += 1
print(count, n)
Answer

(d) 14 1 Trace the loop: the condition is checked before every round.

A3.292Practice1 mark

What is the output of the following code?

D = {'Gita': 47, 'Esha': 74, 'Bela': 94, 'Amit': 88}
print(D.pop("Bela"), len(D))
Answer

(c) 94 3 A dictionary keeps key: value pairs; keys are unique.

A3.293Practice1 mark

What is the output of the following code?

for i in range(6, -2, -1):
    print(i, end=" ")
Answer

(a) 6 5 4 3 2 1 0 -1 range(start, stop, step) starts at start and stops before stop.

A3.294Practice1 mark

What is the output of the following code?

print(20 + 5 % 2 * 3)
Answer

(a) 23 Python applies ** first, then *, /, //, % from left to right, then + and -.

A3.295Practice1 mark

What is the output of the following code?

a = 2
b = 5
a += b
b = a - b
a = a - b
print(a, b)
Answer

(a) 5 2 In a, b = b, a + b the right side is worked out first, with the old values.

A3.296Practice1 mark

What is the output of the following code?

D = {'Esha': 55, 'Gita': 96, 'Bela': 51, 'Farid': 56}
D["Bela"] = 99
print(D)
Answer

(d) {'Esha': 55, 'Gita': 96, 'Bela': 99, 'Farid': 56} A dictionary keeps key: value pairs; keys are unique.

A3.297Practice1 mark

What is the output of the following code?

print(type(7 % 2 == 1))
Answer

(c) <class 'bool'> The type of the result decides the class.

A3.298Practice1 mark

What is the output of the following code?

D = {'Esha': 40, 'Gita': 66, 'Bela': 75, 'Farid': 69}
D["Farid"] = 99
print(D)
Answer

(a) {'Esha': 40, 'Gita': 66, 'Bela': 75, 'Farid': 99} A dictionary keeps key: value pairs; keys are unique.

A4Database concepts and keys1 mark · 108 questions
A4.1Practice1 mark

Which column of the table PATIENT given below can be a candidate key?

Table: PATIENT

PIDAadhaarWardDoctorAdmitDate
16623462346234MaternityDr. Iyer2026-09-18
14423442344234MaternityDr. Iyer2026-09-12
13323432343234GeneralDr. Rao2026-09-10
15523452345234ICUDr. Sen2026-09-15
17723472347234GeneralDr. Rao2026-09-20
11123412341234GeneralDr. Rao2026-09-02
Answer

(c) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.2Practice1 mark

If BookID is the primary key of the table BOOK given below, which is its alternate key?

Table: BOOK

BookIDISBNTitlePublisherPriceMember
2019789352921485Informatics PracticesNCERT210Asha
2079789386551023Learn SQLBPB400Karan
2039780143032311Wings of FireUniversities299Ravi
2059789352925032Chemistry Part 1NCERT190Neha
2029789352920112Physics Part 1NCERT180NULL
Answer

(c) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.3Practice1 mark

If PID is the primary key of the table PATIENT given below, which is its alternate key?

Table: PATIENT

PIDAadhaarWardDoctorAdmitDateFeeInsurance
15523452345234ICUDr. Sen2026-09-159500NULL
14423442344234MaternityDr. Iyer2026-09-125000LIC
16623462346234MaternityDr. Iyer2026-09-184500NULL
13323432343234GeneralDr. Rao2026-09-101200Star
17723472347234GeneralDr. Rao2026-09-20900Star
Answer

(a) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.4Practice1 mark

If PID is the primary key of the table PATIENT given below, which is its alternate key?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
13323432343234OmGeneralDr. Rao2026-09-101200Star
17723472347234SahilGeneralDr. Rao2026-09-20900Star
12223422342234NishaICUDr. Sen2026-09-058000NULL
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
Answer

(a) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.5Practice1 mark

Which column of the table STUDENT given below can be a candidate key?

Table: STUDENT

RollNoAdmNoSectionGenderDOBMarksPhone
64556AF2009-09-09319810066666
44534CF2009-07-21669810044444
14501AM2009-04-12789810011111
Answer

(b) RollNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.6Practice1 mark

Which column of the table BOOK given below can be a candidate key?

Table: BOOK

BookIDISBNTitleSubjectPublisherPriceMember
2019789352921485Informatics PracticesComputerNCERT210Asha
2059789352925032Chemistry Part 1ScienceNCERT190Neha
2029789352920112Physics Part 1ScienceNCERT180NULL
Answer

(b) BookID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.7Practice1 mark

If BookID is the primary key of the table BOOK given below, which is its alternate key?

Table: BOOK

BookIDISBNTitleSubjectPublisher
2079789386551023Learn SQLComputerBPB
2049789386551009Python BasicsComputerBPB
2039780143032311Wings of FireBiographyUniversities
2059789352925032Chemistry Part 1ScienceNCERT
2029789352920112Physics Part 1ScienceNCERT
2019789352921485Informatics PracticesComputerNCERT
Answer

(c) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.8Practice1 mark

What are the degree and cardinality of the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDateMember
2039780143032311Wings of FireBiographyUniversities2026-06-21Ravi
2079789386551023Learn SQLComputerBPB2026-08-12Karan
2049789386551009Python BasicsComputerBPB2026-08-01NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15Neha
Answer

(c) 7 and 4 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.9Practice1 mark

Which of these is NOT a relational DBMS?

Answer

(d) MS Paint MS Paint is a drawing program; MySQL, Oracle and PostgreSQL are relational DBMS.

A4.10Practice1 mark

What are the degree and cardinality of the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
Answer

(d) 8 and 5 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.11Practice1 mark

Data about data, kept in the data dictionary, is

Answer

(a) metadata Metadata describes data, such as column names and types.

A4.12Practice1 mark

The set {'M', 'F'} for the column Gender is its

Answer

(d) domain The set of allowed values of a column is its domain.

A4.13Practice1 mark

If PCode is the primary key of the table PRODUCT given below, which is its alternate key?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePrice
P0489010044MouseElectronicsLogitech2026-02-20650
P0789010077Lunch BoxHomeMilton2025-12-18275
P0589010055Water BottleHomeMilton2025-05-30320
P0689010066EarphonesElectronicsBoat2026-03-05899
P0189010011NotebookStationeryClassmate2026-01-1060
P0289010022Pen DriveElectronicsSanDisk2025-08-15450
P0389010033Geometry BoxStationeryCamlin2025-11-02180
Answer

(a) Barcode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.14Practice1 mark

Which of these is a DBMS?

Answer

(c) MySQL MySQL is a relational DBMS; Python is a language, MS Paint and Windows are not DBMS.

A4.15Practice1 mark

Which column of the table EMPLOYEE given below can be a candidate key?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
Answer

(d) EmpID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.16Practice1 mark

Which column of the table BOOK given below can be a candidate key?

Table: BOOK

BookIDISBNTitleSubjectIssueDatePrice
2019789352921485Informatics PracticesComputer2026-07-03210
2049789386551009Python BasicsComputer2026-08-01350
2079789386551023Learn SQLComputer2026-08-12400
2069780140449136The Story of My ExperimentsBiography2026-05-30250
2039780143032311Wings of FireBiography2026-06-21299
2029789352920112Physics Part 1Science2026-07-10180
Answer

(b) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.17Practice1 mark

If EmpID is the primary key of the table EMPLOYEE given below, which is its alternate key?

Table: EMPLOYEE

EmpIDEmailENameDOJSalary
E106wasim@co.inWasim2022-07-2539000
E107yamini@co.inYamini2017-12-1281000
E104usha@co.inUsha2021-03-1036000
E103tarun@co.inTarun2016-09-2075000
E102seema@co.inSeema2020-01-1558000
E101ravi@co.inRavi2018-06-0142000
E105vikas@co.inVikas2019-11-0564000
Answer

(b) Email Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.18Practice1 mark

Which column of the table PATIENT given below can be a candidate key?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFee
12223422342234NishaICUDr. Sen2026-09-058000
15523452345234QasimICUDr. Sen2026-09-159500
11123412341234MohanGeneralDr. Rao2026-09-021500
16623462346234RekhaMaternityDr. Iyer2026-09-184500
14423442344234PoojaMaternityDr. Iyer2026-09-125000
13323432343234OmGeneralDr. Rao2026-09-101200
Answer

(c) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.19Practice1 mark

Which of these is the best primary key for a table of bank accounts?

Answer

(a) Account number Every account has a different account number; names and cities can repeat.

A4.20Practice1 mark

If RollNo is the primary key of the table STUDENT given below, which is its alternate key?

Table: STUDENT

RollNoAdmNoNameSectionDOBMarksPhone
14501AaravA2009-04-12789810011111
74567GauravC2010-02-28599810077777
44534DivyaC2009-07-21669810044444
64556FarahA2009-09-09319810066666
34523ChiragA2010-01-05459810033333
Answer

(a) AdmNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.21Practice1 mark

When copies of the same data do not match, it is called

Answer

(a) data inconsistency If one copy is changed and another is not, the data becomes inconsistent.

A4.22Practice1 mark

Which column of the table EMPLOYEE given below can be a candidate key?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
E102seema@co.inSeemaHRPune2020-01-1558000NULL
Answer

(d) EmpID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.23Practice1 mark

Which column of the table BOOK given below can be a candidate key?

Table: BOOK

BookIDISBNTitlePublisherIssueDate
2029789352920112Physics Part 1NCERT2026-07-10
2049789386551009Python BasicsBPB2026-08-01
2069780140449136The Story of My ExperimentsPenguin2026-05-30
2019789352921485Informatics PracticesNCERT2026-07-03
2039780143032311Wings of FireUniversities2026-06-21
Answer

(b) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.24Practice1 mark

What are the degree and cardinality of the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E105vikas@co.inVikasITPune2019-11-05640004000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
Answer

(c) 8 and 6 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.25Practice1 mark

State True or False: A primary key can have NULL values.

Answer

(b) False No; a primary key must have a value in every row and no repeats.

A4.26Practice1 mark

Which column of the table STUDENT given below can be a candidate key?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
34523ChiragAM2010-01-05459810033333
24512BhavyaBF2009-11-3092NULL
74567GauravCM2010-02-28599810077777
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
Answer

(b) RollNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.27Practice1 mark

What are the degree and cardinality of the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorInsurance
14423442344234PoojaMaternityDr. IyerLIC
11123412341234MohanGeneralDr. RaoLIC
16623462346234RekhaMaternityDr. IyerNULL
12223422342234NishaICUDr. SenNULL
Answer

(d) 6 and 4 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.28Practice1 mark

Keeping the same data at more than one place is called

Answer

(c) data redundancy Storing the same data many times is redundancy; it wastes space.

A4.29Practice1 mark

The number of tuples (rows) in a relation is its

Answer

(d) cardinality Cardinality counts the rows. (Degree counts the columns.)

A4.30Practice1 mark

A row of a relation is called a

Answer

(c) tuple Each row holds one record and is called a tuple.

A4.31Practice1 mark

What are the degree and cardinality of the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePrice
2049789386551009Python BasicsComputerBPB2026-08-01350
2019789352921485Informatics PracticesComputerNCERT2026-07-03210
2039780143032311Wings of FireBiographyUniversities2026-06-21299
2079789386551023Learn SQLComputerBPB2026-08-12400
Answer

(c) 7 and 4 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.32Practice1 mark

What are the degree and cardinality of the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0789010077Lunch BoxHomeMilton2025-12-182758
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
Answer

(c) 8 and 4 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.33Practice1 mark

What are the degree and cardinality of the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E105vikas@co.inVikasITPune2019-11-05640004000
E103tarun@co.inTarunITDelhi2016-09-20750005000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
Answer

(c) 8 and 5 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.34Practice1 mark

What are the degree and cardinality of the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDOJSalaryBonus
E102seema@co.inSeema2020-01-1558000NULL
E107yamini@co.inYamini2017-12-1281000NULL
E105vikas@co.inVikas2019-11-05640004000
E103tarun@co.inTarun2016-09-20750005000
E101ravi@co.inRavi2018-06-01420003000
E104usha@co.inUsha2021-03-1036000NULL
Answer

(c) 6 and 6 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.35Practice1 mark

A collection of related data stored in an organised way is a

Answer

(b) database A database stores related data, such as all student records, in an organised way.

A4.36Practice1 mark

The structure (design) of a database, such as table names and columns, is the

Answer

(a) schema The schema is the design: tables, columns and types.

A4.37Practice1 mark

The set of all possible values that an attribute can take is its

Answer

(d) domain The domain is the set of allowed values, such as {M, F} for Gender.

A4.38Practice1 mark

If EmpID is the primary key of the table EMPLOYEE given below, which is its alternate key?

Table: EMPLOYEE

EmpIDEmailCityDOJSalaryBonus
E105vikas@co.inPune2019-11-05640004000
E101ravi@co.inDelhi2018-06-01420003000
E103tarun@co.inDelhi2016-09-20750005000
E107yamini@co.inMumbai2017-12-1281000NULL
E102seema@co.inPune2020-01-1558000NULL
E106wasim@co.inDelhi2022-07-25390002000
E104usha@co.inMumbai2021-03-1036000NULL
Answer

(b) Email Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.39Practice1 mark

Which column of the table STUDENT given below can be a candidate key?

Table: STUDENT

RollNoAdmNoNameSectionPhone
24512BhavyaBNULL
44534DivyaC9810044444
54545EshanBNULL
34523ChiragA9810033333
64556FarahA9810066666
14501AaravA9810011111
74567GauravC9810077777
Answer

(b) RollNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.40Practice1 mark

Which column of the table PRODUCT given below can be a candidate key?

Table: PRODUCT

PCodeBarcodeCategoryMfgDatePrice
P0489010044Electronics2026-02-20650
P0289010022Electronics2025-08-15450
P0589010055Home2025-05-30320
P0789010077Home2025-12-18275
P0689010066Electronics2026-03-05899
Answer

(a) PCode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.41Practice1 mark

What are the degree and cardinality of the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameGenderPhone
74567GauravM9810077777
34523ChiragM9810033333
44534DivyaF9810044444
Answer

(c) 5 and 3 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.42Practice1 mark

State True or False: A table can have more than one candidate key.

Answer

(a) True Yes; for example both RollNo and AdmNo can identify every student.

A4.43Practice1 mark

Candidate keys that are not chosen as the primary key are

Answer

(a) alternate keys The remaining candidate keys are called alternate keys.

A4.44Practice1 mark

If PID is the primary key of the table PATIENT given below, which is its alternate key?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
15523452345234QasimICUDr. Sen2026-09-159500NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
17723472347234SahilGeneralDr. Rao2026-09-20900Star
12223422342234NishaICUDr. Sen2026-09-058000NULL
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
Answer

(a) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.45Practice1 mark

If PID is the primary key of the table PATIENT given below, which is its alternate key?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
15523452345234QasimICUDr. Sen2026-09-159500NULL
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
Answer

(a) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.46Practice1 mark

The number of attributes (columns) in a relation is its

Answer

(c) degree Degree counts the columns. (Cardinality counts the rows.)

A4.47Practice1 mark

What are the degree and cardinality of the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
15523452345234QasimICUDr. Sen2026-09-159500NULL
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
12223422342234NishaICUDr. Sen2026-09-058000NULL
Answer

(d) 8 and 6 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.48Practice1 mark

If PCode is the primary key of the table PRODUCT given below, which is its alternate key?

Table: PRODUCT

PCodeBarcodePNameBrandMfgDatePriceDiscount
P0289010022Pen DriveSanDisk2025-08-15450NULL
P0189010011NotebookClassmate2026-01-10605
P0789010077Lunch BoxMilton2025-12-182758
P0689010066EarphonesBoat2026-03-0589920
P0489010044MouseLogitech2026-02-2065015
Answer

(a) Barcode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.49Practice1 mark

If RollNo is the primary key of the table STUDENT given below, which is its alternate key?

Table: STUDENT

RollNoAdmNoGenderMarksPhone
44534F669810044444
74567M599810077777
34523M459810033333
14501M789810011111
64556F319810066666
54545M88NULL
24512F92NULL
Answer

(a) AdmNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.50Practice1 mark

Which column of the table EMPLOYEE given below can be a candidate key?

Table: EMPLOYEE

EmpIDEmailENameDeptDOJSalary
E105vikas@co.inVikasIT2019-11-0564000
E106wasim@co.inWasimHR2022-07-2539000
E107yamini@co.inYaminiIT2017-12-1281000
E101ravi@co.inRaviSales2018-06-0142000
E102seema@co.inSeemaHR2020-01-1558000
E103tarun@co.inTarunIT2016-09-2075000
Answer

(d) Email Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.51Practice1 mark

Which column of the table BOOK given below can be a candidate key?

Table: BOOK

BookIDISBNTitleIssueDatePriceMember
2039780143032311Wings of Fire2026-06-21299Ravi
2029789352920112Physics Part 12026-07-10180NULL
2019789352921485Informatics Practices2026-07-03210Asha
2079789386551023Learn SQL2026-08-12400Karan
Answer

(b) BookID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.52Practice1 mark

If BookID is the primary key of the table BOOK given below, which is its alternate key?

Table: BOOK

BookIDISBNTitleIssueDateMember
2059789352925032Chemistry Part 12026-07-15Neha
2029789352920112Physics Part 12026-07-10NULL
2079789386551023Learn SQL2026-08-12Karan
2039780143032311Wings of Fire2026-06-21Ravi
2069780140449136The Story of My Experiments2026-05-30NULL
2049789386551009Python Basics2026-08-01NULL
Answer

(c) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.53Practice1 mark

A table has 5 columns and 8 rows. Its degree and cardinality are

Answer

(a) 5 and 8 Degree = number of columns = 5; cardinality = number of rows = 8.

A4.54Practice1 mark

A table has 5 columns. A new column is added. The new degree is

Answer

(d) 6 Degree is the number of columns: 5 + 1 = 6.

A4.55Practice1 mark

If PCode is the primary key of the table PRODUCT given below, which is its alternate key?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0189010011NotebookStationeryClassmate2026-01-10605
P0789010077Lunch BoxHomeMilton2025-12-182758
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
Answer

(a) Barcode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.56Practice1 mark

Software used to create and manage a database is a

Answer

(d) DBMS A DBMS (Database Management System) is the software; MySQL is an example.

A4.57Practice1 mark

Which column of the table EMPLOYEE given below can be a candidate key?

Table: EMPLOYEE

EmpIDEmailDeptCityDOJBonus
E106wasim@co.inHRDelhi2022-07-252000
E102seema@co.inHRPune2020-01-15NULL
E103tarun@co.inITDelhi2016-09-205000
E105vikas@co.inITPune2019-11-054000
E104usha@co.inSalesMumbai2021-03-10NULL
Answer

(d) Email Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.58Practice1 mark

Which column of the table STUDENT given below can be a candidate key?

Table: STUDENT

RollNoAdmNoNameGenderMarks
54545EshanM88
74567GauravM59
44534DivyaF66
64556FarahF31
Answer

(b) RollNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.59Practice1 mark

What are the degree and cardinality of the table BOOK given below?

Table: BOOK

BookIDISBNSubjectPublisherPrice
2019789352921485ComputerNCERT210
2029789352920112ScienceNCERT180
2039780143032311BiographyUniversities299
2069780140449136BiographyPenguin250
2079789386551023ComputerBPB400
2049789386551009ComputerBPB350
2059789352925032ScienceNCERT190
Answer

(c) 5 and 7 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.60Practice1 mark

Which column of the table PATIENT given below can be a candidate key?

Table: PATIENT

PIDAadhaarPNameWardAdmitDateFeeInsurance
16623462346234RekhaMaternity2026-09-184500NULL
15523452345234QasimICU2026-09-159500NULL
12223422342234NishaICU2026-09-058000NULL
Answer

(c) PID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.61Practice1 mark

What are the degree and cardinality of the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptDOJSalaryBonus
E106wasim@co.inWasimHR2022-07-25390002000
E102seema@co.inSeemaHR2020-01-1558000NULL
E107yamini@co.inYaminiIT2017-12-1281000NULL
Answer

(c) 7 and 3 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.62Practice1 mark

If BookID is the primary key of the table BOOK given below, which is its alternate key?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDateMember
2049789386551009Python BasicsComputerBPB2026-08-01NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15Neha
2029789352920112Physics Part 1ScienceNCERT2026-07-10NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21Ravi
2079789386551023Learn SQLComputerBPB2026-08-12Karan
2019789352921485Informatics PracticesComputerNCERT2026-07-03Asha
Answer

(c) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.63Practice1 mark

If BookID is the primary key of the table BOOK given below, which is its alternate key?

Table: BOOK

BookIDISBNTitleIssueDateMember
2079789386551023Learn SQL2026-08-12Karan
2039780143032311Wings of Fire2026-06-21Ravi
2069780140449136The Story of My Experiments2026-05-30NULL
Answer

(c) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.64Practice1 mark

Which column of the table PATIENT given below can be a candidate key?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFee
17723472347234SahilGeneralDr. Rao2026-09-20900
15523452345234QasimICUDr. Sen2026-09-159500
16623462346234RekhaMaternityDr. Iyer2026-09-184500
11123412341234MohanGeneralDr. Rao2026-09-021500
12223422342234NishaICUDr. Sen2026-09-058000
14423442344234PoojaMaternityDr. Iyer2026-09-125000
13323432343234OmGeneralDr. Rao2026-09-101200
Answer

(c) PID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.65Practice1 mark

What are the degree and cardinality of the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
Answer

(c) 8 and 3 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.66Practice1 mark

Which column of the table PRODUCT given below can be a candidate key?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
Answer

(a) PCode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.67Practice1 mark

Which column of the table PATIENT given below can be a candidate key?

Table: PATIENT

PIDAadhaarDoctorFeeInsurance
16623462346234Dr. Iyer4500NULL
13323432343234Dr. Rao1200Star
15523452345234Dr. Sen9500NULL
17723472347234Dr. Rao900Star
12223422342234Dr. Sen8000NULL
11123412341234Dr. Rao1500LIC
Answer

(c) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.68Practice1 mark

An attribute (or set of attributes) that can uniquely identify each tuple is a

Answer

(c) candidate key Any column whose value is different in every row can be a candidate key.

A4.69Practice1 mark

If PCode is the primary key of the table PRODUCT given below, which is its alternate key?

Table: PRODUCT

PCodeBarcodePNameCategoryMfgDate
P0289010022Pen DriveElectronics2025-08-15
P0389010033Geometry BoxStationery2025-11-02
P0589010055Water BottleHome2025-05-30
P0489010044MouseElectronics2026-02-20
P0689010066EarphonesElectronics2026-03-05
P0189010011NotebookStationery2026-01-10
P0789010077Lunch BoxHome2025-12-18
Answer

(a) Barcode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.70Practice1 mark

If RollNo is the primary key of the table STUDENT given below, which is its alternate key?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
64556FarahAF2009-09-09319810066666
44534DivyaCF2009-07-21669810044444
34523ChiragAM2010-01-05459810033333
74567GauravCM2010-02-28599810077777
Answer

(a) AdmNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.71Practice1 mark

What are the degree and cardinality of the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameMfgDatePriceDiscount
P0189010011Notebook2026-01-10605
P0789010077Lunch Box2025-12-182758
P0489010044Mouse2026-02-2065015
P0389010033Geometry Box2025-11-0218010
P0689010066Earphones2026-03-0589920
Answer

(c) 6 and 5 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.72Practice1 mark

In a table EMP, every employee has a unique Email and a unique EmpID. These two columns are

Answer

(a) candidate keys Both columns are unique for every row, so both are candidate keys.

A4.73Practice1 mark

What are the degree and cardinality of the table STUDENT given below?

Table: STUDENT

RollNoAdmNoSectionDOBPhone
64556A2009-09-099810066666
24512B2009-11-30NULL
44534C2009-07-219810044444
54545B2010-03-17NULL
34523A2010-01-059810033333
74567C2010-02-289810077777
14501A2009-04-129810011111
Answer

(c) 5 and 7 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.74Practice1 mark

Which column of the table EMPLOYEE given below can be a candidate key?

Table: EMPLOYEE

EmpIDEmailENameSalaryBonus
E104usha@co.inUsha36000NULL
E102seema@co.inSeema58000NULL
E103tarun@co.inTarun750005000
E106wasim@co.inWasim390002000
E105vikas@co.inVikas640004000
E107yamini@co.inYamini81000NULL
E101ravi@co.inRavi420003000
Answer

(d) Email Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.75Practice1 mark

What are the degree and cardinality of the table PATIENT given below?

Table: PATIENT

PIDAadhaarWardFeeInsurance
11123412341234General1500LIC
17723472347234General900Star
15523452345234ICU9500NULL
Answer

(d) 5 and 3 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.76Practice1 mark

What are the degree and cardinality of the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
Answer

(c) 8 and 4 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.77Practice1 mark

If BookID is the primary key of the table BOOK given below, which is its alternate key?

Table: BOOK

BookIDISBNTitleIssueDatePriceMember
2029789352920112Physics Part 12026-07-10180NULL
2079789386551023Learn SQL2026-08-12400Karan
2049789386551009Python Basics2026-08-01350NULL
2039780143032311Wings of Fire2026-06-21299Ravi
2059789352925032Chemistry Part 12026-07-15190Neha
Answer

(c) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.78Practice1 mark

If EmpID is the primary key of the table EMPLOYEE given below, which is its alternate key?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E105vikas@co.inVikasITPune2019-11-05640004000
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E106wasim@co.inWasimHRDelhi2022-07-25390002000
Answer

(b) Email Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.79Practice1 mark

A primary key column

Answer

(b) cannot have NULL or repeated values A primary key must identify every row, so it cannot be empty (NULL) or repeated.

A4.80Practice1 mark

If BookID is the primary key of the table BOOK given below, which is its alternate key?

Table: BOOK

BookIDISBNSubjectIssueDateMember
2049789386551009Computer2026-08-01NULL
2039780143032311Biography2026-06-21Ravi
2079789386551023Computer2026-08-12Karan
2029789352920112Science2026-07-10NULL
2019789352921485Computer2026-07-03Asha
2059789352925032Science2026-07-15Neha
2069780140449136Biography2026-05-30NULL
Answer

(c) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.81Practice1 mark

Which column of the table PATIENT given below can be a candidate key?

Table: PATIENT

PIDAadhaarWardAdmitDateFee
15523452345234ICU2026-09-159500
11123412341234General2026-09-021500
17723472347234General2026-09-20900
Answer

(c) PID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.82Practice1 mark

What are the degree and cardinality of the table BOOK given below?

Table: BOOK

BookIDISBNPublisherIssueDateMember
2049789386551009BPB2026-08-01NULL
2059789352925032NCERT2026-07-15Neha
2029789352920112NCERT2026-07-10NULL
Answer

(c) 5 and 3 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.83Practice1 mark

What are the degree and cardinality of the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandPriceDiscount
P0589010055Water BottleHomeMilton320NULL
P0289010022Pen DriveElectronicsSanDisk450NULL
P0389010033Geometry BoxStationeryCamlin18010
P0189010011NotebookStationeryClassmate605
P0789010077Lunch BoxHomeMilton2758
P0489010044MouseElectronicsLogitech65015
P0689010066EarphonesElectronicsBoat89920
Answer

(c) 7 and 7 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.84Practice1 mark

What are the degree and cardinality of the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptDOJSalary
E104usha@co.inUshaSales2021-03-1036000
E101ravi@co.inRaviSales2018-06-0142000
E102seema@co.inSeemaHR2020-01-1558000
E103tarun@co.inTarunIT2016-09-2075000
E106wasim@co.inWasimHR2022-07-2539000
E107yamini@co.inYaminiIT2017-12-1281000
E105vikas@co.inVikasIT2019-11-0564000
Answer

(c) 6 and 7 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.85Practice1 mark

Which is NOT an advantage of a DBMS?

Answer

(d) More data redundancy A DBMS reduces redundancy; more redundancy is a problem, not an advantage.

A4.86Practice1 mark

The data stored in a database at a given moment is the

Answer

(d) instance (state) The instance is the actual data at a moment; it changes as rows are added or changed.

A4.87Practice1 mark

A table has 6 rows and 4 columns. Two rows are deleted. The new cardinality is

Answer

(b) 4 Cardinality is the number of rows: 6 - 2 = 4. The degree stays 4.

A4.88Practice1 mark

Which column of the table PRODUCT given below can be a candidate key?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandPriceDiscount
P0689010066EarphonesElectronicsBoat89920
P0189010011NotebookStationeryClassmate605
P0389010033Geometry BoxStationeryCamlin18010
P0589010055Water BottleHomeMilton320NULL
Answer

(a) Barcode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.89Practice1 mark

If PID is the primary key of the table PATIENT given below, which is its alternate key?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
15523452345234QasimICUDr. Sen2026-09-159500NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
17723472347234SahilGeneralDr. Rao2026-09-20900Star
Answer

(a) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.90Practice1 mark

What are the degree and cardinality of the table BOOK given below?

Table: BOOK

BookIDISBNSubjectPublisherIssueDatePriceMember
2029789352920112ScienceNCERT2026-07-10180NULL
2079789386551023ComputerBPB2026-08-12400Karan
2049789386551009ComputerBPB2026-08-01350NULL
2069780140449136BiographyPenguin2026-05-30250NULL
2039780143032311BiographyUniversities2026-06-21299Ravi
2019789352921485ComputerNCERT2026-07-03210Asha
Answer

(c) 7 and 6 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.91Practice1 mark

The candidate key chosen to identify the rows of a table is the

Answer

(c) primary key Out of the candidate keys, the one we choose is the primary key.

A4.92Practice1 mark

If RollNo is the primary key of the table STUDENT given below, which is its alternate key?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
64556FarahAF2009-09-09319810066666
34523ChiragAM2010-01-05459810033333
54545EshanBM2010-03-1788NULL
44534DivyaCF2009-07-21669810044444
74567GauravCM2010-02-28599810077777
Answer

(a) AdmNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.93Practice1 mark

What are the degree and cardinality of the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameBrandDiscount
P0589010055Water BottleMiltonNULL
P0689010066EarphonesBoat20
P0189010011NotebookClassmate5
P0289010022Pen DriveSanDiskNULL
P0489010044MouseLogitech15
P0789010077Lunch BoxMilton8
P0389010033Geometry BoxCamlin10
Answer

(c) 5 and 7 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.94Practice1 mark

Which column of the table PATIENT given below can be a candidate key?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
17723472347234SahilGeneralDr. Rao2026-09-20900Star
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
Answer

(c) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.95Practice1 mark

What are the degree and cardinality of the table BOOK given below?

Table: BOOK

BookIDISBNTitlePublisherIssueDate
2019789352921485Informatics PracticesNCERT2026-07-03
2069780140449136The Story of My ExperimentsPenguin2026-05-30
2079789386551023Learn SQLBPB2026-08-12
2049789386551009Python BasicsBPB2026-08-01
2059789352925032Chemistry Part 1NCERT2026-07-15
Answer

(c) 5 and 5 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.96Practice1 mark

In the relational model, a table is called a

Answer

(a) relation In the relational model a table is called a relation.

A4.97Practice1 mark

If RollNo is the primary key of the table STUDENT given below, which is its alternate key?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
34523ChiragAM2010-01-05459810033333
74567GauravCM2010-02-28599810077777
44534DivyaCF2009-07-21669810044444
14501AaravAM2009-04-12789810011111
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
Answer

(a) AdmNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.98Practice1 mark

Which column of the table EMPLOYEE given below can be a candidate key?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E105vikas@co.inVikasITPune2019-11-05640004000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
Answer

(d) Email Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.99Practice1 mark

Which column of the table STUDENT given below can be a candidate key?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
54545EshanBM2010-03-1788NULL
Answer

(b) AdmNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.100Practice1 mark

Which column of the table PRODUCT given below can be a candidate key?

Table: PRODUCT

PCodeBarcodePNameBrandMfgDatePriceDiscount
P0189010011NotebookClassmate2026-01-10605
P0689010066EarphonesBoat2026-03-0589920
P0389010033Geometry BoxCamlin2025-11-0218010
Answer

(a) PCode Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.101Practice1 mark

If PID is the primary key of the table PATIENT given below, which is its alternate key?

Table: PATIENT

PIDAadhaarWardDoctorInsurance
14423442344234MaternityDr. IyerLIC
13323432343234GeneralDr. RaoStar
15523452345234ICUDr. SenNULL
11123412341234GeneralDr. RaoLIC
17723472347234GeneralDr. RaoStar
12223422342234ICUDr. SenNULL
Answer

(a) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.102Practice1 mark

If PID is the primary key of the table PATIENT given below, which is its alternate key?

Table: PATIENT

PIDAadhaarWardDoctorAdmitDateFeeInsurance
13323432343234GeneralDr. Rao2026-09-101200Star
14423442344234MaternityDr. Iyer2026-09-125000LIC
12223422342234ICUDr. Sen2026-09-058000NULL
Answer

(a) Aadhaar Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.103Practice1 mark

A column of a relation is called an

Answer

(a) attribute Each column is an attribute, such as Name or Marks.

A4.104Practice1 mark

Which column of the table BOOK given below can be a candidate key?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
Answer

(b) BookID Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.105Practice1 mark

What are the degree and cardinality of the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderMarksPhone
14501AaravAM789810011111
44534DivyaCF669810044444
24512BhavyaBF92NULL
Answer

(c) 7 and 3 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.106Practice1 mark

Which column of the table BOOK given below can be a candidate key?

Table: BOOK

BookIDISBNTitlePublisherPrice
2049789386551009Python BasicsBPB350
2029789352920112Physics Part 1NCERT180
2079789386551023Learn SQLBPB400
2019789352921485Informatics PracticesNCERT210
2039780143032311Wings of FireUniversities299
2059789352925032Chemistry Part 1NCERT190
2069780140449136The Story of My ExperimentsPenguin250
Answer

(b) ISBN Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.107Practice1 mark

What are the degree and cardinality of the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalary
E106wasim@co.inWasimHRDelhi2022-07-2539000
E104usha@co.inUshaSalesMumbai2021-03-1036000
E103tarun@co.inTarunITDelhi2016-09-2075000
E101ravi@co.inRaviSalesDelhi2018-06-0142000
E102seema@co.inSeemaHRPune2020-01-1558000
Answer

(c) 7 and 5 Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A4.108Practice1 mark

If RollNo is the primary key of the table STUDENT given below, which is its alternate key?

Table: STUDENT

RollNoAdmNoNameGenderMarks
44534DivyaF66
24512BhavyaF92
64556FarahF31
74567GauravM59
34523ChiragM45
Answer

(a) AdmNo Degree = number of columns; cardinality = number of rows; a candidate key has a unique value in every row.

A5SQL1 mark · 137 questions
A5.1Practice1 mark

SQL stands for

Answer

(a) Structured Query Language SQL is Structured Query Language, used to work with relational databases.

A5.2Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT * FROM BOOK WHERE Subject = 'Computer';
Answer

(c) 3 Rows that satisfy the condition: 3.

A5.3Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT Title, Member FROM BOOK WHERE Member IS NOT NULL;
Answer

(c) 4 Rows that satisfy the condition: 4.

A5.4Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 70000;
Answer

(c) 3 Rows that satisfy the condition: 3.

A5.5Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName, Dept FROM EMPLOYEE WHERE NOT Dept = 'IT';
Answer

(c) 4 Rows that satisfy the condition: 4.

A5.6Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name, Marks FROM STUDENT WHERE Marks > 70;
Answer

(d) 3 Rows that satisfy the condition: 3.

A5.7Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name, Section FROM STUDENT WHERE NOT Section = 'A';
Answer

(c) 4 Rows that satisfy the condition: 4.

A5.8Practice1 mark

Which command adds a new column to an existing table?

Answer

(a) ALTER TABLE ... ADD ALTER TABLE STUDENT ADD Phone VARCHAR(10); adds a column.

A5.9Practice1 mark

Which of these is a DML command?

Answer

(c) UPDATE UPDATE changes the data in rows, so it is DML; CREATE, DROP, ALTER are DDL.

A5.10Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 100 AND 500;
Answer

(c) 4 Rows that satisfy the condition: 4.

A5.11Practice1 mark

Which constraint stops a column from having empty values?

Answer

(c) NOT NULL NOT NULL forces a value to be given in every row.

A5.12Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT * FROM STUDENT WHERE Section = 'B';
Answer

(d) 2 Rows that satisfy the condition: 2.

A5.13Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT BookID, Title, Price FROM BOOK WHERE Price BETWEEN 250 AND 300;
Answer

(b) 2 Rows that satisfy the condition: 2.

A5.14Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PID, PName, Fee FROM PATIENT WHERE Fee BETWEEN 1000 AND 1500;
Answer

(d) 2 Rows that satisfy the condition: 2.

A5.15Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 50000 AND 70000;
Answer

(a) 2 Rows that satisfy the condition: 2.

A5.16Practice1 mark

Which logical operator returns rows only when both conditions are true?

Answer

(a) AND AND needs both conditions to be true; OR needs at least one.

A5.17Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName FROM EMPLOYEE WHERE Dept = 'HR' AND Salary >= 40000;
Answer

(a) 1 Rows that satisfy the condition: 1.

A5.18Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT BookID, Title, Price FROM BOOK WHERE Price BETWEEN 200 AND 350;
Answer

(a) 4 Rows that satisfy the condition: 4.

A5.19Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName, Salary FROM EMPLOYEE WHERE Salary < 40000 OR Bonus IS NULL;
Answer

(c) 4 Rows that satisfy the condition: 4.

A5.20Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName FROM PATIENT WHERE Insurance IS NULL;
Answer

(a) 3 Rows that satisfy the condition: 3.

A5.21Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PName, Price FROM PRODUCT WHERE Price > 100;
Answer

(b) 6 Rows that satisfy the condition: 6.

A5.22Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT Title FROM BOOK WHERE Subject = 'Science' AND Price >= 200;
Answer

(d) 0 Rows that satisfy the condition: 0.

A5.23Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name FROM STUDENT WHERE Gender = 'F' AND Phone IS NOT NULL;
Answer

(c) 2 Rows that satisfy the condition: 2.

A5.24Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'IT' OR Dept = 'HR';
Answer

(b) 5 Rows that satisfy the condition: 5.

A5.25Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT Title FROM BOOK WHERE Subject = 'Biography' AND Price >= 250;
Answer

(b) 2 Rows that satisfy the condition: 2.

A5.26Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PName FROM PRODUCT WHERE Category = 'Home' AND Price >= 100;
Answer

(b) 2 Rows that satisfy the condition: 2.

A5.27Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName FROM EMPLOYEE WHERE Bonus IS NULL;
Answer

(d) 3 Rows that satisfy the condition: 3.

A5.28Practice1 mark

Which command lists all the tables of the current database?

Answer

(b) SHOW TABLES; SHOW TABLES; lists the tables of the database in use.

A5.29Practice1 mark

State True or False: SQL keywords are not case sensitive.

Answer

(a) True SELECT, select and Select all work the same.

A5.30Practice1 mark

State True or False: DELETE FROM T; removes the table T from the database.

Answer

(b) False It removes all rows; DROP TABLE removes the table.

A5.31Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName FROM PATIENT WHERE Ward = 'General' AND Fee >= 1000;
Answer

(d) 2 Rows that satisfy the condition: 2.

A5.32Practice1 mark

Which query shows the students with marks from 60 to 80?

Answer

(a) SELECT * FROM STUDENT WHERE Marks BETWEEN 60 AND 80; BETWEEN 60 AND 80 includes both ends, so this is the correct way.

A5.33Practice1 mark

Which command removes rows but keeps the structure of the table?

Answer

(d) DELETE DELETE FROM removes rows; the empty table remains.

A5.34Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 50 AND 60;
Answer

(a) 1 Rows that satisfy the condition: 1.

A5.35Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
Answer

(d) 5 Rows that satisfy the condition: 5.

A5.36Practice1 mark

Which command deletes a whole database?

Answer

(c) DROP DATABASE DROP DATABASE SCHOOL; removes the database with all its tables.

A5.37Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT Title, Price FROM BOOK WHERE Price > 350;
Answer

(b) 1 Rows that satisfy the condition: 1.

A5.38Practice1 mark

State True or False: BETWEEN 10 AND 20 includes 10 and 20.

Answer

(a) True BETWEEN includes both end values.

A5.39Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
Answer

(b) 3 Rows that satisfy the condition: 3.

A5.40Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
Answer

(c) 4 Rows that satisfy the condition: 4.

A5.41Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'NCERT';
Answer

(d) 4 Rows that satisfy the condition: 4.

A5.42Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT * FROM PRODUCT WHERE Category = 'Home';
Answer

(c) 2 Rows that satisfy the condition: 2.

A5.43Practice1 mark

Which data type stores a fixed-length string?

Answer

(c) CHAR CHAR(n) always uses n characters of space.

A5.44Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT * FROM STUDENT WHERE Section = 'A';
Answer

(b) 3 Rows that satisfy the condition: 3.

A5.45Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName FROM EMPLOYEE WHERE Dept = 'HR' AND Salary >= 50000;
Answer

(c) 1 Rows that satisfy the condition: 1.

A5.46Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName FROM EMPLOYEE WHERE City = 'Mumbai' AND Bonus IS NOT NULL;
Answer

(d) 0 Rows that satisfy the condition: 0.

A5.47Practice1 mark

Which keyword gives values in a range, both ends included?

Answer

(a) BETWEEN BETWEEN 60 AND 80 includes 60, 80 and every value in between.

A5.48Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT * FROM PATIENT WHERE Ward = 'General';
Answer

(c) 3 Rows that satisfy the condition: 3.

A5.49Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Stationery';
Answer

(c) 5 Rows that satisfy the condition: 5.

A5.50Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName FROM PATIENT WHERE Ward = 'ICU' AND Fee >= 1000;
Answer

(d) 2 Rows that satisfy the condition: 2.

A5.51Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName FROM PATIENT WHERE Ward = 'Maternity' AND Fee >= 1500;
Answer

(d) 2 Rows that satisfy the condition: 2.

A5.52Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 70000;
Answer

(b) 2 Rows that satisfy the condition: 2.

A5.53Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName, Fee FROM PATIENT WHERE Fee < 4000 OR Insurance IS NULL;
Answer

(d) 6 Rows that satisfy the condition: 6.

A5.54Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';
Answer

(a) 3 Rows that satisfy the condition: 3.

A5.55Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT Title, Price FROM BOOK WHERE Price < 250 OR Member IS NULL;
Answer

(b) 5 Rows that satisfy the condition: 5.

A5.56Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName, Dept FROM EMPLOYEE WHERE NOT Dept = 'Sales';
Answer

(b) 5 Rows that satisfy the condition: 5.

A5.57Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name FROM STUDENT WHERE Section = 'A' AND Marks >= 60;
Answer

(a) 1 Rows that satisfy the condition: 1.

A5.58Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PName FROM PRODUCT WHERE Discount IS NULL;
Answer

(c) 2 Rows that satisfy the condition: 2.

A5.59Practice1 mark

SELECT is a

Answer

(a) DQL command SELECT only reads (queries) the data, so it is DQL (Data Query Language).

A5.60Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
Answer

(d) 4 Rows that satisfy the condition: 4.

A5.61Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT Title, Subject FROM BOOK WHERE NOT Subject = 'Science';
Answer

(d) 5 Rows that satisfy the condition: 5.

A5.62Practice1 mark

Which command removes a table along with its structure?

Answer

(d) DROP TABLE DROP TABLE removes the table itself, with its structure and data.

A5.63Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName FROM EMPLOYEE WHERE Dept = 'IT' AND Salary >= 70000;
Answer

(a) 2 Rows that satisfy the condition: 2.

A5.64Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName FROM PATIENT WHERE Doctor = 'Dr. Sen' AND Insurance IS NOT NULL;
Answer

(d) 0 Rows that satisfy the condition: 0.

A5.65Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Electronics';
Answer

(c) 4 Rows that satisfy the condition: 4.

A5.66Practice1 mark

Every SQL statement in MySQL ends with a

Answer

(b) semicolon (;) The semicolon tells MySQL that the statement is complete.

A5.67Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT Title FROM BOOK WHERE Member IS NULL;
Answer

(c) 3 Rows that satisfy the condition: 3.

A5.68Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName FROM EMPLOYEE WHERE City = 'Pune' AND Bonus IS NOT NULL;
Answer

(c) 1 Rows that satisfy the condition: 1.

A5.69Practice1 mark

Which clause filters rows in a SELECT query?

Answer

(d) WHERE WHERE gives the condition; only rows that satisfy it are shown.

A5.70Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name, Gender FROM STUDENT WHERE Gender <> 'M';
Answer

(a) 3 Rows that satisfy the condition: 3.

A5.71Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Home';
Answer

(c) 5 Rows that satisfy the condition: 5.

A5.72Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PName, MfgDate FROM PRODUCT WHERE MfgDate BETWEEN '2025-10-01' AND '2026-01-31';
Answer

(c) 3 Rows that satisfy the condition: 3.

A5.73Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PName, Category FROM PRODUCT WHERE Category = 'Electronics' OR Category = 'Stationery';
Answer

(c) 5 Rows that satisfy the condition: 5.

A5.74Practice1 mark

Which data type is best for storing a phone number such as 9810011111?

Answer

(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.

A5.75Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName, Ward FROM PATIENT WHERE NOT Ward = 'Maternity';
Answer

(d) 5 Rows that satisfy the condition: 5.

A5.76Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'BPB';
Answer

(b) 5 Rows that satisfy the condition: 5.

A5.77Practice1 mark

The correct way to find rows where Phone has no value is

Answer

(a) WHERE Phone IS NULL NULL means unknown, so = NULL never matches; IS NULL is used.

A5.78Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName, Fee FROM PATIENT WHERE Fee < 1500 OR Insurance IS NULL;
Answer

(d) 5 Rows that satisfy the condition: 5.

A5.79Practice1 mark

Which constraint allows only different values in a column?

Answer

(d) UNIQUE UNIQUE does not allow the same value in two rows.

A5.80Practice1 mark

DELETE FROM STUDENT; without WHERE will

Answer

(d) delete all the rows but keep the table All rows are deleted but the table structure remains; DROP would remove the table.

A5.81Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName, Ward FROM PATIENT WHERE Ward = 'ICU' OR Ward = 'Maternity';
Answer

(c) 4 Rows that satisfy the condition: 4.

A5.82Practice1 mark

Which command removes the column Phone from STUDENT?

Answer

(a) ALTER TABLE STUDENT DROP Phone; Changing the structure needs ALTER; ALTER TABLE STUDENT DROP Phone; removes the column.

A5.83Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT Title FROM BOOK WHERE Publisher = 'Penguin' AND Member IS NOT NULL;
Answer

(c) 0 Rows that satisfy the condition: 0.

A5.84Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName, Doctor FROM PATIENT WHERE Doctor <> 'Dr. Sen';
Answer

(d) 5 Rows that satisfy the condition: 5.

A5.85Practice1 mark

In SQL, the 'not equal to' operator is

Answer

(b) <> (or !=) Both <> and != mean not equal to in MySQL.

A5.86Practice1 mark

Which command adds a primary key to an existing table T on column ID?

Answer

(b) ALTER TABLE T ADD PRIMARY KEY (ID); ALTER TABLE T ADD PRIMARY KEY (ID); sets ID as the primary key.

A5.87Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
Answer

(a) 5 Rows that satisfy the condition: 5.

A5.88Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT * FROM PRODUCT WHERE Category = 'Electronics';
Answer

(b) 3 Rows that satisfy the condition: 3.

A5.89Practice1 mark

Which SQL command creates a new table?

Answer

(d) CREATE TABLE CREATE TABLE name (columns ...); makes a new table.

A5.90Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name FROM STUDENT WHERE Gender = 'M' AND Phone IS NOT NULL;
Answer

(c) 3 Rows that satisfy the condition: 3.

A5.91Practice1 mark

Which is the correct way to write a date in a MySQL query?

Answer

(c) '2009-04-12' MySQL dates are written in quotes in the order year-month-day.

A5.92Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name, Section FROM STUDENT WHERE Section = 'C' OR Section = 'B';
Answer

(c) 4 Rows that satisfy the condition: 4.

A5.93Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 50 AND 70;
Answer

(b) 2 Rows that satisfy the condition: 2.

A5.94Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'Sales' OR Dept = 'IT';
Answer

(a) 5 Rows that satisfy the condition: 5.

A5.95Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName FROM PATIENT WHERE Doctor = 'Dr. Iyer' AND Insurance IS NOT NULL;
Answer

(b) 1 Rows that satisfy the condition: 1.

A5.96Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 60000;
Answer

(d) 2 Rows that satisfy the condition: 2.

A5.97Practice1 mark

Which command is used to select a database for use?

Answer

(b) USE USE SCHOOL; opens the database SCHOOL for the commands that follow.

A5.98Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName, Ward FROM PATIENT WHERE Ward = 'General' OR Ward = 'ICU';
Answer

(d) 5 Rows that satisfy the condition: 5.

A5.99Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT Title, Price FROM BOOK WHERE Price < 300 OR Member IS NULL;
Answer

(c) 6 Rows that satisfy the condition: 6.

A5.100Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName, Ward FROM PATIENT WHERE NOT Ward = 'ICU';
Answer

(c) 5 Rows that satisfy the condition: 5.

A5.101Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT Title FROM BOOK WHERE Publisher = 'NCERT' AND Member IS NOT NULL;
Answer

(a) 2 Rows that satisfy the condition: 2.

A5.102Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName, Bonus FROM EMPLOYEE WHERE Bonus IS NOT NULL;
Answer

(c) 4 Rows that satisfy the condition: 4.

A5.103Practice1 mark

Which operator would you use to find employees not in the Sales department?

Answer

(a) <> (or NOT ... =) WHERE Dept <> 'Sales' (or WHERE NOT Dept = 'Sales') gives all other departments.

A5.104Practice1 mark

Which command shows the structure of a table?

Answer

(c) DESCRIBE (DESC) DESCRIBE STUDENT; (or DESC STUDENT;) shows the columns, types, NULL and keys.

A5.105Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name FROM STUDENT WHERE Section = 'B' AND Marks >= 50;
Answer

(d) 2 Rows that satisfy the condition: 2.

A5.106Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 60000 AND 70000;
Answer

(d) 1 Rows that satisfy the condition: 1.

A5.107Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT Title FROM BOOK WHERE Subject = 'Computer' AND Price >= 350;
Answer

(c) 2 Rows that satisfy the condition: 2.

A5.108Practice1 mark

Which data type stores a variable-length string?

Answer

(b) VARCHAR VARCHAR(n) uses only as much space as the value needs, up to n.

A5.109Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName FROM EMPLOYEE WHERE City = 'Delhi' AND Bonus IS NOT NULL;
Answer

(d) 3 Rows that satisfy the condition: 3.

A5.110Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PName FROM PRODUCT WHERE Brand = 'Milton' AND Discount IS NOT NULL;
Answer

(d) 1 Rows that satisfy the condition: 1.

A5.111Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name, Section FROM STUDENT WHERE Section = 'B' OR Section = 'C';
Answer

(b) 4 Rows that satisfy the condition: 4.

A5.112Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Delhi';
Answer

(a) 4 Rows that satisfy the condition: 4.

A5.113Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name, Gender FROM STUDENT WHERE Gender <> 'F';
Answer

(d) 4 Rows that satisfy the condition: 4.

A5.114Practice1 mark

INSERT INTO STUDENT (RollNo, Name) VALUES (9, 'Isha'); stores what in the other columns?

Answer

(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).

A5.115Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name, Marks FROM STUDENT WHERE Marks < 70 OR Phone IS NULL;
Answer

(c) 6 Rows that satisfy the condition: 6.

A5.116Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT * FROM STUDENT WHERE Section = 'C';
Answer

(d) 2 Rows that satisfy the condition: 2.

A5.117Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PName, Brand FROM PRODUCT WHERE Brand <> 'Boat';
Answer

(d) 6 Rows that satisfy the condition: 6.

A5.118Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Pune';
Answer

(a) 5 Rows that satisfy the condition: 5.

A5.119Practice1 mark

In MySQL, a date is written in the format

Answer

(b) 'YYYY-MM-DD' Dates are written in quotes as 'YYYY-MM-DD', e.g. '2009-04-12'.

A5.120Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName FROM PATIENT WHERE Ward = 'General' AND Fee >= 6000;
Answer

(d) 0 Rows that satisfy the condition: 0.

A5.121Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name FROM STUDENT WHERE Phone IS NULL;
Answer

(c) 2 Rows that satisfy the condition: 2.

A5.122Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name FROM STUDENT WHERE Section = 'A' AND Marks >= 80;
Answer

(b) 0 Rows that satisfy the condition: 0.

A5.123Practice1 mark

How many rows will the query display for the table STUDENT given below?

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777
SELECT Name, Marks FROM STUDENT WHERE Marks > 60;
Answer

(b) 4 Rows that satisfy the condition: 4.

A5.124Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT BookID, Title, Price FROM BOOK WHERE Price BETWEEN 200 AND 300;
Answer

(b) 3 Rows that satisfy the condition: 3.

A5.125Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'Penguin';
Answer

(c) 6 Rows that satisfy the condition: 6.

A5.126Practice1 mark

How many rows will the query display for the table PATIENT given below?

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star
SELECT PName, Fee FROM PATIENT WHERE Fee < 1000 OR Insurance IS NULL;
Answer

(d) 4 Rows that satisfy the condition: 4.

A5.127Practice1 mark

UPDATE STUDENT SET Marks = 90; without WHERE will

Answer

(b) change the marks of every row to 90 Without WHERE the change applies to every row, so be careful.

A5.128Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PName, Price FROM PRODUCT WHERE Price < 300 OR Discount IS NULL;
Answer

(b) 5 Rows that satisfy the condition: 5.

A5.129Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PName, Price FROM PRODUCT WHERE Price > 500;
Answer

(a) 2 Rows that satisfy the condition: 2.

A5.130Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PName, Category FROM PRODUCT WHERE Category = 'Home' OR Category = 'Stationery';
Answer

(a) 4 Rows that satisfy the condition: 4.

A5.131Practice1 mark

Which command changes the values stored in a table?

Answer

(c) UPDATE ... SET UPDATE STUDENT SET Marks = 90 WHERE RollNo = 3; changes values.

A5.132Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT EName, City FROM EMPLOYEE WHERE City <> 'Mumbai';
Answer

(b) 5 Rows that satisfy the condition: 5.

A5.133Practice1 mark

Which of these is a DDL command?

Answer

(c) ALTER ALTER changes the structure of a table, so it is DDL; INSERT, UPDATE are DML; SELECT is DQL.

A5.134Practice1 mark

SELECT * FROM STUDENT; displays

Answer

(b) all the columns and rows of STUDENT * means all columns, and without WHERE all rows are shown.

A5.135Practice1 mark

How many rows will the query display for the table PRODUCT given below?

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758
SELECT PName FROM PRODUCT WHERE Brand = 'Boat' AND Discount IS NOT NULL;
Answer

(a) 1 Rows that satisfy the condition: 1.

A5.136Practice1 mark

How many rows will the query display for the table BOOK given below?

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan
SELECT Title, Subject FROM BOOK WHERE Subject = 'Computer' OR Subject = 'Biography';
Answer

(b) 5 Rows that satisfy the condition: 5.

A5.137Practice1 mark

How many rows will the query display for the table EMPLOYEE given below?

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL
SELECT * FROM EMPLOYEE WHERE Dept = 'IT';
Answer

(c) 3 Rows that satisfy the condition: 3.

A6Emerging trends1 mark · 63 questions
A6.1Practice1 mark

A device that detects changes such as temperature or motion is a

Answer

(a) sensor A sensor detects a physical change and turns it into a signal.

A6.2Practice1 mark

In cloud computing, the user pays

Answer

(a) only for the resources used (pay-as-you-go) Cloud services are pay-as-you-go: you pay for what you use.

A6.3Practice1 mark

Netflix suggesting shows based on what you watched is an example of

Answer

(a) machine learning (recommendation) The system learns your taste from your history: machine learning.

A6.4Practice1 mark

Which of these is NOT a characteristic (V) of Big Data?

Answer

(a) Visibility The Vs are Volume, Velocity, Variety, Veracity and Value; Visibility is not one of them.

A6.5Practice1 mark

A VR headset is used mainly for

Answer

(a) immersive experience It gives an immersive experience of a virtual world.

A6.6Practice1 mark

A digital twin, a smart meter and a fitness band are linked to

Answer

(b) IoT All of them are connected devices that collect and share data: IoT.

A6.7Practice1 mark

Translating a sentence from Hindi to English automatically is an example of

Answer

(c) NLP Translation of human language is a task of NLP.

A6.8Practice1 mark

State True or False: Grid computing uses the computers of many places for one task.

Answer

(a) True Grid computing uses unused power of many computers for one task.

A6.9Practice1 mark

Everyday devices connected to the Internet and sharing data form the

Answer

(c) Internet of Things (IoT) Smart devices with sensors that share data over the Internet form the IoT.

A6.10Practice1 mark

Making computers understand and speak human languages is

Answer

(d) Natural Language Processing (NLP) NLP (Natural Language Processing) deals with human language: speech and text.

A6.11Practice1 mark

A self-driving car mainly uses

Answer

(d) AI, sensors and computer vision Cameras and sensors see the road; AI decides how to drive.

A6.12Practice1 mark

In a blockchain, the records are kept

Answer

(d) on many computers (decentralised) Copies are kept on many computers (nodes), so there is no single owner.

A6.13Practice1 mark

State True or False: AR replaces the real world completely.

Answer

(b) False AR adds to the real world; VR replaces it.

A6.14Practice1 mark

Using computing resources such as storage and software over the Internet, on demand, is

Answer

(a) cloud computing Cloud computing gives these resources over the Internet, on demand, pay as you use.

A6.15Practice1 mark

Which technology keeps a record that is very hard to change once added?

Answer

(b) Blockchain Changing a block breaks the hash chain on many computers, so blockchain records are tamper-proof.

A6.16Practice1 mark

The 'Value' of Big Data means

Answer

(a) the useful insights that can be taken from it Value is the useful knowledge or benefit we get from the data.

A6.17Practice1 mark

The ability of a machine to think and learn like humans is

Answer

(c) Artificial Intelligence Artificial Intelligence lets machines learn, reason and take decisions like humans.

A6.18Practice1 mark

Very large data sets that are too big for normal tools are called

Answer

(c) Big Data Big Data is data too big, fast or varied for ordinary software.

A6.19Practice1 mark

State True or False: Gmail is an example of SaaS.

Answer

(a) True Gmail is ready software used over the Internet.

A6.20Practice1 mark

The large volume of data from sensors in a smart city is an example of

Answer

(b) Big Data Huge, fast data from many sensors is Big Data.

A6.21Practice1 mark

Adding digital information on top of the real world, as in Pokemon Go, is

Answer

(b) Augmented Reality (AR) AR adds digital images on the camera view of the real world.

A6.22Practice1 mark

Bitcoin is based on

Answer

(d) blockchain technology Bitcoin records every transaction in a blockchain.

A6.23Practice1 mark

State True or False: In IoT, devices can share data without human help.

Answer

(a) True IoT devices send data to each other and to the cloud automatically.

A6.24Practice1 mark

Which one is a concern with AI?

Answer

(c) Bias in decisions learned from biased data AI learns from data; if the data is biased, its decisions can be unfair.

A6.25Practice1 mark

Robots that move on their own and avoid obstacles mainly use

Answer

(d) sensors and AI Sensors detect obstacles and AI decides the path.

A6.26Practice1 mark

The 'V' of Big Data that refers to the speed at which data is produced is

Answer

(b) Velocity Velocity is the speed at which data is produced, such as posts every second.

A6.27Practice1 mark

A computer-made world that fully replaces what the user sees, using a headset, is

Answer

(d) Virtual Reality (VR) In VR the user wears a headset and sees only a computer-made world.

A6.28Practice1 mark

The 'V' of Big Data that refers to the trustworthiness of data is

Answer

(a) Veracity Veracity is about how accurate and trustworthy the data is.

A6.29Practice1 mark

Which emerging technology is used by maps apps to show live traffic?

Answer

(a) Big Data and IoT (data from phones and sensors) Location data from crores of phones (Big Data from IoT devices) shows live traffic.

A6.30Practice1 mark

Which technology lets a phone translate a menu by pointing the camera at it?

Answer

(c) AR with computer vision and NLP The camera view with translated text on top is AR; reading and translating the text needs NLP.

A6.31Practice1 mark

Which of these is an example of a smart city service?

Answer

(b) Traffic lights that change with the traffic Smart traffic lights use sensors and data to change with the traffic.

A6.32Practice1 mark

Which of these is an example of IaaS?

Answer

(a) Renting virtual servers from Amazon Web Services (EC2) Renting virtual servers is infrastructure; Gmail, Docs, YouTube are SaaS.

A6.33Practice1 mark

Training doctors with 3D virtual operations uses

Answer

(d) virtual reality Doctors practise in a fully virtual 3D world: virtual reality.

A6.34Practice1 mark

A part of AI in which machines learn from data without being programmed for every case is

Answer

(b) Machine Learning Machine Learning finds patterns in data and improves with experience.

A6.35Practice1 mark

Voice assistants like Alexa and Siri mainly use

Answer

(c) NLP They convert speech to text, understand it and reply in speech: that is NLP.

A6.36Practice1 mark

A public cloud is

Answer

(b) available to anyone over the Internet A public cloud is offered to anyone over the Internet, such as Google Drive.

A6.37Practice1 mark

Many computers in different places working together on one big task form a

Answer

(c) computing grid Grid computing joins many computers to work on one large task.

A6.38Practice1 mark

Which is an example of machine learning?

Answer

(c) A spam filter that learns from e-mails marked as spam The filter learns from examples of spam to catch new spam.

A6.39Practice1 mark

A smart home light that turns on when someone enters uses a

Answer

(b) motion sensor (IoT) A motion sensor detects the person and the connected bulb switches on: IoT.

A6.40Practice1 mark

Robots that work in car factories mostly do

Answer

(a) repetitive tasks like welding and painting Factory robots do repeated, exact jobs like welding and painting.

A6.41Practice1 mark

Each block of a blockchain is linked to the previous block by its

Answer

(b) hash Each block stores the hash of the previous block, forming a chain.

A6.42Practice1 mark

Which of these is NOT a cloud service model?

Answer

(a) GaaS (Grid as a Service) The three models are SaaS, PaaS and IaaS.

A6.43Practice1 mark

Online storage such as Google Drive and OneDrive is an example of

Answer

(b) cloud storage (SaaS) Storage used over the Internet is cloud storage, offered as SaaS.

A6.44Practice1 mark

Which cloud model needs the least technical work from the user?

Answer

(c) SaaS In SaaS the user only uses the app; the provider manages everything else.

A6.45Practice1 mark

The 'V' of Big Data that refers to its huge size is

Answer

(c) Volume Volume is the huge amount of data, in terabytes and more.

A6.46Practice1 mark

State True or False: Machine learning is a part of Artificial Intelligence.

Answer

(a) True ML is one branch of AI.

A6.47Practice1 mark

A temperature sensor in a cold storage that sends alerts to the owner's phone is

Answer

(b) an IoT application The sensor sends data over the Internet to the phone: an IoT application.

A6.48Practice1 mark

Chatbots on websites mostly use

Answer

(d) NLP and AI Chatbots understand typed questions and reply in language: NLP with AI.

A6.49Practice1 mark

Google Docs and Gmail are examples of

Answer

(d) SaaS (Software as a Service) They are ready software used through the browser: Software as a Service.

A6.50Practice1 mark

Smart watches that measure heart rate use

Answer

(c) sensors and IoT A heart-rate sensor measures and the watch shares data over the Internet: IoT.

A6.51Practice1 mark

A shared, decentralised ledger in which records are kept in linked blocks is

Answer

(c) Blockchain Blockchain keeps records in blocks linked by hashes on many computers.

A6.52Practice1 mark

A machine that can do tasks on its own using sensors and programming is a

Answer

(c) robot A robot senses with sensors, decides with a program and acts with motors.

A6.53Practice1 mark

Which is the correct pair?

Answer

(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.

A6.54Practice1 mark

The 'V' of Big Data that refers to different forms such as text, images and video is

Answer

(d) Variety Variety means many forms: text, images, video, sensor readings.

A6.55Practice1 mark

Which is a use of blockchain other than cryptocurrency?

Answer

(b) Keeping land records that cannot be changed secretly Blockchain records cannot be changed secretly, so they suit land records.

A6.56Practice1 mark

Which is an application of AI in daily life?

Answer

(d) Face unlock on a phone Face unlock recognises your face using AI; the others need no learning.

A6.57Practice1 mark

Renting virtual machines, storage and networks from the cloud is

Answer

(d) IaaS (Infrastructure as a Service) This is the basic infrastructure, so it is IaaS.

A6.58Practice1 mark

Which device is a common example of IoT?

Answer

(a) Smart watch A smart watch has sensors and shares data with the phone and the cloud.

A6.59Practice1 mark

Drones and Mars rovers are examples of

Answer

(c) robotics Both are robots that move and work on their own.

A6.60Practice1 mark

A cloud service that gives developers a ready platform to build and run apps is

Answer

(b) PaaS (Platform as a Service) PaaS gives a platform (OS, tools, database) to build and run apps.

A6.61Practice1 mark

A chatbot that answers questions about train timings uses

Answer

(c) NLP Understanding and answering typed questions is NLP.

A6.62Practice1 mark

A city that uses IoT and data to manage traffic, water and electricity is a

Answer

(c) smart city A smart city uses sensors and data to run traffic, water, power and waste services.

A6.63Practice1 mark

SETI@home, where home computers help analyse radio signals, is an example of

Answer

(b) grid computing Home computers shared their spare power for one big task: grid computing.

A7Assertion and Reason1 mark · 48 questions
A7.1Practice1 mark

Assertion (A): In Python, the expression 7 // 2 gives 3.

Reason (R): // is the floor division operator that gives the quotient rounded down.

Answer

(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.

A7.2Practice1 mark

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.

Answer

(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.

A7.3Practice1 mark

Assertion (A): A = 5 and a = 5 create two different variables.

Reason (R): Python is case sensitive.

Answer

(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).

A7.4Practice1 mark

Assertion (A): The expression 2 3 2 gives 512.

Reason (R): The ** operator is evaluated from right to left.

Answer

(a) Both A and R are true and R is the correct explanation of A. 3 2 = 9 first, then 2 9 = 512.

A7.5Practice1 mark

Assertion (A): A comment is executed by the Python interpreter.

Reason (R): A comment starts with the symbol #.

Answer

(d) A is false but R is true. Comments are ignored by the interpreter.

A7.6Practice1 mark

Assertion (A): A logical error is reported by the interpreter.

Reason (R): A logical error gives a wrong result without any error message.

Answer

(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 *.

A7.7Practice1 mark

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.

Answer

(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.

A7.8Practice1 mark

Assertion (A): The else block of a loop runs even after break.

Reason (R): break ends the loop at once.

Answer

(d) A is false but R is true. The loop else is skipped when break runs.

A7.9Practice1 mark

Assertion (A): A while loop is called an entry-controlled loop.

Reason (R): Its condition is checked before every round.

Answer

(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).

A7.10Practice1 mark

Assertion (A): Indentation is important in Python.

Reason (R): Python uses curly brackets to mark a block.

Answer

(c) A is true but R is false. Python uses indentation, not brackets.

A7.11Practice1 mark

Assertion (A): continue ends the loop at once.

Reason (R): continue skips the rest of the current round.

Answer

(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.

A7.12Practice1 mark

Assertion (A): Lists are mutable.

Reason (R): Elements of a list can be changed after the list is made.

Answer

(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.

A7.13Practice1 mark

Assertion (A): L.append([4, 5]) increases the length of L by 2.

Reason (R): append() adds its argument as one element.

Answer

(d) A is false but R is true. The length increases by 1; extend() would add 2.

A7.14Practice1 mark

Assertion (A): L.sort() returns the sorted list.

Reason (R): sort() arranges the list in place.

Answer

(d) A is false but R is true. sort() returns None.

A7.15Practice1 mark

Assertion (A): L.pop() removes the last element of L.

Reason (R): pop() without an index works on the last position.

Answer

(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).

A7.16Practice1 mark

Assertion (A): Two lists can be joined with +.

Reason (R): + is the concatenation operator for lists.

Answer

(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].

A7.17Practice1 mark

Assertion (A): A list can be a key of a dictionary.

Reason (R): Dictionary keys must be immutable.

Answer

(d) A is false but R is true. A list is mutable, so it cannot be a key.

A7.18Practice1 mark

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.

Answer

(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.

A7.19Practice1 mark

Assertion (A): A dictionary can have two pairs with the same key.

Reason (R): Values in a dictionary can be repeated.

Answer

(d) A is false but R is true. Keys are unique; values may repeat.

A7.20Practice1 mark

Assertion (A): L = [1, 2] * 2 gives [1, 2, 1, 2].

Reason (R): * repeats the list.

Answer

(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].

A7.21Practice1 mark

Assertion (A): for i in range(5): print(i) prints the numbers 1 to 5.

Reason (R): range(5) starts from 0.

Answer

(d) A is false but R is true. It prints 0 to 4.

A7.22Practice1 mark

Assertion (A): The expression 10 / 2 gives 5.

Reason (R): The / operator always gives a float.

Answer

(d) A is false but R is true. 10 / 2 gives 5.0.

A7.23Practice1 mark

Assertion (A): len({'a': 1, 'b': 2, 'a': 3}) is 2.

Reason (R): A repeated key keeps only its last value.

Answer

(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).

A7.24Practice1 mark

Assertion (A): max([3, 'a', 5]) gives an error.

Reason (R): Python cannot compare an int and a str with >.

Answer

(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).

A7.25Practice1 mark

Assertion (A): A primary key cannot have duplicate values.

Reason (R): A primary key uniquely identifies each row of a table.

Answer

(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).

A7.26Practice1 mark

Assertion (A): A table can have many alternate keys.

Reason (R): All candidate keys other than the primary key are alternate keys.

Answer

(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).

A7.27Practice1 mark

Assertion (A): DBMS reduces data redundancy.

Reason (R): In a DBMS, data is stored at one place and shared.

Answer

(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).

A7.28Practice1 mark

Assertion (A): The degree of a table changes when a new row is added.

Reason (R): Degree is the number of columns.

Answer

(d) A is false but R is true. Adding a row changes the cardinality, not the degree.

A7.29Practice1 mark

Assertion (A): Roll number can be a candidate key in a class.

Reason (R): Each student has a different roll number.

Answer

(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).

A7.30Practice1 mark

Assertion (A): Name is a good primary key for a table of students.

Reason (R): Two students may have the same name.

Answer

(d) A is false but R is true. Name can repeat, so it is not a good primary key.

A7.31Practice1 mark

Assertion (A): DROP TABLE removes the structure and the data of a table.

Reason (R): DROP is a DDL command.

Answer

(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.

A7.32Practice1 mark

Assertion (A): WHERE Fee = NULL finds the rows where Fee is empty.

Reason (R): NULL cannot be compared with =; IS NULL is used.

Answer

(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.

A7.33Practice1 mark

Assertion (A): UPDATE is a DML command.

Reason (R): UPDATE changes the data stored in a table.

Answer

(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).

A7.34Practice1 mark

Assertion (A): VARCHAR(20) saves space for short names.

Reason (R): VARCHAR stores only as many characters as are entered.

Answer

(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).

A7.35Practice1 mark

Assertion (A): BETWEEN 50 AND 60 includes 50 and 60.

Reason (R): BETWEEN includes both the end values.

Answer

(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.

A7.36Practice1 mark

Assertion (A): ALTER TABLE can add a new column.

Reason (R): ALTER is a DML command.

Answer

(c) A is true but R is false. ALTER is a DDL command.

A7.37Practice1 mark

Assertion (A): SELECT is used to change the data of a table.

Reason (R): SELECT is used to display data.

Answer

(d) A is false but R is true. A is false: UPDATE changes data. R is true: SELECT only displays data.

A7.38Practice1 mark

Assertion (A): A column declared NOT NULL must have a value in every row.

Reason (R): NOT NULL is a constraint.

Answer

(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.

A7.39Practice1 mark

Assertion (A): DELETE FROM STUDENT WHERE Marks < 33; removes some rows only.

Reason (R): The WHERE clause chooses the rows to delete.

Answer

(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).

A7.40Practice1 mark

Assertion (A): Text and date values are written in quotes in SQL.

Reason (R): Numbers must also be written in quotes.

Answer

(c) A is true but R is false. Numbers are written without quotes.

A7.41Practice1 mark

Assertion (A): SQL commands can be typed in small or capital letters.

Reason (R): SQL keywords are not case sensitive.

Answer

(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).

A7.42Practice1 mark

Assertion (A): INSERT INTO T VALUES (1, 'A'); adds a row.

Reason (R): INSERT is a DDL command.

Answer

(c) A is true but R is false. INSERT is a DML command.

A7.43Practice1 mark

Assertion (A): A database is better than many separate files.

Reason (R): A database controls redundancy and keeps data consistent.

Answer

(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).

A7.44Practice1 mark

Assertion (A): CHAR(10) always uses space for 10 characters.

Reason (R): CHAR is a fixed-length data type.

Answer

(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).

A7.45Practice1 mark

Assertion (A): Gmail is SaaS.

Reason (R): In SaaS, the user uses ready software over the Internet.

Answer

(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).

A7.46Practice1 mark

Assertion (A): AR and VR are the same.

Reason (R): AR adds to the real world, while VR replaces it.

Answer

(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.

A7.47Practice1 mark

Assertion (A): np.array([1, 2]) + np.array([3, 4]) gives [4 6].

Reason (R): NumPy adds arrays element by element.

Answer

(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).

A7.48Practice1 mark

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.

Answer

(d) A is false but R is true. NumPy converts them all to one type (here, strings).

Section B · 2 marks each

B1Computer system2 marks · 22 questions
B1.1Practice2 marks

Write any two differences between the first generation (vacuum tube) computers and today's computers.

Answer

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.

B1.2Practice2 marks

What is the stored program concept? Who gave it?

Answer

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.

B1.3Practice2 marks

Draw a block diagram of a computer and name its parts.

Answer

Block diagram of a computer

Central Processing Unit (CPU)Control Unit (CU)fetch · decode · executeALUarithmetic, logicRegistersfastestPrimary memoryRAM · ROM · cacheInput unitkeyboard, mouseOutput unitmonitor, printerSecondary storageHDD · SSD · pen driveData and instructions flow between the unitsdata / instructionscontrol signals from the CU
Block diagram of a computer. The CU controls every unit (dashed lines); data moves along the solid arrows.

Parts and their work

  1. Input unit – takes data and instructions from the user and converts them into a form the computer understands (binary). Examples: keyboard, mouse, scanner.
  2. Central Processing Unit (CPU) – the brain of the computer. It has three parts:
    • Control Unit (CU) – fetches each instruction from memory, decodes it and sends control signals to all parts (like a traffic police officer).
    • Arithmetic Logic Unit (ALU) – does calculations (+, -, *, /) and comparisons (>, <, ==).
    • Registers – very small, very fast memory inside the CPU that holds the data being worked on.
  3. Primary memory (RAM, ROM, cache) – holds the program and data that the CPU is using right now.
  4. Secondary storage – hard disk, SSD, pen drive; stores data permanently and loads it into RAM when needed.
  5. Output unit – converts the result into a form people understand. Examples: monitor, printer, speaker.

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.

B1.4Practice2 marks

Differentiate between the ALU and the Control Unit.

Answer

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.

B1.5Practice2 marks

What is a system bus? Name its three types.

Answer

A set of wires that carries data and signals between the CPU, memory and devices. Types: data bus, address bus and control bus.

B1.6Practice2 marks

Name two input and two output devices used in a bank.

Answer

Input: MICR (cheque reader), biometric scanner, keyboard, barcode reader. Output: printer (passbook printer), monitor, speaker. (Any two of each.)

B1.7Practice2 marks

Differentiate between OMR and OCR.

Answer

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.

B1.8Practice2 marks

What is a microprocessor? Give one example.

Answer

A CPU made on a single integrated circuit chip. Examples: Intel Core i5, AMD Ryzen, Intel 4004 (the first).

B1.9Practice2 marks

Differentiate between primary and secondary memory.

Answer

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.

Memory: primary and secondary

RegistersCacheRAM (main memory)SSD / Hard diskPen drive, DVD, cloudspeed
Higher in the pyramid: faster, smaller and costlier. Lower: slower, bigger and cheaper.
B1.10Practice2 marks

Differentiate between RAM and ROM.

Answer

RAM is volatile, read-write, holds running programs. ROM is non-volatile, mostly read-only, holds the boot (start-up) instructions.

B1.11Practice2 marks

What happens to a file when it is deleted? Can it be recovered?

Answer

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.

B1.12Practice2 marks

Why can data recovery be a security concern? How can it be avoided?

Answer

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.

B1.13Practice2 marks

Convert:

  1. 3 GB to MB
  2. 16384 bits to bytes.
Answer

(i) 3 x 1024 = 3072 MB. (ii) 16384 / 8 = 2048 bytes.

B1.14Practice2 marks

Arrange in increasing order of size: KB, TB, byte, GB, MB, PB.

Answer

byte < KB < MB < GB < TB < PB.

B1.15Practice2 marks

What is cache memory? Why is it used?

Answer

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.

B1.16Practice2 marks

Differentiate between system software and application software.

Answer

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).

B1.17Practice2 marks

Differentiate between general purpose and specific purpose software with an example each.

Answer

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.

B1.18Practice2 marks

Write any two functions of an operating system.

Answer

Process management, memory management, file management, device management, providing a user interface, security. (Any two.)

B1.19Practice2 marks

Differentiate between a compiler and an interpreter.

Answer

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.

How translators work

Source codehigh-level (Python)Translatorcompiler / interpreterMachine code0s and 1s
B1.20Practice2 marks

What is utility software? Give two examples.

Answer

Software that maintains and protects the computer. Examples: antivirus, disk cleanup, disk defragmenter, backup, file compression.

B1.21Practice2 marks

What is a device driver?

Answer

System software that lets the operating system talk to and control a hardware device, such as a printer or a webcam.

B1.22Practice2 marks

Differentiate between open source and proprietary software.

Answer

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).

B2Emerging trends2 marks · 20 questions
B2.1Practice2 marks

What is Artificial Intelligence? Give two examples from daily life.

Answer

The ability of a machine to think, learn and take decisions like humans. Examples: face unlock, voice assistants, map route suggestions, spam filters.

B2.2Practice2 marks

Differentiate between AI and Machine Learning.

Answer

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.

B2.3Practice2 marks

What is NLP? Give two applications.

Answer

Natural Language Processing lets computers understand, process and produce human language. Applications: chatbots, voice assistants, translation, spell check, speech-to-text.

B2.4Practice2 marks

Differentiate between AR and VR.

Answer

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).

B2.5Practice2 marks

What is robotics? Name two uses of robots.

Answer

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.

B2.6Practice2 marks

What is Big Data? Name any three of its characteristics.

Answer

Data sets so large and complex that ordinary tools cannot handle them. Characteristics: Volume, Velocity, Variety, Veracity, Value. (Any three.)

B2.7Practice2 marks

What is IoT? Give two examples.

Answer

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.

B2.8Practice2 marks

What is a smart city? Write two features.

Answer

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.

B2.9Practice2 marks

What is cloud computing? Write two advantages.

Answer

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.

B2.10Practice2 marks

Differentiate between SaaS and IaaS.

Answer

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.

Cloud service models

SaaSSoftware as a Serviceyou only use the app · e.g. Gmail, Google Docs, Zoom
PaaSPlatform as a Serviceyou build apps on a ready platform · e.g. Google App Engine, Heroku
IaaSInfrastructure as a Serviceyou rent servers, storage, network · e.g. Amazon EC2, Azure VMs

Going up the stack, the provider manages more and the user manages less.

B2.11Practice2 marks

What is PaaS? Give an example.

Answer

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.

B2.12Practice2 marks

What is grid computing? How is it different from cloud computing?

Answer

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.

B2.13Practice2 marks

What is blockchain? Write one use.

Answer

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.

Picture: blocks linked by hashes

Block 1A pays B 50Prev hash: 0000Hash: 8f3aBlock 2B pays C 20Prev hash: 8f3aHash: c71dBlock 3C pays D 5Prev hash: c71dHash: 19be
Each block stores the hash of the previous block. Changing one block breaks the chain, so tampering is easy to detect.
B2.14Practice2 marks

Why is data in a blockchain secure?

Answer

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.

Picture: blocks linked by hashes

Block 1A pays B 50Prev hash: 0000Hash: 8f3aBlock 2B pays C 20Prev hash: 8f3aHash: c71dBlock 3C pays D 5Prev hash: c71dHash: 19be
Each block stores the hash of the previous block. Changing one block breaks the chain, so tampering is easy to detect.
B2.15Practice2 marks

What are sensors? Name two types.

Answer

Devices that detect a change in the surroundings and convert it into a signal. Types: temperature, motion, light, humidity, gas, touch sensors.

B2.16Practice2 marks

Write two uses of AI in education.

Answer

Personalised learning apps that adjust to each student; automatic checking of objective tests; chatbots for doubt solving; speech-to-text for students with disabilities.

B2.17Practice2 marks

Write two concerns related to emerging technologies.

Answer

Loss of privacy, misuse of personal data, loss of some jobs due to automation, bias in AI decisions, cyber attacks on IoT devices.

B2.18Practice2 marks

Give one example each of AI, IoT and blockchain in banking.

Answer

AI: fraud detection and chatbots. IoT: smart ATMs and card readers. Blockchain: secure money transfer records.

B2.19Practice2 marks

What are the 5 Vs of Big Data? Explain any two.

Answer

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.

The 5 Vs of Big Data

Big
Data
Volumehuge amount
Velocityproduced very fast
Varietytext, images, video, sensor data
Veracitytrust and accuracy
Valueuseful insights
B2.20Practice2 marks

How does IoT help in agriculture?

Answer

Soil-moisture sensors tell when to water; weather data helps plan sowing; drones spray and watch crops; farmers get alerts on their phones.

B3Python: explain and differentiate2 marks · 43 questions
B3.1Practice2 marks

Write any two differences between a list and a dictionary.

Answer

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.

B3.2Practice2 marks

What is the difference between the append() and insert() methods of a list?

Answer

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.

B3.3Practice2 marks

What is meant by traversing a list? Write code to traverse L = [4, 7, 9].

Answer

Visiting every element of the list one by one. for x in L: print(x)

B3.4Practice2 marks

Write the use of len(), max(), min() and sum() with a list.

Answer

len(L) gives the number of elements; max(L) the largest; min(L) the smallest; sum(L) the total of numeric elements.

B3.5Practice2 marks

What are the list operations? Explain concatenation and repetition.

Answer

Concatenation (+), repetition (*), membership (in), slicing ([a:b]). [1, 2] + [3] gives [1, 2, 3]; [0] * 3 gives [0, 0, 0].

B3.6Practice2 marks

Differentiate between the pop() and remove() methods.

Answer

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.

B3.7Practice2 marks

Differentiate between L.sort() and sorted(L).

Answer

L.sort() sorts the list in place and returns None. sorted(L) gives a new sorted list and leaves L unchanged.

B3.8Practice2 marks

What is a nested list? How do you access 6 in L = [[1, 2], [5, 6]]?

Answer

A list inside another list. L[1][1] gives 6.

B3.9Practice2 marks

How is a dictionary created? Give two ways.

Answer

D = {'a': 1, 'b': 2} (with braces) or D = dict(a=1, b=2) / D = dict([('a', 1), ('b', 2)]).

B3.10Practice2 marks

Write the use of keys(), values() and items().

Answer

keys() gives all the keys, values() all the values, and items() all the (key, value) pairs of a dictionary.

B3.11Practice2 marks

How do you add, update and delete an element in a dictionary? Give code.

Answer

D['c'] = 3 adds a new pair; D['a'] = 10 updates; del D['b'] deletes the key 'b'.

B3.12Practice2 marks

Differentiate between D['x'] and D.get('x').

Answer

D['x'] gives KeyError if 'x' is not a key. D.get('x') returns None (or a default value) without an error.

B3.13Practice2 marks

Differentiate between del D['k'] and D.clear().

Answer

del D['k'] deletes only the key 'k' and its value. D.clear() removes all the pairs; the empty dictionary remains.

B3.14Practice2 marks

Why are dictionaries called mutable? Can keys be changed?

Answer

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.

B3.15Practice2 marks

What is NumPy? Why are NumPy arrays faster than lists?

Answer

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.

B3.16Practice2 marks

Differentiate between a Python list and a NumPy array.

Answer

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.

B3.17Practice2 marks

Write the use of ndim, shape and size of a NumPy array.

Answer

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.

B3.18Practice2 marks

Write code to create a 1-D and a 2-D NumPy array from lists.

Answer

import numpy as np a = np.array([1, 2, 3]) b = np.array([[1, 2], [3, 4]])

B3.19Practice2 marks

What are the features of Python? Write any four.

Answer

Easy to learn and read, free and open source, interpreted, high level, platform independent, case sensitive, has a large library. (Any four.)

B3.20Practice2 marks

What is the difference between a statement and an expression?

Answer

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).

B3.21Practice2 marks

What are l-value and r-value? Give an example.

Answer

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).

B3.22Practice2 marks

What is debugging? Name two ways to debug a program.

Answer

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.

B3.23Practice2 marks

Differentiate between interactive mode and script mode of Python.

Answer

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.

B3.24Practice2 marks

Differentiate between = and == in Python.

Answer

= 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.

B3.25Practice2 marks

Differentiate between / and // with examples.

Answer

/ 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.

B3.26Practice2 marks

What is type conversion? Explain its two kinds with an example each.

Answer

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.

B3.27Practice2 marks

Name the three types of errors with one example each.

Answer

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.

B3.28Practice2 marks

Explain the use of id() and type() functions with an example.

Answer

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'>.

B3.29Practice2 marks

What is the difference between the is and == operators?

Answer

== 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.

B3.30Practice2 marks

Write the precedence of these operators from highest to lowest: +, **, not, *, and, <

Answer

** , then * , then + , then < , then not , then and.

B3.31Practice2 marks

Differentiate between break and continue.

Answer

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.

B3.32Practice2 marks

Differentiate between a for loop and a while loop.

Answer

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.

B3.33Practice2 marks

What is an infinite loop? Give an example.

Answer

A loop whose condition never becomes False, so it never ends. Example: i = 1; while i > 0: i = i + 1

B3.34Practice2 marks

Explain range() with its three parameters, using an example.

Answer

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.

B3.35Practice2 marks

What is the use of the else clause with a loop?

Answer

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.

B3.36Practice2 marks

Rewrite using a while loop:

for i in range(10, 0, -2):
    print(i)
Answer
i = 10
while i > 0:
    print(i)
    i = i - 2
B3.37Practice2 marks

Rewrite using a for loop:

n = 1
while n <= 15:
    print(n * n)
    n += 3
Answer
for n in range(1, 16, 3):
    print(n * n)
B3.38Practice2 marks

Differentiate between append() and extend().

Answer

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).

B3.39Practice2 marks

Differentiate between remove() and pop().

Answer

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.

B3.40Practice2 marks

Differentiate between sort() and sorted().

Answer

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.

B3.41Practice2 marks

What is a nested list? How is an element of it accessed?

Answer

A list inside another list. L = [[1, 2], [3, 4]]: L[1][0] gives 3 (row 1, item 0).

B3.42Practice2 marks

Differentiate between pop() and popitem() of a dictionary.

Answer

pop(key) removes the given key and returns its value. popitem() removes and returns the last inserted (key, value) pair.

B3.43Practice2 marks

Explain keys(), values() and items() with an example.

Answer

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)]).

B4Python: output and error correction2 marks · 144 questions
B4.1Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

L = [10, 20, 30]
L.add(40)
print(L[4])
Answer
L = [10, 20, 30]
L.append(40)
print(L[3])

Lists have append(), not add(); after adding, the last index is 3.

B4.2Practice2 marks

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)
Answer

Output:

a d 31

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'a': 13, 'c': 2, 'e': 11, 'd': 18}D = {'a': 13, 'c': 2, 'e': 11, 'd': 18}
2total = 0total = 0
3for k in D:k = 'a'
4if D[k] > 12:condition is True
5total += D[k]total = 13
6print(k, end=" ")a
3for k in D:k = 'c'
4if D[k] > 12:condition is False
3for k in D:k = 'e'
4if D[k] > 12:condition is False
3for k in D:k = 'd'
4if D[k] > 12:condition is True
5total += D[k]total = 31
6print(k, end=" ")d
3for k in D:loop ends (no more values)
7print(total)31⏎
B4.3Practice2 marks

Write the output of the following code.

x, y = 7, 11
while x < y:
    x = x * 2
    y = y - 1
print(x, y)
Answer

Output:

14 10

Working (step by step)

LineStatementValues after this stepPrinted
1x, y = 7, 11x = 7, y = 11
2while x < y:condition is True
3x = x * 2x = 14
4y = y - 1y = 10
2while x < y:condition is False
5print(x, y)14 10⏎
B4.4Practice2 marks

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)
Answer

Output:

10

Working (step by step)

LineStatementValues after this stepPrinted
1n = 55825n = 55825
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 5
5if d % 2 == 0:condition is False
7n = n // 10n = 5582
3while n > 0:condition is True
4d = n % 10d = 2
5if d % 2 == 0:condition is True
6s = s + ds = 2
7n = n // 10n = 558
3while n > 0:condition is True
4d = n % 10d = 8
5if d % 2 == 0:condition is True
6s = s + ds = 10
7n = n // 10n = 55

… the same steps continue for the remaining values.

B4.5Practice2 marks

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)
Answer

Output:

a c 30

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'b': 4, 'a': 18, 'e': 3, 'c': 12}D = {'b': 4, 'a': 18, 'e': 3, 'c': 12}
2total = 0total = 0
3for k in D:k = 'b'
4if D[k] > 4:condition is False
3for k in D:k = 'a'
4if D[k] > 4:condition is True
5total += D[k]total = 18
6print(k, end=" ")a
3for k in D:k = 'e'
4if D[k] > 4:condition is False
3for k in D:k = 'c'
4if D[k] > 4:condition is True
5total += D[k]total = 30
6print(k, end=" ")c
3for k in D:loop ends (no more values)
7print(total)30⏎
B4.6Practice2 marks

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)
Answer

Output:

97154

Working (step by step)

LineStatementValues after this stepPrinted
1n = 45179n = 45179
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 9
5s = s * 10 + ds = 9
6n = n // 10n = 4517
3while n > 0:condition is True
4d = n % 10d = 7
5s = s * 10 + ds = 97
6n = n // 10n = 451
3while n > 0:condition is True
4d = n % 10d = 1
5s = s * 10 + ds = 971
6n = n // 10n = 45
3while n > 0:condition is True
4d = n % 10d = 5

… the same steps continue for the remaining values.

B4.7Practice2 marks

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)
Answer

Output:

8

Working (step by step)

LineStatementValues after this stepPrinted
1a = 3a = 3
2b = 11b = 11
3if a % 2 == 0 and b % 2 == 0:condition is False
5elif a % 2 == 0 or b > 20:condition is False
8print(b - a)8⏎
B4.8Practice2 marks

Write the output of the following code.

for i in range(1, 4):
    for j in range(i):
        print(i, end="")
    print()
Answer

Output:

1
22
333

Working (step by step)

LineStatementValues after this stepPrinted
1for i in range(1, 4):i = 1
2for j in range(i):j = 0
3print(i, end="")1
2for j in range(i):loop ends (no more values)
4print()⏎
1for i in range(1, 4):i = 2
2for j in range(i):loop ends (no more values)
3print(i, end="")2
2for j in range(i):j = 1
3print(i, end="")2
2for j in range(i):loop ends (no more values)
4print()⏎
1for i in range(1, 4):i = 3
2for j in range(i):j = 0
3print(i, end="")3
2for j in range(i):j = 1

… the same steps continue for the remaining values.

B4.9Practice2 marks

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)
Answer

Output:

{2: 2, 1: 1, 7: 1, 4: 1, 6: 1}

Working (step by step)

LineStatementValues after this stepPrinted
1L = [2, 1, 7, 4, 6, 2]L = [2, 1, 7, 4, 6, 2]
2F = {}F = {}
3for x in L:x = 2
4F[x] = F.get(x, 0) + 1F = {2: 1}
3for x in L:x = 1
4F[x] = F.get(x, 0) + 1F = {2: 1, 1: 1}
3for x in L:x = 7
4F[x] = F.get(x, 0) + 1F = {2: 1, 1: 1, 7: 1}
3for x in L:x = 4
4F[x] = F.get(x, 0) + 1F = {2: 1, 1: 1, 7: 1, 4: 1}
3for x in L:x = 6
4F[x] = F.get(x, 0) + 1F = {2: 1, 1: 1, 7: 1, 4: 1, 6: 1}
3for x in L:x = 2
4F[x] = F.get(x, 0) + 1F = {2: 2, 1: 1, 7: 1, 4: 1, 6: 1}
3for x in L:loop ends (no more values)
5print(F){2: 2, 1: 1, 7: 1, 4: 1, 6: 1}⏎
B4.10Practice2 marks

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)
Answer

Output:

92671

Working (step by step)

LineStatementValues after this stepPrinted
1n = 17629n = 17629
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 9
5s = s * 10 + ds = 9
6n = n // 10n = 1762
3while n > 0:condition is True
4d = n % 10d = 2
5s = s * 10 + ds = 92
6n = n // 10n = 176
3while n > 0:condition is True
4d = n % 10d = 6
5s = s * 10 + ds = 926
6n = n // 10n = 17
3while n > 0:condition is True
4d = n % 10d = 7

… the same steps continue for the remaining values.

B4.11Practice2 marks

Write the output of the following code.

x, y = 9, 13
while x < y:
    x = x * 2
    y = y - 1
print(x, y)
Answer

Output:

18 12

Working (step by step)

LineStatementValues after this stepPrinted
1x, y = 9, 13x = 9, y = 13
2while x < y:condition is True
3x = x * 2x = 18
4y = y - 1y = 12
2while x < y:condition is False
5print(x, y)18 12⏎
B4.12Practice2 marks

Write the output of the following code.

x, y = 9, 25
while x < y:
    x = x * 2
    y = y - 1
print(x, y)
Answer

Output:

36 23

Working (step by step)

LineStatementValues after this stepPrinted
1x, y = 9, 25x = 9, y = 25
2while x < y:condition is True
3x = x * 2x = 18
4y = y - 1y = 24
2while x < y:condition is True
3x = x * 2x = 36
4y = y - 1y = 23
2while x < y:condition is False
5print(x, y)36 23⏎
B4.13Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

L = [5, 3, 8]
L = L.sort()
print(L[0])
Answer
L = [5, 3, 8]
L.sort()
print(L[0])

sort() returns None; it sorts L in place, so do not assign its result.

B4.14Practice2 marks

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)
Answer

Output:

19472

Working (step by step)

LineStatementValues after this stepPrinted
1n = 27491n = 27491
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 1
5s = s * 10 + ds = 1
6n = n // 10n = 2749
3while n > 0:condition is True
4d = n % 10d = 9
5s = s * 10 + ds = 19
6n = n // 10n = 274
3while n > 0:condition is True
4d = n % 10d = 4
5s = s * 10 + ds = 194
6n = n // 10n = 27
3while n > 0:condition is True
4d = n % 10d = 7

… the same steps continue for the remaining values.

B4.15Practice2 marks

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)
Answer

Output:

[34, 52, 12, 40, 46, 56]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [17, 26, 24, 20, 23, 28]L = [17, 26, 24, 20, 23, 28]
2for i in range(len(L)):i = 0
3if L[i] % 3 == 0:condition is False
6L[i] = L[i] * 2L = [34, 26, 24, 20, 23, 28]
2for i in range(len(L)):i = 1
3if L[i] % 3 == 0:condition is False
6L[i] = L[i] * 2L = [34, 52, 24, 20, 23, 28]
2for i in range(len(L)):i = 2
3if L[i] % 3 == 0:condition is True
4L[i] = L[i] // 2L = [34, 52, 12, 20, 23, 28]
2for i in range(len(L)):i = 3
3if L[i] % 3 == 0:condition is False
6L[i] = L[i] * 2L = [34, 52, 12, 40, 23, 28]
2for i in range(len(L)):i = 4
3if L[i] % 3 == 0:condition is False
6L[i] = L[i] * 2L = [34, 52, 12, 40, 46, 28]

… the same steps continue for the remaining values.

B4.16Practice2 marks

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()
Answer

Output:

1 
2 4 
3 6 9 
4 8 12 16 

Working (step by step)

LineStatementValues after this stepPrinted
1for i in range(1, 5):i = 1
2for j in range(1, i + 1):j = 1
3print(j * i, end=" ")1
2for j in range(1, i + 1):loop ends (no more values)
4print()⏎
1for i in range(1, 5):i = 2
2for j in range(1, i + 1):loop ends (no more values)
3print(j * i, end=" ")2
2for j in range(1, i + 1):j = 2
3print(j * i, end=" ")4
2for j in range(1, i + 1):loop ends (no more values)
4print()⏎
1for i in range(1, 5):i = 3
2for j in range(1, i + 1):j = 1
3print(j * i, end=" ")3
2for j in range(1, i + 1):j = 2

… the same steps continue for the remaining values.

B4.17Practice2 marks

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)
Answer

Output:

{6: 2, 4: 1, 3: 1, 7: 1, 8: 1}

Working (step by step)

LineStatementValues after this stepPrinted
1L = [6, 6, 4, 3, 7, 8]L = [6, 6, 4, 3, 7, 8]
2F = {}F = {}
3for x in L:x = 6
4F[x] = F.get(x, 0) + 1F = {6: 1}
3for x in L:loop ends (no more values)
4F[x] = F.get(x, 0) + 1F = {6: 2}
3for x in L:x = 4
4F[x] = F.get(x, 0) + 1F = {6: 2, 4: 1}
3for x in L:x = 3
4F[x] = F.get(x, 0) + 1F = {6: 2, 4: 1, 3: 1}
3for x in L:x = 7
4F[x] = F.get(x, 0) + 1F = {6: 2, 4: 1, 3: 1, 7: 1}
3for x in L:x = 8
4F[x] = F.get(x, 0) + 1F = {6: 2, 4: 1, 3: 1, 7: 1, 8: 1}
3for x in L:loop ends (no more values)
5print(F){6: 2, 4: 1, 3: 1, 7: 1, 8: 1}⏎
B4.18Practice2 marks

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)
Answer

Output:

[ 7 12  2  3 16]
[False  True False False  True]

Working (step by step)

LineStatementValues after this stepPrinted
2a = np.array([14, 24, 5, 7, 33])a = array([14, 24, 5, 7, 33])
3b = a // 2b = array([ 7, 12, 2, 3, 16])
4print(b)[ 7 12 2 3 16]⏎
5print(a > 15)[False True False False True]⏎
B4.19Practice2 marks

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)
Answer

Output:

c b e 42

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'c': 16, 'b': 12, 'e': 14, 'd': 2}D = {'c': 16, 'b': 12, 'e': 14, 'd': 2}
2total = 0total = 0
3for k in D:k = 'c'
4if D[k] > 8:condition is True
5total += D[k]total = 16
6print(k, end=" ")c
3for k in D:k = 'b'
4if D[k] > 8:condition is True
5total += D[k]total = 28
6print(k, end=" ")b
3for k in D:k = 'e'
4if D[k] > 8:condition is True
5total += D[k]total = 42
6print(k, end=" ")e
3for k in D:k = 'd'
4if D[k] > 8:condition is False
3for k in D:loop ends (no more values)
7print(total)42⏎
B4.20Practice2 marks

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)
Answer

Output:

(2, 3)
[ 4  6 16]
[[ 90  60 150]
 [ 40  60 160]]

Working (step by step)

LineStatementValues after this stepPrinted
2L = [[9, 6, 15], [4, 6, 16]]L = [[9, 6, 15], [4, 6, 16]]
3a = np.array(L)a = array([[ 9, 6, 15], [ 4, 6, 16]])
4print(a.shape)(2, 3)⏎
5print(a[1])[ 4 6 16]⏎
6print(a * 10)[[ 90 60 150]⏎ [ 40 60 160]]⏎
B4.21Practice2 marks

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)
Answer

Output:

[42, 14, 5, 6, 4, 6]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [21, 7, 16, 20, 14, 18]L = [21, 7, 16, 20, 14, 18]
2for i in range(len(L)):i = 0
3if L[i] % 2 == 0:condition is False
6L[i] = L[i] * 2L = [42, 7, 16, 20, 14, 18]
2for i in range(len(L)):i = 1
3if L[i] % 2 == 0:condition is False
6L[i] = L[i] * 2L = [42, 14, 16, 20, 14, 18]
2for i in range(len(L)):i = 2
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 3L = [42, 14, 5, 20, 14, 18]
2for i in range(len(L)):i = 3
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 3L = [42, 14, 5, 6, 14, 18]
2for i in range(len(L)):i = 4
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 3L = [42, 14, 5, 6, 4, 18]

… the same steps continue for the remaining values.

B4.22Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

for i in range(5):
    if i == 3:
        Break
    print(i)
else
    print('done')
Answer
for i in range(5):
    if i == 3:
        break
    print(i)
else:
    print('done')

break is in small letters; colon after else.

B4.23Practice2 marks

Write the output of the following code.

x, y = 2, 20
while x < y:
    x = x * 2
    y = y - 1
print(x, y)
Answer

Output:

32 16

Working (step by step)

LineStatementValues after this stepPrinted
1x, y = 2, 20x = 2, y = 20
2while x < y:condition is True
3x = x * 2x = 4
4y = y - 1y = 19
2while x < y:condition is True
3x = x * 2x = 8
4y = y - 1y = 18
2while x < y:condition is True
3x = x * 2x = 16
4y = y - 1y = 17
2while x < y:condition is True
3x = x * 2x = 32
4y = y - 1y = 16
2while x < y:condition is False
5print(x, y)32 16⏎
B4.24Practice2 marks

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)
Answer

Output:

[42 34 26 33  9]
5 1

Working (step by step)

LineStatementValues after this stepPrinted
2marks = [37, 29, 21, 28, 4]marks = [37, 29, 21, 28, 4]
3a = np.array(marks)a = array([37, 29, 21, 28, 4])
4print(a + 5)[42 34 26 33 9]⏎
5print(a.size, a.ndim)5 1⏎
B4.25Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

a = 10
b = '20'
c = a + b
print 'Sum =', c
Answer
a = 10
b = '20'
c = a + int(b)
print('Sum =', c)

Convert b to int before adding; print is a function and needs brackets.

B4.26Practice2 marks

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)
Answer

Output:

[52, 7, 44, 36, 48, 24]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [26, 15, 22, 18, 24, 12]L = [26, 15, 22, 18, 24, 12]
2for i in range(len(L)):i = 0
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [52, 15, 22, 18, 24, 12]
2for i in range(len(L)):i = 1
3if L[i] % 5 == 0:condition is True
4L[i] = L[i] // 2L = [52, 7, 22, 18, 24, 12]
2for i in range(len(L)):i = 2
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [52, 7, 44, 18, 24, 12]
2for i in range(len(L)):i = 3
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [52, 7, 44, 36, 24, 12]
2for i in range(len(L)):i = 4
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [52, 7, 44, 36, 48, 12]

… the same steps continue for the remaining values.

B4.27Practice2 marks

Write the output of the following code.

x, y = 6, 18
while x < y:
    x = x * 2
    y = y - 1
print(x, y)
Answer

Output:

24 16

Working (step by step)

LineStatementValues after this stepPrinted
1x, y = 6, 18x = 6, y = 18
2while x < y:condition is True
3x = x * 2x = 12
4y = y - 1y = 17
2while x < y:condition is True
3x = x * 2x = 24
4y = y - 1y = 16
2while x < y:condition is False
5print(x, y)24 16⏎
B4.28Practice2 marks

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)
Answer

Output:

1

Working (step by step)

LineStatementValues after this stepPrinted
1a = 9a = 9
2b = 10b = 10
3if a % 2 == 0 and b % 2 == 0:condition is False
5elif a % 2 == 0 or b > 20:condition is False
8print(b - a)1⏎
B4.29Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

n = 5
while n > 0
print(n)
n = n - 1
Answer
n = 5
while n > 0:
    print(n)
    n = n - 1

Colon after while; the body must be indented.

B4.30Practice2 marks

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)
Answer

Output:

b e a d 59

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'b': 10, 'e': 18, 'a': 19, 'd': 12}D = {'b': 10, 'e': 18, 'a': 19, 'd': 12}
2total = 0total = 0
3for k in D:k = 'b'
4if D[k] > 7:condition is True
5total += D[k]total = 10
6print(k, end=" ")b
3for k in D:k = 'e'
4if D[k] > 7:condition is True
5total += D[k]total = 28
6print(k, end=" ")e
3for k in D:k = 'a'
4if D[k] > 7:condition is True
5total += D[k]total = 47
6print(k, end=" ")a
3for k in D:k = 'd'
4if D[k] > 7:condition is True

… the same steps continue for the remaining values.

B4.31Practice2 marks

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)
Answer
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().

B4.32Practice2 marks

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)
Answer

Output:

[ 5 12 10 19  1]
[False  True False  True False]

Working (step by step)

LineStatementValues after this stepPrinted
2a = np.array([10, 25, 21, 38, 2])a = array([10, 25, 21, 38, 2])
3b = a // 2b = array([ 5, 12, 10, 19, 1])
4print(b)[ 5 12 10 19 1]⏎
5print(a > 24)[False True False True False]⏎
B4.33Practice2 marks

Write the output of the following code.

x, y = 6, 13
while x < y:
    x = x * 2
    y = y - 1
print(x, y)
Answer

Output:

12 12

Working (step by step)

LineStatementValues after this stepPrinted
1x, y = 6, 13x = 6, y = 13
2while x < y:condition is True
3x = x * 2x = 12
4y = y - 1y = 12
2while x < y:condition is False
5print(x, y)12 12⏎
B4.34Practice2 marks

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))
Answer

Output:

[9, 8, 7] 3

Working (step by step)

LineStatementValues after this stepPrinted
1L = [9, 8, 8, 8, 7, 9]L = [9, 8, 8, 8, 7, 9]
2S = []S = []
3for x in L:x = 9
4if x not in S:condition is True
5S.append(x)S = [9]
3for x in L:x = 8
4if x not in S:condition is True
5S.append(x)S = [9, 8]
3for x in L:loop ends (no more values)
4if x not in S:condition is False
3for x in L:loop ends (no more values)
4if x not in S:condition is False
3for x in L:x = 7
4if x not in S:condition is True
5S.append(x)S = [9, 8, 7]
3for x in L:x = 9

… the same steps continue for the remaining values.

B4.35Practice2 marks

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)
Answer

Output:

[15 18 24 40 25]
5 1

Working (step by step)

LineStatementValues after this stepPrinted
2marks = [10, 13, 19, 35, 20]marks = [10, 13, 19, 35, 20]
3a = np.array(marks)a = array([10, 13, 19, 35, 20])
4print(a + 5)[15 18 24 40 25]⏎
5print(a.size, a.ndim)5 1⏎
B4.36Practice2 marks

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)
Answer
L = [1, 2, 3]
for i in range(len(L)):
    L[i] = L[i] * 2
print(L)

Colon after for; print L, not l.

B4.37Practice2 marks

Write the output of the following code.

x, y = 3, 27
while x < y:
    x = x * 2
    y = y - 1
print(x, y)
Answer

Output:

24 24

Working (step by step)

LineStatementValues after this stepPrinted
1x, y = 3, 27x = 3, y = 27
2while x < y:condition is True
3x = x * 2x = 6
4y = y - 1y = 26
2while x < y:condition is True
3x = x * 2x = 12
4y = y - 1y = 25
2while x < y:condition is True
3x = x * 2x = 24
4y = y - 1y = 24
2while x < y:condition is False
5print(x, y)24 24⏎
B4.38Practice2 marks

Write the output of the following code.

x, y = 7, 10
while x < y:
    x = x * 2
    y = y - 1
print(x, y)
Answer

Output:

14 9

Working (step by step)

LineStatementValues after this stepPrinted
1x, y = 7, 10x = 7, y = 10
2while x < y:condition is True
3x = x * 2x = 14
4y = y - 1y = 9
2while x < y:condition is False
5print(x, y)14 9⏎
B4.39Practice2 marks

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))
Answer

Output:

[3, 8, 5, 4, 9] 1

Working (step by step)

LineStatementValues after this stepPrinted
1L = [3, 8, 5, 4, 9, 4]L = [3, 8, 5, 4, 9, 4]
2S = []S = []
3for x in L:x = 3
4if x not in S:condition is True
5S.append(x)S = [3]
3for x in L:x = 8
4if x not in S:condition is True
5S.append(x)S = [3, 8]
3for x in L:x = 5
4if x not in S:condition is True
5S.append(x)S = [3, 8, 5]
3for x in L:x = 4
4if x not in S:condition is True
5S.append(x)S = [3, 8, 5, 4]
3for x in L:x = 9
4if x not in S:condition is True

… the same steps continue for the remaining values.

B4.40Practice2 marks

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)
Answer

Output:

24

Working (step by step)

LineStatementValues after this stepPrinted
1a = 2a = 2
2b = 22b = 22
3if a % 2 == 0 and b % 2 == 0:condition is True
4print(a + b)24⏎
B4.41Practice2 marks

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)
Answer

Output:

4912

Working (step by step)

LineStatementValues after this stepPrinted
1n = 2194n = 2194
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 4
5s = s * 10 + ds = 4
6n = n // 10n = 219
3while n > 0:condition is True
4d = n % 10d = 9
5s = s * 10 + ds = 49
6n = n // 10n = 21
3while n > 0:condition is True
4d = n % 10d = 1
5s = s * 10 + ds = 491
6n = n // 10n = 2
3while n > 0:condition is True
4d = n % 10d = 2

… the same steps continue for the remaining values.

B4.42Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

T = 1, 2, 3
T += 4
print(T)
Answer
T = 1, 2, 3
T += (4,)
print(T)

A tuple can be joined only with another tuple; write (4,).

B4.43Practice2 marks

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)
Answer

Output:

[58, 8, 44, 28, 54, 14]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [29, 25, 22, 14, 27, 7]L = [29, 25, 22, 14, 27, 7]
2for i in range(len(L)):i = 0
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [58, 25, 22, 14, 27, 7]
2for i in range(len(L)):i = 1
3if L[i] % 5 == 0:condition is True
4L[i] = L[i] // 3L = [58, 8, 22, 14, 27, 7]
2for i in range(len(L)):i = 2
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [58, 8, 44, 14, 27, 7]
2for i in range(len(L)):i = 3
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [58, 8, 44, 28, 27, 7]
2for i in range(len(L)):i = 4
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [58, 8, 44, 28, 54, 7]

… the same steps continue for the remaining values.

B4.44Practice2 marks

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)
Answer

Output:

b d c a 43

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'b': 15, 'd': 12, 'c': 9, 'a': 7}D = {'b': 15, 'd': 12, 'c': 9, 'a': 7}
2total = 0total = 0
3for k in D:k = 'b'
4if D[k] > 5:condition is True
5total += D[k]total = 15
6print(k, end=" ")b
3for k in D:k = 'd'
4if D[k] > 5:condition is True
5total += D[k]total = 27
6print(k, end=" ")d
3for k in D:k = 'c'
4if D[k] > 5:condition is True
5total += D[k]total = 36
6print(k, end=" ")c
3for k in D:k = 'a'
4if D[k] > 5:condition is True

… the same steps continue for the remaining values.

B4.45Practice2 marks

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)
Answer

Output:

d b e 37

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'d': 16, 'b': 12, 'a': 4, 'e': 9}D = {'d': 16, 'b': 12, 'a': 4, 'e': 9}
2total = 0total = 0
3for k in D:k = 'd'
4if D[k] > 5:condition is True
5total += D[k]total = 16
6print(k, end=" ")d
3for k in D:k = 'b'
4if D[k] > 5:condition is True
5total += D[k]total = 28
6print(k, end=" ")b
3for k in D:k = 'a'
4if D[k] > 5:condition is False
3for k in D:k = 'e'
4if D[k] > 5:condition is True
5total += D[k]total = 37
6print(k, end=" ")e
3for k in D:loop ends (no more values)
7print(total)37⏎
B4.46Practice2 marks

Write the output of the following code.

for i in range(1, 5):
    print(" " * (4 - i) + "#" * i)
Answer

Output:

   #
  ##
 ###
####

Working (step by step)

LineStatementValues after this stepPrinted
1for i in range(1, 5):i = 1
2print(" " * (4 - i) + "#" * i) #⏎
1for i in range(1, 5):i = 2
2print(" " * (4 - i) + "#" * i) ##⏎
1for i in range(1, 5):i = 3
2print(" " * (4 - i) + "#" * i) ###⏎
1for i in range(1, 5):i = 4
2print(" " * (4 - i) + "#" * i)####⏎
1for i in range(1, 5):loop ends (no more values)
B4.47Practice2 marks

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)
Answer

Output:

(2, 3)
[17  7 10]
[[ 40  60 190]
 [170  70 100]]

Working (step by step)

LineStatementValues after this stepPrinted
2L = [[4, 6, 19], [17, 7, 10]]L = [[4, 6, 19], [17, 7, 10]]
3a = np.array(L)a = array([[ 4, 6, 19], [17, 7, 10]])
4print(a.shape)(2, 3)⏎
5print(a[1])[17 7 10]⏎
6print(a * 10)[[ 40 60 190]⏎ [170 70 100]]⏎
B4.48Practice2 marks

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)
Answer

Output:

8

Working (step by step)

LineStatementValues after this stepPrinted
1a = 7a = 7
2b = 15b = 15
3if a % 2 == 0 and b % 2 == 0:condition is False
5elif a % 2 == 0 or b > 20:condition is False
8print(b - a)8⏎
B4.49Practice2 marks

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)
Answer

Output:

{3: 3, 2: 1, 6: 2}

Working (step by step)

LineStatementValues after this stepPrinted
1L = [3, 2, 6, 3, 6, 3]L = [3, 2, 6, 3, 6, 3]
2F = {}F = {}
3for x in L:x = 3
4F[x] = F.get(x, 0) + 1F = {3: 1}
3for x in L:x = 2
4F[x] = F.get(x, 0) + 1F = {3: 1, 2: 1}
3for x in L:x = 6
4F[x] = F.get(x, 0) + 1F = {3: 1, 2: 1, 6: 1}
3for x in L:x = 3
4F[x] = F.get(x, 0) + 1F = {3: 2, 2: 1, 6: 1}
3for x in L:x = 6
4F[x] = F.get(x, 0) + 1F = {3: 2, 2: 1, 6: 2}
3for x in L:x = 3
4F[x] = F.get(x, 0) + 1F = {3: 3, 2: 1, 6: 2}
3for x in L:loop ends (no more values)
5print(F){3: 3, 2: 1, 6: 2}⏎
B4.50Practice2 marks

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))
Answer

Output:

[2, 8, 3, 4] 2

Working (step by step)

LineStatementValues after this stepPrinted
1L = [2, 8, 3, 3, 4, 2]L = [2, 8, 3, 3, 4, 2]
2S = []S = []
3for x in L:x = 2
4if x not in S:condition is True
5S.append(x)S = [2]
3for x in L:x = 8
4if x not in S:condition is True
5S.append(x)S = [2, 8]
3for x in L:x = 3
4if x not in S:condition is True
5S.append(x)S = [2, 8, 3]
3for x in L:loop ends (no more values)
4if x not in S:condition is False
3for x in L:x = 4
4if x not in S:condition is True
5S.append(x)S = [2, 8, 3, 4]

… the same steps continue for the remaining values.

B4.51Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

Marks = 90
if Marks >= 90 and <= 100:
    print('A1')
Answer
Marks = 90
if Marks >= 90 and Marks <= 100:
    print('A1')

Each side of and must be a full condition (or write 90 <= Marks <= 100).

B4.52Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

num = [4, 5, 6]
num.insert(10)
num.remove(1)
print(num.length)
Answer
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().

B4.53Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

x = 5
y = 2
print(x ^ y, x ** y, x // y, x % y))
Answer
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.

B4.54Practice2 marks

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)
Answer

Output:

[5, 18, 9, 8, 42, 34]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [16, 9, 28, 24, 21, 17]L = [16, 9, 28, 24, 21, 17]
2for i in range(len(L)):i = 0
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 3L = [5, 9, 28, 24, 21, 17]
2for i in range(len(L)):i = 1
3if L[i] % 2 == 0:condition is False
6L[i] = L[i] * 2L = [5, 18, 28, 24, 21, 17]
2for i in range(len(L)):i = 2
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 3L = [5, 18, 9, 24, 21, 17]
2for i in range(len(L)):i = 3
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 3L = [5, 18, 9, 8, 21, 17]
2for i in range(len(L)):i = 4
3if L[i] % 2 == 0:condition is False
6L[i] = L[i] * 2L = [5, 18, 9, 8, 42, 17]

… the same steps continue for the remaining values.

B4.55Practice2 marks

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)
Answer

Output:

0

Working (step by step)

LineStatementValues after this stepPrinted
1n = 79101n = 79101
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 1
5if d % 2 == 0:condition is False
7n = n // 10n = 7910
3while n > 0:condition is True
4d = n % 10d = 0
5if d % 2 == 0:condition is True
7n = n // 10n = 791
3while n > 0:condition is True
4d = n % 10d = 1
5if d % 2 == 0:condition is False
7n = n // 10n = 79
3while n > 0:condition is True
4d = n % 10d = 9

… the same steps continue for the remaining values.

B4.56Practice2 marks

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)
Answer

Output:

{6: 1, 3: 3, 8: 1, 2: 1}

Working (step by step)

LineStatementValues after this stepPrinted
1L = [6, 3, 3, 8, 2, 3]L = [6, 3, 3, 8, 2, 3]
2F = {}F = {}
3for x in L:x = 6
4F[x] = F.get(x, 0) + 1F = {6: 1}
3for x in L:x = 3
4F[x] = F.get(x, 0) + 1F = {6: 1, 3: 1}
3for x in L:loop ends (no more values)
4F[x] = F.get(x, 0) + 1F = {6: 1, 3: 2}
3for x in L:x = 8
4F[x] = F.get(x, 0) + 1F = {6: 1, 3: 2, 8: 1}
3for x in L:x = 2
4F[x] = F.get(x, 0) + 1F = {6: 1, 3: 2, 8: 1, 2: 1}
3for x in L:x = 3
4F[x] = F.get(x, 0) + 1F = {6: 1, 3: 3, 8: 1, 2: 1}
3for x in L:loop ends (no more values)
5print(F){6: 1, 3: 3, 8: 1, 2: 1}⏎
B4.57Practice2 marks

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)
Answer

Output:

[58, 13, 46, 12, 1, 42]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [29, 26, 23, 24, 2, 21]L = [29, 26, 23, 24, 2, 21]
2for i in range(len(L)):i = 0
3if L[i] % 2 == 0:condition is False
6L[i] = L[i] * 2L = [58, 26, 23, 24, 2, 21]
2for i in range(len(L)):i = 1
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 2L = [58, 13, 23, 24, 2, 21]
2for i in range(len(L)):i = 2
3if L[i] % 2 == 0:condition is False
6L[i] = L[i] * 2L = [58, 13, 46, 24, 2, 21]
2for i in range(len(L)):i = 3
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 2L = [58, 13, 46, 12, 2, 21]
2for i in range(len(L)):i = 4
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 2L = [58, 13, 46, 12, 1, 21]

… the same steps continue for the remaining values.

B4.58Practice2 marks

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)
Answer

Output:

a 12

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'b': 7, 'a': 12, 'c': 1, 'd': 2}D = {'b': 7, 'a': 12, 'c': 1, 'd': 2}
2total = 0total = 0
3for k in D:k = 'b'
4if D[k] > 8:condition is False
3for k in D:k = 'a'
4if D[k] > 8:condition is True
5total += D[k]total = 12
6print(k, end=" ")a
3for k in D:k = 'c'
4if D[k] > 8:condition is False
3for k in D:k = 'd'
4if D[k] > 8:condition is False
3for k in D:loop ends (no more values)
7print(total)12⏎
B4.59Practice2 marks

Write the output of the following code.

for i in range(1, 6):
    for j in range(i):
        print(i, end="")
    print()
Answer

Output:

1
22
333
4444
55555

Working (step by step)

LineStatementValues after this stepPrinted
1for i in range(1, 6):i = 1
2for j in range(i):j = 0
3print(i, end="")1
2for j in range(i):loop ends (no more values)
4print()⏎
1for i in range(1, 6):i = 2
2for j in range(i):loop ends (no more values)
3print(i, end="")2
2for j in range(i):j = 1
3print(i, end="")2
2for j in range(i):loop ends (no more values)
4print()⏎
1for i in range(1, 6):i = 3
2for j in range(i):j = 0
3print(i, end="")3
2for j in range(i):j = 1

… the same steps continue for the remaining values.

B4.60Practice2 marks

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)
Answer

Output:

{5: 2, 1: 1, 2: 1, 7: 1, 6: 1}

Working (step by step)

LineStatementValues after this stepPrinted
1L = [5, 1, 2, 5, 7, 6]L = [5, 1, 2, 5, 7, 6]
2F = {}F = {}
3for x in L:x = 5
4F[x] = F.get(x, 0) + 1F = {5: 1}
3for x in L:x = 1
4F[x] = F.get(x, 0) + 1F = {5: 1, 1: 1}
3for x in L:x = 2
4F[x] = F.get(x, 0) + 1F = {5: 1, 1: 1, 2: 1}
3for x in L:x = 5
4F[x] = F.get(x, 0) + 1F = {5: 2, 1: 1, 2: 1}
3for x in L:x = 7
4F[x] = F.get(x, 0) + 1F = {5: 2, 1: 1, 2: 1, 7: 1}
3for x in L:x = 6
4F[x] = F.get(x, 0) + 1F = {5: 2, 1: 1, 2: 1, 7: 1, 6: 1}
3for x in L:loop ends (no more values)
5print(F){5: 2, 1: 1, 2: 1, 7: 1, 6: 1}⏎
B4.61Practice2 marks

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)
Answer

Output:

[6, 42, 38, 3, 30, 54]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [3, 21, 19, 10, 15, 27]L = [3, 21, 19, 10, 15, 27]
2for i in range(len(L)):i = 0
3if L[i] % 2 == 0:condition is False
6L[i] = L[i] * 2L = [6, 21, 19, 10, 15, 27]
2for i in range(len(L)):i = 1
3if L[i] % 2 == 0:condition is False
6L[i] = L[i] * 2L = [6, 42, 19, 10, 15, 27]
2for i in range(len(L)):i = 2
3if L[i] % 2 == 0:condition is False
6L[i] = L[i] * 2L = [6, 42, 38, 10, 15, 27]
2for i in range(len(L)):i = 3
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 3L = [6, 42, 38, 3, 15, 27]
2for i in range(len(L)):i = 4
3if L[i] % 2 == 0:condition is False
6L[i] = L[i] * 2L = [6, 42, 38, 3, 30, 27]

… the same steps continue for the remaining values.

B4.62Practice2 marks

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)
Answer

Output:

[10  6  7 17  8]
[ True False False  True False]

Working (step by step)

LineStatementValues after this stepPrinted
2a = np.array([20, 12, 14, 34, 16])a = array([20, 12, 14, 34, 16])
3b = a // 2b = array([10, 6, 7, 17, 8])
4print(b)[10 6 7 17 8]⏎
5print(a > 19)[ True False False True False]⏎
B4.63Practice2 marks

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)
Answer

Output:

{3: 2, 9: 3, 1: 1}

Working (step by step)

LineStatementValues after this stepPrinted
1L = [3, 9, 3, 1, 9, 9]L = [3, 9, 3, 1, 9, 9]
2F = {}F = {}
3for x in L:x = 3
4F[x] = F.get(x, 0) + 1F = {3: 1}
3for x in L:x = 9
4F[x] = F.get(x, 0) + 1F = {3: 1, 9: 1}
3for x in L:x = 3
4F[x] = F.get(x, 0) + 1F = {3: 2, 9: 1}
3for x in L:x = 1
4F[x] = F.get(x, 0) + 1F = {3: 2, 9: 1, 1: 1}
3for x in L:x = 9
4F[x] = F.get(x, 0) + 1F = {3: 2, 9: 2, 1: 1}
3for x in L:loop ends (no more values)
4F[x] = F.get(x, 0) + 1F = {3: 2, 9: 3, 1: 1}
3for x in L:loop ends (no more values)
5print(F){3: 2, 9: 3, 1: 1}⏎
B4.64Practice2 marks

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)
Answer

Output:

12

Working (step by step)

LineStatementValues after this stepPrinted
1n = 2287n = 2287
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 7
5if d % 2 == 0:condition is False
7n = n // 10n = 228
3while n > 0:condition is True
4d = n % 10d = 8
5if d % 2 == 0:condition is True
6s = s + ds = 8
7n = n // 10n = 22
3while n > 0:condition is True
4d = n % 10d = 2
5if d % 2 == 0:condition is True
6s = s + ds = 10
7n = n // 10n = 2

… the same steps continue for the remaining values.

B4.65Practice2 marks

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)
Answer

Output:

c d e a 61

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'c': 13, 'd': 15, 'e': 14, 'a': 19}D = {'c': 13, 'd': 15, 'e': 14, 'a': 19}
2total = 0total = 0
3for k in D:k = 'c'
4if D[k] > 5:condition is True
5total += D[k]total = 13
6print(k, end=" ")c
3for k in D:k = 'd'
4if D[k] > 5:condition is True
5total += D[k]total = 28
6print(k, end=" ")d
3for k in D:k = 'e'
4if D[k] > 5:condition is True
5total += D[k]total = 42
6print(k, end=" ")e
3for k in D:k = 'a'
4if D[k] > 5:condition is True

… the same steps continue for the remaining values.

B4.66Practice2 marks

Write the output of the following code.

x, y = 6, 10
while x < y:
    x = x * 2
    y = y - 1
print(x, y)
Answer

Output:

12 9

Working (step by step)

LineStatementValues after this stepPrinted
1x, y = 6, 10x = 6, y = 10
2while x < y:condition is True
3x = x * 2x = 12
4y = y - 1y = 9
2while x < y:condition is False
5print(x, y)12 9⏎
B4.67Practice2 marks

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)
Answer

Output:

[11 40 19 10 30]
5 1

Working (step by step)

LineStatementValues after this stepPrinted
2marks = [6, 35, 14, 5, 25]marks = [6, 35, 14, 5, 25]
3a = np.array(marks)a = array([ 6, 35, 14, 5, 25])
4print(a + 5)[11 40 19 10 30]⏎
5print(a.size, a.ndim)5 1⏎
B4.68Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

def = 5
for i in range(def):
    print(i)
Answer
d = 5
for i in range(d):
    print(i)

def is a keyword; it cannot be a variable name.

B4.69Practice2 marks

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)
Answer

Output:

[50, 1, 4, 6, 2, 26]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [25, 2, 8, 12, 4, 13]L = [25, 2, 8, 12, 4, 13]
2for i in range(len(L)):i = 0
3if L[i] % 2 == 0:condition is False
6L[i] = L[i] * 2L = [50, 2, 8, 12, 4, 13]
2for i in range(len(L)):i = 1
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 2L = [50, 1, 8, 12, 4, 13]
2for i in range(len(L)):i = 2
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 2L = [50, 1, 4, 12, 4, 13]
2for i in range(len(L)):i = 3
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 2L = [50, 1, 4, 6, 4, 13]
2for i in range(len(L)):i = 4
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 2L = [50, 1, 4, 6, 2, 13]

… the same steps continue for the remaining values.

B4.70Practice2 marks

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))
Answer

Output:

[7, 6, 4, 2] 2

Working (step by step)

LineStatementValues after this stepPrinted
1L = [7, 6, 4, 6, 2, 2]L = [7, 6, 4, 6, 2, 2]
2S = []S = []
3for x in L:x = 7
4if x not in S:condition is True
5S.append(x)S = [7]
3for x in L:x = 6
4if x not in S:condition is True
5S.append(x)S = [7, 6]
3for x in L:x = 4
4if x not in S:condition is True
5S.append(x)S = [7, 6, 4]
3for x in L:x = 6
4if x not in S:condition is False
3for x in L:x = 2
4if x not in S:condition is True
5S.append(x)S = [7, 6, 4, 2]

… the same steps continue for the remaining values.

B4.71Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

L = [1, 2, 3]
L[3] = 4
print(L)
Answer
L = [1, 2, 3]
L.append(4)
print(L)

Index 3 does not exist (IndexError); add a new element with append().

B4.72Practice2 marks

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)
Answer

Output:

[ 8 11 10  3 17]
[ True  True  True False  True]

Working (step by step)

LineStatementValues after this stepPrinted
2a = np.array([17, 22, 20, 7, 34])a = array([17, 22, 20, 7, 34])
3b = a // 2b = array([ 8, 11, 10, 3, 17])
4print(b)[ 8 11 10 3 17]⏎
5print(a > 10)[ True True True False True]⏎
B4.73Practice2 marks

Write the output of the following code.

x, y = 2, 29
while x < y:
    x = x * 2
    y = y - 1
print(x, y)
Answer

Output:

32 25

Working (step by step)

LineStatementValues after this stepPrinted
1x, y = 2, 29x = 2, y = 29
2while x < y:condition is True
3x = x * 2x = 4
4y = y - 1y = 28
2while x < y:condition is True
3x = x * 2x = 8
4y = y - 1y = 27
2while x < y:condition is True
3x = x * 2x = 16
4y = y - 1y = 26
2while x < y:condition is True
3x = x * 2x = 32
4y = y - 1y = 25
2while x < y:condition is False
5print(x, y)32 25⏎
B4.74Practice2 marks

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)
Answer

Output:

95257

Working (step by step)

LineStatementValues after this stepPrinted
1n = 75259n = 75259
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 9
5s = s * 10 + ds = 9
6n = n // 10n = 7525
3while n > 0:condition is True
4d = n % 10d = 5
5s = s * 10 + ds = 95
6n = n // 10n = 752
3while n > 0:condition is True
4d = n % 10d = 2
5s = s * 10 + ds = 952
6n = n // 10n = 75
3while n > 0:condition is True
4d = n % 10d = 5

… the same steps continue for the remaining values.

B4.75Practice2 marks

Write the output of the following code.

x, y = 3, 17
while x < y:
    x = x * 2
    y = y - 1
print(x, y)
Answer

Output:

24 14

Working (step by step)

LineStatementValues after this stepPrinted
1x, y = 3, 17x = 3, y = 17
2while x < y:condition is True
3x = x * 2x = 6
4y = y - 1y = 16
2while x < y:condition is True
3x = x * 2x = 12
4y = y - 1y = 15
2while x < y:condition is True
3x = x * 2x = 24
4y = y - 1y = 14
2while x < y:condition is False
5print(x, y)24 14⏎
B4.76Practice2 marks

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)
Answer

Output:

{3: 2, 5: 1, 6: 1, 1: 1, 2: 1}

Working (step by step)

LineStatementValues after this stepPrinted
1L = [3, 5, 6, 3, 1, 2]L = [3, 5, 6, 3, 1, 2]
2F = {}F = {}
3for x in L:x = 3
4F[x] = F.get(x, 0) + 1F = {3: 1}
3for x in L:x = 5
4F[x] = F.get(x, 0) + 1F = {3: 1, 5: 1}
3for x in L:x = 6
4F[x] = F.get(x, 0) + 1F = {3: 1, 5: 1, 6: 1}
3for x in L:x = 3
4F[x] = F.get(x, 0) + 1F = {3: 2, 5: 1, 6: 1}
3for x in L:x = 1
4F[x] = F.get(x, 0) + 1F = {3: 2, 5: 1, 6: 1, 1: 1}
3for x in L:x = 2
4F[x] = F.get(x, 0) + 1F = {3: 2, 5: 1, 6: 1, 1: 1, 2: 1}
3for x in L:loop ends (no more values)
5print(F){3: 2, 5: 1, 6: 1, 1: 1, 2: 1}⏎
B4.77Practice2 marks

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))
Answer

Output:

[8, 7, 1, 2, 4] 1

Working (step by step)

LineStatementValues after this stepPrinted
1L = [8, 7, 1, 2, 4, 7]L = [8, 7, 1, 2, 4, 7]
2S = []S = []
3for x in L:x = 8
4if x not in S:condition is True
5S.append(x)S = [8]
3for x in L:x = 7
4if x not in S:condition is True
5S.append(x)S = [8, 7]
3for x in L:x = 1
4if x not in S:condition is True
5S.append(x)S = [8, 7, 1]
3for x in L:x = 2
4if x not in S:condition is True
5S.append(x)S = [8, 7, 1, 2]
3for x in L:x = 4
4if x not in S:condition is True

… the same steps continue for the remaining values.

B4.78Practice2 marks

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)
Answer

Output:

8

Working (step by step)

LineStatementValues after this stepPrinted
1n = 55018n = 55018
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 8
5if d % 2 == 0:condition is True
6s = s + ds = 8
7n = n // 10n = 5501
3while n > 0:condition is True
4d = n % 10d = 1
5if d % 2 == 0:condition is False
7n = n // 10n = 550
3while n > 0:condition is True
4d = n % 10d = 0
5if d % 2 == 0:condition is True
7n = n // 10n = 55
3while n > 0:condition is True

… the same steps continue for the remaining values.

B4.79Practice2 marks

Write the output of the following code.

for i in range(1, 5):
    for j in range(i):
        print(i, end="")
    print()
Answer

Output:

1
22
333
4444

Working (step by step)

LineStatementValues after this stepPrinted
1for i in range(1, 5):i = 1
2for j in range(i):j = 0
3print(i, end="")1
2for j in range(i):loop ends (no more values)
4print()⏎
1for i in range(1, 5):i = 2
2for j in range(i):loop ends (no more values)
3print(i, end="")2
2for j in range(i):j = 1
3print(i, end="")2
2for j in range(i):loop ends (no more values)
4print()⏎
1for i in range(1, 5):i = 3
2for j in range(i):j = 0
3print(i, end="")3
2for j in range(i):j = 1

… the same steps continue for the remaining values.

B4.80Practice2 marks

Write the output of the following code.

for i in range(1, 6):
    print(" " * (5 - i) + "#" * i)
Answer

Output:

    #
   ##
  ###
 ####
#####

Working (step by step)

LineStatementValues after this stepPrinted
1for i in range(1, 6):i = 1
2print(" " * (5 - i) + "#" * i) #⏎
1for i in range(1, 6):i = 2
2print(" " * (5 - i) + "#" * i) ##⏎
1for i in range(1, 6):i = 3
2print(" " * (5 - i) + "#" * i) ###⏎
1for i in range(1, 6):i = 4
2print(" " * (5 - i) + "#" * i) ####⏎
1for i in range(1, 6):i = 5
2print(" " * (5 - i) + "#" * i)#####⏎
1for i in range(1, 6):loop ends (no more values)
B4.81Practice2 marks

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)
Answer

Output:

{4: 3, 1: 1, 7: 1, 9: 1}

Working (step by step)

LineStatementValues after this stepPrinted
1L = [4, 1, 7, 4, 9, 4]L = [4, 1, 7, 4, 9, 4]
2F = {}F = {}
3for x in L:x = 4
4F[x] = F.get(x, 0) + 1F = {4: 1}
3for x in L:x = 1
4F[x] = F.get(x, 0) + 1F = {4: 1, 1: 1}
3for x in L:x = 7
4F[x] = F.get(x, 0) + 1F = {4: 1, 1: 1, 7: 1}
3for x in L:x = 4
4F[x] = F.get(x, 0) + 1F = {4: 2, 1: 1, 7: 1}
3for x in L:x = 9
4F[x] = F.get(x, 0) + 1F = {4: 2, 1: 1, 7: 1, 9: 1}
3for x in L:x = 4
4F[x] = F.get(x, 0) + 1F = {4: 3, 1: 1, 7: 1, 9: 1}
3for x in L:loop ends (no more values)
5print(F){4: 3, 1: 1, 7: 1, 9: 1}⏎
B4.82Practice2 marks

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)
Answer

Output:

b c 29

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'b': 14, 'e': 4, 'c': 15, 'a': 2}D = {'b': 14, 'e': 4, 'c': 15, 'a': 2}
2total = 0total = 0
3for k in D:k = 'b'
4if D[k] > 10:condition is True
5total += D[k]total = 14
6print(k, end=" ")b
3for k in D:k = 'e'
4if D[k] > 10:condition is False
3for k in D:k = 'c'
4if D[k] > 10:condition is True
5total += D[k]total = 29
6print(k, end=" ")c
3for k in D:k = 'a'
4if D[k] > 10:condition is False
3for k in D:loop ends (no more values)
7print(total)29⏎
B4.83Practice2 marks

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)
Answer

Output:

16

Working (step by step)

LineStatementValues after this stepPrinted
1n = 66407n = 66407
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 7
5if d % 2 == 0:condition is False
7n = n // 10n = 6640
3while n > 0:condition is True
4d = n % 10d = 0
5if d % 2 == 0:condition is True
7n = n // 10n = 664
3while n > 0:condition is True
4d = n % 10d = 4
5if d % 2 == 0:condition is True
6s = s + ds = 4
7n = n // 10n = 66
3while n > 0:condition is True

… the same steps continue for the remaining values.

B4.84Practice2 marks

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)
Answer

Output:

49767

Working (step by step)

LineStatementValues after this stepPrinted
1n = 76794n = 76794
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 4
5s = s * 10 + ds = 4
6n = n // 10n = 7679
3while n > 0:condition is True
4d = n % 10d = 9
5s = s * 10 + ds = 49
6n = n // 10n = 767
3while n > 0:condition is True
4d = n % 10d = 7
5s = s * 10 + ds = 497
6n = n // 10n = 76
3while n > 0:condition is True
4d = n % 10d = 6

… the same steps continue for the remaining values.

B4.85Practice2 marks

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)
Answer

Output:

c e a 44

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'b': 7, 'c': 13, 'e': 15, 'a': 16}D = {'b': 7, 'c': 13, 'e': 15, 'a': 16}
2total = 0total = 0
3for k in D:k = 'b'
4if D[k] > 9:condition is False
3for k in D:k = 'c'
4if D[k] > 9:condition is True
5total += D[k]total = 13
6print(k, end=" ")c
3for k in D:k = 'e'
4if D[k] > 9:condition is True
5total += D[k]total = 28
6print(k, end=" ")e
3for k in D:k = 'a'
4if D[k] > 9:condition is True
5total += D[k]total = 44
6print(k, end=" ")a
3for k in D:loop ends (no more values)
7print(total)44⏎
B4.86Practice2 marks

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)
Answer

Output:

0

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'c': 7, 'b': 6, 'e': 4, 'a': 1}D = {'c': 7, 'b': 6, 'e': 4, 'a': 1}
2total = 0total = 0
3for k in D:k = 'c'
4if D[k] > 10:condition is False
3for k in D:k = 'b'
4if D[k] > 10:condition is False
3for k in D:k = 'e'
4if D[k] > 10:condition is False
3for k in D:k = 'a'
4if D[k] > 10:condition is False
3for k in D:loop ends (no more values)
7print(total)0⏎
B4.87Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

D = dict()
D[1] = 'one'
D.[2] = 'two'
print(D.key())
Answer
D = dict()
D[1] = 'one'
D[2] = 'two'
print(D.keys())

Use D[2] to add; the method is keys().

B4.88Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

x = input('Enter a number')
if x % 2 = 0
    print('Even')
else
    print('Odd')
Answer
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.

B4.89Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

i = 1
while i < 10:
    if i % 2 = 0:
        continue
    print(i)
    i =+ 1
Answer
i = 1
while i < 10:
    if i % 2 == 0:
        i += 1
        continue
    print(i)
    i += 1

Use == to compare; =+ means 'assign +1', write += 1; i must change before continue, or the loop never ends.

B4.90Practice2 marks

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)
Answer

Output:

{1: 1, 9: 2, 8: 1, 3: 1, 6: 1}

Working (step by step)

LineStatementValues after this stepPrinted
1L = [1, 9, 9, 8, 3, 6]L = [1, 9, 9, 8, 3, 6]
2F = {}F = {}
3for x in L:x = 1
4F[x] = F.get(x, 0) + 1F = {1: 1}
3for x in L:x = 9
4F[x] = F.get(x, 0) + 1F = {1: 1, 9: 1}
3for x in L:loop ends (no more values)
4F[x] = F.get(x, 0) + 1F = {1: 1, 9: 2}
3for x in L:x = 8
4F[x] = F.get(x, 0) + 1F = {1: 1, 9: 2, 8: 1}
3for x in L:x = 3
4F[x] = F.get(x, 0) + 1F = {1: 1, 9: 2, 8: 1, 3: 1}
3for x in L:x = 6
4F[x] = F.get(x, 0) + 1F = {1: 1, 9: 2, 8: 1, 3: 1, 6: 1}
3for x in L:loop ends (no more values)
5print(F){1: 1, 9: 2, 8: 1, 3: 1, 6: 1}⏎
B4.91Practice2 marks

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)
Answer

Output:

[52, 4, 12, 8, 16, 24]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [26, 2, 6, 25, 8, 12]L = [26, 2, 6, 25, 8, 12]
2for i in range(len(L)):i = 0
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [52, 2, 6, 25, 8, 12]
2for i in range(len(L)):i = 1
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [52, 4, 6, 25, 8, 12]
2for i in range(len(L)):i = 2
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [52, 4, 12, 25, 8, 12]
2for i in range(len(L)):i = 3
3if L[i] % 5 == 0:condition is True
4L[i] = L[i] // 3L = [52, 4, 12, 8, 8, 12]
2for i in range(len(L)):i = 4
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [52, 4, 12, 8, 16, 12]

… the same steps continue for the remaining values.

B4.92Practice2 marks

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)
Answer

Output:

82506

Working (step by step)

LineStatementValues after this stepPrinted
1n = 60528n = 60528
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 8
5s = s * 10 + ds = 8
6n = n // 10n = 6052
3while n > 0:condition is True
4d = n % 10d = 2
5s = s * 10 + ds = 82
6n = n // 10n = 605
3while n > 0:condition is True
4d = n % 10d = 5
5s = s * 10 + ds = 825
6n = n // 10n = 60
3while n > 0:condition is True
4d = n % 10d = 0

… the same steps continue for the remaining values.

B4.93Practice2 marks

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)
Answer

Output:

c a 23

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'d': 6, 'e': 8, 'c': 10, 'a': 13}D = {'d': 6, 'e': 8, 'c': 10, 'a': 13}
2total = 0total = 0
3for k in D:k = 'd'
4if D[k] > 9:condition is False
3for k in D:k = 'e'
4if D[k] > 9:condition is False
3for k in D:k = 'c'
4if D[k] > 9:condition is True
5total += D[k]total = 10
6print(k, end=" ")c
3for k in D:k = 'a'
4if D[k] > 9:condition is True
5total += D[k]total = 23
6print(k, end=" ")a
3for k in D:loop ends (no more values)
7print(total)23⏎
B4.94Practice2 marks

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))
Answer

Output:

[7, 1, 2, 5] 2

Working (step by step)

LineStatementValues after this stepPrinted
1L = [7, 1, 1, 2, 7, 5]L = [7, 1, 1, 2, 7, 5]
2S = []S = []
3for x in L:x = 7
4if x not in S:condition is True
5S.append(x)S = [7]
3for x in L:x = 1
4if x not in S:condition is True
5S.append(x)S = [7, 1]
3for x in L:loop ends (no more values)
4if x not in S:condition is False
3for x in L:x = 2
4if x not in S:condition is True
5S.append(x)S = [7, 1, 2]
3for x in L:x = 7
4if x not in S:condition is False
3for x in L:x = 5

… the same steps continue for the remaining values.

B4.95Practice2 marks

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)
Answer

Output:

87494

Working (step by step)

LineStatementValues after this stepPrinted
1n = 49478n = 49478
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 8
5s = s * 10 + ds = 8
6n = n // 10n = 4947
3while n > 0:condition is True
4d = n % 10d = 7
5s = s * 10 + ds = 87
6n = n // 10n = 494
3while n > 0:condition is True
4d = n % 10d = 4
5s = s * 10 + ds = 874
6n = n // 10n = 49
3while n > 0:condition is True
4d = n % 10d = 9

… the same steps continue for the remaining values.

B4.96Practice2 marks

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)
Answer

Output:

22

Working (step by step)

LineStatementValues after this stepPrinted
1a = 4a = 4
2b = 18b = 18
3if a % 2 == 0 and b % 2 == 0:condition is True
4print(a + b)22⏎
B4.97Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

student = {'name' = 'Asha', 'age' = 16}
print(student[name])
Answer
student = {'name': 'Asha', 'age': 16}
print(student['name'])

Use : between key and value; the key is the string 'name'.

B4.98Practice2 marks

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)
Answer

Output:

51753

Working (step by step)

LineStatementValues after this stepPrinted
1n = 35715n = 35715
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 5
5s = s * 10 + ds = 5
6n = n // 10n = 3571
3while n > 0:condition is True
4d = n % 10d = 1
5s = s * 10 + ds = 51
6n = n // 10n = 357
3while n > 0:condition is True
4d = n % 10d = 7
5s = s * 10 + ds = 517
6n = n // 10n = 35
3while n > 0:condition is True
4d = n % 10d = 5

… the same steps continue for the remaining values.

B4.99Practice2 marks

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))
Answer

Output:

[2, 7, 3, 9] 2

Working (step by step)

LineStatementValues after this stepPrinted
1L = [2, 7, 3, 2, 7, 9]L = [2, 7, 3, 2, 7, 9]
2S = []S = []
3for x in L:x = 2
4if x not in S:condition is True
5S.append(x)S = [2]
3for x in L:x = 7
4if x not in S:condition is True
5S.append(x)S = [2, 7]
3for x in L:x = 3
4if x not in S:condition is True
5S.append(x)S = [2, 7, 3]
3for x in L:x = 2
4if x not in S:condition is False
3for x in L:x = 7
4if x not in S:condition is False
3for x in L:x = 9

… the same steps continue for the remaining values.

B4.100Practice2 marks

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()
Answer

Output:

1 
2 4 
3 6 9 

Working (step by step)

LineStatementValues after this stepPrinted
1for i in range(1, 4):i = 1
2for j in range(1, i + 1):j = 1
3print(j * i, end=" ")1
2for j in range(1, i + 1):loop ends (no more values)
4print()⏎
1for i in range(1, 4):i = 2
2for j in range(1, i + 1):loop ends (no more values)
3print(j * i, end=" ")2
2for j in range(1, i + 1):j = 2
3print(j * i, end=" ")4
2for j in range(1, i + 1):loop ends (no more values)
4print()⏎
1for i in range(1, 4):i = 3
2for j in range(1, i + 1):j = 1
3print(j * i, end=" ")3
2for j in range(1, i + 1):j = 2

… the same steps continue for the remaining values.

B4.101Practice2 marks

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)
Answer

Output:

[32, 6, 7, 34, 10, 2]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [16, 3, 15, 17, 20, 5]L = [16, 3, 15, 17, 20, 5]
2for i in range(len(L)):i = 0
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [32, 3, 15, 17, 20, 5]
2for i in range(len(L)):i = 1
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [32, 6, 15, 17, 20, 5]
2for i in range(len(L)):i = 2
3if L[i] % 5 == 0:condition is True
4L[i] = L[i] // 2L = [32, 6, 7, 17, 20, 5]
2for i in range(len(L)):i = 3
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [32, 6, 7, 34, 20, 5]
2for i in range(len(L)):i = 4
3if L[i] % 5 == 0:condition is True
4L[i] = L[i] // 2L = [32, 6, 7, 34, 10, 5]

… the same steps continue for the remaining values.

B4.102Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

D = {'a': 1, 'b': 2]
for k in D
    print(k, D(k))
Answer
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].

B4.103Practice2 marks

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)
Answer

Output:

27405

Working (step by step)

LineStatementValues after this stepPrinted
1n = 50472n = 50472
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 2
5s = s * 10 + ds = 2
6n = n // 10n = 5047
3while n > 0:condition is True
4d = n % 10d = 7
5s = s * 10 + ds = 27
6n = n // 10n = 504
3while n > 0:condition is True
4d = n % 10d = 4
5s = s * 10 + ds = 274
6n = n // 10n = 50
3while n > 0:condition is True
4d = n % 10d = 0

… the same steps continue for the remaining values.

B4.104Practice2 marks

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)
Answer

Output:

b c d a 66

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'b': 18, 'c': 19, 'd': 14, 'a': 15}D = {'b': 18, 'c': 19, 'd': 14, 'a': 15}
2total = 0total = 0
3for k in D:k = 'b'
4if D[k] > 12:condition is True
5total += D[k]total = 18
6print(k, end=" ")b
3for k in D:k = 'c'
4if D[k] > 12:condition is True
5total += D[k]total = 37
6print(k, end=" ")c
3for k in D:k = 'd'
4if D[k] > 12:condition is True
5total += D[k]total = 51
6print(k, end=" ")d
3for k in D:k = 'a'
4if D[k] > 12:condition is True

… the same steps continue for the remaining values.

B4.105Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

a = int(input('A: ')
b = float(input('B: '))
print('Total' + a + b)
Answer
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.

B4.106Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

for i in range(1, 6)
    sum = sum + i
print(Sum)
Answer
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).

B4.107Practice2 marks

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')
Answer
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'.

B4.108Practice2 marks

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)
Answer

Output:

0

Working (step by step)

LineStatementValues after this stepPrinted
1n = 73711n = 73711
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 1
5if d % 2 == 0:condition is False
7n = n // 10n = 7371
3while n > 0:condition is True
5if d % 2 == 0:condition is False
7n = n // 10n = 737
3while n > 0:condition is True
4d = n % 10d = 7
5if d % 2 == 0:condition is False
7n = n // 10n = 73
3while n > 0:condition is True
4d = n % 10d = 3
5if d % 2 == 0:condition is False

… the same steps continue for the remaining values.

B4.109Practice2 marks

Write the output of the following code.

for i in range(4, 0, -1):
    print("*" * i)
Answer

Output:

****
***
**
*

Working (step by step)

LineStatementValues after this stepPrinted
1for i in range(4, 0, -1):i = 4
2print("*" * i)****⏎
1for i in range(4, 0, -1):i = 3
2print("*" * i)***⏎
1for i in range(4, 0, -1):i = 2
2print("*" * i)**⏎
1for i in range(4, 0, -1):i = 1
2print("*" * i)*⏎
1for i in range(4, 0, -1):loop ends (no more values)
B4.110Practice2 marks

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))
Answer

Output:

[5, 6, 2, 3, 1] 1

Working (step by step)

LineStatementValues after this stepPrinted
1L = [5, 6, 2, 3, 5, 1]L = [5, 6, 2, 3, 5, 1]
2S = []S = []
3for x in L:x = 5
4if x not in S:condition is True
5S.append(x)S = [5]
3for x in L:x = 6
4if x not in S:condition is True
5S.append(x)S = [5, 6]
3for x in L:x = 2
4if x not in S:condition is True
5S.append(x)S = [5, 6, 2]
3for x in L:x = 3
4if x not in S:condition is True
5S.append(x)S = [5, 6, 2, 3]
3for x in L:x = 5
4if x not in S:condition is False

… the same steps continue for the remaining values.

B4.111Practice2 marks

Write the output of the following code.

x, y = 8, 21
while x < y:
    x = x * 2
    y = y - 1
print(x, y)
Answer

Output:

32 19

Working (step by step)

LineStatementValues after this stepPrinted
1x, y = 8, 21x = 8, y = 21
2while x < y:condition is True
3x = x * 2x = 16
4y = y - 1y = 20
2while x < y:condition is True
3x = x * 2x = 32
4y = y - 1y = 19
2while x < y:condition is False
5print(x, y)32 19⏎
B4.112Practice2 marks

Write the output of the following code.

x, y = 9, 30
while x < y:
    x = x * 2
    y = y - 1
print(x, y)
Answer

Output:

36 28

Working (step by step)

LineStatementValues after this stepPrinted
1x, y = 9, 30x = 9, y = 30
2while x < y:condition is True
3x = x * 2x = 18
4y = y - 1y = 29
2while x < y:condition is True
3x = x * 2x = 36
4y = y - 1y = 28
2while x < y:condition is False
5print(x, y)36 28⏎
B4.113Practice2 marks

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)
Answer

Output:

[6, 4, 4, 54, 3, 38]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [20, 14, 12, 27, 10, 19]L = [20, 14, 12, 27, 10, 19]
2for i in range(len(L)):i = 0
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 3L = [6, 14, 12, 27, 10, 19]
2for i in range(len(L)):i = 1
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 3L = [6, 4, 12, 27, 10, 19]
2for i in range(len(L)):i = 2
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 3L = [6, 4, 4, 27, 10, 19]
2for i in range(len(L)):i = 3
3if L[i] % 2 == 0:condition is False
6L[i] = L[i] * 2L = [6, 4, 4, 54, 10, 19]
2for i in range(len(L)):i = 4
3if L[i] % 2 == 0:condition is True
4L[i] = L[i] // 3L = [6, 4, 4, 54, 3, 19]

… the same steps continue for the remaining values.

B4.114Practice2 marks

Write the output of the following code.

for i in range(3, 0, -1):
    print("*" * i)
Answer

Output:

***
**
*

Working (step by step)

LineStatementValues after this stepPrinted
1for i in range(3, 0, -1):i = 3
2print("*" * i)***⏎
1for i in range(3, 0, -1):i = 2
2print("*" * i)**⏎
1for i in range(3, 0, -1):i = 1
2print("*" * i)*⏎
1for i in range(3, 0, -1):loop ends (no more values)
B4.115Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

L = [3, 6, 9]
L.insert(1)
print(L.sort())
Answer
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.

B4.116Practice2 marks

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)
Answer

Output:

e a b 44

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'e': 12, 'a': 15, 'b': 17, 'c': 1}D = {'e': 12, 'a': 15, 'b': 17, 'c': 1}
2total = 0total = 0
3for k in D:k = 'e'
4if D[k] > 10:condition is True
5total += D[k]total = 12
6print(k, end=" ")e
3for k in D:k = 'a'
4if D[k] > 10:condition is True
5total += D[k]total = 27
6print(k, end=" ")a
3for k in D:k = 'b'
4if D[k] > 10:condition is True
5total += D[k]total = 44
6print(k, end=" ")b
3for k in D:k = 'c'
4if D[k] > 10:condition is False
3for k in D:loop ends (no more values)
7print(total)44⏎
B4.117Practice2 marks

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)
Answer

Output:

(2, 3)
[1 4 8]
[[ 30 130  50]
 [ 10  40  80]]

Working (step by step)

LineStatementValues after this stepPrinted
2L = [[3, 13, 5], [1, 4, 8]]L = [[3, 13, 5], [1, 4, 8]]
3a = np.array(L)a = array([[ 3, 13, 5], [ 1, 4, 8]])
4print(a.shape)(2, 3)⏎
5print(a[1])[1 4 8]⏎
6print(a * 10)[[ 30 130 50]⏎ [ 10 40 80]]⏎
B4.118Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

D = {[1, 2]: 'a', 'b': 2}
print(D.items)
Answer
D = {(1, 2): 'a', 'b': 2}
print(D.items())

A list cannot be a key (it is mutable); use a tuple. items() needs brackets.

B4.119Practice2 marks

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)
Answer

Output:

20222

Working (step by step)

LineStatementValues after this stepPrinted
1n = 22202n = 22202
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 2
5s = s * 10 + ds = 2
6n = n // 10n = 2220
3while n > 0:condition is True
4d = n % 10d = 0
5s = s * 10 + ds = 20
6n = n // 10n = 222
3while n > 0:condition is True
4d = n % 10d = 2
5s = s * 10 + ds = 202
6n = n // 10n = 22
3while n > 0:condition is True
5s = s * 10 + ds = 2022

… the same steps continue for the remaining values.

B4.120Practice2 marks

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))
Answer

Output:

[9, 5, 3, 4, 7] 1

Working (step by step)

LineStatementValues after this stepPrinted
1L = [9, 5, 3, 4, 3, 7]L = [9, 5, 3, 4, 3, 7]
2S = []S = []
3for x in L:x = 9
4if x not in S:condition is True
5S.append(x)S = [9]
3for x in L:x = 5
4if x not in S:condition is True
5S.append(x)S = [9, 5]
3for x in L:x = 3
4if x not in S:condition is True
5S.append(x)S = [9, 5, 3]
3for x in L:x = 4
4if x not in S:condition is True
5S.append(x)S = [9, 5, 3, 4]
3for x in L:x = 3
4if x not in S:condition is False

… the same steps continue for the remaining values.

B4.121Practice2 marks

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)
Answer

Output:

(2, 3)
[14  2 11]
[[ 50  70 100]
 [140  20 110]]

Working (step by step)

LineStatementValues after this stepPrinted
2L = [[5, 7, 10], [14, 2, 11]]L = [[5, 7, 10], [14, 2, 11]]
3a = np.array(L)a = array([[ 5, 7, 10], [14, 2, 11]])
4print(a.shape)(2, 3)⏎
5print(a[1])[14 2 11]⏎
6print(a * 10)[[ 50 70 100]⏎ [140 20 110]]⏎
B4.122Practice2 marks

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)
Answer

Output:

e 15

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'c': 10, 'e': 15, 'b': 7, 'd': 2}D = {'c': 10, 'e': 15, 'b': 7, 'd': 2}
2total = 0total = 0
3for k in D:k = 'c'
4if D[k] > 12:condition is False
3for k in D:k = 'e'
4if D[k] > 12:condition is True
5total += D[k]total = 15
6print(k, end=" ")e
3for k in D:k = 'b'
4if D[k] > 12:condition is False
3for k in D:k = 'd'
4if D[k] > 12:condition is False
3for k in D:loop ends (no more values)
7print(total)15⏎
B4.123Practice2 marks

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)
Answer

Output:

91587

Working (step by step)

LineStatementValues after this stepPrinted
1n = 78519n = 78519
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 9
5s = s * 10 + ds = 9
6n = n // 10n = 7851
3while n > 0:condition is True
4d = n % 10d = 1
5s = s * 10 + ds = 91
6n = n // 10n = 785
3while n > 0:condition is True
4d = n % 10d = 5
5s = s * 10 + ds = 915
6n = n // 10n = 78
3while n > 0:condition is True
4d = n % 10d = 8

… the same steps continue for the remaining values.

B4.124Practice2 marks

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)
Answer

Output:

95358

Working (step by step)

LineStatementValues after this stepPrinted
1n = 85359n = 85359
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 9
5s = s * 10 + ds = 9
6n = n // 10n = 8535
3while n > 0:condition is True
4d = n % 10d = 5
5s = s * 10 + ds = 95
6n = n // 10n = 853
3while n > 0:condition is True
4d = n % 10d = 3
5s = s * 10 + ds = 953
6n = n // 10n = 85
3while n > 0:condition is True
4d = n % 10d = 5

… the same steps continue for the remaining values.

B4.125Practice2 marks

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)
Answer

Output:

[ 2  2 11 15  4]
[False False  True  True False]

Working (step by step)

LineStatementValues after this stepPrinted
2a = np.array([4, 5, 23, 31, 8])a = array([ 4, 5, 23, 31, 8])
3b = a // 2b = array([ 2, 2, 11, 15, 4])
4print(b)[ 2 2 11 15 4]⏎
5print(a > 10)[False False True True False]⏎
B4.126Practice2 marks

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)
Answer

Output:

[35 34 17 33 27]
5 1

Working (step by step)

LineStatementValues after this stepPrinted
2marks = [30, 29, 12, 28, 22]marks = [30, 29, 12, 28, 22]
3a = np.array(marks)a = array([30, 29, 12, 28, 22])
4print(a + 5)[35 34 17 33 27]⏎
5print(a.size, a.ndim)5 1⏎
B4.127Practice2 marks

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)
Answer

Output:

[52, 3, 54, 38, 46, 34]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [26, 10, 27, 19, 23, 17]L = [26, 10, 27, 19, 23, 17]
2for i in range(len(L)):i = 0
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [52, 10, 27, 19, 23, 17]
2for i in range(len(L)):i = 1
3if L[i] % 5 == 0:condition is True
4L[i] = L[i] // 3L = [52, 3, 27, 19, 23, 17]
2for i in range(len(L)):i = 2
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [52, 3, 54, 19, 23, 17]
2for i in range(len(L)):i = 3
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [52, 3, 54, 38, 23, 17]
2for i in range(len(L)):i = 4
3if L[i] % 5 == 0:condition is False
6L[i] = L[i] * 2L = [52, 3, 54, 38, 46, 17]

… the same steps continue for the remaining values.

B4.128Practice2 marks

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)
Answer

Output:

{5: 2, 2: 2, 1: 1, 4: 1}

Working (step by step)

LineStatementValues after this stepPrinted
1L = [5, 2, 1, 2, 5, 4]L = [5, 2, 1, 2, 5, 4]
2F = {}F = {}
3for x in L:x = 5
4F[x] = F.get(x, 0) + 1F = {5: 1}
3for x in L:x = 2
4F[x] = F.get(x, 0) + 1F = {5: 1, 2: 1}
3for x in L:x = 1
4F[x] = F.get(x, 0) + 1F = {5: 1, 2: 1, 1: 1}
3for x in L:x = 2
4F[x] = F.get(x, 0) + 1F = {5: 1, 2: 2, 1: 1}
3for x in L:x = 5
4F[x] = F.get(x, 0) + 1F = {5: 2, 2: 2, 1: 1}
3for x in L:x = 4
4F[x] = F.get(x, 0) + 1F = {5: 2, 2: 2, 1: 1, 4: 1}
3for x in L:loop ends (no more values)
5print(F){5: 2, 2: 2, 1: 1, 4: 1}⏎
B4.129Practice2 marks

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)
Answer

Output:

c 11

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'c': 11, 'a': 2, 'b': 9, 'e': 3}D = {'c': 11, 'a': 2, 'b': 9, 'e': 3}
2total = 0total = 0
3for k in D:k = 'c'
4if D[k] > 10:condition is True
5total += D[k]total = 11
6print(k, end=" ")c
3for k in D:k = 'a'
4if D[k] > 10:condition is False
3for k in D:k = 'b'
4if D[k] > 10:condition is False
3for k in D:k = 'e'
4if D[k] > 10:condition is False
3for k in D:loop ends (no more values)
7print(total)11⏎
B4.130Practice2 marks

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)
Answer

Output:

e d a c 51

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'e': 9, 'd': 11, 'a': 16, 'c': 15}D = {'e': 9, 'd': 11, 'a': 16, 'c': 15}
2total = 0total = 0
3for k in D:k = 'e'
4if D[k] > 7:condition is True
5total += D[k]total = 9
6print(k, end=" ")e
3for k in D:k = 'd'
4if D[k] > 7:condition is True
5total += D[k]total = 20
6print(k, end=" ")d
3for k in D:k = 'a'
4if D[k] > 7:condition is True
5total += D[k]total = 36
6print(k, end=" ")a
3for k in D:k = 'c'
4if D[k] > 7:condition is True

… the same steps continue for the remaining values.

B4.131Practice2 marks

Write the output of the following code.

x, y = 4, 25
while x < y:
    x = x * 2
    y = y - 1
print(x, y)
Answer

Output:

32 22

Working (step by step)

LineStatementValues after this stepPrinted
1x, y = 4, 25x = 4, y = 25
2while x < y:condition is True
3x = x * 2x = 8
4y = y - 1y = 24
2while x < y:condition is True
3x = x * 2x = 16
4y = y - 1y = 23
2while x < y:condition is True
3x = x * 2x = 32
4y = y - 1y = 22
2while x < y:condition is False
5print(x, y)32 22⏎
B4.132Practice2 marks

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])
Answer
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.

B4.133Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

x = 10
y = 0
if y != 0:
    print(x / y)
Else:
    print('Cannot divide')
Answer
x = 10
y = 0
if y != 0:
    print(x / y)
else:
    print('Cannot divide')

Python is case sensitive: the keyword is else.

B4.134Practice2 marks

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()
Answer
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.

B4.135Practice2 marks

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)
Answer

Output:

15

Working (step by step)

LineStatementValues after this stepPrinted
1a = 5a = 5
2b = 20b = 20
3if a % 2 == 0 and b % 2 == 0:condition is False
5elif a % 2 == 0 or b > 20:condition is False
8print(b - a)15⏎
B4.136Practice2 marks

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)
Answer

Output:

[22, 4, 56, 3, 16, 28]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [11, 2, 28, 6, 8, 14]L = [11, 2, 28, 6, 8, 14]
2for i in range(len(L)):i = 0
3if L[i] % 3 == 0:condition is False
6L[i] = L[i] * 2L = [22, 2, 28, 6, 8, 14]
2for i in range(len(L)):i = 1
3if L[i] % 3 == 0:condition is False
6L[i] = L[i] * 2L = [22, 4, 28, 6, 8, 14]
2for i in range(len(L)):i = 2
3if L[i] % 3 == 0:condition is False
6L[i] = L[i] * 2L = [22, 4, 56, 6, 8, 14]
2for i in range(len(L)):i = 3
3if L[i] % 3 == 0:condition is True
4L[i] = L[i] // 2L = [22, 4, 56, 3, 8, 14]
2for i in range(len(L)):i = 4
3if L[i] % 3 == 0:condition is False
6L[i] = L[i] * 2L = [22, 4, 56, 3, 16, 14]

… the same steps continue for the remaining values.

B4.137Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

t = (10, 20, 30)
a, b = t
print(a + b)
Answer
t = (10, 20, 30)
a, b, c = t
print(a + b)

The number of variables must match the number of values when unpacking.

B4.138Practice2 marks

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)
Answer

Output:

8

Working (step by step)

LineStatementValues after this stepPrinted
1n = 65299n = 65299
2s = 0s = 0
3while n > 0:condition is True
4d = n % 10d = 9
5if d % 2 == 0:condition is False
7n = n // 10n = 6529
3while n > 0:condition is True
5if d % 2 == 0:condition is False
7n = n // 10n = 652
3while n > 0:condition is True
4d = n % 10d = 2
5if d % 2 == 0:condition is True
6s = s + ds = 2
7n = n // 10n = 65
3while n > 0:condition is True
4d = n % 10d = 5

… the same steps continue for the remaining values.

B4.139Practice2 marks

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)
Answer

Output:

e a c 40

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'e': 13, 'a': 18, 'c': 9, 'b': 2}D = {'e': 13, 'a': 18, 'c': 9, 'b': 2}
2total = 0total = 0
3for k in D:k = 'e'
4if D[k] > 6:condition is True
5total += D[k]total = 13
6print(k, end=" ")e
3for k in D:k = 'a'
4if D[k] > 6:condition is True
5total += D[k]total = 31
6print(k, end=" ")a
3for k in D:k = 'c'
4if D[k] > 6:condition is True
5total += D[k]total = 40
6print(k, end=" ")c
3for k in D:k = 'b'
4if D[k] > 6:condition is False
3for k in D:loop ends (no more values)
7print(total)40⏎
B4.140Practice2 marks

Write the output of the following code.

for i in range(1, 4):
    print(" " * (3 - i) + "#" * i)
Answer

Output:

  #
 ##
###

Working (step by step)

LineStatementValues after this stepPrinted
1for i in range(1, 4):i = 1
2print(" " * (3 - i) + "#" * i) #⏎
1for i in range(1, 4):i = 2
2print(" " * (3 - i) + "#" * i) ##⏎
1for i in range(1, 4):i = 3
2print(" " * (3 - i) + "#" * i)###⏎
1for i in range(1, 4):loop ends (no more values)
B4.141Practice2 marks

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)
Answer

Output:

{5: 1, 2: 1, 8: 3, 7: 1}

Working (step by step)

LineStatementValues after this stepPrinted
1L = [5, 2, 8, 8, 8, 7]L = [5, 2, 8, 8, 8, 7]
2F = {}F = {}
3for x in L:x = 5
4F[x] = F.get(x, 0) + 1F = {5: 1}
3for x in L:x = 2
4F[x] = F.get(x, 0) + 1F = {5: 1, 2: 1}
3for x in L:x = 8
4F[x] = F.get(x, 0) + 1F = {5: 1, 2: 1, 8: 1}
3for x in L:loop ends (no more values)
4F[x] = F.get(x, 0) + 1F = {5: 1, 2: 1, 8: 2}
3for x in L:loop ends (no more values)
4F[x] = F.get(x, 0) + 1F = {5: 1, 2: 1, 8: 3}
3for x in L:x = 7
4F[x] = F.get(x, 0) + 1F = {5: 1, 2: 1, 8: 3, 7: 1}
3for x in L:loop ends (no more values)
5print(F){5: 1, 2: 1, 8: 3, 7: 1}⏎
B4.142Practice2 marks

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)
Answer

Output:

[12 38 29 32 41]
5 1

Working (step by step)

LineStatementValues after this stepPrinted
2marks = [7, 33, 24, 27, 36]marks = [7, 33, 24, 27, 36]
3a = np.array(marks)a = array([ 7, 33, 24, 27, 36])
4print(a + 5)[12 38 29 32 41]⏎
5print(a.size, a.ndim)5 1⏎
B4.143Practice2 marks

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)
Answer

Output:

c 13

Working (step by step)

LineStatementValues after this stepPrinted
1D = {'b': 4, 'e': 3, 'd': 7, 'c': 13}D = {'b': 4, 'e': 3, 'd': 7, 'c': 13}
2total = 0total = 0
3for k in D:k = 'b'
4if D[k] > 8:condition is False
3for k in D:k = 'e'
4if D[k] > 8:condition is False
3for k in D:k = 'd'
4if D[k] > 8:condition is False
3for k in D:k = 'c'
4if D[k] > 8:condition is True
5total += D[k]total = 13
6print(k, end=" ")c
3for k in D:loop ends (no more values)
7print(total)13⏎
B4.144Practice2 marks

Rewrite the code after removing the errors. Underline each correction.

1st_num = 10
second num = 20
print(1st_num + second num)
Answer
num1 = 10
second_num = 20
print(num1 + second_num)

An identifier cannot start with a digit or have a space.

B5Database concepts and SQL commands2 marks · 40 questions
B5.1Practice2 marks

What is a database? Why is a DBMS better than a file system?

Answer

An organised collection of related data. A DBMS reduces redundancy and inconsistency, allows sharing, gives security and makes searching easy.

B5.2Practice2 marks

What is a DBMS? Give two examples.

Answer

Software to create, store, manage and retrieve data in a database. Examples: MySQL, Oracle, MS Access, PostgreSQL, SQL Server.

B5.3Practice2 marks

Define:

  1. Relation
  2. Tuple.
Answer

(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.

B5.4Practice2 marks

Define degree and cardinality with an example.

Answer

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.

B5.5Practice2 marks

What is a domain? Give an example.

Answer

The set of all valid values of an attribute. The domain of Gender may be {M, F}; of Marks, whole numbers 0 to 100.

B5.6Practice2 marks

Differentiate between a primary key and a candidate key.

Answer

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.

B5.7Practice2 marks

What is an alternate key? Give an example.

Answer

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.

B5.8Practice2 marks

What is data redundancy? Why is it a problem?

Answer

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.

B5.9Practice2 marks

Differentiate between schema and instance of a database.

Answer

Schema is the design: table names, columns and types; it rarely changes. Instance is the actual data stored at a moment; it changes often.

B5.10Practice2 marks

What are the limitations of a file system?

Answer

Data redundancy, data inconsistency, difficulty in accessing data, data isolation, poor security and no control over sharing.

B5.11Practice2 marks

What is SQL? Write two of its advantages.

Answer

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.

B5.12Practice2 marks

Differentiate between DDL and DML with two commands each.

Answer

DDL defines or changes the structure of tables: CREATE, ALTER, DROP. DML changes the data in tables: INSERT, UPDATE, DELETE.

B5.13Practice2 marks

Differentiate between CHAR and VARCHAR.

Answer

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.

B5.14Practice2 marks

Differentiate between DELETE and DROP.

Answer

DELETE (DML) removes rows from a table; the structure remains. DROP (DDL) removes the whole table, structure and data, from the database.

B5.15Practice2 marks

Differentiate between ALTER and UPDATE.

Answer

ALTER (DDL) changes the structure of a table, such as adding a column. UPDATE (DML) changes the values stored in rows.

B5.16Practice2 marks

What is a constraint? Name any three.

Answer

A rule applied on a column to keep the data valid. NOT NULL, UNIQUE, PRIMARY KEY, DEFAULT. (Any three.)

B5.17Practice2 marks

What is NULL? How do we search for NULL values?

Answer

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.

B5.18Practice2 marks

Write the use of the BETWEEN operator with an example.

Answer

It selects values in a range, both ends included. SELECT * FROM STUDENT WHERE Marks BETWEEN 60 AND 80;

B5.19Practice2 marks

Write the commands to:

  1. Create a database SCHOOL
  2. Open it.
Answer

(i) CREATE DATABASE SCHOOL; (ii) USE SCHOOL;

B5.20Practice2 marks

Write the commands to:

  1. See all the databases
  2. See all the tables of the open database.
Answer

(i) SHOW DATABASES; (ii) SHOW TABLES;

B5.21Practice2 marks

Write the command to add a column Email VARCHAR(40) to the table STUDENT, and to remove it again.

Answer
ALTER TABLE STUDENT ADD Email VARCHAR(40);
ALTER TABLE STUDENT DROP Email;
B5.22Practice2 marks

Write the command to make RollNo the primary key of an existing table STUDENT, and to remove the primary key.

Answer
ALTER TABLE STUDENT ADD PRIMARY KEY (RollNo);
ALTER TABLE STUDENT DROP PRIMARY KEY;
B5.23Practice2 marks

What is the use of the DESCRIBE command? Write its syntax.

Answer

It shows the structure of a table: column names, types, NULL allowed, keys. Syntax: DESCRIBE STUDENT; or DESC STUDENT;

B5.24Practice2 marks

Differentiate between the AND and OR operators in SQL.

Answer

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';

B5.25Practice2 marks

Why is a primary key important? What happens if we insert a duplicate value in it?

Answer

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.

B5.26Practice2 marks

Write any four data types of MySQL with their use.

Answer

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.)

B5.27Practice2 marks

What is the difference between the = and IS operators in SQL?

Answer

= 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 =.

B5.28Practice2 marks

What is MySQL? Write two of its features.

Answer

A free, open-source relational DBMS that uses SQL. Features: free and open source, fast, works on many platforms, supports many users, secure.

B5.29Practice2 marks

Explain the use of the logical operator NOT with an example.

Answer

NOT reverses a condition. SELECT * FROM EMP WHERE NOT Dept = 'Sales'; shows employees of all departments other than Sales.

B5.30Practice2 marks

Write the general syntax of the SELECT command with WHERE.

Answer
SELECT column1, column2, ... FROM table_name WHERE condition;
B5.31Practice2 marks

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?

Answer

At first: degree 4, cardinality 12. After the changes: degree 5, cardinality 15.

B5.32Practice2 marks

Can a table have no primary key? Is it a good idea?

Answer

Yes, MySQL allows it, but it is not a good idea: duplicate rows may be entered and rows cannot be identified uniquely.

B5.33Practice2 marks

Give two examples of real-life databases.

Answer

School records of students, bank account records, railway reservations, library catalogue, hospital patient records. (Any two.)

B5.34Practice2 marks

What is data inconsistency? Give an example.

Answer

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.

B5.35Practice2 marks

Why is Aadhaar number a candidate key in a table of citizens?

Answer

Because every citizen has a unique Aadhaar number, so it can identify each row uniquely.

B5.36Practice2 marks

What is the difference between DDL and DQL?

Answer

DDL commands (CREATE, ALTER, DROP) define the structure of the database. DQL (SELECT) only reads and displays data.

B5.37Practice2 marks

Write the output of: SELECT 5 * 4 + 3; and SELECT 17 > 10;

Answer

23 and 1 (MySQL shows a true condition as 1).

B5.38Practice2 marks

Write two rules for writing SQL statements.

Answer

Each statement ends with a semicolon; text and dates are written in single quotes; keywords are not case sensitive; commas separate the column names.

B5.39Practice2 marks

Write a command to insert a row (101, 'Asha', 'XI', 92) into STUDENT(RollNo, Name, Class, Marks).

Answer
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.

B5.40Practice2 marks

Write a command to change the marks of roll number 101 to 95 in STUDENT.

Answer
UPDATE STUDENT SET Marks = 95 WHERE RollNo = 101;
B6Write SQL queries on a table2 marks · 110 questions
B6.1Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PCode, PName and Price of the products whose Price is between 300 and 400.
  2. Display PName of the products whose Discount is not known (NULL).
Answer

(i)

SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 300 AND 400;
PCodePNamePrice
P05Water Bottle320

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 =.)

B6.2Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EName and Dept of the employees whose Dept is IT or Sales.
  2. Display EName of the employees whose Dept is HR and Salary is at least 60000.
Answer

(i)

SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'IT' OR Dept = 'Sales';
ENameDept
RaviSales
TarunIT
UshaSales
VikasIT
YaminiIT

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.

B6.3Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display RollNo, Name and Marks of the students whose Marks is between 60 and 70.
  2. Display Name and Section of the students whose Section is B or A.
Answer

(i)

SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 60 AND 70;
RollNoNameMarks
4Divya66

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';
NameSection
AaravA
BhavyaB
ChiragA
EshanB
FarahA

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.

B6.4Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName and Price of the products whose Price is less than 100 or whose Discount is NULL.
  2. Display PCode, Price and Price increased by 10 for every product.
Answer

(i)

SELECT PName, Price FROM PRODUCT WHERE Price < 100 OR Discount IS NULL;
PNamePrice
Notebook60
Pen Drive450
Water Bottle320

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;
PCodePricePrice + 10
P016070
P02450460
P03180190
P04650660
P05320330
P06899909
P07275285

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.

B6.5Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display RollNo, Marks and Marks increased by 10 for every student.
  2. Display Name and Section of the students whose Section is B or C.
Answer

(i)

SELECT RollNo, Marks, Marks + 10 FROM STUDENT;
RollNoMarksMarks + 10
17888
292102
34555
46676
58898
63141
75969

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';
NameSection
BhavyaB
DivyaC
EshanB
GauravC

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.

B6.6Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName and Category of the products whose Category is Electronics or Stationery.
  2. Display PName and Price of all the products whose Price is more than 400.
Answer

(i)

SELECT PName, Category FROM PRODUCT WHERE Category = 'Electronics' OR Category = 'Stationery';
PNameCategory
NotebookStationery
Pen DriveElectronics
Geometry BoxStationery
MouseElectronics
EarphonesElectronics

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;
PNamePrice
Pen Drive450
Mouse650
Earphones899

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.

B6.7Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName and Fee of the patients whose Fee is less than 1500 or whose Insurance is NULL.
  2. Display PName of the patients whose Doctor is Dr. Iyer and Insurance is not NULL.
Answer

(i)

SELECT PName, Fee FROM PATIENT WHERE Fee < 1500 OR Insurance IS NULL;
PNameFee
Nisha8000
Om1200
Qasim9500
Rekha4500
Sahil900

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 =.)

B6.8Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title and Member of the books whose Member is not NULL.
  2. Display Title and Price of all the books whose Price is more than 200.
Answer

(i)

SELECT Title, Member FROM BOOK WHERE Member IS NOT NULL;
TitleMember
Informatics PracticesAsha
Wings of FireRavi
Chemistry Part 1Neha
Learn SQLKaran

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;
TitlePrice
Informatics Practices210
Wings of Fire299
Python Basics350
The Story of My Experiments250
Learn SQL400

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.

B6.9Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PID, Fee and Fee increased by 10 for every patient.
  2. Display PID, PName and Fee of the patients whose Fee is between 4000 and 6000.
Answer

(i)

SELECT PID, Fee, Fee + 10 FROM PATIENT;
PIDFeeFee + 10
1115001510
1280008010
1312001210
1450005010
1595009510
1645004510
17900910

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;
PIDPNameFee
14Pooja5000
16Rekha4500

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.

B6.10Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EName and DOJ of the employees whose DOJ is between '2018-01-01' and '2020-12-31'.
  2. Display EName of the employees whose City is Mumbai and Bonus is not NULL.
Answer

(i)

SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';
ENameDOJ
Ravi2018-06-01
Seema2020-01-15
Vikas2019-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 =.)

B6.11Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName and Fee of all the patients whose Fee is more than 4000.
  2. Display PName of the patients whose Doctor is Dr. Sen and Insurance is not NULL.
Answer

(i)

SELECT PName, Fee FROM PATIENT WHERE Fee > 4000;
PNameFee
Nisha8000
Pooja5000
Qasim9500
Rekha4500

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 =.)

B6.12Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PCode, PName and Price of the products whose Price is between 100 and 300.
  2. Display PName and Price of all the products whose Price is more than 400.
Answer

(i)

SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 100 AND 300;
PCodePNamePrice
P03Geometry Box180
P07Lunch Box275

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;
PNamePrice
Pen Drive450
Mouse650
Earphones899

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.

B6.13Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName and Price of the products whose Price is less than 300 or whose Discount is NULL.
  2. Display PName and Discount of the products whose Discount is not NULL.
Answer

(i)

SELECT PName, Price FROM PRODUCT WHERE Price < 300 OR Discount IS NULL;
PNamePrice
Notebook60
Pen Drive450
Geometry Box180
Water Bottle320
Lunch Box275

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;
PNameDiscount
Notebook5
Geometry Box10
Mouse15
Earphones20
Lunch Box8

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 =.)

B6.14Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name and Phone of the students whose Phone is not NULL.
  2. Display Name of the students whose Gender is M and Phone is not NULL.
Answer

(i)

SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
NamePhone
Aarav9810011111
Chirag9810033333
Divya9810044444
Farah9810066666
Gaurav9810077777

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 =.)

B6.15Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName and Ward of the patients whose Ward is not General.
  2. Display PName of the patients whose Insurance is not known (NULL).
Answer

(i)

SELECT PName, Ward FROM PATIENT WHERE NOT Ward = 'General';
PNameWard
NishaICU
PoojaMaternity
QasimICU
RekhaMaternity

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 =.)

B6.16Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName and AdmitDate of the patients whose AdmitDate is between '2026-09-05' and '2026-09-15'.
  2. Display PName and Insurance of the patients whose Insurance is not NULL.
Answer

(i)

SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
PNameAdmitDate
Nisha2026-09-05
Om2026-09-10
Pooja2026-09-12
Qasim2026-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;
PNameInsurance
MohanLIC
OmStar
PoojaLIC
SahilStar

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 =.)

B6.17Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title and Price of all the books whose Price is more than 300.
  2. Display Title and Price of the books whose Price is less than 300 or whose Member is NULL.
Answer

(i)

SELECT Title, Price FROM BOOK WHERE Price > 300;
TitlePrice
Python Basics350
Learn SQL400

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;
TitlePrice
Informatics Practices210
Physics Part 1180
Wings of Fire299
Python Basics350
Chemistry Part 1190
The Story of My Experiments250

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 =.)

B6.18Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName and AdmitDate of the patients whose AdmitDate is between '2026-09-05' and '2026-09-15'.
  2. Display PName and Ward of the patients whose Ward is General or Maternity.
Answer

(i)

SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
PNameAdmitDate
Nisha2026-09-05
Om2026-09-10
Pooja2026-09-12
Qasim2026-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';
PNameWard
MohanGeneral
OmGeneral
PoojaMaternity
RekhaMaternity
SahilGeneral

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.

B6.19Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name of the students whose Section is C and Marks is at least 50.
  2. Display Name and Section of the students whose Section is A or B.
Answer

(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';
NameSection
AaravA
BhavyaB
ChiragA
EshanB
FarahA

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.

B6.20Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name and DOB of the students whose DOB is between '2009-06-01' and '2009-12-31'.
  2. Display Name of the students whose Phone is not known (NULL).
Answer

(i)

SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
NameDOB
Bhavya2009-11-30
Divya2009-07-21
Farah2009-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 =.)

B6.21Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName and Ward of the patients whose Ward is not Maternity.
  2. Display PName and Fee of the patients whose Fee is less than 1500 or whose Insurance is NULL.
Answer

(i)

SELECT PName, Ward FROM PATIENT WHERE NOT Ward = 'Maternity';
PNameWard
MohanGeneral
NishaICU
OmGeneral
QasimICU
SahilGeneral

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;
PNameFee
Nisha8000
Om1200
Qasim9500
Rekha4500
Sahil900

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 =.)

B6.22Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName of the products whose Discount is not known (NULL).
  2. Display PName of the products whose Brand is Boat and Discount is not NULL.
Answer

(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 =.)

B6.23Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EName and Dept of the employees whose Dept is IT or HR.
  2. Display EName and DOJ of the employees whose DOJ is between '2018-01-01' and '2020-12-31'.
Answer

(i)

SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'IT' OR Dept = 'HR';
ENameDept
SeemaHR
TarunIT
VikasIT
WasimHR
YaminiIT

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';
ENameDOJ
Ravi2018-06-01
Seema2020-01-15
Vikas2019-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.

B6.24Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name and Gender of the students whose Gender is not M.
  2. Display Name and DOB of the students whose DOB is between '2009-06-01' and '2009-12-31'.
Answer

(i)

SELECT Name, Gender FROM STUDENT WHERE Gender <> 'M';
NameGender
BhavyaF
DivyaF
FarahF

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';
NameDOB
Bhavya2009-11-30
Divya2009-07-21
Farah2009-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.

B6.25Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EName and DOJ of the employees whose DOJ is between '2018-01-01' and '2020-12-31'.
  2. Display EName and City of the employees whose City is not Delhi.
Answer

(i)

SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';
ENameDOJ
Ravi2018-06-01
Seema2020-01-15
Vikas2019-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';
ENameCity
SeemaPune
UshaMumbai
VikasPune
YaminiMumbai

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.

B6.26Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName and Doctor of the patients whose Doctor is not Dr. Sen.
  2. Display PID, PName and Fee of the patients whose Fee is between 1500 and 4000.
Answer

(i)

SELECT PName, Doctor FROM PATIENT WHERE Doctor <> 'Dr. Sen';
PNameDoctor
MohanDr. Rao
OmDr. Rao
PoojaDr. Iyer
RekhaDr. Iyer
SahilDr. 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;
PIDPNameFee
11Mohan1500

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.

B6.27Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name of the students whose Gender is M and Phone is not NULL.
  2. Display all the details of the students whose Section is B.
Answer

(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';
RollNoAdmNoNameSectionGenderDOBMarksPhone
24512BhavyaBF2009-11-3092NULL
54545EshanBM2010-03-1788NULL

Explanation: WHERE keeps only the rows where Section is 'B': 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows all the columns (*).

B6.28Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName and Discount of the products whose Discount is not NULL.
  2. Display PName and Price of the products whose Price is less than 300 or whose Discount is NULL.
Answer

(i)

SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
PNameDiscount
Notebook5
Geometry Box10
Mouse15
Earphones20
Lunch Box8

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;
PNamePrice
Notebook60
Pen Drive450
Geometry Box180
Water Bottle320
Lunch Box275

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 =.)

B6.29Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display all the details of the students whose Section is C.
  2. Display Name and Section of the students whose Section is not C.
Answer

(i)

SELECT * FROM STUDENT WHERE Section = 'C';
RollNoAdmNoNameSectionGenderDOBMarksPhone
44534DivyaCF2009-07-21669810044444
74567GauravCM2010-02-28599810077777

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';
NameSection
AaravA
BhavyaB
ChiragA
EshanB
FarahA

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.

B6.30Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name and Section of the students whose Section is B or C.
  2. Display Name and Section of the students whose Section is not B.
Answer

(i)

SELECT Name, Section FROM STUDENT WHERE Section = 'B' OR Section = 'C';
NameSection
BhavyaB
DivyaC
EshanB
GauravC

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';
NameSection
AaravA
ChiragA
DivyaC
FarahA
GauravC

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.

B6.31Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title of the books whose Subject is Biography and Price is at least 200.
  2. Display Title and IssueDate of the books whose IssueDate is between '2026-07-01' and '2026-07-31'.
Answer

(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';
TitleIssueDate
Informatics Practices2026-07-03
Physics Part 12026-07-10
Chemistry Part 12026-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.

B6.32Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title and Subject of the books whose Subject is Computer or Biography.
  2. Display all the details of the books whose Subject is Science.
Answer

(i)

SELECT Title, Subject FROM BOOK WHERE Subject = 'Computer' OR Subject = 'Biography';
TitleSubject
Informatics PracticesComputer
Wings of FireBiography
Python BasicsComputer
The Story of My ExperimentsBiography
Learn SQLComputer

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';
BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha

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 (*).

B6.33Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName and Discount of the products whose Discount is not NULL.
  2. Display PCode, Price and Price increased by 10 for every product.
Answer

(i)

SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
PNameDiscount
Notebook5
Geometry Box10
Mouse15
Earphones20
Lunch Box8

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;
PCodePricePrice + 10
P016070
P02450460
P03180190
P04650660
P05320330
P06899909
P07275285

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.

B6.34Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display RollNo, Marks and Marks increased by 10 for every student.
  2. Display Name and DOB of the students whose DOB is between '2009-06-01' and '2009-12-31'.
Answer

(i)

SELECT RollNo, Marks, Marks + 10 FROM STUDENT;
RollNoMarksMarks + 10
17888
292102
34555
46676
58898
63141
75969

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';
NameDOB
Bhavya2009-11-30
Divya2009-07-21
Farah2009-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.

B6.35Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName of the patients whose Doctor is Dr. Sen and Insurance is not NULL.
  2. Display PName and AdmitDate of the patients whose AdmitDate is between '2026-09-05' and '2026-09-15'.
Answer

(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';
PNameAdmitDate
Nisha2026-09-05
Om2026-09-10
Pooja2026-09-12
Qasim2026-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.

B6.36Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name and Phone of the students whose Phone is not NULL.
  2. Display Name of the students whose Phone is not known (NULL).
Answer

(i)

SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
NamePhone
Aarav9810011111
Chirag9810033333
Divya9810044444
Farah9810066666
Gaurav9810077777

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 =.)

B6.37Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName and Doctor of the patients whose Doctor is not Dr. Sen.
  2. Display PName and Ward of the patients whose Ward is not ICU.
Answer

(i)

SELECT PName, Doctor FROM PATIENT WHERE Doctor <> 'Dr. Sen';
PNameDoctor
MohanDr. Rao
OmDr. Rao
PoojaDr. Iyer
RekhaDr. Iyer
SahilDr. 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';
PNameWard
MohanGeneral
OmGeneral
PoojaMaternity
RekhaMaternity
SahilGeneral

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.

B6.38Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EName of the employees whose Bonus is not known (NULL).
  2. Display EName and Dept of the employees whose Dept is not IT.
Answer

(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';
ENameDept
RaviSales
SeemaHR
UshaSales
WasimHR

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.

B6.39Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName of the patients whose Ward is ICU and Fee is at least 4000.
  2. Display PID, PName and Fee of the patients whose Fee is between 1500 and 4000.
Answer

(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;
PIDPNameFee
11Mohan1500

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.

B6.40Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName and Insurance of the patients whose Insurance is not NULL.
  2. Display PName and Fee of all the patients whose Fee is more than 6000.
Answer

(i)

SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
PNameInsurance
MohanLIC
OmStar
PoojaLIC
SahilStar

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;
PNameFee
Nisha8000
Qasim9500

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.

B6.41Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EName and Dept of the employees whose Dept is not Sales.
  2. Display EName and Bonus of the employees whose Bonus is not NULL.
Answer

(i)

SELECT EName, Dept FROM EMPLOYEE WHERE NOT Dept = 'Sales';
ENameDept
SeemaHR
TarunIT
VikasIT
WasimHR
YaminiIT

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;
ENameBonus
Ravi3000
Tarun5000
Vikas4000
Wasim2000

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 =.)

B6.42Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName of the products whose Category is Home and Price is at least 300.
  2. Display PName and Discount of the products whose Discount is not NULL.
Answer

(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;
PNameDiscount
Notebook5
Geometry Box10
Mouse15
Earphones20
Lunch Box8

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 =.)

B6.43Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display BookID, Price and Price increased by 10 for every book.
  2. Display BookID, Title and Price of the books whose Price is between 200 and 300.
Answer

(i)

SELECT BookID, Price, Price + 10 FROM BOOK;
BookIDPricePrice + 10
201210220
202180190
203299309
204350360
205190200
206250260
207400410

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;
BookIDTitlePrice
201Informatics Practices210
203Wings of Fire299
206The Story of My Experiments250

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.

B6.44Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName and Category of the products whose Category is not Stationery.
  2. Display PName and MfgDate of the products whose MfgDate is between '2025-10-01' and '2026-01-31'.
Answer

(i)

SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Stationery';
PNameCategory
Pen DriveElectronics
MouseElectronics
Water BottleHome
EarphonesElectronics
Lunch BoxHome

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';
PNameMfgDate
Notebook2026-01-10
Geometry Box2025-11-02
Lunch Box2025-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.

B6.45Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName and Category of the products whose Category is not Stationery.
  2. Display PCode, Price and Price increased by 10 for every product.
Answer

(i)

SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Stationery';
PNameCategory
Pen DriveElectronics
MouseElectronics
Water BottleHome
EarphonesElectronics
Lunch BoxHome

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;
PCodePricePrice + 10
P016070
P02450460
P03180190
P04650660
P05320330
P06899909
P07275285

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.

B6.46Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title and Price of the books whose Price is less than 200 or whose Member is NULL.
  2. Display Title of the books whose Publisher is BPB and Member is not NULL.
Answer

(i)

SELECT Title, Price FROM BOOK WHERE Price < 200 OR Member IS NULL;
TitlePrice
Physics Part 1180
Python Basics350
Chemistry Part 1190
The Story of My Experiments250

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 =.)

B6.47Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name and Marks of the students whose Marks is less than 60 or whose Phone is NULL.
  2. Display Name and Section of the students whose Section is not C.
Answer

(i)

SELECT Name, Marks FROM STUDENT WHERE Marks < 60 OR Phone IS NULL;
NameMarks
Bhavya92
Chirag45
Eshan88
Farah31
Gaurav59

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';
NameSection
AaravA
BhavyaB
ChiragA
EshanB
FarahA

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.

B6.48Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title of the books whose Member is not known (NULL).
  2. Display Title and Publisher of the books whose Publisher is not NCERT.
Answer

(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';
TitlePublisher
Wings of FireUniversities
Python BasicsBPB
The Story of My ExperimentsPenguin
Learn SQLBPB

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.

B6.49Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EmpID, Salary and Salary increased by 10 for every employee.
  2. Display EName and DOJ of the employees whose DOJ is between '2018-01-01' and '2020-12-31'.
Answer

(i)

SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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';
ENameDOJ
Ravi2018-06-01
Seema2020-01-15
Vikas2019-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.

B6.50Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PID, Fee and Fee increased by 10 for every patient.
  2. Display PName of the patients whose Insurance is not known (NULL).
Answer

(i)

SELECT PID, Fee, Fee + 10 FROM PATIENT;
PIDFeeFee + 10
1115001510
1280008010
1312001210
1450005010
1595009510
1645004510
17900910

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 =.)

B6.51Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName and Fee of the patients whose Fee is less than 4000 or whose Insurance is NULL.
  2. Display PName and Insurance of the patients whose Insurance is not NULL.
Answer

(i)

SELECT PName, Fee FROM PATIENT WHERE Fee < 4000 OR Insurance IS NULL;
PNameFee
Mohan1500
Nisha8000
Om1200
Qasim9500
Rekha4500
Sahil900

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;
PNameInsurance
MohanLIC
OmStar
PoojaLIC
SahilStar

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 =.)

B6.52Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name and Phone of the students whose Phone is not NULL.
  2. Display Name and Section of the students whose Section is B or A.
Answer

(i)

SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
NamePhone
Aarav9810011111
Chirag9810033333
Divya9810044444
Farah9810066666
Gaurav9810077777

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';
NameSection
AaravA
BhavyaB
ChiragA
EshanB
FarahA

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.

B6.53Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EmpID, EName and Salary of the employees whose Salary is between 40000 and 70000.
  2. Display EName of the employees whose Bonus is not known (NULL).
Answer

(i)

SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 70000;
EmpIDENameSalary
E101Ravi42000
E102Seema58000
E105Vikas64000

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 =.)

B6.54Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName of the products whose Brand is Milton and Discount is not NULL.
  2. Display all the details of the products whose Category is Electronics.
Answer

(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';
PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0489010044MouseElectronicsLogitech2026-02-2065015
P0689010066EarphonesElectronicsBoat2026-03-0589920

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 (*).

B6.55Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display BookID, Price and Price increased by 10 for every book.
  2. Display all the details of the books whose Subject is Biography.
Answer

(i)

SELECT BookID, Price, Price + 10 FROM BOOK;
BookIDPricePrice + 10
201210220
202180190
203299309
204350360
205190200
206250260
207400410

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';
BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL

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 (*).

B6.56Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName of the products whose Discount is not known (NULL).
  2. Display PCode, Price and Price increased by 10 for every product.
Answer

(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;
PCodePricePrice + 10
P016070
P02450460
P03180190
P04650660
P05320330
P06899909
P07275285

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.

B6.57Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EName of the employees whose City is Pune and Bonus is not NULL.
  2. Display all the details of the employees whose Dept is HR.
Answer

(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';
EmpIDEmailENameDeptCityDOJSalaryBonus
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E106wasim@co.inWasimHRDelhi2022-07-25390002000

Explanation: WHERE keeps only the rows where Dept is 'HR': 2 of the 7 rows match (Seema, Wasim). SELECT then shows all the columns (*).

B6.58Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EmpID, EName and Salary of the employees whose Salary is between 40000 and 50000.
  2. Display EName and City of the employees whose City is not Mumbai.
Answer

(i)

SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 50000;
EmpIDENameSalary
E101Ravi42000

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';
ENameCity
RaviDelhi
SeemaPune
TarunDelhi
VikasPune
WasimDelhi

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.

B6.59Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name of the students whose Gender is F and Phone is not NULL.
  2. Display Name and Marks of the students whose Marks is less than 50 or whose Phone is NULL.
Answer

(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;
NameMarks
Bhavya92
Chirag45
Eshan88
Farah31

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 =.)

B6.60Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display BookID, Price and Price increased by 10 for every book.
  2. Display Title and Subject of the books whose Subject is not Computer.
Answer

(i)

SELECT BookID, Price, Price + 10 FROM BOOK;
BookIDPricePrice + 10
201210220
202180190
203299309
204350360
205190200
206250260
207400410

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';
TitleSubject
Physics Part 1Science
Wings of FireBiography
Chemistry Part 1Science
The Story of My ExperimentsBiography

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.

B6.61Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PCode, Price and Price increased by 10 for every product.
  2. Display PCode, PName and Price of the products whose Price is between 300 and 400.
Answer

(i)

SELECT PCode, Price, Price + 10 FROM PRODUCT;
PCodePricePrice + 10
P016070
P02450460
P03180190
P04650660
P05320330
P06899909
P07275285

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;
PCodePNamePrice
P05Water Bottle320

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.

B6.62Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName and AdmitDate of the patients whose AdmitDate is between '2026-09-05' and '2026-09-15'.
  2. Display PName of the patients whose Ward is General and Fee is at least 1000.
Answer

(i)

SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
PNameAdmitDate
Nisha2026-09-05
Om2026-09-10
Pooja2026-09-12
Qasim2026-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.

B6.63Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name of the students whose Gender is M and Phone is not NULL.
  2. Display Name and DOB of the students whose DOB is between '2009-06-01' and '2009-12-31'.
Answer

(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';
NameDOB
Bhavya2009-11-30
Divya2009-07-21
Farah2009-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.

B6.64Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EName of the employees whose Dept is IT and Salary is at least 40000.
  2. Display EName and Salary of the employees whose Salary is less than 40000 or whose Bonus is NULL.
Answer

(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;
ENameSalary
Seema58000
Usha36000
Wasim39000
Yamini81000

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 =.)

B6.65Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display all the details of the books whose Subject is Science.
  2. Display Title of the books whose Member is not known (NULL).
Answer

(i)

SELECT * FROM BOOK WHERE Subject = 'Science';
BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha

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 =.)

B6.66Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName and AdmitDate of the patients whose AdmitDate is between '2026-09-05' and '2026-09-15'.
  2. Display PName and Ward of the patients whose Ward is not Maternity.
Answer

(i)

SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
PNameAdmitDate
Nisha2026-09-05
Om2026-09-10
Pooja2026-09-12
Qasim2026-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';
PNameWard
MohanGeneral
NishaICU
OmGeneral
QasimICU
SahilGeneral

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.

B6.67Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title and Subject of the books whose Subject is Biography or Science.
  2. Display Title and Subject of the books whose Subject is not Computer.
Answer

(i)

SELECT Title, Subject FROM BOOK WHERE Subject = 'Biography' OR Subject = 'Science';
TitleSubject
Physics Part 1Science
Wings of FireBiography
Chemistry Part 1Science
The Story of My ExperimentsBiography

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';
TitleSubject
Physics Part 1Science
Wings of FireBiography
Chemistry Part 1Science
The Story of My ExperimentsBiography

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.

B6.68Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName and Brand of the products whose Brand is not Camlin.
  2. Display PName of the products whose Discount is not known (NULL).
Answer

(i)

SELECT PName, Brand FROM PRODUCT WHERE Brand <> 'Camlin';
PNameBrand
NotebookClassmate
Pen DriveSanDisk
MouseLogitech
Water BottleMilton
EarphonesBoat
Lunch BoxMilton

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 =.)

B6.69Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title and Price of the books whose Price is less than 300 or whose Member is NULL.
  2. Display Title of the books whose Member is not known (NULL).
Answer

(i)

SELECT Title, Price FROM BOOK WHERE Price < 300 OR Member IS NULL;
TitlePrice
Informatics Practices210
Physics Part 1180
Wings of Fire299
Python Basics350
Chemistry Part 1190
The Story of My Experiments250

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 =.)

B6.70Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName and Brand of the products whose Brand is not Boat.
  2. Display PName of the products whose Category is Electronics and Price is at least 300.
Answer

(i)

SELECT PName, Brand FROM PRODUCT WHERE Brand <> 'Boat';
PNameBrand
NotebookClassmate
Pen DriveSanDisk
Geometry BoxCamlin
MouseLogitech
Water BottleMilton
Lunch BoxMilton

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.

B6.71Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name and Gender of the students whose Gender is not F.
  2. Display Name and DOB of the students whose DOB is between '2009-06-01' and '2009-12-31'.
Answer

(i)

SELECT Name, Gender FROM STUDENT WHERE Gender <> 'F';
NameGender
AaravM
ChiragM
EshanM
GauravM

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';
NameDOB
Bhavya2009-11-30
Divya2009-07-21
Farah2009-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.

B6.72Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName and AdmitDate of the patients whose AdmitDate is between '2026-09-05' and '2026-09-15'.
  2. Display PName and Fee of all the patients whose Fee is more than 1500.
Answer

(i)

SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
PNameAdmitDate
Nisha2026-09-05
Om2026-09-10
Pooja2026-09-12
Qasim2026-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;
PNameFee
Nisha8000
Pooja5000
Qasim9500
Rekha4500

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.

B6.73Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName and Insurance of the patients whose Insurance is not NULL.
  2. Display all the details of the patients whose Ward is ICU.
Answer

(i)

SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
PNameInsurance
MohanLIC
OmStar
PoojaLIC
SahilStar

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';
PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
12223422342234NishaICUDr. Sen2026-09-058000NULL
15523452345234QasimICUDr. Sen2026-09-159500NULL

Explanation: WHERE keeps only the rows where Ward is 'ICU': 2 of the 7 rows match (Nisha, Qasim). SELECT then shows all the columns (*).

B6.74Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name and Marks of all the students whose Marks is more than 70.
  2. Display Name and Phone of the students whose Phone is not NULL.
Answer

(i)

SELECT Name, Marks FROM STUDENT WHERE Marks > 70;
NameMarks
Aarav78
Bhavya92
Eshan88

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;
NamePhone
Aarav9810011111
Chirag9810033333
Divya9810044444
Farah9810066666
Gaurav9810077777

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 =.)

B6.75Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title and Member of the books whose Member is not NULL.
  2. Display BookID, Price and Price increased by 10 for every book.
Answer

(i)

SELECT Title, Member FROM BOOK WHERE Member IS NOT NULL;
TitleMember
Informatics PracticesAsha
Wings of FireRavi
Chemistry Part 1Neha
Learn SQLKaran

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;
BookIDPricePrice + 10
201210220
202180190
203299309
204350360
205190200
206250260
207400410

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.

B6.76Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title and Price of the books whose Price is less than 200 or whose Member is NULL.
  2. Display BookID, Title and Price of the books whose Price is between 200 and 350.
Answer

(i)

SELECT Title, Price FROM BOOK WHERE Price < 200 OR Member IS NULL;
TitlePrice
Physics Part 1180
Python Basics350
Chemistry Part 1190
The Story of My Experiments250

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;
BookIDTitlePrice
201Informatics Practices210
203Wings of Fire299
204Python Basics350
206The Story of My Experiments250

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.

B6.77Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title and Subject of the books whose Subject is Science or Biography.
  2. Display BookID, Title and Price of the books whose Price is between 300 and 350.
Answer

(i)

SELECT Title, Subject FROM BOOK WHERE Subject = 'Science' OR Subject = 'Biography';
TitleSubject
Physics Part 1Science
Wings of FireBiography
Chemistry Part 1Science
The Story of My ExperimentsBiography

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;
BookIDTitlePrice
204Python Basics350

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.

B6.78Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title of the books whose Publisher is BPB and Member is not NULL.
  2. Display Title and Price of the books whose Price is less than 300 or whose Member is NULL.
Answer

(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;
TitlePrice
Informatics Practices210
Physics Part 1180
Wings of Fire299
Python Basics350
Chemistry Part 1190
The Story of My Experiments250

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 =.)

B6.79Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName and Price of all the products whose Price is more than 100.
  2. Display PName and Price of the products whose Price is less than 400 or whose Discount is NULL.
Answer

(i)

SELECT PName, Price FROM PRODUCT WHERE Price > 100;
PNamePrice
Pen Drive450
Geometry Box180
Mouse650
Water Bottle320
Earphones899
Lunch Box275

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;
PNamePrice
Notebook60
Pen Drive450
Geometry Box180
Water Bottle320
Lunch Box275

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 =.)

B6.80Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EName of the employees whose Dept is HR and Salary is at least 40000.
  2. Display EName and City of the employees whose City is not Pune.
Answer

(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';
ENameCity
RaviDelhi
TarunDelhi
UshaMumbai
WasimDelhi
YaminiMumbai

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.

B6.81Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName of the patients whose Insurance is not known (NULL).
  2. Display PName and Fee of the patients whose Fee is less than 1000 or whose Insurance is NULL.
Answer

(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;
PNameFee
Nisha8000
Qasim9500
Rekha4500
Sahil900

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 =.)

B6.82Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EmpID, Salary and Salary increased by 10 for every employee.
  2. Display EName of the employees whose Bonus is not known (NULL).
Answer

(i)

SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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 =.)

B6.83Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName and MfgDate of the products whose MfgDate is between '2025-10-01' and '2026-01-31'.
  2. Display PName and Price of the products whose Price is less than 300 or whose Discount is NULL.
Answer

(i)

SELECT PName, MfgDate FROM PRODUCT WHERE MfgDate BETWEEN '2025-10-01' AND '2026-01-31';
PNameMfgDate
Notebook2026-01-10
Geometry Box2025-11-02
Lunch Box2025-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;
PNamePrice
Notebook60
Pen Drive450
Geometry Box180
Water Bottle320
Lunch Box275

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 =.)

B6.84Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EmpID, Salary and Salary increased by 10 for every employee.
  2. Display EName of the employees whose Dept is HR and Salary is at least 40000.
Answer

(i)

SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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.

B6.85Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName and Category of the products whose Category is Stationery or Home.
  2. Display PName of the products whose Category is Electronics and Price is at least 300.
Answer

(i)

SELECT PName, Category FROM PRODUCT WHERE Category = 'Stationery' OR Category = 'Home';
PNameCategory
NotebookStationery
Geometry BoxStationery
Water BottleHome
Lunch BoxHome

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.

B6.86Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title of the books whose Publisher is BPB and Member is not NULL.
  2. Display Title of the books whose Member is not known (NULL).
Answer

(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 =.)

B6.87Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName and Category of the products whose Category is not Home.
  2. Display PName of the products whose Brand is Milton and Discount is not NULL.
Answer

(i)

SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Home';
PNameCategory
NotebookStationery
Pen DriveElectronics
Geometry BoxStationery
MouseElectronics
EarphonesElectronics

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 =.)

B6.88Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EName and Dept of the employees whose Dept is not IT.
  2. Display all the details of the employees whose Dept is IT.
Answer

(i)

SELECT EName, Dept FROM EMPLOYEE WHERE NOT Dept = 'IT';
ENameDept
RaviSales
SeemaHR
UshaSales
WasimHR

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';
EmpIDEmailENameDeptCityDOJSalaryBonus
E103tarun@co.inTarunITDelhi2016-09-20750005000
E105vikas@co.inVikasITPune2019-11-05640004000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

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 (*).

B6.89Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name and Marks of the students whose Marks is less than 60 or whose Phone is NULL.
  2. Display Name and Marks of all the students whose Marks is more than 60.
Answer

(i)

SELECT Name, Marks FROM STUDENT WHERE Marks < 60 OR Phone IS NULL;
NameMarks
Bhavya92
Chirag45
Eshan88
Farah31
Gaurav59

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;
NameMarks
Aarav78
Bhavya92
Divya66
Eshan88

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.

B6.90Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title of the books whose Subject is Computer and Price is at least 250.
  2. Display Title and IssueDate of the books whose IssueDate is between '2026-07-01' and '2026-07-31'.
Answer

(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';
TitleIssueDate
Informatics Practices2026-07-03
Physics Part 12026-07-10
Chemistry Part 12026-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.

B6.91Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title of the books whose Publisher is Penguin and Member is not NULL.
  2. Display Title and Member of the books whose Member is not NULL.
Answer

(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;
TitleMember
Informatics PracticesAsha
Wings of FireRavi
Chemistry Part 1Neha
Learn SQLKaran

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 =.)

B6.92Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EmpID, Salary and Salary increased by 10 for every employee.
  2. Display EmpID, EName and Salary of the employees whose Salary is between 40000 and 50000.
Answer

(i)

SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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;
EmpIDENameSalary
E101Ravi42000

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.

B6.93Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName and Discount of the products whose Discount is not NULL.
  2. Display PName of the products whose Brand is Boat and Discount is not NULL.
Answer

(i)

SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
PNameDiscount
Notebook5
Geometry Box10
Mouse15
Earphones20
Lunch Box8

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 =.)

B6.94Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title and Subject of the books whose Subject is Biography or Computer.
  2. Display Title and Price of all the books whose Price is more than 350.
Answer

(i)

SELECT Title, Subject FROM BOOK WHERE Subject = 'Biography' OR Subject = 'Computer';
TitleSubject
Informatics PracticesComputer
Wings of FireBiography
Python BasicsComputer
The Story of My ExperimentsBiography
Learn SQLComputer

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;
TitlePrice
Learn SQL400

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.

B6.95Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name and Section of the students whose Section is C or A.
  2. Display Name and Marks of all the students whose Marks is more than 80.
Answer

(i)

SELECT Name, Section FROM STUDENT WHERE Section = 'C' OR Section = 'A';
NameSection
AaravA
ChiragA
DivyaC
FarahA
GauravC

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;
NameMarks
Bhavya92
Eshan88

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.

B6.96Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title and IssueDate of the books whose IssueDate is between '2026-07-01' and '2026-07-31'.
  2. Display Title of the books whose Subject is Biography and Price is at least 250.
Answer

(i)

SELECT Title, IssueDate FROM BOOK WHERE IssueDate BETWEEN '2026-07-01' AND '2026-07-31';
TitleIssueDate
Informatics Practices2026-07-03
Physics Part 12026-07-10
Chemistry Part 12026-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.

B6.97Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EmpID, EName and Salary of the employees whose Salary is between 40000 and 60000.
  2. Display EName and Dept of the employees whose Dept is not IT.
Answer

(i)

SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 60000;
EmpIDENameSalary
E101Ravi42000
E102Seema58000

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';
ENameDept
RaviSales
SeemaHR
UshaSales
WasimHR

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.

B6.98Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PCode, PName and Price of the products whose Price is between 100 and 500.
  2. Display PName of the products whose Brand is Camlin and Discount is not NULL.
Answer

(i)

SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 100 AND 500;
PCodePNamePrice
P02Pen Drive450
P03Geometry Box180
P05Water Bottle320
P07Lunch Box275

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 =.)

B6.99Practice2 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL queries for the following:

  1. Display PName of the products whose Brand is Camlin and Discount is not NULL.
  2. Display PName of the products whose Discount is not known (NULL).
Answer

(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 =.)

B6.100Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PName and Insurance of the patients whose Insurance is not NULL.
  2. Display PName of the patients whose Insurance is not known (NULL).
Answer

(i)

SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
PNameInsurance
MohanLIC
OmStar
PoojaLIC
SahilStar

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 =.)

B6.101Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name and Marks of all the students whose Marks is more than 80.
  2. Display Name and Phone of the students whose Phone is not NULL.
Answer

(i)

SELECT Name, Marks FROM STUDENT WHERE Marks > 80;
NameMarks
Bhavya92
Eshan88

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;
NamePhone
Aarav9810011111
Chirag9810033333
Divya9810044444
Farah9810066666
Gaurav9810077777

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 =.)

B6.102Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display RollNo, Name and Marks of the students whose Marks is between 50 and 70.
  2. Display Name of the students whose Gender is F and Phone is not NULL.
Answer

(i)

SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 50 AND 70;
RollNoNameMarks
4Divya66
7Gaurav59

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 =.)

B6.103Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EName and Dept of the employees whose Dept is IT or HR.
  2. Display EmpID, EName and Salary of the employees whose Salary is between 40000 and 60000.
Answer

(i)

SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'IT' OR Dept = 'HR';
ENameDept
SeemaHR
TarunIT
VikasIT
WasimHR
YaminiIT

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;
EmpIDENameSalary
E101Ravi42000
E102Seema58000

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.

B6.104Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title and Publisher of the books whose Publisher is not BPB.
  2. Display Title of the books whose Member is not known (NULL).
Answer

(i)

SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'BPB';
TitlePublisher
Informatics PracticesNCERT
Physics Part 1NCERT
Wings of FireUniversities
Chemistry Part 1NCERT
The Story of My ExperimentsPenguin

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 =.)

B6.105Practice2 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL queries for the following:

  1. Display Title of the books whose Subject is Science and Price is at least 250.
  2. Display Title and Price of all the books whose Price is more than 250.
Answer

(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;
TitlePrice
Wings of Fire299
Python Basics350
Learn SQL400

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.

B6.106Practice2 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL queries for the following:

  1. Display EName and Salary of the employees whose Salary is less than 40000 or whose Bonus is NULL.
  2. Display EmpID, Salary and Salary increased by 10 for every employee.
Answer

(i)

SELECT EName, Salary FROM EMPLOYEE WHERE Salary < 40000 OR Bonus IS NULL;
ENameSalary
Seema58000
Usha36000
Wasim39000
Yamini81000

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;
EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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.

B6.107Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name of the students whose Phone is not known (NULL).
  2. Display RollNo, Name and Marks of the students whose Marks is between 60 and 80.
Answer

(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;
RollNoNameMarks
1Aarav78
4Divya66

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.

B6.108Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name and Section of the students whose Section is A or B.
  2. Display Name of the students whose Phone is not known (NULL).
Answer

(i)

SELECT Name, Section FROM STUDENT WHERE Section = 'A' OR Section = 'B';
NameSection
AaravA
BhavyaB
ChiragA
EshanB
FarahA

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 =.)

B6.109Practice2 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL queries for the following:

  1. Display PID, Fee and Fee increased by 10 for every patient.
  2. Display PName and Ward of the patients whose Ward is Maternity or ICU.
Answer

(i)

SELECT PID, Fee, Fee + 10 FROM PATIENT;
PIDFeeFee + 10
1115001510
1280008010
1312001210
1450005010
1595009510
1645004510
17900910

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';
PNameWard
NishaICU
PoojaMaternity
QasimICU
RekhaMaternity

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.

B6.110Practice2 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL queries for the following:

  1. Display Name and Gender of the students whose Gender is not F.
  2. Display Name and Section of the students whose Section is A or B.
Answer

(i)

SELECT Name, Gender FROM STUDENT WHERE Gender <> 'F';
NameGender
AaravM
ChiragM
EshanM
GauravM

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';
NameSection
AaravA
BhavyaB
ChiragA
EshanB
FarahA

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.

Section C · 3 marks each

C1Python: output of a program3 marks · 66 questions
C1.1Practice3 marks

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()))
Answer

Output:

{'Map': 80, 'Pen': 25, 'Ink': 20, 'Glue': 7}
4 132

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Bag': 20, 'Map': 80, 'Pen': 15, 'Ink': 10}stock = {'Bag': 20, 'Map': 80, 'Pen': 15, 'Ink': 10}
2for item in stock:item = 'Bag'
3if stock[item] < 51:condition is True
4stock[item] += 10stock = {'Bag': 30, 'Map': 80, 'Pen': 15, 'Ink': 10}
2for item in stock:item = 'Map'
3if stock[item] < 51:condition is False
2for item in stock:item = 'Pen'
3if stock[item] < 51:condition is True
4stock[item] += 10stock = {'Bag': 30, 'Map': 80, 'Pen': 25, 'Ink': 10}
2for item in stock:item = 'Ink'
3if stock[item] < 51:condition is True
4stock[item] += 10stock = {'Bag': 30, 'Map': 80, 'Pen': 25, 'Ink': 20}
2for item in stock:loop ends (no more values)
5stock["Glue"] = 7stock = {'Bag': 30, 'Map': 80, 'Pen': 25, 'Ink': 20, 'Glue': 7}
6del stock['Bag']stock = {'Map': 80, 'Pen': 25, 'Ink': 20, 'Glue': 7}
7print(stock){'Map': 80, 'Pen': 25, 'Ink': 20, 'Glue': 7}⏎
8print(len(stock), sum(stock.values()))4 132⏎
C1.2Practice3 marks

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)
Answer

Output:

[77, 97, 66, 49, 33, 11]
[77, 33] 7

Working (step by step)

LineStatementValues after this stepPrinted
1L = [19, 58, 39, 27, 22, 11]L = [19, 58, 39, 27, 22, 11]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [77, 58, 39, 27, 22, 11]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [77, 97, 39, 27, 22, 11]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [77, 97, 66, 27, 22, 11]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [77, 97, 66, 49, 22, 11]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [77, 97, 66, 49, 33, 11]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[77, 97, 66, 49, 33, 11]⏎
5print(L[::4], max(L) % 9)[77, 33] 7⏎
C1.3Practice3 marks

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()
Answer

Output:

    1
   121
  12321
 1234321
123454321

Working (step by step)

LineStatementValues after this stepPrinted
1n = 5n = 5
2for i in range(1, n + 1):i = 1
3print(" " * (n - i), end="")
4for j in range(1, i + 1):j = 1
5print(j, end="")1
4for j in range(1, i + 1):loop ends (no more values)
6for j in range(i - 1, 0, -1):loop ends (no more values)
8print()⏎
2for i in range(1, n + 1):i = 2
3print(" " * (n - i), end="")
4for j in range(1, i + 1):loop ends (no more values)
5print(j, end="")1
4for j in range(1, i + 1):j = 2
5print(j, end="")2
4for j in range(1, i + 1):loop ends (no more values)
6for j in range(i - 1, 0, -1):j = 1

… the same steps continue for the remaining values.

C1.4Practice3 marks

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])
Answer

Output:

[56, 36]
[47, 39, 49, 25]
[56, 36, 47, 39]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [25, 56, 36, 49, 39, 47]L = [25, 56, 36, 49, 39, 47]
2A, B = [], []A = [], B = []
3for x in L:x = 25
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [25]
3for x in L:x = 56
4if x % 4 == 0:condition is True
5A.append(x)A = [56]
3for x in L:x = 36
4if x % 4 == 0:condition is True
5A.append(x)A = [56, 36]
3for x in L:x = 49
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [49, 25]
3for x in L:x = 39
4if x % 4 == 0:condition is False

… the same steps continue for the remaining values.

C1.5Practice3 marks

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)
Answer

Output:

0 1 1 2 3 5 8 
34

Working (step by step)

LineStatementValues after this stepPrinted
1a, b = 0, 1a = 0, b = 1
2for i in range(7):i = 0
3print(a, end=" ")0
4a, b = b, a + ba = 1
2for i in range(7):i = 1
3print(a, end=" ")1
4a, b = b, a + bb = 2
2for i in range(7):i = 2
3print(a, end=" ")1
4a, b = b, a + ba = 2, b = 3
2for i in range(7):i = 3
3print(a, end=" ")2
4a, b = b, a + ba = 3, b = 5
2for i in range(7):i = 4
3print(a, end=" ")3
4a, b = b, a + ba = 5, b = 8

… the same steps continue for the remaining values.

C1.6Practice3 marks

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])
Answer

Output:

[44]
[37, 9, 49, 5, 43]
[44, 37, 9]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [43, 5, 44, 49, 9, 37]L = [43, 5, 44, 49, 9, 37]
2A, B = [], []A = [], B = []
3for x in L:x = 43
4if x % 2 == 0:condition is False
7B.insert(0, x)B = [43]
3for x in L:x = 5
4if x % 2 == 0:condition is False
7B.insert(0, x)B = [5, 43]
3for x in L:x = 44
4if x % 2 == 0:condition is True
5A.append(x)A = [44]
3for x in L:x = 49
4if x % 2 == 0:condition is False
7B.insert(0, x)B = [49, 5, 43]
3for x in L:x = 9
4if x % 2 == 0:condition is False

… the same steps continue for the remaining values.

C1.7Practice3 marks

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])
Answer

Output:

[12, 32]
[46, 35, 29, 22]
[12, 32, 46, 35]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [12, 22, 29, 35, 46, 32]L = [12, 22, 29, 35, 46, 32]
2A, B = [], []A = [], B = []
3for x in L:x = 12
4if x % 4 == 0:condition is True
5A.append(x)A = [12]
3for x in L:x = 22
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [22]
3for x in L:x = 29
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [29, 22]
3for x in L:x = 35
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [35, 29, 22]
3for x in L:x = 46
4if x % 4 == 0:condition is False

… the same steps continue for the remaining values.

C1.8Practice3 marks

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()))
Answer

Output:

{'Map': 75, 'Ink': 65, 'Book': 70, 'Glue': 17}
4 227

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Map': 75, 'Bag': 85, 'Ink': 65, 'Book': 70}stock = {'Map': 75, 'Bag': 85, 'Ink': 65, 'Book': 70}
2for item in stock:item = 'Map'
3if stock[item] < 37:condition is False
2for item in stock:item = 'Bag'
3if stock[item] < 37:condition is False
2for item in stock:item = 'Ink'
3if stock[item] < 37:condition is False
2for item in stock:item = 'Book'
3if stock[item] < 37:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 17stock = {'Map': 75, 'Bag': 85, 'Ink': 65, 'Book': 70, 'Glue': 17}
6del stock['Bag']stock = {'Map': 75, 'Ink': 65, 'Book': 70, 'Glue': 17}
7print(stock){'Map': 75, 'Ink': 65, 'Book': 70, 'Glue': 17}⏎
8print(len(stock), sum(stock.values()))4 227⏎
C1.9Practice3 marks

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)
Answer

Output:

0 1 1 2 3 5 8 13 
55

Working (step by step)

LineStatementValues after this stepPrinted
1a, b = 0, 1a = 0, b = 1
2for i in range(8):i = 0
3print(a, end=" ")0
4a, b = b, a + ba = 1
2for i in range(8):i = 1
3print(a, end=" ")1
4a, b = b, a + bb = 2
2for i in range(8):i = 2
3print(a, end=" ")1
4a, b = b, a + ba = 2, b = 3
2for i in range(8):i = 3
3print(a, end=" ")2
4a, b = b, a + ba = 3, b = 5
2for i in range(8):i = 4
3print(a, end=" ")3
4a, b = b, a + ba = 5, b = 8

… the same steps continue for the remaining values.

C1.10Practice3 marks

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])
Answer

Output:

[10, 18, 16, 12, 6]
[41]
[10, 18, 16, 12, 6, 41]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [10, 18, 16, 12, 41, 6]L = [10, 18, 16, 12, 41, 6]
2A, B = [], []A = [], B = []
3for x in L:x = 10
4if x % 2 == 0:condition is True
5A.append(x)A = [10]
3for x in L:x = 18
4if x % 2 == 0:condition is True
5A.append(x)A = [10, 18]
3for x in L:x = 16
4if x % 2 == 0:condition is True
5A.append(x)A = [10, 18, 16]
3for x in L:x = 12
4if x % 2 == 0:condition is True
5A.append(x)A = [10, 18, 16, 12]
3for x in L:x = 41
4if x % 2 == 0:condition is False

… the same steps continue for the remaining values.

C1.11Practice3 marks

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)
Answer

Output:

[60, 63, 102, 86, 82, 44]
[60, 86] 3

Working (step by step)

LineStatementValues after this stepPrinted
1L = [51, 9, 54, 48, 38, 44]L = [51, 9, 54, 48, 38, 44]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [60, 9, 54, 48, 38, 44]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [60, 63, 54, 48, 38, 44]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [60, 63, 102, 48, 38, 44]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [60, 63, 102, 86, 38, 44]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [60, 63, 102, 86, 82, 44]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[60, 63, 102, 86, 82, 44]⏎
5print(L[::3], max(L) % 9)[60, 86] 3⏎
C1.12Practice3 marks

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)
Answer

Output:

[64, 95, 71, 55, 85, 56]
[64, 71, 85] 4

Working (step by step)

LineStatementValues after this stepPrinted
1L = [14, 50, 45, 26, 29, 56]L = [14, 50, 45, 26, 29, 56]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [64, 50, 45, 26, 29, 56]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [64, 95, 45, 26, 29, 56]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [64, 95, 71, 26, 29, 56]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [64, 95, 71, 55, 29, 56]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [64, 95, 71, 55, 85, 56]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[64, 95, 71, 55, 85, 56]⏎
5print(L[::2], max(L) % 7)[64, 71, 85] 4⏎
C1.13Practice3 marks

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])
Answer

Output:

[16]
[34, 58, 7, 22, 37]
[16, 34, 58]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [37, 22, 7, 16, 58, 34]L = [37, 22, 7, 16, 58, 34]
2A, B = [], []A = [], B = []
3for x in L:x = 37
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [37]
3for x in L:x = 22
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [22, 37]
3for x in L:x = 7
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [7, 22, 37]
3for x in L:x = 16
4if x % 4 == 0:condition is True
5A.append(x)A = [16]
3for x in L:x = 58
4if x % 4 == 0:condition is False

… the same steps continue for the remaining values.

C1.14Practice3 marks

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])
Answer

Output:

[44]
[57, 27, 17, 59, 25]
[44, 57, 27]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [25, 59, 44, 17, 27, 57]L = [25, 59, 44, 17, 27, 57]
2A, B = [], []A = [], B = []
3for x in L:x = 25
4if x % 2 == 0:condition is False
7B.insert(0, x)B = [25]
3for x in L:x = 59
4if x % 2 == 0:condition is False
7B.insert(0, x)B = [59, 25]
3for x in L:x = 44
4if x % 2 == 0:condition is True
5A.append(x)A = [44]
3for x in L:x = 17
4if x % 2 == 0:condition is False
7B.insert(0, x)B = [17, 59, 25]
3for x in L:x = 27
4if x % 2 == 0:condition is False

… the same steps continue for the remaining values.

C1.15Practice3 marks

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()))
Answer

Output:

{'Ruler': 40, 'Ink': 55, 'Pen': 45, 'Glue': 13}
4 153

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Map': 45, 'Ruler': 30, 'Ink': 55, 'Pen': 35}stock = {'Map': 45, 'Ruler': 30, 'Ink': 55, 'Pen': 35}
2for item in stock:item = 'Map'
3if stock[item] < 49:condition is True
4stock[item] += 10stock = {'Map': 55, 'Ruler': 30, 'Ink': 55, 'Pen': 35}
2for item in stock:item = 'Ruler'
3if stock[item] < 49:condition is True
4stock[item] += 10stock = {'Map': 55, 'Ruler': 40, 'Ink': 55, 'Pen': 35}
2for item in stock:item = 'Ink'
3if stock[item] < 49:condition is False
2for item in stock:item = 'Pen'
3if stock[item] < 49:condition is True
4stock[item] += 10stock = {'Map': 55, 'Ruler': 40, 'Ink': 55, 'Pen': 45}
2for item in stock:loop ends (no more values)
5stock["Glue"] = 13stock = {'Map': 55, 'Ruler': 40, 'Ink': 55, 'Pen': 45, 'Glue': 13}
6del stock['Map']stock = {'Ruler': 40, 'Ink': 55, 'Pen': 45, 'Glue': 13}
7print(stock){'Ruler': 40, 'Ink': 55, 'Pen': 45, 'Glue': 13}⏎
8print(len(stock), sum(stock.values()))4 153⏎
C1.16Practice3 marks

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()))
Answer

Output:

{'Bag': 50, 'Ruler': 25, 'Map': 80, 'Glue': 12}
4 167

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Bag': 50, 'Ruler': 15, 'Map': 80, 'Ink': 65}stock = {'Bag': 50, 'Ruler': 15, 'Map': 80, 'Ink': 65}
2for item in stock:item = 'Bag'
3if stock[item] < 38:condition is False
2for item in stock:item = 'Ruler'
3if stock[item] < 38:condition is True
4stock[item] += 10stock = {'Bag': 50, 'Ruler': 25, 'Map': 80, 'Ink': 65}
2for item in stock:item = 'Map'
3if stock[item] < 38:condition is False
2for item in stock:item = 'Ink'
3if stock[item] < 38:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 12stock = {'Bag': 50, 'Ruler': 25, 'Map': 80, 'Ink': 65, 'Glue': 12}
6del stock['Ink']stock = {'Bag': 50, 'Ruler': 25, 'Map': 80, 'Glue': 12}
7print(stock){'Bag': 50, 'Ruler': 25, 'Map': 80, 'Glue': 12}⏎
8print(len(stock), sum(stock.values()))4 167⏎
C1.17Practice3 marks

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])
Answer

Output:

[40, 12, 8, 44]
[50, 37]
[40, 12, 8, 44, 50, 37]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [37, 40, 12, 8, 50, 44]L = [37, 40, 12, 8, 50, 44]
2A, B = [], []A = [], B = []
3for x in L:x = 37
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [37]
3for x in L:x = 40
4if x % 4 == 0:condition is True
5A.append(x)A = [40]
3for x in L:x = 12
4if x % 4 == 0:condition is True
5A.append(x)A = [40, 12]
3for x in L:x = 8
4if x % 4 == 0:condition is True
5A.append(x)A = [40, 12, 8]
3for x in L:x = 50
4if x % 4 == 0:condition is False

… the same steps continue for the remaining values.

C1.18Practice3 marks

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])
Answer

Output:

[57]
[29, 10, 59, 8, 44]
[57, 29, 10]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [44, 8, 57, 59, 10, 29]L = [44, 8, 57, 59, 10, 29]
2A, B = [], []A = [], B = []
3for x in L:x = 44
4if x % 3 == 0:condition is False
7B.insert(0, x)B = [44]
3for x in L:x = 8
4if x % 3 == 0:condition is False
7B.insert(0, x)B = [8, 44]
3for x in L:x = 57
4if x % 3 == 0:condition is True
5A.append(x)A = [57]
3for x in L:x = 59
4if x % 3 == 0:condition is False
7B.insert(0, x)B = [59, 8, 44]
3for x in L:x = 10
4if x % 3 == 0:condition is False

… the same steps continue for the remaining values.

C1.19Practice3 marks

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)
Answer

Output:

[53, 55, 59, 96, 73, 15]
[53, 59, 73] 1

Working (step by step)

LineStatementValues after this stepPrinted
1L = [19, 34, 21, 38, 58, 15]L = [19, 34, 21, 38, 58, 15]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [53, 34, 21, 38, 58, 15]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [53, 55, 21, 38, 58, 15]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [53, 55, 59, 38, 58, 15]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [53, 55, 59, 96, 58, 15]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [53, 55, 59, 96, 73, 15]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[53, 55, 59, 96, 73, 15]⏎
5print(L[::2], max(L) % 5)[53, 59, 73] 1⏎
C1.20Practice3 marks

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)
Answer

Output:

[53, 75, 53, 69, 88, 42]
[53, 88] 3

Working (step by step)

LineStatementValues after this stepPrinted
1L = [8, 45, 30, 23, 46, 42]L = [8, 45, 30, 23, 46, 42]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [53, 45, 30, 23, 46, 42]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [53, 75, 30, 23, 46, 42]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [53, 75, 53, 23, 46, 42]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [53, 75, 53, 69, 46, 42]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [53, 75, 53, 69, 88, 42]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[53, 75, 53, 69, 88, 42]⏎
5print(L[::4], max(L) % 5)[53, 88] 3⏎
C1.21Practice3 marks

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()))
Answer

Output:

{'Pen': 50, 'Bag': 20, 'Map': 30, 'Glue': 15}
4 115

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Pen': 50, 'Bag': 10, 'Ruler': 55, 'Map': 20}stock = {'Pen': 50, 'Bag': 10, 'Ruler': 55, 'Map': 20}
2for item in stock:item = 'Pen'
3if stock[item] < 32:condition is False
2for item in stock:item = 'Bag'
3if stock[item] < 32:condition is True
4stock[item] += 10stock = {'Pen': 50, 'Bag': 20, 'Ruler': 55, 'Map': 20}
2for item in stock:item = 'Ruler'
3if stock[item] < 32:condition is False
2for item in stock:item = 'Map'
3if stock[item] < 32:condition is True
4stock[item] += 10stock = {'Pen': 50, 'Bag': 20, 'Ruler': 55, 'Map': 30}
2for item in stock:loop ends (no more values)
5stock["Glue"] = 15stock = {'Pen': 50, 'Bag': 20, 'Ruler': 55, 'Map': 30, 'Glue': 15}
6del stock['Ruler']stock = {'Pen': 50, 'Bag': 20, 'Map': 30, 'Glue': 15}
7print(stock){'Pen': 50, 'Bag': 20, 'Map': 30, 'Glue': 15}⏎
8print(len(stock), sum(stock.values()))4 115⏎
C1.22Practice3 marks

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])
Answer

Output:

[36, 16, 38, 10]
[19, 59]
[36, 16, 38, 10, 19, 59]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [36, 16, 59, 19, 38, 10]L = [36, 16, 59, 19, 38, 10]
2A, B = [], []A = [], B = []
3for x in L:x = 36
4if x % 2 == 0:condition is True
5A.append(x)A = [36]
3for x in L:x = 16
4if x % 2 == 0:condition is True
5A.append(x)A = [36, 16]
3for x in L:x = 59
4if x % 2 == 0:condition is False
7B.insert(0, x)B = [59]
3for x in L:x = 19
4if x % 2 == 0:condition is False
7B.insert(0, x)B = [19, 59]
3for x in L:x = 38
4if x % 2 == 0:condition is True

… the same steps continue for the remaining values.

C1.23Practice3 marks

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()))
Answer

Output:

{'Map': 65, 'Bag': 70, 'Ink': 60, 'Glue': 14}
4 209

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Map': 65, 'Bag': 70, 'Ink': 50, 'Book': 20}stock = {'Map': 65, 'Bag': 70, 'Ink': 50, 'Book': 20}
2for item in stock:item = 'Map'
3if stock[item] < 53:condition is False
2for item in stock:item = 'Bag'
3if stock[item] < 53:condition is False
2for item in stock:item = 'Ink'
3if stock[item] < 53:condition is True
4stock[item] += 10stock = {'Map': 65, 'Bag': 70, 'Ink': 60, 'Book': 20}
2for item in stock:item = 'Book'
3if stock[item] < 53:condition is True
4stock[item] += 10stock = {'Map': 65, 'Bag': 70, 'Ink': 60, 'Book': 30}
2for item in stock:loop ends (no more values)
5stock["Glue"] = 14stock = {'Map': 65, 'Bag': 70, 'Ink': 60, 'Book': 30, 'Glue': 14}
6del stock['Book']stock = {'Map': 65, 'Bag': 70, 'Ink': 60, 'Glue': 14}
7print(stock){'Map': 65, 'Bag': 70, 'Ink': 60, 'Glue': 14}⏎
8print(len(stock), sum(stock.values()))4 209⏎
C1.24Practice3 marks

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)
Answer

Output:

[82, 57, 30, 79, 87, 31]
[82, 79] 7

Working (step by step)

LineStatementValues after this stepPrinted
1L = [32, 50, 7, 23, 56, 31]L = [32, 50, 7, 23, 56, 31]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [82, 50, 7, 23, 56, 31]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [82, 57, 7, 23, 56, 31]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [82, 57, 30, 23, 56, 31]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [82, 57, 30, 79, 56, 31]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [82, 57, 30, 79, 87, 31]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[82, 57, 30, 79, 87, 31]⏎
5print(L[::3], max(L) % 8)[82, 79] 7⏎
C1.25Practice3 marks

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()))
Answer

Output:

{'Pen': 60, 'Map': 45, 'Book': 80, 'Glue': 9}
4 194

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Ink': 85, 'Pen': 60, 'Map': 45, 'Book': 80}stock = {'Ink': 85, 'Pen': 60, 'Map': 45, 'Book': 80}
2for item in stock:item = 'Ink'
3if stock[item] < 38:condition is False
2for item in stock:item = 'Pen'
3if stock[item] < 38:condition is False
2for item in stock:item = 'Map'
3if stock[item] < 38:condition is False
2for item in stock:item = 'Book'
3if stock[item] < 38:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 9stock = {'Ink': 85, 'Pen': 60, 'Map': 45, 'Book': 80, 'Glue': 9}
6del stock['Ink']stock = {'Pen': 60, 'Map': 45, 'Book': 80, 'Glue': 9}
7print(stock){'Pen': 60, 'Map': 45, 'Book': 80, 'Glue': 9}⏎
8print(len(stock), sum(stock.values()))4 194⏎
C1.26Practice3 marks

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)
Answer

Output:

[54, 26, 37, 47, 86, 55]
[54, 86] 6

Working (step by step)

LineStatementValues after this stepPrinted
1L = [49, 5, 21, 16, 31, 55]L = [49, 5, 21, 16, 31, 55]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [54, 5, 21, 16, 31, 55]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [54, 26, 21, 16, 31, 55]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [54, 26, 37, 16, 31, 55]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [54, 26, 37, 47, 31, 55]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [54, 26, 37, 47, 86, 55]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[54, 26, 37, 47, 86, 55]⏎
5print(L[::4], max(L) % 8)[54, 86] 6⏎
C1.27Practice3 marks

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()))
Answer

Output:

{'Pen': 80, 'Ink': 55, 'Book': 60, 'Glue': 9}
4 204

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Pen': 80, 'Map': 70, 'Ink': 45, 'Book': 60}stock = {'Pen': 80, 'Map': 70, 'Ink': 45, 'Book': 60}
2for item in stock:item = 'Pen'
3if stock[item] < 50:condition is False
2for item in stock:item = 'Map'
3if stock[item] < 50:condition is False
2for item in stock:item = 'Ink'
3if stock[item] < 50:condition is True
4stock[item] += 10stock = {'Pen': 80, 'Map': 70, 'Ink': 55, 'Book': 60}
2for item in stock:item = 'Book'
3if stock[item] < 50:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 9stock = {'Pen': 80, 'Map': 70, 'Ink': 55, 'Book': 60, 'Glue': 9}
6del stock['Map']stock = {'Pen': 80, 'Ink': 55, 'Book': 60, 'Glue': 9}
7print(stock){'Pen': 80, 'Ink': 55, 'Book': 60, 'Glue': 9}⏎
8print(len(stock), sum(stock.values()))4 204⏎
C1.28Practice3 marks

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)
Answer

Output:

[71, 82, 83, 58, 61, 47]
[71, 83, 61] 2

Working (step by step)

LineStatementValues after this stepPrinted
1L = [28, 43, 39, 44, 14, 47]L = [28, 43, 39, 44, 14, 47]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [71, 43, 39, 44, 14, 47]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [71, 82, 39, 44, 14, 47]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [71, 82, 83, 44, 14, 47]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [71, 82, 83, 58, 14, 47]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [71, 82, 83, 58, 61, 47]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[71, 82, 83, 58, 61, 47]⏎
5print(L[::2], max(L) % 9)[71, 83, 61] 2⏎
C1.29Practice3 marks

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()))
Answer

Output:

{'Ink': 75, 'Bag': 55, 'Map': 20, 'Glue': 12}
4 162

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Ink': 75, 'Book': 55, 'Bag': 45, 'Map': 10}stock = {'Ink': 75, 'Book': 55, 'Bag': 45, 'Map': 10}
2for item in stock:item = 'Ink'
3if stock[item] < 52:condition is False
2for item in stock:item = 'Book'
3if stock[item] < 52:condition is False
2for item in stock:item = 'Bag'
3if stock[item] < 52:condition is True
4stock[item] += 10stock = {'Ink': 75, 'Book': 55, 'Bag': 55, 'Map': 10}
2for item in stock:item = 'Map'
3if stock[item] < 52:condition is True
4stock[item] += 10stock = {'Ink': 75, 'Book': 55, 'Bag': 55, 'Map': 20}
2for item in stock:loop ends (no more values)
5stock["Glue"] = 12stock = {'Ink': 75, 'Book': 55, 'Bag': 55, 'Map': 20, 'Glue': 12}
6del stock['Book']stock = {'Ink': 75, 'Bag': 55, 'Map': 20, 'Glue': 12}
7print(stock){'Ink': 75, 'Bag': 55, 'Map': 20, 'Glue': 12}⏎
8print(len(stock), sum(stock.values()))4 162⏎
C1.30Practice3 marks

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()))
Answer

Output:

{'Bag': 60, 'Pen': 45, 'Map': 40, 'Glue': 13}
4 158

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Bag': 60, 'Pen': 45, 'Map': 40, 'Ink': 70}stock = {'Bag': 60, 'Pen': 45, 'Map': 40, 'Ink': 70}
2for item in stock:item = 'Bag'
3if stock[item] < 33:condition is False
2for item in stock:item = 'Pen'
3if stock[item] < 33:condition is False
2for item in stock:item = 'Map'
3if stock[item] < 33:condition is False
2for item in stock:item = 'Ink'
3if stock[item] < 33:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 13stock = {'Bag': 60, 'Pen': 45, 'Map': 40, 'Ink': 70, 'Glue': 13}
6del stock['Ink']stock = {'Bag': 60, 'Pen': 45, 'Map': 40, 'Glue': 13}
7print(stock){'Bag': 60, 'Pen': 45, 'Map': 40, 'Glue': 13}⏎
8print(len(stock), sum(stock.values()))4 158⏎
C1.31Practice3 marks

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])
Answer

Output:

[34, 6]
[33, 15, 37, 51]
[34, 6, 33, 15]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [51, 34, 6, 37, 15, 33]L = [51, 34, 6, 37, 15, 33]
2A, B = [], []A = [], B = []
3for x in L:x = 51
4if x % 2 == 0:condition is False
7B.insert(0, x)B = [51]
3for x in L:x = 34
4if x % 2 == 0:condition is True
5A.append(x)A = [34]
3for x in L:x = 6
4if x % 2 == 0:condition is True
5A.append(x)A = [34, 6]
3for x in L:x = 37
4if x % 2 == 0:condition is False
7B.insert(0, x)B = [37, 51]
3for x in L:x = 15
4if x % 2 == 0:condition is False

… the same steps continue for the remaining values.

C1.32Practice3 marks

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])
Answer

Output:

[27, 15]
[46, 8, 43, 19]
[27, 15, 46, 8]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [19, 27, 43, 15, 8, 46]L = [19, 27, 43, 15, 8, 46]
2A, B = [], []A = [], B = []
3for x in L:x = 19
4if x % 3 == 0:condition is False
7B.insert(0, x)B = [19]
3for x in L:x = 27
4if x % 3 == 0:condition is True
5A.append(x)A = [27]
3for x in L:x = 43
4if x % 3 == 0:condition is False
7B.insert(0, x)B = [43, 19]
3for x in L:x = 15
4if x % 3 == 0:condition is True
5A.append(x)A = [27, 15]
3for x in L:x = 8
4if x % 3 == 0:condition is False

… the same steps continue for the remaining values.

C1.33Practice3 marks

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()))
Answer

Output:

{'Bag': 35, 'Map': 50, 'Ink': 80, 'Glue': 12}
4 177

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Bag': 35, 'Map': 50, 'Ruler': 40, 'Ink': 80}stock = {'Bag': 35, 'Map': 50, 'Ruler': 40, 'Ink': 80}
2for item in stock:item = 'Bag'
3if stock[item] < 31:condition is False
2for item in stock:item = 'Map'
3if stock[item] < 31:condition is False
2for item in stock:item = 'Ruler'
3if stock[item] < 31:condition is False
2for item in stock:item = 'Ink'
3if stock[item] < 31:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 12stock = {'Bag': 35, 'Map': 50, 'Ruler': 40, 'Ink': 80, 'Glue': 12}
6del stock['Ruler']stock = {'Bag': 35, 'Map': 50, 'Ink': 80, 'Glue': 12}
7print(stock){'Bag': 35, 'Map': 50, 'Ink': 80, 'Glue': 12}⏎
8print(len(stock), sum(stock.values()))4 177⏎
C1.34Practice3 marks

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()
Answer

Output:

   1
  121
 12321
1234321

Working (step by step)

LineStatementValues after this stepPrinted
1n = 4n = 4
2for i in range(1, n + 1):i = 1
3print(" " * (n - i), end="")
4for j in range(1, i + 1):j = 1
5print(j, end="")1
4for j in range(1, i + 1):loop ends (no more values)
6for j in range(i - 1, 0, -1):loop ends (no more values)
8print()⏎
2for i in range(1, n + 1):i = 2
3print(" " * (n - i), end="")
4for j in range(1, i + 1):loop ends (no more values)
5print(j, end="")1
4for j in range(1, i + 1):j = 2
5print(j, end="")2
4for j in range(1, i + 1):loop ends (no more values)
6for j in range(i - 1, 0, -1):j = 1

… the same steps continue for the remaining values.

C1.35Practice3 marks

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()))
Answer

Output:

{'Bag': 85, 'Map': 35, 'Pen': 70, 'Glue': 6}
4 196

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Bag': 85, 'Ruler': 30, 'Map': 25, 'Pen': 70}stock = {'Bag': 85, 'Ruler': 30, 'Map': 25, 'Pen': 70}
2for item in stock:item = 'Bag'
3if stock[item] < 42:condition is False
2for item in stock:item = 'Ruler'
3if stock[item] < 42:condition is True
4stock[item] += 10stock = {'Bag': 85, 'Ruler': 40, 'Map': 25, 'Pen': 70}
2for item in stock:item = 'Map'
3if stock[item] < 42:condition is True
4stock[item] += 10stock = {'Bag': 85, 'Ruler': 40, 'Map': 35, 'Pen': 70}
2for item in stock:item = 'Pen'
3if stock[item] < 42:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 6stock = {'Bag': 85, 'Ruler': 40, 'Map': 35, 'Pen': 70, 'Glue': 6}
6del stock['Ruler']stock = {'Bag': 85, 'Map': 35, 'Pen': 70, 'Glue': 6}
7print(stock){'Bag': 85, 'Map': 35, 'Pen': 70, 'Glue': 6}⏎
8print(len(stock), sum(stock.values()))4 196⏎
C1.36Practice3 marks

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])
Answer

Output:

[40, 56, 12]
[10, 19, 39]
[40, 56, 12, 10, 19]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [39, 19, 40, 10, 56, 12]L = [39, 19, 40, 10, 56, 12]
2A, B = [], []A = [], B = []
3for x in L:x = 39
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [39]
3for x in L:x = 19
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [19, 39]
3for x in L:x = 40
4if x % 4 == 0:condition is True
5A.append(x)A = [40]
3for x in L:x = 10
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [10, 19, 39]
3for x in L:x = 56
4if x % 4 == 0:condition is True

… the same steps continue for the remaining values.

C1.37Practice3 marks

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()))
Answer

Output:

{'Bag': 30, 'Pen': 35, 'Book': 55, 'Glue': 16}
4 136

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Bag': 30, 'Pen': 25, 'Ruler': 50, 'Book': 55}stock = {'Bag': 30, 'Pen': 25, 'Ruler': 50, 'Book': 55}
2for item in stock:item = 'Bag'
3if stock[item] < 30:condition is False
2for item in stock:item = 'Pen'
3if stock[item] < 30:condition is True
4stock[item] += 10stock = {'Bag': 30, 'Pen': 35, 'Ruler': 50, 'Book': 55}
2for item in stock:item = 'Ruler'
3if stock[item] < 30:condition is False
2for item in stock:item = 'Book'
3if stock[item] < 30:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 16stock = {'Bag': 30, 'Pen': 35, 'Ruler': 50, 'Book': 55, 'Glue': 16}
6del stock['Ruler']stock = {'Bag': 30, 'Pen': 35, 'Book': 55, 'Glue': 16}
7print(stock){'Bag': 30, 'Pen': 35, 'Book': 55, 'Glue': 16}⏎
8print(len(stock), sum(stock.values()))4 136⏎
C1.38Practice3 marks

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])
Answer

Output:

[46, 10, 44, 36]
[29, 33]
[46, 10, 44, 36, 29, 33]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [46, 33, 29, 10, 44, 36]L = [46, 33, 29, 10, 44, 36]
2A, B = [], []A = [], B = []
3for x in L:x = 46
4if x % 2 == 0:condition is True
5A.append(x)A = [46]
3for x in L:x = 33
4if x % 2 == 0:condition is False
7B.insert(0, x)B = [33]
3for x in L:x = 29
4if x % 2 == 0:condition is False
7B.insert(0, x)B = [29, 33]
3for x in L:x = 10
4if x % 2 == 0:condition is True
5A.append(x)A = [46, 10]
3for x in L:x = 44
4if x % 2 == 0:condition is True

… the same steps continue for the remaining values.

C1.39Practice3 marks

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)
Answer

Output:

[96, 69, 53, 57, 33, 18]
[96, 57] 5

Working (step by step)

LineStatementValues after this stepPrinted
1L = [38, 58, 11, 42, 15, 18]L = [38, 58, 11, 42, 15, 18]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [96, 58, 11, 42, 15, 18]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [96, 69, 11, 42, 15, 18]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [96, 69, 53, 42, 15, 18]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [96, 69, 53, 57, 15, 18]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [96, 69, 53, 57, 33, 18]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[96, 69, 53, 57, 33, 18]⏎
5print(L[::3], max(L) % 7)[96, 57] 5⏎
C1.40Practice3 marks

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])
Answer

Output:

[36, 24]
[44, 56, 47, 46]
[36, 24, 44, 56]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [36, 46, 47, 56, 24, 44]L = [36, 46, 47, 56, 24, 44]
2A, B = [], []A = [], B = []
3for x in L:x = 36
4if x % 3 == 0:condition is True
5A.append(x)A = [36]
3for x in L:x = 46
4if x % 3 == 0:condition is False
7B.insert(0, x)B = [46]
3for x in L:x = 47
4if x % 3 == 0:condition is False
7B.insert(0, x)B = [47, 46]
3for x in L:x = 56
4if x % 3 == 0:condition is False
7B.insert(0, x)B = [56, 47, 46]
3for x in L:x = 24
4if x % 3 == 0:condition is True

… the same steps continue for the remaining values.

C1.41Practice3 marks

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()))
Answer

Output:

{'Pen': 30, 'Bag': 60, 'Ink': 75, 'Glue': 15}
4 180

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Pen': 20, 'Bag': 60, 'Ruler': 55, 'Ink': 75}stock = {'Pen': 20, 'Bag': 60, 'Ruler': 55, 'Ink': 75}
2for item in stock:item = 'Pen'
3if stock[item] < 35:condition is True
4stock[item] += 10stock = {'Pen': 30, 'Bag': 60, 'Ruler': 55, 'Ink': 75}
2for item in stock:item = 'Bag'
3if stock[item] < 35:condition is False
2for item in stock:item = 'Ruler'
3if stock[item] < 35:condition is False
2for item in stock:item = 'Ink'
3if stock[item] < 35:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 15stock = {'Pen': 30, 'Bag': 60, 'Ruler': 55, 'Ink': 75, 'Glue': 15}
6del stock['Ruler']stock = {'Pen': 30, 'Bag': 60, 'Ink': 75, 'Glue': 15}
7print(stock){'Pen': 30, 'Bag': 60, 'Ink': 75, 'Glue': 15}⏎
8print(len(stock), sum(stock.values()))4 180⏎
C1.42Practice3 marks

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)
Answer

Output:

[49, 71, 82, 105, 102, 52]
[49, 102] 6

Working (step by step)

LineStatementValues after this stepPrinted
1L = [5, 44, 27, 55, 50, 52]L = [5, 44, 27, 55, 50, 52]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [49, 44, 27, 55, 50, 52]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [49, 71, 27, 55, 50, 52]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [49, 71, 82, 55, 50, 52]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [49, 71, 82, 105, 50, 52]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [49, 71, 82, 105, 102, 52]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[49, 71, 82, 105, 102, 52]⏎
5print(L[::4], max(L) % 9)[49, 102] 6⏎
C1.43Practice3 marks

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()))
Answer

Output:

{'Book': 35, 'Map': 20, 'Ink': 75, 'Glue': 18}
4 148

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Book': 25, 'Map': 10, 'Bag': 85, 'Ink': 75}stock = {'Book': 25, 'Map': 10, 'Bag': 85, 'Ink': 75}
2for item in stock:item = 'Book'
3if stock[item] < 47:condition is True
4stock[item] += 10stock = {'Book': 35, 'Map': 10, 'Bag': 85, 'Ink': 75}
2for item in stock:item = 'Map'
3if stock[item] < 47:condition is True
4stock[item] += 10stock = {'Book': 35, 'Map': 20, 'Bag': 85, 'Ink': 75}
2for item in stock:item = 'Bag'
3if stock[item] < 47:condition is False
2for item in stock:item = 'Ink'
3if stock[item] < 47:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 18stock = {'Book': 35, 'Map': 20, 'Bag': 85, 'Ink': 75, 'Glue': 18}
6del stock['Bag']stock = {'Book': 35, 'Map': 20, 'Ink': 75, 'Glue': 18}
7print(stock){'Book': 35, 'Map': 20, 'Ink': 75, 'Glue': 18}⏎
8print(len(stock), sum(stock.values()))4 148⏎
C1.44Practice3 marks

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()))
Answer

Output:

{'Ruler': 35, 'Ink': 85, 'Map': 75, 'Glue': 18}
4 213

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Book': 80, 'Ruler': 35, 'Ink': 85, 'Map': 75}stock = {'Book': 80, 'Ruler': 35, 'Ink': 85, 'Map': 75}
2for item in stock:item = 'Book'
3if stock[item] < 31:condition is False
2for item in stock:item = 'Ruler'
3if stock[item] < 31:condition is False
2for item in stock:item = 'Ink'
3if stock[item] < 31:condition is False
2for item in stock:item = 'Map'
3if stock[item] < 31:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 18stock = {'Book': 80, 'Ruler': 35, 'Ink': 85, 'Map': 75, 'Glue': 18}
6del stock['Book']stock = {'Ruler': 35, 'Ink': 85, 'Map': 75, 'Glue': 18}
7print(stock){'Ruler': 35, 'Ink': 85, 'Map': 75, 'Glue': 18}⏎
8print(len(stock), sum(stock.values()))4 213⏎
C1.45Practice3 marks

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)
Answer

Output:

0 1 1 2 3 5 8 13 21 
89

Working (step by step)

LineStatementValues after this stepPrinted
1a, b = 0, 1a = 0, b = 1
2for i in range(9):i = 0
3print(a, end=" ")0
4a, b = b, a + ba = 1
2for i in range(9):i = 1
3print(a, end=" ")1
4a, b = b, a + bb = 2
2for i in range(9):i = 2
3print(a, end=" ")1
4a, b = b, a + ba = 2, b = 3
2for i in range(9):i = 3
3print(a, end=" ")2
4a, b = b, a + ba = 3, b = 5
2for i in range(9):i = 4
3print(a, end=" ")3
4a, b = b, a + ba = 5, b = 8

… the same steps continue for the remaining values.

C1.46Practice3 marks

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])
Answer

Output:

[18, 27, 51]
[28, 7, 26]
[18, 27, 51, 28, 7]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [26, 18, 27, 51, 7, 28]L = [26, 18, 27, 51, 7, 28]
2A, B = [], []A = [], B = []
3for x in L:x = 26
4if x % 3 == 0:condition is False
7B.insert(0, x)B = [26]
3for x in L:x = 18
4if x % 3 == 0:condition is True
5A.append(x)A = [18]
3for x in L:x = 27
4if x % 3 == 0:condition is True
5A.append(x)A = [18, 27]
3for x in L:x = 51
4if x % 3 == 0:condition is True
5A.append(x)A = [18, 27, 51]
3for x in L:x = 7
4if x % 3 == 0:condition is False

… the same steps continue for the remaining values.

C1.47Practice3 marks

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)
Answer

Output:

[27, 58, 100, 101, 84, 30]
[27, 100, 84] 5

Working (step by step)

LineStatementValues after this stepPrinted
1L = [22, 5, 53, 47, 54, 30]L = [22, 5, 53, 47, 54, 30]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [27, 5, 53, 47, 54, 30]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [27, 58, 53, 47, 54, 30]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [27, 58, 100, 47, 54, 30]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [27, 58, 100, 101, 54, 30]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [27, 58, 100, 101, 84, 30]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[27, 58, 100, 101, 84, 30]⏎
5print(L[::2], max(L) % 6)[27, 100, 84] 5⏎
C1.48Practice3 marks

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])
Answer

Output:

[56, 52]
[26, 11, 22, 18]
[56, 52, 26, 11]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [56, 18, 52, 22, 11, 26]L = [56, 18, 52, 22, 11, 26]
2A, B = [], []A = [], B = []
3for x in L:x = 56
4if x % 4 == 0:condition is True
5A.append(x)A = [56]
3for x in L:x = 18
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [18]
3for x in L:x = 52
4if x % 4 == 0:condition is True
5A.append(x)A = [56, 52]
3for x in L:x = 22
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [22, 18]
3for x in L:x = 11
4if x % 4 == 0:condition is False

… the same steps continue for the remaining values.

C1.49Practice3 marks

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()))
Answer

Output:

{'Pen': 60, 'Map': 40, 'Ruler': 65, 'Glue': 9}
4 174

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Ink': 85, 'Pen': 60, 'Map': 30, 'Ruler': 65}stock = {'Ink': 85, 'Pen': 60, 'Map': 30, 'Ruler': 65}
2for item in stock:item = 'Ink'
3if stock[item] < 33:condition is False
2for item in stock:item = 'Pen'
3if stock[item] < 33:condition is False
2for item in stock:item = 'Map'
3if stock[item] < 33:condition is True
4stock[item] += 10stock = {'Ink': 85, 'Pen': 60, 'Map': 40, 'Ruler': 65}
2for item in stock:item = 'Ruler'
3if stock[item] < 33:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 9stock = {'Ink': 85, 'Pen': 60, 'Map': 40, 'Ruler': 65, 'Glue': 9}
6del stock['Ink']stock = {'Pen': 60, 'Map': 40, 'Ruler': 65, 'Glue': 9}
7print(stock){'Pen': 60, 'Map': 40, 'Ruler': 65, 'Glue': 9}⏎
8print(len(stock), sum(stock.values()))4 174⏎
C1.50Practice3 marks

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()))
Answer

Output:

{'Book': 40, 'Map': 45, 'Pen': 25, 'Glue': 5}
4 115

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Book': 30, 'Bag': 45, 'Map': 35, 'Pen': 15}stock = {'Book': 30, 'Bag': 45, 'Map': 35, 'Pen': 15}
2for item in stock:item = 'Book'
3if stock[item] < 56:condition is True
4stock[item] += 10stock = {'Book': 40, 'Bag': 45, 'Map': 35, 'Pen': 15}
2for item in stock:item = 'Bag'
3if stock[item] < 56:condition is True
4stock[item] += 10stock = {'Book': 40, 'Bag': 55, 'Map': 35, 'Pen': 15}
2for item in stock:item = 'Map'
3if stock[item] < 56:condition is True
4stock[item] += 10stock = {'Book': 40, 'Bag': 55, 'Map': 45, 'Pen': 15}
2for item in stock:item = 'Pen'
3if stock[item] < 56:condition is True
4stock[item] += 10stock = {'Book': 40, 'Bag': 55, 'Map': 45, 'Pen': 25}
2for item in stock:loop ends (no more values)
5stock["Glue"] = 5stock = {'Book': 40, 'Bag': 55, 'Map': 45, 'Pen': 25, 'Glue': 5}
6del stock['Bag']stock = {'Book': 40, 'Map': 45, 'Pen': 25, 'Glue': 5}
7print(stock){'Book': 40, 'Map': 45, 'Pen': 25, 'Glue': 5}⏎
8print(len(stock), sum(stock.values()))4 115⏎
C1.51Practice3 marks

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)
Answer

Output:

[84, 66, 60, 103, 77, 24]
[84, 103] 1

Working (step by step)

LineStatementValues after this stepPrinted
1L = [28, 56, 10, 50, 53, 24]L = [28, 56, 10, 50, 53, 24]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [84, 56, 10, 50, 53, 24]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [84, 66, 10, 50, 53, 24]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [84, 66, 60, 50, 53, 24]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [84, 66, 60, 103, 53, 24]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [84, 66, 60, 103, 77, 24]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[84, 66, 60, 103, 77, 24]⏎
5print(L[::3], max(L) % 6)[84, 103] 1⏎
C1.52Practice3 marks

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)
Answer

Output:

[84, 34, 53, 102, 79, 24]
[84, 79] 0

Working (step by step)

LineStatementValues after this stepPrinted
1L = [56, 28, 6, 47, 55, 24]L = [56, 28, 6, 47, 55, 24]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [84, 28, 6, 47, 55, 24]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [84, 34, 6, 47, 55, 24]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [84, 34, 53, 47, 55, 24]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [84, 34, 53, 102, 55, 24]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [84, 34, 53, 102, 79, 24]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[84, 34, 53, 102, 79, 24]⏎
5print(L[::4], max(L) % 6)[84, 79] 0⏎
C1.53Practice3 marks

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)
Answer

Output:

[17, 43, 70, 47, 69, 56]
[17, 70, 69] 0

Working (step by step)

LineStatementValues after this stepPrinted
1L = [10, 7, 36, 34, 13, 56]L = [10, 7, 36, 34, 13, 56]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [17, 7, 36, 34, 13, 56]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [17, 43, 36, 34, 13, 56]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [17, 43, 70, 34, 13, 56]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [17, 43, 70, 47, 13, 56]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [17, 43, 70, 47, 69, 56]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[17, 43, 70, 47, 69, 56]⏎
5print(L[::2], max(L) % 7)[17, 70, 69] 0⏎
C1.54Practice3 marks

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()))
Answer

Output:

{'Bag': 25, 'Book': 65, 'Ink': 55, 'Glue': 8}
4 153

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Bag': 15, 'Pen': 35, 'Book': 65, 'Ink': 55}stock = {'Bag': 15, 'Pen': 35, 'Book': 65, 'Ink': 55}
2for item in stock:item = 'Bag'
3if stock[item] < 48:condition is True
4stock[item] += 10stock = {'Bag': 25, 'Pen': 35, 'Book': 65, 'Ink': 55}
2for item in stock:item = 'Pen'
3if stock[item] < 48:condition is True
4stock[item] += 10stock = {'Bag': 25, 'Pen': 45, 'Book': 65, 'Ink': 55}
2for item in stock:item = 'Book'
3if stock[item] < 48:condition is False
2for item in stock:item = 'Ink'
3if stock[item] < 48:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 8stock = {'Bag': 25, 'Pen': 45, 'Book': 65, 'Ink': 55, 'Glue': 8}
6del stock['Pen']stock = {'Bag': 25, 'Book': 65, 'Ink': 55, 'Glue': 8}
7print(stock){'Bag': 25, 'Book': 65, 'Ink': 55, 'Glue': 8}⏎
8print(len(stock), sum(stock.values()))4 153⏎
C1.55Practice3 marks

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()))
Answer

Output:

{'Pen': 50, 'Bag': 35, 'Map': 55, 'Glue': 17}
4 157

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Pen': 40, 'Bag': 25, 'Ruler': 50, 'Map': 45}stock = {'Pen': 40, 'Bag': 25, 'Ruler': 50, 'Map': 45}
2for item in stock:item = 'Pen'
3if stock[item] < 51:condition is True
4stock[item] += 10stock = {'Pen': 50, 'Bag': 25, 'Ruler': 50, 'Map': 45}
2for item in stock:item = 'Bag'
3if stock[item] < 51:condition is True
4stock[item] += 10stock = {'Pen': 50, 'Bag': 35, 'Ruler': 50, 'Map': 45}
2for item in stock:item = 'Ruler'
3if stock[item] < 51:condition is True
4stock[item] += 10stock = {'Pen': 50, 'Bag': 35, 'Ruler': 60, 'Map': 45}
2for item in stock:item = 'Map'
3if stock[item] < 51:condition is True
4stock[item] += 10stock = {'Pen': 50, 'Bag': 35, 'Ruler': 60, 'Map': 55}
2for item in stock:loop ends (no more values)
5stock["Glue"] = 17stock = {'Pen': 50, 'Bag': 35, 'Ruler': 60, 'Map': 55, 'Glue': 17}
6del stock['Ruler']stock = {'Pen': 50, 'Bag': 35, 'Map': 55, 'Glue': 17}
7print(stock){'Pen': 50, 'Bag': 35, 'Map': 55, 'Glue': 17}⏎
8print(len(stock), sum(stock.values()))4 157⏎
C1.56Practice3 marks

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()))
Answer

Output:

{'Ink': 55, 'Book': 40, 'Ruler': 45, 'Glue': 15}
4 155

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Bag': 25, 'Ink': 55, 'Book': 30, 'Ruler': 45}stock = {'Bag': 25, 'Ink': 55, 'Book': 30, 'Ruler': 45}
2for item in stock:item = 'Bag'
3if stock[item] < 31:condition is True
4stock[item] += 10stock = {'Bag': 35, 'Ink': 55, 'Book': 30, 'Ruler': 45}
2for item in stock:item = 'Ink'
3if stock[item] < 31:condition is False
2for item in stock:item = 'Book'
3if stock[item] < 31:condition is True
4stock[item] += 10stock = {'Bag': 35, 'Ink': 55, 'Book': 40, 'Ruler': 45}
2for item in stock:item = 'Ruler'
3if stock[item] < 31:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 15stock = {'Bag': 35, 'Ink': 55, 'Book': 40, 'Ruler': 45, 'Glue': 15}
6del stock['Bag']stock = {'Ink': 55, 'Book': 40, 'Ruler': 45, 'Glue': 15}
7print(stock){'Ink': 55, 'Book': 40, 'Ruler': 45, 'Glue': 15}⏎
8print(len(stock), sum(stock.values()))4 155⏎
C1.57Practice3 marks

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()))
Answer

Output:

{'Ruler': 70, 'Bag': 80, 'Ink': 65, 'Glue': 17}
4 232

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Map': 25, 'Ruler': 70, 'Bag': 80, 'Ink': 65}stock = {'Map': 25, 'Ruler': 70, 'Bag': 80, 'Ink': 65}
2for item in stock:item = 'Map'
3if stock[item] < 38:condition is True
4stock[item] += 10stock = {'Map': 35, 'Ruler': 70, 'Bag': 80, 'Ink': 65}
2for item in stock:item = 'Ruler'
3if stock[item] < 38:condition is False
2for item in stock:item = 'Bag'
3if stock[item] < 38:condition is False
2for item in stock:item = 'Ink'
3if stock[item] < 38:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 17stock = {'Map': 35, 'Ruler': 70, 'Bag': 80, 'Ink': 65, 'Glue': 17}
6del stock['Map']stock = {'Ruler': 70, 'Bag': 80, 'Ink': 65, 'Glue': 17}
7print(stock){'Ruler': 70, 'Bag': 80, 'Ink': 65, 'Glue': 17}⏎
8print(len(stock), sum(stock.values()))4 232⏎
C1.58Practice3 marks

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)
Answer

Output:

[35, 74, 53, 21, 62, 50]
[35, 62] 4

Working (step by step)

LineStatementValues after this stepPrinted
1L = [5, 30, 44, 9, 12, 50]L = [5, 30, 44, 9, 12, 50]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [35, 30, 44, 9, 12, 50]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [35, 74, 44, 9, 12, 50]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [35, 74, 53, 9, 12, 50]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [35, 74, 53, 21, 12, 50]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [35, 74, 53, 21, 62, 50]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[35, 74, 53, 21, 62, 50]⏎
5print(L[::4], max(L) % 7)[35, 62] 4⏎
C1.59Practice3 marks

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])
Answer

Output:

[36, 16]
[21, 49, 29, 10]
[36, 16, 21, 49]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [36, 10, 29, 49, 16, 21]L = [36, 10, 29, 49, 16, 21]
2A, B = [], []A = [], B = []
3for x in L:x = 36
4if x % 4 == 0:condition is True
5A.append(x)A = [36]
3for x in L:x = 10
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [10]
3for x in L:x = 29
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [29, 10]
3for x in L:x = 49
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [49, 29, 10]
3for x in L:x = 16
4if x % 4 == 0:condition is True

… the same steps continue for the remaining values.

C1.60Practice3 marks

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()))
Answer

Output:

{'Book': 30, 'Ruler': 25, 'Map': 55, 'Glue': 14}
4 124

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Bag': 50, 'Book': 20, 'Ruler': 15, 'Map': 55}stock = {'Bag': 50, 'Book': 20, 'Ruler': 15, 'Map': 55}
2for item in stock:item = 'Bag'
3if stock[item] < 37:condition is False
2for item in stock:item = 'Book'
3if stock[item] < 37:condition is True
4stock[item] += 10stock = {'Bag': 50, 'Book': 30, 'Ruler': 15, 'Map': 55}
2for item in stock:item = 'Ruler'
3if stock[item] < 37:condition is True
4stock[item] += 10stock = {'Bag': 50, 'Book': 30, 'Ruler': 25, 'Map': 55}
2for item in stock:item = 'Map'
3if stock[item] < 37:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 14stock = {'Bag': 50, 'Book': 30, 'Ruler': 25, 'Map': 55, 'Glue': 14}
6del stock['Bag']stock = {'Book': 30, 'Ruler': 25, 'Map': 55, 'Glue': 14}
7print(stock){'Book': 30, 'Ruler': 25, 'Map': 55, 'Glue': 14}⏎
8print(len(stock), sum(stock.values()))4 124⏎
C1.61Practice3 marks

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()))
Answer

Output:

{'Map': 40, 'Pen': 40, 'Ink': 75, 'Glue': 5}
4 160

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Bag': 15, 'Map': 40, 'Pen': 30, 'Ink': 75}stock = {'Bag': 15, 'Map': 40, 'Pen': 30, 'Ink': 75}
2for item in stock:item = 'Bag'
3if stock[item] < 32:condition is True
4stock[item] += 10stock = {'Bag': 25, 'Map': 40, 'Pen': 30, 'Ink': 75}
2for item in stock:item = 'Map'
3if stock[item] < 32:condition is False
2for item in stock:item = 'Pen'
3if stock[item] < 32:condition is True
4stock[item] += 10stock = {'Bag': 25, 'Map': 40, 'Pen': 40, 'Ink': 75}
2for item in stock:item = 'Ink'
3if stock[item] < 32:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 5stock = {'Bag': 25, 'Map': 40, 'Pen': 40, 'Ink': 75, 'Glue': 5}
6del stock['Bag']stock = {'Map': 40, 'Pen': 40, 'Ink': 75, 'Glue': 5}
7print(stock){'Map': 40, 'Pen': 40, 'Ink': 75, 'Glue': 5}⏎
8print(len(stock), sum(stock.values()))4 160⏎
C1.62Practice3 marks

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])
Answer

Output:

[]
[41, 53, 42, 33, 15, 25]
[41, 53]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [25, 15, 33, 42, 53, 41]L = [25, 15, 33, 42, 53, 41]
2A, B = [], []A = [], B = []
3for x in L:x = 25
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [25]
3for x in L:x = 15
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [15, 25]
3for x in L:x = 33
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [33, 15, 25]
3for x in L:x = 42
4if x % 4 == 0:condition is False
7B.insert(0, x)B = [42, 33, 15, 25]
3for x in L:x = 53
4if x % 4 == 0:condition is False

… the same steps continue for the remaining values.

C1.63Practice3 marks

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()))
Answer

Output:

{'Ruler': 25, 'Pen': 50, 'Ink': 65, 'Glue': 19}
4 159

Working (step by step)

LineStatementValues after this stepPrinted
1stock = {'Ruler': 15, 'Pen': 40, 'Map': 75, 'Ink': 65}stock = {'Ruler': 15, 'Pen': 40, 'Map': 75, 'Ink': 65}
2for item in stock:item = 'Ruler'
3if stock[item] < 45:condition is True
4stock[item] += 10stock = {'Ruler': 25, 'Pen': 40, 'Map': 75, 'Ink': 65}
2for item in stock:item = 'Pen'
3if stock[item] < 45:condition is True
4stock[item] += 10stock = {'Ruler': 25, 'Pen': 50, 'Map': 75, 'Ink': 65}
2for item in stock:item = 'Map'
3if stock[item] < 45:condition is False
2for item in stock:item = 'Ink'
3if stock[item] < 45:condition is False
2for item in stock:loop ends (no more values)
5stock["Glue"] = 19stock = {'Ruler': 25, 'Pen': 50, 'Map': 75, 'Ink': 65, 'Glue': 19}
6del stock['Map']stock = {'Ruler': 25, 'Pen': 50, 'Ink': 65, 'Glue': 19}
7print(stock){'Ruler': 25, 'Pen': 50, 'Ink': 65, 'Glue': 19}⏎
8print(len(stock), sum(stock.values()))4 159⏎
C1.64Practice3 marks

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)
Answer

Output:

[91, 77, 66, 100, 63, 5]
[91, 63] 4

Working (step by step)

LineStatementValues after this stepPrinted
1L = [38, 53, 24, 42, 58, 5]L = [38, 53, 24, 42, 58, 5]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [91, 53, 24, 42, 58, 5]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [91, 77, 24, 42, 58, 5]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [91, 77, 66, 42, 58, 5]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [91, 77, 66, 100, 58, 5]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [91, 77, 66, 100, 63, 5]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[91, 77, 66, 100, 63, 5]⏎
5print(L[::4], max(L) % 6)[91, 63] 4⏎
C1.65Practice3 marks

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)
Answer

Output:

[113, 61, 18, 45, 86, 53]
[113, 45] 1

Working (step by step)

LineStatementValues after this stepPrinted
1L = [58, 55, 6, 12, 33, 53]L = [58, 55, 6, 12, 33, 53]
2for i in range(1, len(L)):i = 1
3L[i - 1] = L[i - 1] + L[i]L = [113, 55, 6, 12, 33, 53]
2for i in range(1, len(L)):i = 2
3L[i - 1] = L[i - 1] + L[i]L = [113, 61, 6, 12, 33, 53]
2for i in range(1, len(L)):i = 3
3L[i - 1] = L[i - 1] + L[i]L = [113, 61, 18, 12, 33, 53]
2for i in range(1, len(L)):i = 4
3L[i - 1] = L[i - 1] + L[i]L = [113, 61, 18, 45, 33, 53]
2for i in range(1, len(L)):i = 5
3L[i - 1] = L[i - 1] + L[i]L = [113, 61, 18, 45, 86, 53]
2for i in range(1, len(L)):loop ends (no more values)
4print(L)[113, 61, 18, 45, 86, 53]⏎
5print(L[::3], max(L) % 7)[113, 45] 1⏎
C1.66Practice3 marks

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])
Answer

Output:

[50, 46, 14, 42, 58]
[15]
[50, 46, 14, 42, 58, 15]

Working (step by step)

LineStatementValues after this stepPrinted
1L = [50, 46, 14, 42, 15, 58]L = [50, 46, 14, 42, 15, 58]
2A, B = [], []A = [], B = []
3for x in L:x = 50
4if x % 2 == 0:condition is True
5A.append(x)A = [50]
3for x in L:x = 46
4if x % 2 == 0:condition is True
5A.append(x)A = [50, 46]
3for x in L:x = 14
4if x % 2 == 0:condition is True
5A.append(x)A = [50, 46, 14]
3for x in L:x = 42
4if x % 2 == 0:condition is True
5A.append(x)A = [50, 46, 14, 42]
3for x in L:x = 15
4if x % 2 == 0:condition is False

… the same steps continue for the remaining values.

C2Python programs3 marks · 65 questions
C2.1Practice3 marks

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).

Answer
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
C2.2Practice3 marks

Write a program to find the sale price of an item, given its cost and the discount percentage.

Answer
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
C2.3Practice3 marks

Write a program to find the area and the perimeter of a rectangle.

Answer
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
C2.4Practice3 marks

Write a program to find the area and the circumference of a circle.

Answer
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
C2.5Practice3 marks

Write a program to find the area and the perimeter of a square.

Answer
s = float(input('Side: '))
print('Area =', s * s)
print('Perimeter =', 4 * s)

Sample run

Side: 9
Area = 81.0
Perimeter = 36.0
C2.6Practice3 marks

Write a program to find the area of a triangle using Heron's formula, and its perimeter.

Answer
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
C2.7Practice3 marks

Write a program to find the simple interest and the compound interest.

Answer
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
C2.8Practice3 marks

Write a program to find the profit or loss, given the cost price and the selling price.

Answer
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
C2.9Practice3 marks

Write a program to calculate the EMI, given the amount, the yearly rate of interest and the period in months.

Answer
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
C2.10Practice3 marks

Write a program to calculate the GST and the total bill amount for a given price and GST rate.

Answer
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
C2.11Practice3 marks

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.

Answer
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
C2.12Practice3 marks

Write a program to print the first n multiples of a given number.

Answer
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 
C2.13Practice3 marks

Write a program to find the sum of the squares of the first 100 natural numbers.

Answer
s = 0
for i in range(1, 101):
    s = s + i * i
print('Sum of squares =', s)

Sample run

Sum of squares = 338350
C2.14Practice3 marks

Write a program to count the vowels in a string entered by the user.

Answer
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
C2.15Practice3 marks

Write a program to count how many times a given letter occurs in a string.

Answer
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
C2.16Practice3 marks

Write a program to print the words of a string that start with a given letter.

Answer
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
C2.17Practice3 marks

Write a program to check whether a number is even or odd and positive or negative.

Answer
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
C2.18Practice3 marks

Write a program to print the multiplication table of a number.

Answer
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
C2.19Practice3 marks

Write a program to find the factorial of a number using a while loop.

Answer
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
C2.20Practice3 marks

Write a program to find the sum of the digits of a number.

Answer
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
C2.21Practice3 marks

Write a program to convert a temperature from Celsius to Fahrenheit.

Answer
c = float(input('Celsius: '))
f = c * 9 / 5 + 32
print('Fahrenheit =', f)

Sample run

Celsius: 36.6
Fahrenheit = 97.88000000000001
C2.22Practice3 marks

Write a program to check whether a year is a leap year.

Answer
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
C2.23Practice3 marks

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.

Answer
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
C2.24Practice3 marks

Write a program to find the largest of three numbers.

Answer
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
C2.25Practice3 marks

Write a program to print the sum of all even numbers from 1 to n.

Answer
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
C2.26Practice3 marks

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'.

Answer
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
C2.27Practice3 marks

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.

Answer
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
C2.28Practice3 marks

Write a program to swap two numbers without a third variable.

Answer
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
C2.29Practice3 marks

Write a program to input a number and print its factorial.

Answer
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
C2.30Practice3 marks

Write a program to input a number and find the sum of its digits.

Answer
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
C2.31Practice3 marks

Write a program to input a number and check whether it is a palindrome.

Answer
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
C2.32Practice3 marks

Write a program to input a number and check whether it is prime.

Answer
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
C2.33Practice3 marks

Write a program to check whether a three-digit number is an Armstrong number.

Answer
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
C2.34Practice3 marks

Write a program to input two numbers and find their GCD (HCF) and LCM.

Answer
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
C2.35Practice3 marks

Write a program to print the first n terms of the Fibonacci series.

Answer
n = int(input('How many terms? '))
a, b = 0, 1
for i in range(n):
    print(a, end=' ')
    a, b = b, a + b

Sample run

How many terms? 8
0 1 1 2 3 5 8 13 
C2.36Practice3 marks

Write a program to input a number and print its multiplication table up to 10.

Answer
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
C2.37Practice3 marks

Write a program to input a year and check whether it is a leap year.

Answer
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
C2.38Practice3 marks

Write a program to input three numbers and print the largest.

Answer
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
C2.39Practice3 marks

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).

Answer
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
C2.40Practice3 marks

Write a program to check whether a number is a perfect number (equal to the sum of its factors other than itself).

Answer
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
C2.41Practice3 marks

Write a program to input a number and count its digits.

Answer
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
C2.42Practice3 marks

Write a program to print all prime numbers between 1 and n.

Answer
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 
C2.43Practice3 marks

Write a program to find the sum of even numbers and the sum of odd numbers from 1 to n.

Answer
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
C2.44Practice3 marks

Write a program to input a number and print its reverse.

Answer
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
C2.45Practice3 marks

Write a program to input the principal, rate and time and print the simple interest and compound interest.

Answer
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
C2.46Practice3 marks

Write a program to convert a temperature in Celsius to Fahrenheit and Kelvin.

Answer
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
C2.47Practice3 marks

Write a program to input the three sides of a triangle and check whether it is equilateral, isosceles or scalene.

Answer
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
C2.48Practice3 marks

Write a program to find the sum of the squares of the first n natural numbers.

Answer
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
C2.49Practice3 marks

Write a program to input n numbers and print their average, the largest and the smallest.

Answer
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
C2.50Practice3 marks

Write a program to print all the factors of a number and their count.

Answer
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
C2.51Practice3 marks

Write a program to input a number and print whether it is positive, negative or zero, and whether it is even or odd.

Answer
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
C2.52Practice3 marks

Write a program to print the following pattern for n rows (shown for n = 4):

*
* *
* * *
* * * *
Answer
n = int(input('Rows: '))
for i in range(1, n + 1):
    print('* ' * i)

Sample run

Rows: 4
* 
* * 
* * * 
* * * * 
C2.53Practice3 marks

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
Answer
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 
C2.54Practice3 marks

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
Answer
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 
C2.55Practice3 marks

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
Answer
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 
C2.56Practice3 marks

Write a program to print the following pattern for n rows (shown for n = 4):

   *
  **
 ***
****
Answer
n = int(input('Rows: '))
for i in range(1, n + 1):
    print(' ' * (n - i) + '*' * i)

Sample run

Rows: 4
   *
  **
 ***
****
C2.57Practice3 marks

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
Answer
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 
C2.58Practice3 marks

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
Answer
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 
C2.59Practice3 marks

Write a program to input the values needed and find the sum of the series: 1 + x + x² + x³ + ... + xⁿ

Answer
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
C2.60Practice3 marks

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ⁿ)

Answer
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
C2.61Practice3 marks

Write a program to input the values needed and find the sum of the series: x - x²/2 + x³/3 - ... up to n terms

Answer
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
C2.62Practice3 marks

Write a program to input the values needed and find the sum of the series: 1 + 1/2 + 1/3 + ... + 1/n

Answer
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
C2.63Practice3 marks

Write a program to input the values needed and find the sum of the series: 1² + 2² + 3² + ... + n² and 1³ + 2³ + ... + n³

Answer
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
C2.64Practice3 marks

Write a program to input the values needed and find the sum of the series: 1 + 2 + 4 + 8 + ... (n terms)

Answer
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
C2.65Practice3 marks

Write a program to input the values needed and find the sum of the series: 1 + 3 + 5 + ... (first n odd numbers)

Answer
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
C3SQL: three commands3 marks · 50 questions
C3.1Practice3 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL commands for the following:

  1. Increase the Price of all the books whose Subject is Science by 10.
  2. Display Title of the books whose Subject is Computer and Price is at least 300.
  3. Display BookID, Title and Price of the books whose Price is between 200 and 250.
Answer

(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;
BookIDTitlePrice
201Informatics Practices210
206The Story of My Experiments250

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.

C3.2Practice3 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL commands for the following:

  1. Display PName and MfgDate of the products whose MfgDate is between '2025-10-01' and '2026-01-31'.
  2. Display PName of the products whose Brand is Camlin and Discount is not NULL.
  3. Increase the Price of all the products whose Category is Stationery by 10.
Answer

(i)

SELECT PName, MfgDate FROM PRODUCT WHERE MfgDate BETWEEN '2025-10-01' AND '2026-01-31';
PNameMfgDate
Notebook2026-01-10
Geometry Box2025-11-02
Lunch Box2025-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.

C3.3Practice3 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL commands for the following:

  1. Display PName of the products whose Brand is Camlin and Discount is not NULL.
  2. Display PName and Category of the products whose Category is Electronics or Stationery.
  3. Display PCode, Price and Price increased by 10 for every product.
Answer

(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';
PNameCategory
NotebookStationery
Pen DriveElectronics
Geometry BoxStationery
MouseElectronics
EarphonesElectronics

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;
PCodePricePrice + 10
P016070
P02450460
P03180190
P04650660
P05320330
P06899909
P07275285

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.

C3.4Practice3 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL commands for the following:

  1. Display EName and City of the employees whose City is not Mumbai.
  2. Display EName of the employees whose City is Mumbai and Bonus is not NULL.
  3. Display EName of the employees whose Dept is IT and Salary is at least 70000.
Answer

(i)

SELECT EName, City FROM EMPLOYEE WHERE City <> 'Mumbai';
ENameCity
RaviDelhi
SeemaPune
TarunDelhi
VikasPune
WasimDelhi

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.

C3.5Practice3 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL commands for the following:

  1. Display PName and Doctor of the patients whose Doctor is not Dr. Iyer.
  2. Display PID, Fee and Fee increased by 10 for every patient.
  3. Display PName and Fee of all the patients whose Fee is more than 4000.
Answer

(i)

SELECT PName, Doctor FROM PATIENT WHERE Doctor <> 'Dr. Iyer';
PNameDoctor
MohanDr. Rao
NishaDr. Sen
OmDr. Rao
QasimDr. Sen
SahilDr. 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;
PIDFeeFee + 10
1115001510
1280008010
1312001210
1450005010
1595009510
1645004510
17900910

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;
PNameFee
Nisha8000
Pooja5000
Qasim9500
Rekha4500

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.

C3.6Practice3 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL commands for the following:

  1. Display all the details of the books whose Subject is Computer.
  2. Display Title and Publisher of the books whose Publisher is not Penguin.
  3. Display Title and Subject of the books whose Subject is not Computer.
Answer

(i)

SELECT * FROM BOOK WHERE Subject = 'Computer';
BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

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';
TitlePublisher
Informatics PracticesNCERT
Physics Part 1NCERT
Wings of FireUniversities
Python BasicsBPB
Chemistry Part 1NCERT
Learn SQLBPB

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';
TitleSubject
Physics Part 1Science
Wings of FireBiography
Chemistry Part 1Science
The Story of My ExperimentsBiography

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.

C3.7Practice3 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL commands for the following:

  1. Display PName and Fee of all the patients whose Fee is more than 1500.
  2. Display PName and Ward of the patients whose Ward is Maternity or General.
  3. Display PName and Insurance of the patients whose Insurance is not NULL.
Answer

(i)

SELECT PName, Fee FROM PATIENT WHERE Fee > 1500;
PNameFee
Nisha8000
Pooja5000
Qasim9500
Rekha4500

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';
PNameWard
MohanGeneral
OmGeneral
PoojaMaternity
RekhaMaternity
SahilGeneral

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;
PNameInsurance
MohanLIC
OmStar
PoojaLIC
SahilStar

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 =.)

C3.8Practice3 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL commands for the following:

  1. Display PName of the patients whose Ward is General and Fee is at least 1000.
  2. Display PName and Insurance of the patients whose Insurance is not NULL.
  3. Display PName and Doctor of the patients whose Doctor is not Dr. Rao.
Answer

(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;
PNameInsurance
MohanLIC
OmStar
PoojaLIC
SahilStar

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';
PNameDoctor
NishaDr. Sen
PoojaDr. Iyer
QasimDr. Sen
RekhaDr. 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.

C3.9Practice3 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL commands for the following:

  1. Display Name and Section of the students whose Section is not A.
  2. Display Name and Marks of the students whose Marks is less than 60 or whose Phone is NULL.
  3. Display all the details of the students whose Section is A.
Answer

(i)

SELECT Name, Section FROM STUDENT WHERE NOT Section = 'A';
NameSection
BhavyaB
DivyaC
EshanB
GauravC

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;
NameMarks
Bhavya92
Chirag45
Eshan88
Farah31
Gaurav59

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';
RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
34523ChiragAM2010-01-05459810033333
64556FarahAF2009-09-09319810066666

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 (*).

C3.10Practice3 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL commands for the following:

  1. Display EmpID, Salary and Salary increased by 10 for every employee.
  2. Display EName and Bonus of the employees whose Bonus is not NULL.
  3. Display EName and Salary of the employees whose Salary is less than 50000 or whose Bonus is NULL.
Answer

(i)

SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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;
ENameBonus
Ravi3000
Tarun5000
Vikas4000
Wasim2000

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;
ENameSalary
Ravi42000
Seema58000
Usha36000
Wasim39000
Yamini81000

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 =.)

C3.11Practice3 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL commands for the following:

  1. Display Name and Phone of the students whose Phone is not NULL.
  2. Display RollNo, Name and Marks of the students whose Marks is between 70 and 80.
  3. Display Name and Marks of all the students whose Marks is more than 50.
Answer

(i)

SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
NamePhone
Aarav9810011111
Chirag9810033333
Divya9810044444
Farah9810066666
Gaurav9810077777

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;
RollNoNameMarks
1Aarav78

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;
NameMarks
Aarav78
Bhavya92
Divya66
Eshan88
Gaurav59

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.

C3.12Practice3 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL commands for the following:

  1. Display PName and Price of all the products whose Price is more than 500.
  2. Display PName of the products whose Category is Stationery and Price is at least 500.
  3. Display PName and Discount of the products whose Discount is not NULL.
Answer

(i)

SELECT PName, Price FROM PRODUCT WHERE Price > 500;
PNamePrice
Mouse650
Earphones899

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;
PNameDiscount
Notebook5
Geometry Box10
Mouse15
Earphones20
Lunch Box8

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 =.)

C3.13Practice3 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL commands for the following:

  1. Display Name and DOB of the students whose DOB is between '2009-06-01' and '2009-12-31'.
  2. Display RollNo, Marks and Marks increased by 10 for every student.
  3. Display Name and Marks of the students whose Marks is less than 60 or whose Phone is NULL.
Answer

(i)

SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
NameDOB
Bhavya2009-11-30
Divya2009-07-21
Farah2009-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;
RollNoMarksMarks + 10
17888
292102
34555
46676
58898
63141
75969

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;
NameMarks
Bhavya92
Chirag45
Eshan88
Farah31
Gaurav59

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 =.)

C3.14Practice3 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL commands for the following:

  1. Display Name and Gender of the students whose Gender is not F.
  2. Display Name of the students whose Section is B and Marks is at least 60.
  3. Display Name and Marks of all the students whose Marks is more than 60.
Answer

(i)

SELECT Name, Gender FROM STUDENT WHERE Gender <> 'F';
NameGender
AaravM
ChiragM
EshanM
GauravM

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;
NameMarks
Aarav78
Bhavya92
Divya66
Eshan88

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.

C3.15Practice3 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL commands for the following:

  1. Display Name and Gender of the students whose Gender is not M.
  2. Display RollNo, Marks and Marks increased by 10 for every student.
  3. Display all the details of the students whose Section is A.
Answer

(i)

SELECT Name, Gender FROM STUDENT WHERE Gender <> 'M';
NameGender
BhavyaF
DivyaF
FarahF

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;
RollNoMarksMarks + 10
17888
292102
34555
46676
58898
63141
75969

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';
RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
34523ChiragAM2010-01-05459810033333
64556FarahAF2009-09-09319810066666

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 (*).

C3.16Practice3 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL commands for the following:

  1. Display PName and AdmitDate of the patients whose AdmitDate is between '2026-09-05' and '2026-09-15'.
  2. Display PName and Fee of the patients whose Fee is less than 4000 or whose Insurance is NULL.
  3. Display PName of the patients whose Ward is General and Fee is at least 1500.
Answer

(i)

SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
PNameAdmitDate
Nisha2026-09-05
Om2026-09-10
Pooja2026-09-12
Qasim2026-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;
PNameFee
Mohan1500
Nisha8000
Om1200
Qasim9500
Rekha4500
Sahil900

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.

C3.17Practice3 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL commands for the following:

  1. Display PID, Fee and Fee increased by 10 for every patient.
  2. Display PName and Ward of the patients whose Ward is Maternity or ICU.
  3. Display PName of the patients whose Insurance is not known (NULL).
Answer

(i)

SELECT PID, Fee, Fee + 10 FROM PATIENT;
PIDFeeFee + 10
1115001510
1280008010
1312001210
1450005010
1595009510
1645004510
17900910

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';
PNameWard
NishaICU
PoojaMaternity
QasimICU
RekhaMaternity

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 =.)

C3.18Practice3 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL commands for the following:

  1. Display Name and Section of the students whose Section is not A.
  2. Display RollNo, Name and Marks of the students whose Marks is between 60 and 80.
  3. Display Name and Marks of all the students whose Marks is more than 80.
Answer

(i)

SELECT Name, Section FROM STUDENT WHERE NOT Section = 'A';
NameSection
BhavyaB
DivyaC
EshanB
GauravC

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;
RollNoNameMarks
1Aarav78
4Divya66

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;
NameMarks
Bhavya92
Eshan88

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.

C3.19Practice3 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL commands for the following:

  1. Display Name and DOB of the students whose DOB is between '2009-06-01' and '2009-12-31'.
  2. Display Name of the students whose Phone is not known (NULL).
  3. Display RollNo, Marks and Marks increased by 10 for every student.
Answer

(i)

SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
NameDOB
Bhavya2009-11-30
Divya2009-07-21
Farah2009-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;
RollNoMarksMarks + 10
17888
292102
34555
46676
58898
63141
75969

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.

C3.20Practice3 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL commands for the following:

  1. Display EmpID, EName and Salary of the employees whose Salary is between 60000 and 70000.
  2. Display EName and Salary of the employees whose Salary is less than 60000 or whose Bonus is NULL.
  3. Display EmpID, Salary and Salary increased by 10 for every employee.
Answer

(i)

SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 60000 AND 70000;
EmpIDENameSalary
E105Vikas64000

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;
ENameSalary
Ravi42000
Seema58000
Usha36000
Wasim39000
Yamini81000

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;
EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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.

C3.21Practice3 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL commands for the following:

  1. Display PName and Brand of the products whose Brand is not Camlin.
  2. Display PName of the products whose Discount is not known (NULL).
  3. Display PName and Price of all the products whose Price is more than 400.
Answer

(i)

SELECT PName, Brand FROM PRODUCT WHERE Brand <> 'Camlin';
PNameBrand
NotebookClassmate
Pen DriveSanDisk
MouseLogitech
Water BottleMilton
EarphonesBoat
Lunch BoxMilton

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;
PNamePrice
Pen Drive450
Mouse650
Earphones899

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.

C3.22Practice3 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL commands for the following:

  1. Display EmpID, Salary and Salary increased by 10 for every employee.
  2. Display EName and City of the employees whose City is not Mumbai.
  3. Display EName and Salary of the employees whose Salary is less than 40000 or whose Bonus is NULL.
Answer

(i)

SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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';
ENameCity
RaviDelhi
SeemaPune
TarunDelhi
VikasPune
WasimDelhi

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;
ENameSalary
Seema58000
Usha36000
Wasim39000
Yamini81000

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 =.)

C3.23Practice3 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL commands for the following:

  1. Increase the Salary of all the employees whose Dept is Sales by 10.
  2. Display EName of the employees whose Dept is Sales and Salary is at least 60000.
  3. Display EName of the employees whose Bonus is not known (NULL).
Answer

(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 =.)

C3.24Practice3 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL commands for the following:

  1. Display Name and DOB of the students whose DOB is between '2009-06-01' and '2009-12-31'.
  2. Display RollNo, Name and Marks of the students whose Marks is between 50 and 80.
  3. Display Name of the students whose Section is B and Marks is at least 80.
Answer

(i)

SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
NameDOB
Bhavya2009-11-30
Divya2009-07-21
Farah2009-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;
RollNoNameMarks
1Aarav78
4Divya66
7Gaurav59

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.

C3.25Practice3 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL commands for the following:

  1. Display Name and Marks of all the students whose Marks is more than 50.
  2. Display Name and Marks of the students whose Marks is less than 50 or whose Phone is NULL.
  3. Display all the details of the students whose Section is B.
Answer

(i)

SELECT Name, Marks FROM STUDENT WHERE Marks > 50;
NameMarks
Aarav78
Bhavya92
Divya66
Eshan88
Gaurav59

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;
NameMarks
Bhavya92
Chirag45
Eshan88
Farah31

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';
RollNoAdmNoNameSectionGenderDOBMarksPhone
24512BhavyaBF2009-11-3092NULL
54545EshanBM2010-03-1788NULL

Explanation: WHERE keeps only the rows where Section is 'B': 2 of the 7 rows match (Bhavya, Eshan). SELECT then shows all the columns (*).

C3.26Practice3 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL commands for the following:

  1. Display PName and Category of the products whose Category is Home or Stationery.
  2. Display PName of the products whose Brand is Milton and Discount is not NULL.
  3. Display all the details of the products whose Category is Stationery.
Answer

(i)

SELECT PName, Category FROM PRODUCT WHERE Category = 'Home' OR Category = 'Stationery';
PNameCategory
NotebookStationery
Geometry BoxStationery
Water BottleHome
Lunch BoxHome

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';
PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0389010033Geometry BoxStationeryCamlin2025-11-0218010

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 (*).

C3.27Practice3 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL commands for the following:

  1. Display BookID, Price and Price increased by 10 for every book.
  2. Display BookID, Title and Price of the books whose Price is between 200 and 250.
  3. Display Title and Subject of the books whose Subject is Computer or Science.
Answer

(i)

SELECT BookID, Price, Price + 10 FROM BOOK;
BookIDPricePrice + 10
201210220
202180190
203299309
204350360
205190200
206250260
207400410

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;
BookIDTitlePrice
201Informatics Practices210
206The Story of My Experiments250

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';
TitleSubject
Informatics PracticesComputer
Physics Part 1Science
Python BasicsComputer
Chemistry Part 1Science
Learn SQLComputer

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.

C3.28Practice3 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL commands for the following:

  1. Display EmpID, Salary and Salary increased by 10 for every employee.
  2. Display EName and DOJ of the employees whose DOJ is between '2018-01-01' and '2020-12-31'.
  3. Display EName and Salary of the employees whose Salary is less than 40000 or whose Bonus is NULL.
Answer

(i)

SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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';
ENameDOJ
Ravi2018-06-01
Seema2020-01-15
Vikas2019-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;
ENameSalary
Seema58000
Usha36000
Wasim39000
Yamini81000

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 =.)

C3.29Practice3 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL commands for the following:

  1. Display Name of the students whose Phone is not known (NULL).
  2. Display Name and DOB of the students whose DOB is between '2009-06-01' and '2009-12-31'.
  3. Display Name and Gender of the students whose Gender is not F.
Answer

(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';
NameDOB
Bhavya2009-11-30
Divya2009-07-21
Farah2009-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';
NameGender
AaravM
ChiragM
EshanM
GauravM

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.

C3.30Practice3 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL commands for the following:

  1. Display PName and Insurance of the patients whose Insurance is not NULL.
  2. Display PName and Fee of the patients whose Fee is less than 1500 or whose Insurance is NULL.
  3. Display PName and Fee of all the patients whose Fee is more than 1000.
Answer

(i)

SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;
PNameInsurance
MohanLIC
OmStar
PoojaLIC
SahilStar

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;
PNameFee
Nisha8000
Om1200
Qasim9500
Rekha4500
Sahil900

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;
PNameFee
Mohan1500
Nisha8000
Om1200
Pooja5000
Qasim9500
Rekha4500

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.

C3.31Practice3 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL commands for the following:

  1. Display PName and Category of the products whose Category is Electronics or Home.
  2. Display PName and Price of all the products whose Price is more than 100.
  3. Display PName and Category of the products whose Category is not Electronics.
Answer

(i)

SELECT PName, Category FROM PRODUCT WHERE Category = 'Electronics' OR Category = 'Home';
PNameCategory
Pen DriveElectronics
MouseElectronics
Water BottleHome
EarphonesElectronics
Lunch BoxHome

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;
PNamePrice
Pen Drive450
Geometry Box180
Mouse650
Water Bottle320
Earphones899
Lunch Box275

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';
PNameCategory
NotebookStationery
Geometry BoxStationery
Water BottleHome
Lunch BoxHome

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.

C3.32Practice3 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL commands for the following:

  1. Display PName of the patients whose Insurance is not known (NULL).
  2. Display PName and AdmitDate of the patients whose AdmitDate is between '2026-09-05' and '2026-09-15'.
  3. Display PName of the patients whose Ward is Maternity and Fee is at least 6000.
Answer

(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';
PNameAdmitDate
Nisha2026-09-05
Om2026-09-10
Pooja2026-09-12
Qasim2026-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.

C3.33Practice3 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL commands for the following:

  1. Display EName and DOJ of the employees whose DOJ is between '2018-01-01' and '2020-12-31'.
  2. Display EName and Bonus of the employees whose Bonus is not NULL.
  3. Display EmpID, Salary and Salary increased by 10 for every employee.
Answer

(i)

SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';
ENameDOJ
Ravi2018-06-01
Seema2020-01-15
Vikas2019-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;
ENameBonus
Ravi3000
Tarun5000
Vikas4000
Wasim2000

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;
EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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.

C3.34Practice3 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL commands for the following:

  1. Display PName and Price of the products whose Price is less than 100 or whose Discount is NULL.
  2. Display PName and Discount of the products whose Discount is not NULL.
  3. Display PName and Price of all the products whose Price is more than 400.
Answer

(i)

SELECT PName, Price FROM PRODUCT WHERE Price < 100 OR Discount IS NULL;
PNamePrice
Notebook60
Pen Drive450
Water Bottle320

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;
PNameDiscount
Notebook5
Geometry Box10
Mouse15
Earphones20
Lunch Box8

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;
PNamePrice
Pen Drive450
Mouse650
Earphones899

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.

C3.35Practice3 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL commands for the following:

  1. Display RollNo, Name and Marks of the students whose Marks is between 60 and 70.
  2. Display Name and Phone of the students whose Phone is not NULL.
  3. Display Name of the students whose Gender is M and Phone is not NULL.
Answer

(i)

SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 60 AND 70;
RollNoNameMarks
4Divya66

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;
NamePhone
Aarav9810011111
Chirag9810033333
Divya9810044444
Farah9810066666
Gaurav9810077777

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 =.)

C3.36Practice3 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL commands for the following:

  1. Increase the Fee of all the patients whose Ward is ICU by 10.
  2. Display PName and Doctor of the patients whose Doctor is not Dr. Sen.
  3. Display PName and AdmitDate of the patients whose AdmitDate is between '2026-09-05' and '2026-09-15'.
Answer

(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';
PNameDoctor
MohanDr. Rao
OmDr. Rao
PoojaDr. Iyer
RekhaDr. Iyer
SahilDr. 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';
PNameAdmitDate
Nisha2026-09-05
Om2026-09-10
Pooja2026-09-12
Qasim2026-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.

C3.37Practice3 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL commands for the following:

  1. Display RollNo, Marks and Marks increased by 10 for every student.
  2. Display Name and Gender of the students whose Gender is not F.
  3. Display Name and Section of the students whose Section is not B.
Answer

(i)

SELECT RollNo, Marks, Marks + 10 FROM STUDENT;
RollNoMarksMarks + 10
17888
292102
34555
46676
58898
63141
75969

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';
NameGender
AaravM
ChiragM
EshanM
GauravM

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';
NameSection
AaravA
ChiragA
DivyaC
FarahA
GauravC

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.

C3.38Practice3 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL commands for the following:

  1. Display PName of the products whose Brand is Milton and Discount is not NULL.
  2. Display PName and Brand of the products whose Brand is not Milton.
  3. Display PName and Category of the products whose Category is not Electronics.
Answer

(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';
PNameBrand
NotebookClassmate
Pen DriveSanDisk
Geometry BoxCamlin
MouseLogitech
EarphonesBoat

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';
PNameCategory
NotebookStationery
Geometry BoxStationery
Water BottleHome
Lunch BoxHome

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.

C3.39Practice3 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL commands for the following:

  1. Display PCode, PName and Price of the products whose Price is between 100 and 500.
  2. Display PName and Price of the products whose Price is less than 100 or whose Discount is NULL.
  3. Display PName of the products whose Discount is not known (NULL).
Answer

(i)

SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 100 AND 500;
PCodePNamePrice
P02Pen Drive450
P03Geometry Box180
P05Water Bottle320
P07Lunch Box275

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;
PNamePrice
Notebook60
Pen Drive450
Water Bottle320

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 =.)

C3.40Practice3 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL commands for the following:

  1. Display Title of the books whose Subject is Biography and Price is at least 250.
  2. Display Title and Price of all the books whose Price is more than 250.
  3. Display Title and Subject of the books whose Subject is Biography or Science.
Answer

(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;
TitlePrice
Wings of Fire299
Python Basics350
Learn SQL400

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';
TitleSubject
Physics Part 1Science
Wings of FireBiography
Chemistry Part 1Science
The Story of My ExperimentsBiography

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.

C3.41Practice3 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL commands for the following:

  1. Display PName and Price of the products whose Price is less than 100 or whose Discount is NULL.
  2. Display PName and Discount of the products whose Discount is not NULL.
  3. Display PName of the products whose Brand is Camlin and Discount is not NULL.
Answer

(i)

SELECT PName, Price FROM PRODUCT WHERE Price < 100 OR Discount IS NULL;
PNamePrice
Notebook60
Pen Drive450
Water Bottle320

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;
PNameDiscount
Notebook5
Geometry Box10
Mouse15
Earphones20
Lunch Box8

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 =.)

C3.42Practice3 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

Write SQL commands for the following:

  1. Display EName and Salary of all the employees whose Salary is more than 50000.
  2. Display EName and Bonus of the employees whose Bonus is not NULL.
  3. Display EName of the employees whose Dept is Sales and Salary is at least 50000.
Answer

(i)

SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 50000;
ENameSalary
Seema58000
Tarun75000
Vikas64000
Yamini81000

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;
ENameBonus
Ravi3000
Tarun5000
Vikas4000
Wasim2000

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.

C3.43Practice3 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL commands for the following:

  1. Display Name of the students whose Gender is F and Phone is not NULL.
  2. Display Name and Section of the students whose Section is not A.
  3. Display Name and Marks of the students whose Marks is less than 50 or whose Phone is NULL.
Answer

(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';
NameSection
BhavyaB
DivyaC
EshanB
GauravC

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;
NameMarks
Bhavya92
Chirag45
Eshan88
Farah31

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 =.)

C3.44Practice3 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL commands for the following:

  1. Display PName of the patients whose Ward is Maternity and Fee is at least 1000.
  2. Display PName and Insurance of the patients whose Insurance is not NULL.
  3. Display PName of the patients whose Insurance is not known (NULL).
Answer

(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;
PNameInsurance
MohanLIC
OmStar
PoojaLIC
SahilStar

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 =.)

C3.45Practice3 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

Write SQL commands for the following:

  1. Display PName and Doctor of the patients whose Doctor is not Dr. Iyer.
  2. Display PName of the patients whose Ward is Maternity and Fee is at least 6000.
  3. Display PName and Fee of all the patients whose Fee is more than 6000.
Answer

(i)

SELECT PName, Doctor FROM PATIENT WHERE Doctor <> 'Dr. Iyer';
PNameDoctor
MohanDr. Rao
NishaDr. Sen
OmDr. Rao
QasimDr. Sen
SahilDr. 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;
PNameFee
Nisha8000
Qasim9500

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.

C3.46Practice3 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL commands for the following:

  1. Display BookID, Price and Price increased by 10 for every book.
  2. Display BookID, Title and Price of the books whose Price is between 300 and 350.
  3. Display Title of the books whose Publisher is Penguin and Member is not NULL.
Answer

(i)

SELECT BookID, Price, Price + 10 FROM BOOK;
BookIDPricePrice + 10
201210220
202180190
203299309
204350360
205190200
206250260
207400410

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;
BookIDTitlePrice
204Python Basics350

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 =.)

C3.47Practice3 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL commands for the following:

  1. Display PName of the products whose Category is Home and Price is at least 300.
  2. Increase the Price of all the products whose Category is Electronics by 10.
  3. Display PCode, PName and Price of the products whose Price is between 300 and 500.
Answer

(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;
PCodePNamePrice
P02Pen Drive450
P05Water Bottle320

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.

C3.48Practice3 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

Write SQL commands for the following:

  1. Display RollNo, Name and Marks of the students whose Marks is between 50 and 70.
  2. Display Name and Marks of all the students whose Marks is more than 70.
  3. Increase the Marks of all the students whose Section is B by 10.
Answer

(i)

SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 50 AND 70;
RollNoNameMarks
4Divya66
7Gaurav59

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;
NameMarks
Aarav78
Bhavya92
Eshan88

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.

C3.49Practice3 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

Write SQL commands for the following:

  1. Display Title and Publisher of the books whose Publisher is not BPB.
  2. Display Title of the books whose Subject is Computer and Price is at least 300.
  3. Display Title and Subject of the books whose Subject is Computer or Science.
Answer

(i)

SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'BPB';
TitlePublisher
Informatics PracticesNCERT
Physics Part 1NCERT
Wings of FireUniversities
Chemistry Part 1NCERT
The Story of My ExperimentsPenguin

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';
TitleSubject
Informatics PracticesComputer
Physics Part 1Science
Python BasicsComputer
Chemistry Part 1Science
Learn SQLComputer

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.

C3.50Practice3 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

Write SQL commands for the following:

  1. Display PName and Price of the products whose Price is less than 100 or whose Discount is NULL.
  2. Display PName and MfgDate of the products whose MfgDate is between '2025-10-01' and '2026-01-31'.
  3. Display PName and Discount of the products whose Discount is not NULL.
Answer

(i)

SELECT PName, Price FROM PRODUCT WHERE Price < 100 OR Discount IS NULL;
PNamePrice
Notebook60
Pen Drive450
Water Bottle320

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';
PNameMfgDate
Notebook2026-01-10
Geometry Box2025-11-02
Lunch Box2025-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;
PNameDiscount
Notebook5
Geometry Box10
Mouse15
Earphones20
Lunch Box8

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 =.)

C4Keys, degree and cardinality3 marks · 45 questions
C4.1Practice3 marks

Observe the table STUDENT and answer.

Table: STUDENT

RollNoAdmNoNameSectionDOBMarksPhone
64556FarahA2009-09-09319810066666
24512BhavyaB2009-11-3092NULL
34523ChiragA2010-01-05459810033333
74567GauravC2010-02-28599810077777
  1. Identify the candidate keys of the table.
  2. If RollNo is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. RollNo and AdmNo (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. AdmNo. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.2Practice3 marks

Observe the table EMPLOYEE and answer.

Table: EMPLOYEE

EmpIDEmailDeptCityDOJSalaryBonus
E103tarun@co.inITDelhi2016-09-20750005000
E105vikas@co.inITPune2019-11-05640004000
E101ravi@co.inSalesDelhi2018-06-01420003000
E104usha@co.inSalesMumbai2021-03-1036000NULL
  1. Identify the candidate keys of the table.
  2. If Email is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. EmpID and Email (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. EmpID. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.3Practice3 marks

Observe the table PRODUCT and answer.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePrice
P0489010044MouseElectronicsLogitech2026-02-20650
P0189010011NotebookStationeryClassmate2026-01-1060
P0289010022Pen DriveElectronicsSanDisk2025-08-15450
P0789010077Lunch BoxHomeMilton2025-12-18275
  1. Identify the candidate keys of the table.
  2. If PCode is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PCode and Barcode (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. Barcode. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.4Practice3 marks

Observe the table BOOK and answer.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDateMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10NULL
2079789386551023Learn SQLComputerBPB2026-08-12Karan
2049789386551009Python BasicsComputerBPB2026-08-01NULL
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30NULL
  1. Identify the candidate keys of the table.
  2. If ISBN is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. BookID and ISBN (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. BookID. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 5 (count of rows). The heading row is not counted.
C4.5Practice3 marks

Observe the table PATIENT and answer.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateInsurance
13323432343234OmGeneralDr. Rao2026-09-10Star
14423442344234PoojaMaternityDr. Iyer2026-09-12LIC
11123412341234MohanGeneralDr. Rao2026-09-02LIC
16623462346234RekhaMaternityDr. Iyer2026-09-18NULL
12223422342234NishaICUDr. Sen2026-09-05NULL
17723472347234SahilGeneralDr. Rao2026-09-20Star
  1. Identify the candidate keys of the table.
  2. If PID is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PID and Aadhaar (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. Aadhaar. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 6 (count of rows). The heading row is not counted.
C4.6Practice3 marks

Observe the table STUDENT and answer.

Table: STUDENT

RollNoAdmNoSectionGenderDOBMarksPhone
44534CF2009-07-21669810044444
24512BF2009-11-3092NULL
74567CM2010-02-28599810077777
54545BM2010-03-1788NULL
  1. Identify the candidate keys of the table.
  2. If AdmNo is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. RollNo and AdmNo (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. RollNo. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.7Practice3 marks

Observe the table EMPLOYEE and answer.

Table: EMPLOYEE

EmpIDEmailDeptCityDOJSalaryBonus
E106wasim@co.inHRDelhi2022-07-25390002000
E105vikas@co.inITPune2019-11-05640004000
E102seema@co.inHRPune2020-01-1558000NULL
E104usha@co.inSalesMumbai2021-03-1036000NULL
E103tarun@co.inITDelhi2016-09-20750005000
  1. Identify the candidate keys of the table.
  2. If EmpID is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. EmpID and Email (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. Email. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 5 (count of rows). The heading row is not counted.
C4.8Practice3 marks

Observe the table PRODUCT and answer.

Table: PRODUCT

PCodeBarcodePNameCategoryMfgDatePriceDiscount
P0789010077Lunch BoxHome2025-12-182758
P0289010022Pen DriveElectronics2025-08-15450NULL
P0489010044MouseElectronics2026-02-2065015
P0589010055Water BottleHome2025-05-30320NULL
P0389010033Geometry BoxStationery2025-11-0218010
  1. Identify the candidate keys of the table.
  2. If Barcode is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PCode and Barcode (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. PCode. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 5 (count of rows). The heading row is not counted.
C4.9Practice3 marks

Observe the table BOOK and answer.

Table: BOOK

BookIDISBNSubjectPublisherIssueDatePriceMember
2029789352920112ScienceNCERT2026-07-10180NULL
2039780143032311BiographyUniversities2026-06-21299Ravi
2019789352921485ComputerNCERT2026-07-03210Asha
2069780140449136BiographyPenguin2026-05-30250NULL
  1. Identify the candidate keys of the table.
  2. If BookID is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. BookID and ISBN (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. ISBN. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.10Practice3 marks

Observe the table PATIENT and answer.

Table: PATIENT

PIDAadhaarWardDoctorAdmitDateFeeInsurance
12223422342234ICUDr. Sen2026-09-058000NULL
15523452345234ICUDr. Sen2026-09-159500NULL
16623462346234MaternityDr. Iyer2026-09-184500NULL
11123412341234GeneralDr. Rao2026-09-021500LIC
  1. Identify the candidate keys of the table.
  2. If Aadhaar is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PID and Aadhaar (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. PID. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.11Practice3 marks

Observe the table STUDENT and answer.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBPhone
34523ChiragAM2010-01-059810033333
14501AaravAM2009-04-129810011111
74567GauravCM2010-02-289810077777
44534DivyaCF2009-07-219810044444
  1. Identify the candidate keys of the table.
  2. If RollNo is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. RollNo and AdmNo (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. AdmNo. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.12Practice3 marks

Observe the table EMPLOYEE and answer.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJBonus
E106wasim@co.inWasimHRDelhi2022-07-252000
E107yamini@co.inYaminiITMumbai2017-12-12NULL
E104usha@co.inUshaSalesMumbai2021-03-10NULL
E103tarun@co.inTarunITDelhi2016-09-205000
E105vikas@co.inVikasITPune2019-11-054000
E102seema@co.inSeemaHRPune2020-01-15NULL
E101ravi@co.inRaviSalesDelhi2018-06-013000
  1. Identify the candidate keys of the table.
  2. If Email is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. EmpID and Email (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. EmpID. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 7 (count of rows). The heading row is not counted.
C4.13Practice3 marks

Observe the table PRODUCT and answer.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePrice
P0789010077Lunch BoxHomeMilton2025-12-18275
P0489010044MouseElectronicsLogitech2026-02-20650
P0189010011NotebookStationeryClassmate2026-01-1060
P0689010066EarphonesElectronicsBoat2026-03-05899
  1. Identify the candidate keys of the table.
  2. If PCode is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PCode and Barcode (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. Barcode. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.14Practice3 marks

Observe the table BOOK and answer.

Table: BOOK

BookIDISBNTitleSubjectIssueDatePriceMember
2069780140449136The Story of My ExperimentsBiography2026-05-30250NULL
2019789352921485Informatics PracticesComputer2026-07-03210Asha
2029789352920112Physics Part 1Science2026-07-10180NULL
2079789386551023Learn SQLComputer2026-08-12400Karan
2039780143032311Wings of FireBiography2026-06-21299Ravi
2059789352925032Chemistry Part 1Science2026-07-15190Neha
  1. Identify the candidate keys of the table.
  2. If ISBN is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. BookID and ISBN (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. BookID. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 6 (count of rows). The heading row is not counted.
C4.15Practice3 marks

Observe the table PATIENT and answer.

Table: PATIENT

PIDAadhaarWardDoctorAdmitDateFeeInsurance
14423442344234MaternityDr. Iyer2026-09-125000LIC
11123412341234GeneralDr. Rao2026-09-021500LIC
15523452345234ICUDr. Sen2026-09-159500NULL
16623462346234MaternityDr. Iyer2026-09-184500NULL
  1. Identify the candidate keys of the table.
  2. If PID is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PID and Aadhaar (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. Aadhaar. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.16Practice3 marks

Observe the table STUDENT and answer.

Table: STUDENT

RollNoAdmNoNameSectionDOBMarksPhone
74567GauravC2010-02-28599810077777
54545EshanB2010-03-1788NULL
44534DivyaC2009-07-21669810044444
34523ChiragA2010-01-05459810033333
24512BhavyaB2009-11-3092NULL
14501AaravA2009-04-12789810011111
  1. Identify the candidate keys of the table.
  2. If AdmNo is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. RollNo and AdmNo (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. RollNo. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 6 (count of rows). The heading row is not counted.
C4.17Practice3 marks

Observe the table EMPLOYEE and answer.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJBonus
E103tarun@co.inTarunITDelhi2016-09-205000
E107yamini@co.inYaminiITMumbai2017-12-12NULL
E105vikas@co.inVikasITPune2019-11-054000
E104usha@co.inUshaSalesMumbai2021-03-10NULL
E101ravi@co.inRaviSalesDelhi2018-06-013000
E106wasim@co.inWasimHRDelhi2022-07-252000
E102seema@co.inSeemaHRPune2020-01-15NULL
  1. Identify the candidate keys of the table.
  2. If EmpID is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. EmpID and Email (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. Email. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 7 (count of rows). The heading row is not counted.
C4.18Practice3 marks

Observe the table PRODUCT and answer.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandPriceDiscount
P0589010055Water BottleHomeMilton320NULL
P0389010033Geometry BoxStationeryCamlin18010
P0789010077Lunch BoxHomeMilton2758
P0489010044MouseElectronicsLogitech65015
P0189010011NotebookStationeryClassmate605
P0289010022Pen DriveElectronicsSanDisk450NULL
P0689010066EarphonesElectronicsBoat89920
  1. Identify the candidate keys of the table.
  2. If Barcode is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PCode and Barcode (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. PCode. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 7 (count of rows). The heading row is not counted.
C4.19Practice3 marks

Observe the table BOOK and answer.

Table: BOOK

BookIDISBNSubjectPublisherIssueDatePriceMember
2059789352925032ScienceNCERT2026-07-15190Neha
2069780140449136BiographyPenguin2026-05-30250NULL
2029789352920112ScienceNCERT2026-07-10180NULL
2019789352921485ComputerNCERT2026-07-03210Asha
2039780143032311BiographyUniversities2026-06-21299Ravi
2049789386551009ComputerBPB2026-08-01350NULL
  1. Identify the candidate keys of the table.
  2. If BookID is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. BookID and ISBN (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. ISBN. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 6 (count of rows). The heading row is not counted.
C4.20Practice3 marks

Observe the table PATIENT and answer.

Table: PATIENT

PIDAadhaarWardDoctorAdmitDateFeeInsurance
17723472347234GeneralDr. Rao2026-09-20900Star
11123412341234GeneralDr. Rao2026-09-021500LIC
13323432343234GeneralDr. Rao2026-09-101200Star
14423442344234MaternityDr. Iyer2026-09-125000LIC
12223422342234ICUDr. Sen2026-09-058000NULL
16623462346234MaternityDr. Iyer2026-09-184500NULL
15523452345234ICUDr. Sen2026-09-159500NULL
  1. Identify the candidate keys of the table.
  2. If Aadhaar is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PID and Aadhaar (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. PID. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 7 (count of rows). The heading row is not counted.
C4.21Practice3 marks

Observe the table STUDENT and answer.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarks
54545EshanBM2010-03-1788
74567GauravCM2010-02-2859
44534DivyaCF2009-07-2166
24512BhavyaBF2009-11-3092
34523ChiragAM2010-01-0545
64556FarahAF2009-09-0931
  1. Identify the candidate keys of the table.
  2. If RollNo is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. RollNo and AdmNo (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. AdmNo. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 6 (count of rows). The heading row is not counted.
C4.22Practice3 marks

Observe the table EMPLOYEE and answer.

Table: EMPLOYEE

EmpIDEmailENameDeptDOJSalaryBonus
E101ravi@co.inRaviSales2018-06-01420003000
E106wasim@co.inWasimHR2022-07-25390002000
E103tarun@co.inTarunIT2016-09-20750005000
E102seema@co.inSeemaHR2020-01-1558000NULL
E107yamini@co.inYaminiIT2017-12-1281000NULL
E104usha@co.inUshaSales2021-03-1036000NULL
E105vikas@co.inVikasIT2019-11-05640004000
  1. Identify the candidate keys of the table.
  2. If Email is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. EmpID and Email (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. EmpID. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 7 (count of rows). The heading row is not counted.
C4.23Practice3 marks

Observe the table PRODUCT and answer.

Table: PRODUCT

PCodeBarcodePNameCategoryMfgDatePriceDiscount
P0389010033Geometry BoxStationery2025-11-0218010
P0689010066EarphonesElectronics2026-03-0589920
P0289010022Pen DriveElectronics2025-08-15450NULL
P0589010055Water BottleHome2025-05-30320NULL
P0789010077Lunch BoxHome2025-12-182758
  1. Identify the candidate keys of the table.
  2. If PCode is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PCode and Barcode (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. Barcode. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 5 (count of rows). The heading row is not counted.
C4.24Practice3 marks

Observe the table BOOK and answer.

Table: BOOK

BookIDISBNTitlePublisherIssueDatePriceMember
2069780140449136The Story of My ExperimentsPenguin2026-05-30250NULL
2059789352925032Chemistry Part 1NCERT2026-07-15190Neha
2029789352920112Physics Part 1NCERT2026-07-10180NULL
2019789352921485Informatics PracticesNCERT2026-07-03210Asha
2049789386551009Python BasicsBPB2026-08-01350NULL
  1. Identify the candidate keys of the table.
  2. If ISBN is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. BookID and ISBN (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. BookID. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 5 (count of rows). The heading row is not counted.
C4.25Practice3 marks

Observe the table PATIENT and answer.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFee
11123412341234MohanGeneralDr. Rao2026-09-021500
16623462346234RekhaMaternityDr. Iyer2026-09-184500
17723472347234SahilGeneralDr. Rao2026-09-20900
12223422342234NishaICUDr. Sen2026-09-058000
14423442344234PoojaMaternityDr. Iyer2026-09-125000
15523452345234QasimICUDr. Sen2026-09-159500
13323432343234OmGeneralDr. Rao2026-09-101200
  1. Identify the candidate keys of the table.
  2. If PID is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PID and Aadhaar (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. Aadhaar. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 7 (count of rows). The heading row is not counted.
C4.26Practice3 marks

Observe the table STUDENT and answer.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarks
24512BhavyaBF2009-11-3092
14501AaravAM2009-04-1278
44534DivyaCF2009-07-2166
74567GauravCM2010-02-2859
  1. Identify the candidate keys of the table.
  2. If AdmNo is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. RollNo and AdmNo (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. RollNo. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.27Practice3 marks

Observe the table EMPLOYEE and answer.

Table: EMPLOYEE

EmpIDEmailENameCityDOJSalaryBonus
E106wasim@co.inWasimDelhi2022-07-25390002000
E104usha@co.inUshaMumbai2021-03-1036000NULL
E101ravi@co.inRaviDelhi2018-06-01420003000
E102seema@co.inSeemaPune2020-01-1558000NULL
E103tarun@co.inTarunDelhi2016-09-20750005000
E105vikas@co.inVikasPune2019-11-05640004000
E107yamini@co.inYaminiMumbai2017-12-1281000NULL
  1. Identify the candidate keys of the table.
  2. If EmpID is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. EmpID and Email (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. Email. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 7 (count of rows). The heading row is not counted.
C4.28Practice3 marks

Observe the table PRODUCT and answer.

Table: PRODUCT

PCodeBarcodePNameCategoryMfgDatePriceDiscount
P0189010011NotebookStationery2026-01-10605
P0489010044MouseElectronics2026-02-2065015
P0289010022Pen DriveElectronics2025-08-15450NULL
P0689010066EarphonesElectronics2026-03-0589920
  1. Identify the candidate keys of the table.
  2. If Barcode is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PCode and Barcode (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. PCode. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.29Practice3 marks

Observe the table BOOK and answer.

Table: BOOK

BookIDISBNTitlePublisherIssueDatePriceMember
2059789352925032Chemistry Part 1NCERT2026-07-15190Neha
2029789352920112Physics Part 1NCERT2026-07-10180NULL
2039780143032311Wings of FireUniversities2026-06-21299Ravi
2049789386551009Python BasicsBPB2026-08-01350NULL
2019789352921485Informatics PracticesNCERT2026-07-03210Asha
  1. Identify the candidate keys of the table.
  2. If BookID is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. BookID and ISBN (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. ISBN. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 5 (count of rows). The heading row is not counted.
C4.30Practice3 marks

Observe the table PATIENT and answer.

Table: PATIENT

PIDAadhaarPNameWardDoctorFeeInsurance
17723472347234SahilGeneralDr. Rao900Star
16623462346234RekhaMaternityDr. Iyer4500NULL
11123412341234MohanGeneralDr. Rao1500LIC
14423442344234PoojaMaternityDr. Iyer5000LIC
  1. Identify the candidate keys of the table.
  2. If Aadhaar is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PID and Aadhaar (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. PID. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.31Practice3 marks

Observe the table STUDENT and answer.

Table: STUDENT

RollNoAdmNoNameSectionGenderMarksPhone
74567GauravCM599810077777
44534DivyaCF669810044444
34523ChiragAM459810033333
64556FarahAF319810066666
24512BhavyaBF92NULL
  1. Identify the candidate keys of the table.
  2. If RollNo is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. RollNo and AdmNo (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. AdmNo. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 5 (count of rows). The heading row is not counted.
C4.32Practice3 marks

Observe the table EMPLOYEE and answer.

Table: EMPLOYEE

EmpIDEmailDeptCityDOJSalaryBonus
E102seema@co.inHRPune2020-01-1558000NULL
E106wasim@co.inHRDelhi2022-07-25390002000
E107yamini@co.inITMumbai2017-12-1281000NULL
E101ravi@co.inSalesDelhi2018-06-01420003000
  1. Identify the candidate keys of the table.
  2. If Email is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. EmpID and Email (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. EmpID. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.33Practice3 marks

Observe the table PRODUCT and answer.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandPriceDiscount
P0189010011NotebookStationeryClassmate605
P0389010033Geometry BoxStationeryCamlin18010
P0489010044MouseElectronicsLogitech65015
P0789010077Lunch BoxHomeMilton2758
P0689010066EarphonesElectronicsBoat89920
P0289010022Pen DriveElectronicsSanDisk450NULL
  1. Identify the candidate keys of the table.
  2. If PCode is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PCode and Barcode (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. Barcode. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 6 (count of rows). The heading row is not counted.
C4.34Practice3 marks

Observe the table BOOK and answer.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePrice
2019789352921485Informatics PracticesComputerNCERT2026-07-03210
2039780143032311Wings of FireBiographyUniversities2026-06-21299
2049789386551009Python BasicsComputerBPB2026-08-01350
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190
  1. Identify the candidate keys of the table.
  2. If ISBN is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. BookID and ISBN (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. BookID. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.35Practice3 marks

Observe the table PATIENT and answer.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateInsurance
15523452345234QasimICUDr. Sen2026-09-15NULL
16623462346234RekhaMaternityDr. Iyer2026-09-18NULL
14423442344234PoojaMaternityDr. Iyer2026-09-12LIC
12223422342234NishaICUDr. Sen2026-09-05NULL
  1. Identify the candidate keys of the table.
  2. If PID is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PID and Aadhaar (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. Aadhaar. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.36Practice3 marks

Observe the table STUDENT and answer.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarks
54545EshanBM2010-03-1788
64556FarahAF2009-09-0931
74567GauravCM2010-02-2859
34523ChiragAM2010-01-0545
24512BhavyaBF2009-11-3092
  1. Identify the candidate keys of the table.
  2. If AdmNo is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. RollNo and AdmNo (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. RollNo. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 5 (count of rows). The heading row is not counted.
C4.37Practice3 marks

Observe the table EMPLOYEE and answer.

Table: EMPLOYEE

EmpIDEmailENameCityDOJSalaryBonus
E102seema@co.inSeemaPune2020-01-1558000NULL
E103tarun@co.inTarunDelhi2016-09-20750005000
E104usha@co.inUshaMumbai2021-03-1036000NULL
E105vikas@co.inVikasPune2019-11-05640004000
  1. Identify the candidate keys of the table.
  2. If EmpID is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. EmpID and Email (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. Email. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 4 (count of rows). The heading row is not counted.
C4.38Practice3 marks

Observe the table PRODUCT and answer.

Table: PRODUCT

PCodeBarcodePNameBrandMfgDatePriceDiscount
P0289010022Pen DriveSanDisk2025-08-15450NULL
P0689010066EarphonesBoat2026-03-0589920
P0189010011NotebookClassmate2026-01-10605
P0389010033Geometry BoxCamlin2025-11-0218010
P0489010044MouseLogitech2026-02-2065015
P0589010055Water BottleMilton2025-05-30320NULL
  1. Identify the candidate keys of the table.
  2. If Barcode is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PCode and Barcode (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. PCode. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 6 (count of rows). The heading row is not counted.
C4.39Practice3 marks

Observe the table BOOK and answer.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePrice
2029789352920112Physics Part 1ScienceNCERT2026-07-10180
2049789386551009Python BasicsComputerBPB2026-08-01350
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190
2079789386551023Learn SQLComputerBPB2026-08-12400
2019789352921485Informatics PracticesComputerNCERT2026-07-03210
2039780143032311Wings of FireBiographyUniversities2026-06-21299
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250
  1. Identify the candidate keys of the table.
  2. If BookID is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. BookID and ISBN (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. ISBN. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 7 (count of rows). The heading row is not counted.
C4.40Practice3 marks

Observe the table PATIENT and answer.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateInsurance
14423442344234PoojaMaternityDr. Iyer2026-09-12LIC
15523452345234QasimICUDr. Sen2026-09-15NULL
11123412341234MohanGeneralDr. Rao2026-09-02LIC
16623462346234RekhaMaternityDr. Iyer2026-09-18NULL
12223422342234NishaICUDr. Sen2026-09-05NULL
13323432343234OmGeneralDr. Rao2026-09-10Star
  1. Identify the candidate keys of the table.
  2. If Aadhaar is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PID and Aadhaar (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. PID. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 6 (count of rows). The heading row is not counted.
C4.41Practice3 marks

Observe the table STUDENT and answer.

Table: STUDENT

RollNoAdmNoSectionGenderDOBMarksPhone
44534CF2009-07-21669810044444
24512BF2009-11-3092NULL
74567CM2010-02-28599810077777
64556AF2009-09-09319810066666
14501AM2009-04-12789810011111
34523AM2010-01-05459810033333
54545BM2010-03-1788NULL
  1. Identify the candidate keys of the table.
  2. If RollNo is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. RollNo and AdmNo (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. AdmNo. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 7 (count of rows). The heading row is not counted.
C4.42Practice3 marks

Observe the table EMPLOYEE and answer.

Table: EMPLOYEE

EmpIDEmailENameCityDOJSalaryBonus
E105vikas@co.inVikasPune2019-11-05640004000
E107yamini@co.inYaminiMumbai2017-12-1281000NULL
E104usha@co.inUshaMumbai2021-03-1036000NULL
E101ravi@co.inRaviDelhi2018-06-01420003000
E106wasim@co.inWasimDelhi2022-07-25390002000
E103tarun@co.inTarunDelhi2016-09-20750005000
E102seema@co.inSeemaPune2020-01-1558000NULL
  1. Identify the candidate keys of the table.
  2. If Email is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. EmpID and Email (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. EmpID. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 7 (count of rows). The heading row is not counted.
C4.43Practice3 marks

Observe the table PRODUCT and answer.

Table: PRODUCT

PCodeBarcodePNameBrandMfgDatePriceDiscount
P0789010077Lunch BoxMilton2025-12-182758
P0189010011NotebookClassmate2026-01-10605
P0389010033Geometry BoxCamlin2025-11-0218010
P0689010066EarphonesBoat2026-03-0589920
P0289010022Pen DriveSanDisk2025-08-15450NULL
P0589010055Water BottleMilton2025-05-30320NULL
  1. Identify the candidate keys of the table.
  2. If PCode is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PCode and Barcode (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. Barcode. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 6 (count of rows). The heading row is not counted.
C4.44Practice3 marks

Observe the table BOOK and answer.

Table: BOOK

BookIDISBNTitleSubjectIssueDatePriceMember
2039780143032311Wings of FireBiography2026-06-21299Ravi
2029789352920112Physics Part 1Science2026-07-10180NULL
2069780140449136The Story of My ExperimentsBiography2026-05-30250NULL
2059789352925032Chemistry Part 1Science2026-07-15190Neha
2049789386551009Python BasicsComputer2026-08-01350NULL
  1. Identify the candidate keys of the table.
  2. If ISBN is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. BookID and ISBN (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. BookID. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 5 (count of rows). The heading row is not counted.
C4.45Practice3 marks

Observe the table PATIENT and answer.

Table: PATIENT

PIDAadhaarPNameWardDoctorFeeInsurance
17723472347234SahilGeneralDr. Rao900Star
15523452345234QasimICUDr. Sen9500NULL
13323432343234OmGeneralDr. Rao1200Star
14423442344234PoojaMaternityDr. Iyer5000LIC
16623462346234RekhaMaternityDr. Iyer4500NULL
12223422342234NishaICUDr. Sen8000NULL
  1. Identify the candidate keys of the table.
  2. If PID is the primary key, which is the alternate key?
  3. What are the degree and the cardinality of the table?
Answer
  1. PID and Aadhaar (both have a different value in every row, so each can identify a row; the other columns have repeated or NULL values).
  2. Aadhaar. The candidate key not chosen as the primary key is the alternate key.
  3. Degree = 7 (count of columns), cardinality = 6 (count of rows). The heading row is not counted.

Section D · 4 marks each

D1Computer system case4 marks · 22 questions
D1.1Practice4 marks

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.

  1. Classify the devices into input and output devices.
  2. Which of the given memories is volatile?
  3. Convert 512 GB into MB.
  4. Why is an SSD faster than a hard disk?
Answer
  1. Input: keyboard, mouse, webcam, scanner. Output: monitor, printer.
  2. RAM (8 GB).
  3. 512 × 1024 = 524288 MB.
  4. It has no moving parts; it stores data on flash chips, so data is read and written electronically.
D1.2Practice4 marks

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.

  1. Can the files still be recovered? Why?
  2. Name the kind of software that can help.
  3. What risk does selling the old phone carry?
  4. Suggest two ways to protect her data before selling.
Answer
  1. Often yes: the data stays on the disk until new data overwrites it.
  2. Data recovery software.
  3. The buyer may recover her deleted photos, messages and passwords and misuse them.
  4. Back up and then securely wipe / factory reset with encryption; remove the memory card and SIM; use data-shredding tools.
D1.3Practice4 marks

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.

  1. Classify the software into system and application software.
  2. Which software is specific purpose?
  3. Which software is general purpose?
  4. Name the category of the antivirus.
Answer
  1. System: Linux, antivirus. Application: reservation software, word processor.
  2. The railway reservation software.
  3. The word processor.
  4. Utility software (system software).
D1.4Practice4 marks

The history of computing goes from the abacus and Pascaline to Babbage's Analytical Engine, then ENIAC, and today's laptops and smartphones.

  1. What was the abacus used for?
  2. Who is called the father of the computer and why?
  3. What did ENIAC use for processing?
  4. Name the invention that made personal computers possible.
Answer
  1. Counting and simple calculations.
  2. Charles Babbage, because his Analytical Engine had the main ideas of a modern computer: input, a mill (processor), a store (memory) and output.
  3. Vacuum tubes.
  4. The microprocessor (integrated circuit).
D1.5Practice4 marks

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.

  1. Name two input devices it needs.
  2. Which storage should keep the X-ray images for years?
  3. Name two output devices it uses.
  4. Which part of the computer will compare the queue numbers?
Answer
  1. Keyboard, scanner / camera / barcode reader.
  2. Secondary storage such as a hard disk / SSD / cloud storage.
  3. Printer and a large monitor (display screen).
  4. The ALU (Arithmetic Logic Unit).
D1.6Practice4 marks

Aman's computer is slow. It has 4 GB RAM and a nearly full 1 TB hard disk. He wants to make it faster.

  1. How can more RAM help?
  2. How many GB are there in 1 TB?
  3. Name a utility that can free disk space.
  4. Replacing the hard disk with which device will make it faster?
Answer
  1. More programs and data can be kept in RAM, so the computer reads the slow disk less often.
  2. 1024 GB.
  3. Disk cleanup (also file compression, uninstalling unused programs).
  4. A solid state drive (SSD).
D1.7Practice4 marks

A company is choosing software: an operating system, an office suite and a payroll system made by a local firm only for it.

  1. Give one open source choice for the operating system.
  2. Give one open source choice for the office suite.
  3. Is the payroll system general or specific purpose?
  4. Write one benefit of open source software.
Answer
  1. Ubuntu Linux.
  2. LibreOffice.
  3. Specific purpose (customised).
  4. Free to use and change; no licence cost; community support.
D1.8Practice4 marks

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.

  1. Where are the program and data kept while running?
  2. Which unit fetches and decodes the instructions?
  3. Which language translator runs Python?
  4. Name the cycle the CPU repeats for each instruction.
Answer
  1. In RAM (primary memory).
  2. The control unit.
  3. The Python interpreter.
  4. The fetch-decode-execute (machine) cycle.
D1.9Practice4 marks

A pen drive of 32 GB has 12,000 photos of 2 MB each.

  1. How much space do the photos use, in GB (approx.)?
  2. Is a pen drive primary or secondary memory?
  3. Is it volatile?
  4. Name one faster type of storage than a pen drive.
Answer
  1. 12000 × 2 = 24000 MB ≈ 23.4 GB.
  2. Secondary memory.
  3. No, it is non-volatile.
  4. SSD (or RAM, which is primary memory).
D1.10Practice4 marks

In a bank, cheques are read by a machine, customers' fingerprints are scanned, and passbooks are printed.

  1. Name the device that reads cheques.
  2. What is the fingerprint scanner an example of?
  3. Is the passbook printer input or output?
  4. Name one more input device used in banks.
Answer
  1. MICR (Magnetic Ink Character Recognition) reader.
  2. A biometric input device.
  3. Output.
  4. Barcode/QR reader, keyboard, card reader, webcam.
D1.11Practice4 marks

A student lists: registers, RAM, ROM, cache, hard disk, pen drive, cloud storage.

  1. Arrange the primary memories from fastest to slowest.
  2. Which of them keep data without power?
  3. Which one stores the start-up program?
  4. Which one is the slowest to reach?
Answer
  1. Registers, cache, RAM (ROM is also fast to read).
  2. ROM, hard disk, pen drive, cloud storage.
  3. ROM.
  4. Cloud storage (it depends on the Internet).

Memory: from fastest to slowest

RegistersCacheRAM (main memory)SSD / Hard diskPen drive, DVD, cloudspeed
Higher in the pyramid: faster, smaller and costlier. Lower: slower, bigger and cheaper.
D1.12Practice4 marks

Your school is replacing old CRT monitors and printers.

  1. Is a monitor hardware or software?
  2. Name the software needed for a new printer to work.
  3. Name one generic software teachers use.
  4. Name one specific purpose software a school uses.
Answer
  1. Hardware.
  2. Device driver of the printer.
  3. A word processor / presentation / spreadsheet software.
  4. Fee management / attendance / exam result software made for the school.
D1.13Practice4 marks

Answer the following about a computer lab.

  1. Classify into input and output devices: Webcam, 3D printer, MICR, Speaker, Plotter, Joystick.
  2. Convert 4 TB into GB.
  3. Classify into system and application software: Python interpreter, Railway reservation software, Photo editor, Disk cleanup.
  4. Is Cache volatile or non-volatile? Why?
Answer
  1. Input: Webcam, MICR, Joystick. Output: 3D printer, Speaker, Plotter.
  2. 4 × 1024 = 4096 GB.
  3. System: Python interpreter, Disk cleanup. Application: Railway reservation software, Photo editor.
  4. Cache is volatile; very fast memory between the CPU and RAM.
D1.14Practice4 marks

Answer the following about a computer lab.

  1. Classify into input and output devices: Headphones, Scanner, MICR, Monitor, Speaker, Graphics tablet.
  2. Convert 12 GB into MB.
  3. Classify into system and application software: Word processor, Printer driver, Python interpreter, Photo editor.
  4. Is RAM volatile or non-volatile? Why?
Answer
  1. Input: Scanner, MICR, Graphics tablet. Output: Headphones, Monitor, Speaker.
  2. 12 × 1024 = 12288 MB.
  3. System: Printer driver, Python interpreter. Application: Word processor, Photo editor.
  4. RAM is volatile; it loses data when the power goes off.
D1.15Practice4 marks

Answer the following about a computer lab.

  1. Classify into input and output devices: Printer, Headphones, Keyboard, Projector, Light pen, Biometric scanner.
  2. Convert 12 GB into MB.
  3. Classify into system and application software: Billing software, Disk cleanup, Python interpreter, Photo editor.
  4. Is ROM volatile or non-volatile? Why?
Answer
  1. Input: Keyboard, Light pen, Biometric scanner. Output: Printer, Headphones, Projector.
  2. 12 × 1024 = 12288 MB.
  3. System: Disk cleanup, Python interpreter. Application: Billing software, Photo editor.
  4. ROM is non-volatile; it keeps the start-up program.
D1.16Practice4 marks

Answer the following about a computer lab.

  1. Classify into input and output devices: Speaker, Microphone, Scanner, Biometric scanner, Monitor, Printer.
  2. Convert 7 PB into TB.
  3. Classify into system and application software: Web browser, Printer driver, Linux, Railway reservation software.
  4. Is ROM volatile or non-volatile? Why?
Answer
  1. Input: Microphone, Scanner, Biometric scanner. Output: Speaker, Monitor, Printer.
  2. 7 × 1024 = 7168 TB.
  3. System: Printer driver, Linux. Application: Web browser, Railway reservation software.
  4. ROM is non-volatile; it keeps the start-up program.
D1.17Practice4 marks

Answer the following about a computer lab.

  1. Classify into input and output devices: Plotter, 3D printer, Keyboard, OMR, Printer, Barcode reader.
  2. Convert 8 PB into TB.
  3. Classify into system and application software: Spreadsheet, Disk cleanup, Photo editor, Printer driver.
  4. Is ROM volatile or non-volatile? Why?
Answer
  1. Input: Keyboard, OMR, Barcode reader. Output: Plotter, 3D printer, Printer.
  2. 8 × 1024 = 8192 TB.
  3. System: Disk cleanup, Printer driver. Application: Spreadsheet, Photo editor.
  4. ROM is non-volatile; it keeps the start-up program.
D1.18Practice4 marks

Answer the following about a computer lab.

  1. Classify into input and output devices: Graphics tablet, Biometric scanner, 3D printer, Speaker, Keyboard, Projector.
  2. Convert 11 KB into bytes.
  3. Classify into system and application software: Python interpreter, Word processor, Web browser, Compiler.
  4. Is RAM volatile or non-volatile? Why?
Answer
  1. Input: Graphics tablet, Biometric scanner, Keyboard. Output: 3D printer, Speaker, Projector.
  2. 11 × 1024 = 11264 bytes.
  3. System: Python interpreter, Compiler. Application: Word processor, Web browser.
  4. RAM is volatile; it loses data when the power goes off.
D1.19Practice4 marks

Answer the following about a computer lab.

  1. Classify into input and output devices: Joystick, MICR, Printer, Monitor, 3D printer, Mouse.
  2. Convert 4 MB into KB.
  3. Classify into system and application software: Web browser, Disk cleanup, Railway reservation software, Android.
  4. Is Cache volatile or non-volatile? Why?
Answer
  1. Input: Joystick, MICR, Mouse. Output: Printer, Monitor, 3D printer.
  2. 4 × 1024 = 4096 KB.
  3. System: Disk cleanup, Android. Application: Web browser, Railway reservation software.
  4. Cache is volatile; very fast memory between the CPU and RAM.
D1.20Practice4 marks

Answer the following about a computer lab.

  1. Classify into input and output devices: Barcode reader, Plotter, Graphics tablet, Joystick, Headphones, Printer.
  2. Convert 5 TB into GB.
  3. Classify into system and application software: Word processor, Android, Spreadsheet, Windows.
  4. Is ROM volatile or non-volatile? Why?
Answer
  1. Input: Barcode reader, Graphics tablet, Joystick. Output: Plotter, Headphones, Printer.
  2. 5 × 1024 = 5120 GB.
  3. System: Android, Windows. Application: Word processor, Spreadsheet.
  4. ROM is non-volatile; it keeps the start-up program.
D1.21Practice4 marks

Answer the following about a computer lab.

  1. Classify into input and output devices: Headphones, MICR, Printer, Scanner, Plotter, Barcode reader.
  2. Convert 7 TB into GB.
  3. Classify into system and application software: Compiler, Railway reservation software, Python interpreter, Media player.
  4. Is ROM volatile or non-volatile? Why?
Answer
  1. Input: MICR, Scanner, Barcode reader. Output: Headphones, Printer, Plotter.
  2. 7 × 1024 = 7168 GB.
  3. System: Compiler, Python interpreter. Application: Railway reservation software, Media player.
  4. ROM is non-volatile; it keeps the start-up program.
D1.22Practice4 marks

Answer the following about a computer lab.

  1. Classify into input and output devices: Webcam, Headphones, Monitor, Plotter, OMR, MICR.
  2. Convert 7 TB into GB.
  3. Classify into system and application software: Python interpreter, Linux, Web browser, Spreadsheet.
  4. Is RAM volatile or non-volatile? Why?
Answer
  1. Input: Webcam, OMR, MICR. Output: Headphones, Monitor, Plotter.
  2. 7 × 1024 = 7168 GB.
  3. System: Python interpreter, Linux. Application: Web browser, Spreadsheet.
  4. RAM is volatile; it loses data when the power goes off.
D2List, dictionary and NumPy programs4 marks · 42 questions
D2.1Practice4 marks

Write a program to find the largest and the smallest numbers in a list.

Answer
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
D2.2Practice4 marks

Write a program to find the third largest and the third smallest numbers in a list.

Answer
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
D2.3Practice4 marks

Write a program to find the third largest and the third smallest numbers in a list without sort().

Answer
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
D2.4Practice4 marks

Write a program to create a list of n numbers entered by the user and print their sum and average.

Answer
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
D2.5Practice4 marks

Write a program to search for a number in a list and print its position (index) or 'Not found'.

Answer
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
D2.6Practice4 marks

Write a program to count the even and the odd numbers in a list.

Answer
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
D2.7Practice4 marks

Write a program to make a new list with only the numbers greater than 50 from a given list.

Answer
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]
D2.8Practice4 marks

Write a program to remove all the occurrences of a number from a list.

Answer
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]
D2.9Practice4 marks

Write a program to create a dictionary of states and their capitals, and print the capital of a state given by the user.

Answer
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
D2.10Practice4 marks

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.

Answer
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 64
D2.11Practice4 marks

Write a program to count the frequency of each element of a list using a dictionary.

Answer
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}
D2.12Practice4 marks

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.

Answer
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
D2.13Practice4 marks

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.

Answer
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
D2.14Practice4 marks

Write a program to update the price of an item in a dictionary of items and prices, and then delete one item.

Answer
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}
D2.15Practice4 marks

Write a program to print the keys, the values and the items of a dictionary of fruits and their prices, and the total price.

Answer
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 = 260
D2.16Practice4 marks

Write a program to input a list and print it in reverse order without reverse().

Answer
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 
D2.17Practice4 marks

Write a program to find the sum of the numbers at even positions (indices) of a list.

Answer
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
D2.18Practice4 marks

Write a program to insert an element at a given position in a list and then sort the list.

Answer
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]
D2.19Practice4 marks

Write a program to merge two dictionaries using update() and print the number of keys.

Answer
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: 3
D2.20Practice4 marks

Write a program to create a NumPy array of the prices of five items and print the prices after a 10% discount.

Answer
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]
D2.21Practice4 marks

Write a program to input the marks of n students in a list and print how many students scored above the class average.

Answer
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
D2.22Practice4 marks

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).

Answer
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
D2.23Practice4 marks

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.

Answer
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. ]
D2.24Practice4 marks

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.

Answer
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
D2.25Practice4 marks

Write a program to input a list of numbers and search for a number (linear search). Print its position or 'not found'.

Answer
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
D2.26Practice4 marks

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].

Answer
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]
D2.27Practice4 marks

Write a program to find the largest and the second largest element of a list without sorting.

Answer
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
D2.28Practice4 marks

Write a program to rotate the elements of a list one place to the left: [1, 2, 3, 4] becomes [2, 3, 4, 1].

Answer
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]
D2.29Practice4 marks

Write a program to rotate the elements of a list one place to the right.

Answer
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]
D2.30Practice4 marks

Write a program to remove the duplicate elements from a list.

Answer
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]
D2.31Practice4 marks

Write a program to input a list and put the positive and the negative numbers into two separate lists.

Answer
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]
D2.32Practice4 marks

Write a program to find the frequency of each element of a list using a dictionary.

Answer
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
D2.33Practice4 marks

Write a program to input a list and replace every even element by its half and every odd element by its double.

Answer
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]
D2.34Practice4 marks

Write a program to print the cumulative sum of a list: [1, 2, 3] gives [1, 3, 6].

Answer
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]
D2.35Practice4 marks

Write a program to create a dictionary of n students' roll numbers and names, and search for a roll number.

Answer
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
D2.36Practice4 marks

Write a program to create a dictionary of country names and their capitals, and print the capital of a country given by the user.

Answer
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
D2.37Practice4 marks

Write a program to find the key with the largest value in a dictionary of items and prices.

Answer
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 650
D2.38Practice4 marks

Write a program to input a list of numbers and print the numbers that are divisible by 3 but not by 5.

Answer
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 
D2.39Practice4 marks

Write a program to merge two lists and print the merged list in ascending order, without using + or extend().

Answer
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]
D2.40Practice4 marks

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.

Answer
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
Chetan
D2.41Practice4 marks

Write a program to input a list of numbers and create a new list that has the square of each odd number.

Answer
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]
D2.42Practice4 marks

Write a program to find the sum of the elements at even indices and at odd indices of a list.

Answer
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

Section E · 5 marks each

E1Long Python programs5 marks · 65 questions
E1.1Practice5 marks

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.

Answer
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
E1.2Practice5 marks

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.

Answer
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:
        break

Sample 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
E1.3Practice5 marks

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.

Answer
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: 4
E1.4Practice5 marks

Write a program to input the name and marks of 4 students and store them in a dictionary. Then:

  1. Display the names whose marks is more than 75, and
  2. Display the name with the highest marks.
Answer
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
E1.5Practice5 marks

Write a program to input the name and marks of 4 students and store them in a dictionary. Then:

  1. Display the name with the highest marks, and
  2. Display the total and the average marks.
Answer
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
E1.6Practice5 marks

Write a program to input the name and marks of 4 students and store them in a dictionary. Then:

  1. Display the total and the average marks, and
  2. Display the records in alphabetical order of name.
Answer
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
E1.7Practice5 marks

Write a program to input the name and marks of 4 students and store them in a dictionary. Then:

  1. Display the records in alphabetical order of name, and
  2. Count the names whose marks is less than 75.
Answer
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
E1.8Practice5 marks

Write a program to input the name and marks of 4 students and store them in a dictionary. Then:

  1. Count the names whose marks is less than 75, and
  2. Increase the marks of every name by 10 percent and display the dictionary.
Answer
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}
E1.9Practice5 marks

Write a program to input the name and salary of 4 employees and store them in a dictionary. Then:

  1. Display the names whose salary is more than 50000, and
  2. Display the total and the average salary.
Answer
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
E1.10Practice5 marks

Write a program to input the name and salary of 4 employees and store them in a dictionary. Then:

  1. Display the name with the highest salary, and
  2. Display the records in alphabetical order of name.
Answer
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
E1.11Practice5 marks

Write a program to input the name and salary of 4 employees and store them in a dictionary. Then:

  1. Display the total and the average salary, and
  2. Count the names whose salary is less than 50000.
Answer
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
E1.12Practice5 marks

Write a program to input the name and salary of 4 employees and store them in a dictionary. Then:

  1. Display the records in alphabetical order of name, and
  2. Increase the salary of every name by 10 percent and display the dictionary.
Answer
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}
E1.13Practice5 marks

Write a program to input the name and salary of 4 employees and store them in a dictionary. Then:

  1. Increase the salary of every name by 10 percent and display the dictionary, and
  2. Display the name with the highest salary.
Answer
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.0
E1.14Practice5 marks

Write a program to input the item and price of 4 items and store them in a dictionary. Then:

  1. Display the items whose price is more than 300, and
  2. Display the records in alphabetical order of item.
Answer
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
E1.15Practice5 marks

Write a program to input the item and price of 4 items and store them in a dictionary. Then:

  1. Display the item with the highest price, and
  2. Count the items whose price is less than 300.
Answer
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
E1.16Practice5 marks

Write a program to input the item and price of 4 items and store them in a dictionary. Then:

  1. Display the total and the average price, and
  2. Increase the price of every item by 10 percent and display the dictionary.
Answer
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}
E1.17Practice5 marks

Write a program to input the item and price of 4 items and store them in a dictionary. Then:

  1. Display the records in alphabetical order of item, and
  2. Display the items whose price is more than 300.
Answer
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
E1.18Practice5 marks

Write a program to input the item and price of 4 items and store them in a dictionary. Then:

  1. Count the items whose price is less than 300, and
  2. Display the item with the highest price.
Answer
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
E1.19Practice5 marks

Write a program to input the player and runs of 4 players and store them in a dictionary. Then:

  1. Display the players whose runs is more than 50, and
  2. Count the players whose runs is less than 50.
Answer
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
E1.20Practice5 marks

Write a program to input the player and runs of 4 players and store them in a dictionary. Then:

  1. Display the player with the highest runs, and
  2. Increase the runs of every player by 10 percent and display the dictionary.
Answer
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}
E1.21Practice5 marks

Write a program to input the player and runs of 4 players and store them in a dictionary. Then:

  1. Display the total and the average runs, and
  2. Display the players whose runs is more than 50.
Answer
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
E1.22Practice5 marks

Write a program to input the player and runs of 4 players and store them in a dictionary. Then:

  1. Display the records in alphabetical order of player, and
  2. Display the player with the highest runs.
Answer
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
E1.23Practice5 marks

Write a program to input the player and runs of 4 players and store them in a dictionary. Then:

  1. Increase the runs of every player by 10 percent and display the dictionary, and
  2. Display the records in alphabetical order of player.
Answer
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.1
E1.24Practice5 marks

Write a program to input the title and copies of 4 books and store them in a dictionary. Then:

  1. Display the titles whose copies is more than 10, and
  2. Increase the copies of every title by 10 percent and display the dictionary.
Answer
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}
E1.25Practice5 marks

Write a program to input the title and copies of 4 books and store them in a dictionary. Then:

  1. Display the title with the highest copies, and
  2. Display the titles whose copies is more than 10.
Answer
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
E1.26Practice5 marks

Write a program to input the title and copies of 4 books and store them in a dictionary. Then:

  1. Display the total and the average copies, and
  2. Display the title with the highest copies.
Answer
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
E1.27Practice5 marks

Write a program to input the title and copies of 4 books and store them in a dictionary. Then:

  1. Display the records in alphabetical order of title, and
  2. Display the total and the average copies.
Answer
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
E1.28Practice5 marks

Write a program to input the title and copies of 4 books and store them in a dictionary. Then:

  1. Count the titles whose copies is less than 10, and
  2. Display the records in alphabetical order of title.
Answer
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
E1.29Practice5 marks

Write a program to input the city and population (lakh) of 4 cities and store them in a dictionary. Then:

  1. Display the citys whose population (lakh) is more than 50, and
  2. Display the citys whose population (lakh) is more than 50.
Answer
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
E1.30Practice5 marks

Write a program to input the city and population (lakh) of 4 cities and store them in a dictionary. Then:

  1. Display the city with the highest population (lakh), and
  2. Display the city with the highest population (lakh).
Answer
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
E1.31Practice5 marks

Write a program to input the city and population (lakh) of 4 cities and store them in a dictionary. Then:

  1. Display the total and the average population (lakh), and
  2. Display the total and the average population (lakh).
Answer
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
E1.32Practice5 marks

Write a program to input the city and population (lakh) of 4 cities and store them in a dictionary. Then:

  1. Display the records in alphabetical order of city, and
  2. Display the records in alphabetical order of city.
Answer
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
E1.33Practice5 marks

Write a program to input the city and population (lakh) of 4 cities and store them in a dictionary. Then:

  1. Increase the population (lakh) of every city by 10 percent and display the dictionary, and
  2. Increase the population (lakh) of every city by 10 percent and display the dictionary.
Answer
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}
E1.34Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the sum and the average of the elements, and
  2. Display the list in reverse order without using reverse().
Answer
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]
E1.35Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the sum and the average of the elements, and
  2. Count the even and the odd elements.
Answer
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
E1.36Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the sum and the average of the elements, and
  2. Display the largest and the smallest element without max() and min().
Answer
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
E1.37Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the sum and the average of the elements, and
  2. Display the elements that are greater than the average.
Answer
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 
E1.38Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the sum and the average of the elements, and
  2. Display the prime numbers in the list.
Answer
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 
E1.39Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the sum and the average of the elements, and
  2. Create a new list of the elements at even indices.
Answer
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]
E1.40Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the sum and the average of the elements, and
  2. Display how many times each element occurs, using a dictionary.
Answer
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}
E1.41Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the sum and the average of the elements, and
  2. Sort the list in descending order and display the top three.
Answer
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]
E1.42Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the sum and the average of the elements, and
  2. Remove all the occurrences of the first element.
Answer
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]
E1.43Practice5 marks

Write a program to input a list of numbers. Then:

  1. Count the even and the odd elements, and
  2. Display the largest and the smallest element without max() and min().
Answer
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
E1.44Practice5 marks

Write a program to input a list of numbers. Then:

  1. Count the even and the odd elements, and
  2. Display the elements that are greater than the average.
Answer
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 
E1.45Practice5 marks

Write a program to input a list of numbers. Then:

  1. Count the even and the odd elements, and
  2. Display the prime numbers in the list.
Answer
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 
E1.46Practice5 marks

Write a program to input a list of numbers. Then:

  1. Count the even and the odd elements, and
  2. Create a new list of the elements at even indices.
Answer
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]
E1.47Practice5 marks

Write a program to input a list of numbers. Then:

  1. Count the even and the odd elements, and
  2. Display how many times each element occurs, using a dictionary.
Answer
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}
E1.48Practice5 marks

Write a program to input a list of numbers. Then:

  1. Count the even and the odd elements, and
  2. Sort the list in descending order and display the top three.
Answer
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]
E1.49Practice5 marks

Write a program to input a list of numbers. Then:

  1. Count the even and the odd elements, and
  2. Remove all the occurrences of the first element.
Answer
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]
E1.50Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the largest and the smallest element without max() and min(), and
  2. Display the elements that are greater than the average.
Answer
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 
E1.51Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the largest and the smallest element without max() and min(), and
  2. Display the prime numbers in the list.
Answer
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 
E1.52Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the largest and the smallest element without max() and min(), and
  2. Create a new list of the elements at even indices.
Answer
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]
E1.53Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the largest and the smallest element without max() and min(), and
  2. Display how many times each element occurs, using a dictionary.
Answer
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}
E1.54Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the largest and the smallest element without max() and min(), and
  2. Sort the list in descending order and display the top three.
Answer
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]
E1.55Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the largest and the smallest element without max() and min(), and
  2. Remove all the occurrences of the first element.
Answer
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]
E1.56Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the prime numbers in the list, and
  2. Create a new list of the elements at even indices.
Answer
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]
E1.57Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the prime numbers in the list, and
  2. Display how many times each element occurs, using a dictionary.
Answer
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}
E1.58Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the prime numbers in the list, and
  2. Sort the list in descending order and display the top three.
Answer
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]
E1.59Practice5 marks

Write a program to input a list of numbers. Then:

  1. Display the prime numbers in the list, and
  2. Remove all the occurrences of the first element.
Answer
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]
E1.60Practice5 marks

Write a program to input a list of numbers. Then:

  1. Create a new list of the elements at even indices, and
  2. Display how many times each element occurs, using a dictionary.
Answer
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}
E1.61Practice5 marks

Write a program to input a list of numbers. Then:

  1. Create a new list of the elements at even indices, and
  2. Sort the list in descending order and display the top three.
Answer
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]
E1.62Practice5 marks

Write a program to input a list of numbers. Then:

  1. Create a new list of the elements at even indices, and
  2. Remove all the occurrences of the first element.
Answer
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]
E1.63Practice5 marks

Write a program to input a list of numbers. Then:

  1. Sort the list in descending order and display the top three, and
  2. Remove all the occurrences of the first element.
Answer
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]
E1.64Practice5 marks

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.

Answer
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
E1.65Practice5 marks

Write a program to create a dictionary of n states and their capitals entered by the user. Then:

  1. Display all the states and capitals, and
  2. Search for the capital of a state.
Answer
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
E2SQL: outputs and queries5 marks · 45 questions
E2.1Practice5 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

(a) Write the output of the following queries:

  1. SELECT Name, Section FROM STUDENT WHERE Section = 'C' OR Section = 'B';
  2. SELECT Name, Marks FROM STUDENT WHERE Marks > 80;
  3. SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;

(b) Write SQL queries for the following:

  1. Display Name and Section of the students whose Section is not B.
  2. Display Name of the students whose Section is B and Marks is at least 80.
Answer

(i)

NameSection
BhavyaB
DivyaC
EshanB
GauravC

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)

NameMarks
Bhavya92
Eshan88

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)

NamePhone
Aarav9810011111
Chirag9810033333
Divya9810044444
Farah9810066666
Gaurav9810077777

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';
NameSection
AaravA
ChiragA
DivyaC
FarahA
GauravC

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.

E2.2Practice5 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

(a) Write the output of the following queries:

  1. SELECT Title, IssueDate FROM BOOK WHERE IssueDate BETWEEN '2026-07-01' AND '2026-07-31';
  2. SELECT Title FROM BOOK WHERE Publisher = 'Penguin' AND Member IS NOT NULL;
  3. SELECT Title, Price FROM BOOK WHERE Price < 250 OR Member IS NULL;

(b) Write SQL queries for the following:

  1. Display Title and Member of the books whose Member is not NULL.
  2. Display Title of the books whose Subject is Computer and Price is at least 200.
Answer

(i)

TitleIssueDate
Informatics Practices2026-07-03
Physics Part 12026-07-10
Chemistry Part 12026-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)

TitlePrice
Informatics Practices210
Physics Part 1180
Python Basics350
Chemistry Part 1190
The Story of My Experiments250

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;
TitleMember
Informatics PracticesAsha
Wings of FireRavi
Chemistry Part 1Neha
Learn SQLKaran

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.

E2.3Practice5 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

(a) Write the output of the following queries:

  1. SELECT Name FROM STUDENT WHERE Gender = 'M' AND Phone IS NOT NULL;
  2. SELECT Name FROM STUDENT WHERE Phone IS NULL;
  3. SELECT Name FROM STUDENT WHERE Section = 'A' AND Marks >= 50;

(b) Write SQL queries for the following:

  1. Display Name and DOB of the students whose DOB is between '2009-06-01' and '2009-12-31'.
  2. Display RollNo, Name and Marks of the students whose Marks is between 70 and 80.
Answer

(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';
NameDOB
Bhavya2009-11-30
Divya2009-07-21
Farah2009-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;
RollNoNameMarks
1Aarav78

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.

E2.4Practice5 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

(a) Write the output of the following queries:

  1. SELECT EName FROM EMPLOYEE WHERE Bonus IS NULL;
  2. SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 50000;
  3. SELECT EName FROM EMPLOYEE WHERE Dept = 'IT' AND Salary >= 40000;

(b) Write SQL queries for the following:

  1. Display EName and City of the employees whose City is not Delhi.
  2. Display EName and Salary of the employees whose Salary is less than 40000 or whose Bonus is NULL.
Answer

(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)

EmpIDENameSalary
E101Ravi42000

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';
ENameCity
SeemaPune
UshaMumbai
VikasPune
YaminiMumbai

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;
ENameSalary
Seema58000
Usha36000
Wasim39000
Yamini81000

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 =.)

E2.5Practice5 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

(a) Write the output of the following queries:

  1. SELECT EName FROM EMPLOYEE WHERE Dept = 'HR' AND Salary >= 70000;
  2. SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 70000;
  3. SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 60000 AND 70000;

(b) Write SQL queries for the following:

  1. Display EName and City of the employees whose City is not Delhi.
  2. Display EmpID, Salary and Salary increased by 10 for every employee.
Answer

(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)

ENameSalary
Tarun75000
Yamini81000

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)

EmpIDENameSalary
E105Vikas64000

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';
ENameCity
SeemaPune
UshaMumbai
VikasPune
YaminiMumbai

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;
EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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.

E2.6Practice5 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

(a) Write the output of the following queries:

  1. SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 100 AND 300;
  2. SELECT PName, Brand FROM PRODUCT WHERE Brand <> 'Camlin';
  3. SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;

(b) Write SQL queries for the following:

  1. Display PName and Category of the products whose Category is Stationery or Home.
  2. Display PName and Category of the products whose Category is not Home.
Answer

(i)

PCodePNamePrice
P03Geometry Box180
P07Lunch Box275

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)

PNameBrand
NotebookClassmate
Pen DriveSanDisk
MouseLogitech
Water BottleMilton
EarphonesBoat
Lunch BoxMilton

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)

PNameDiscount
Notebook5
Geometry Box10
Mouse15
Earphones20
Lunch Box8

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';
PNameCategory
NotebookStationery
Geometry BoxStationery
Water BottleHome
Lunch BoxHome

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';
PNameCategory
NotebookStationery
Pen DriveElectronics
Geometry BoxStationery
MouseElectronics
EarphonesElectronics

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.

E2.7Practice5 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

(a) Write the output of the following queries:

  1. SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'Penguin';
  2. SELECT Title, Subject FROM BOOK WHERE NOT Subject = 'Biography';
  3. SELECT * FROM BOOK WHERE Subject = 'Biography';

(b) Write SQL queries for the following:

  1. Display BookID, Title and Price of the books whose Price is between 200 and 250.
  2. Display Title of the books whose Publisher is Penguin and Member is not NULL.
Answer

(i)

TitlePublisher
Informatics PracticesNCERT
Physics Part 1NCERT
Wings of FireUniversities
Python BasicsBPB
Chemistry Part 1NCERT
Learn SQLBPB

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)

TitleSubject
Informatics PracticesComputer
Physics Part 1Science
Python BasicsComputer
Chemistry Part 1Science
Learn SQLComputer

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)

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL

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;
BookIDTitlePrice
201Informatics Practices210
206The Story of My Experiments250

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 =.)

E2.8Practice5 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

(a) Write the output of the following queries:

  1. SELECT PID, Fee, Fee + 10 FROM PATIENT;
  2. SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
  3. SELECT PName, Insurance FROM PATIENT WHERE Insurance IS NOT NULL;

(b) Write SQL queries for the following:

  1. Display PName and Fee of the patients whose Fee is less than 1000 or whose Insurance is NULL.
  2. Display PName of the patients whose Insurance is not known (NULL).
Answer

(i)

PIDFeeFee + 10
1115001510
1280008010
1312001210
1450005010
1595009510
1645004510
17900910

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)

PNameAdmitDate
Nisha2026-09-05
Om2026-09-10
Pooja2026-09-12
Qasim2026-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)

PNameInsurance
MohanLIC
OmStar
PoojaLIC
SahilStar

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;
PNameFee
Nisha8000
Qasim9500
Rekha4500
Sahil900

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 =.)

E2.9Practice5 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

(a) Write the output of the following queries:

  1. SELECT PName, Ward FROM PATIENT WHERE NOT Ward = 'Maternity';
  2. SELECT PName FROM PATIENT WHERE Doctor = 'Dr. Sen' AND Insurance IS NOT NULL;
  3. SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';

(b) Write SQL queries for the following:

  1. Display PName and Insurance of the patients whose Insurance is not NULL.
  2. Display PName of the patients whose Insurance is not known (NULL).
Answer

(i)

PNameWard
MohanGeneral
NishaICU
OmGeneral
QasimICU
SahilGeneral

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)

PNameAdmitDate
Nisha2026-09-05
Om2026-09-10
Pooja2026-09-12
Qasim2026-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;
PNameInsurance
MohanLIC
OmStar
PoojaLIC
SahilStar

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 =.)

E2.10Practice5 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

(a) Write the output of the following queries:

  1. SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
  2. SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 40000;
  3. SELECT EName, Dept FROM EMPLOYEE WHERE NOT Dept = 'IT';

(b) Write SQL queries for the following:

  1. Display EName and DOJ of the employees whose DOJ is between '2018-01-01' and '2020-12-31'.
  2. Display EName of the employees whose Dept is IT and Salary is at least 40000.
Answer

(i)

EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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)

ENameSalary
Ravi42000
Seema58000
Tarun75000
Vikas64000
Yamini81000

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)

ENameDept
RaviSales
SeemaHR
UshaSales
WasimHR

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';
ENameDOJ
Ravi2018-06-01
Seema2020-01-15
Vikas2019-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.

E2.11Practice5 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

(a) Write the output of the following queries:

  1. SELECT PName, AdmitDate FROM PATIENT WHERE AdmitDate BETWEEN '2026-09-05' AND '2026-09-15';
  2. SELECT PName, Fee FROM PATIENT WHERE Fee < 4000 OR Insurance IS NULL;
  3. SELECT PName, Ward FROM PATIENT WHERE Ward = 'ICU' OR Ward = 'General';

(b) Write SQL queries for the following:

  1. Display PID, PName and Fee of the patients whose Fee is between 4000 and 6000.
  2. Display PName and Fee of all the patients whose Fee is more than 4000.
Answer

(i)

PNameAdmitDate
Nisha2026-09-05
Om2026-09-10
Pooja2026-09-12
Qasim2026-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)

PNameFee
Mohan1500
Nisha8000
Om1200
Qasim9500
Rekha4500
Sahil900

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)

PNameWard
MohanGeneral
NishaICU
OmGeneral
QasimICU
SahilGeneral

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;
PIDPNameFee
14Pooja5000
16Rekha4500

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;
PNameFee
Nisha8000
Pooja5000
Qasim9500
Rekha4500

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.

E2.12Practice5 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

(a) Write the output of the following queries:

  1. SELECT Title FROM BOOK WHERE Publisher = 'NCERT' AND Member IS NOT NULL;
  2. SELECT Title, Subject FROM BOOK WHERE NOT Subject = 'Biography';
  3. SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'NCERT';

(b) Write SQL queries for the following:

  1. Display Title of the books whose Subject is Biography and Price is at least 250.
  2. Display Title of the books whose Member is not known (NULL).
Answer

(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)

TitleSubject
Informatics PracticesComputer
Physics Part 1Science
Python BasicsComputer
Chemistry Part 1Science
Learn SQLComputer

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)

TitlePublisher
Wings of FireUniversities
Python BasicsBPB
The Story of My ExperimentsPenguin
Learn SQLBPB

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 =.)

E2.13Practice5 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

(a) Write the output of the following queries:

  1. SELECT PName FROM PATIENT WHERE Insurance IS NULL;
  2. SELECT PName FROM PATIENT WHERE Ward = 'Maternity' AND Fee >= 6000;
  3. SELECT PName, Fee FROM PATIENT WHERE Fee < 1000 OR Insurance IS NULL;

(b) Write SQL queries for the following:

  1. Display PName of the patients whose Doctor is Dr. Iyer and Insurance is not NULL.
  2. Display all the details of the patients whose Ward is Maternity.
Answer

(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)

PNameFee
Nisha8000
Qasim9500
Rekha4500
Sahil900

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';
PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL

Explanation: WHERE keeps only the rows where Ward is 'Maternity': 2 of the 7 rows match (Pooja, Rekha). SELECT then shows all the columns (*).

E2.14Practice5 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

(a) Write the output of the following queries:

  1. SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
  2. SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 70000;
  3. SELECT EName, Bonus FROM EMPLOYEE WHERE Bonus IS NOT NULL;

(b) Write SQL queries for the following:

  1. Display EName and Dept of the employees whose Dept is IT or Sales.
  2. Display EName of the employees whose Bonus is not known (NULL).
Answer

(i)

EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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)

ENameSalary
Tarun75000
Yamini81000

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)

ENameBonus
Ravi3000
Tarun5000
Vikas4000
Wasim2000

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';
ENameDept
RaviSales
TarunIT
UshaSales
VikasIT
YaminiIT

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 =.)

E2.15Practice5 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

(a) Write the output of the following queries:

  1. SELECT PName FROM PRODUCT WHERE Brand = 'Camlin' AND Discount IS NOT NULL;
  2. SELECT PName FROM PRODUCT WHERE Discount IS NULL;
  3. SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 400 AND 500;

(b) Write SQL queries for the following:

  1. Display PCode, Price and Price increased by 10 for every product.
  2. Display PName and MfgDate of the products whose MfgDate is between '2025-10-01' and '2026-01-31'.
Answer

(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)

PCodePNamePrice
P02Pen Drive450

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;
PCodePricePrice + 10
P016070
P02450460
P03180190
P04650660
P05320330
P06899909
P07275285

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';
PNameMfgDate
Notebook2026-01-10
Geometry Box2025-11-02
Lunch Box2025-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.

E2.16Practice5 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

(a) Write the output of the following queries:

  1. SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'Sales' OR Dept = 'IT';
  2. SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 60000;
  3. SELECT EName FROM EMPLOYEE WHERE Dept = 'HR' AND Salary >= 60000;

(b) Write SQL queries for the following:

  1. Display EName and Dept of the employees whose Dept is not HR.
  2. Display EName and DOJ of the employees whose DOJ is between '2018-01-01' and '2020-12-31'.
Answer

(i)

ENameDept
RaviSales
TarunIT
UshaSales
VikasIT
YaminiIT

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)

ENameSalary
Tarun75000
Vikas64000
Yamini81000

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';
ENameDept
RaviSales
TarunIT
UshaSales
VikasIT
YaminiIT

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';
ENameDOJ
Ravi2018-06-01
Seema2020-01-15
Vikas2019-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.

E2.17Practice5 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

(a) Write the output of the following queries:

  1. SELECT Name FROM STUDENT WHERE Gender = 'F' AND Phone IS NOT NULL;
  2. SELECT Name, Marks FROM STUDENT WHERE Marks > 80;
  3. SELECT Name, Section FROM STUDENT WHERE NOT Section = 'A';

(b) Write SQL queries for the following:

  1. Display all the details of the students whose Section is A.
  2. Display Name and Gender of the students whose Gender is not F.
Answer

(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)

NameMarks
Bhavya92
Eshan88

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)

NameSection
BhavyaB
DivyaC
EshanB
GauravC

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';
RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
34523ChiragAM2010-01-05459810033333
64556FarahAF2009-09-09319810066666

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';
NameGender
AaravM
ChiragM
EshanM
GauravM

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.

E2.18Practice5 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

(a) Write the output of the following queries:

  1. SELECT EName, City FROM EMPLOYEE WHERE City <> 'Delhi';
  2. SELECT * FROM EMPLOYEE WHERE Dept = 'Sales';
  3. SELECT EName FROM EMPLOYEE WHERE City = 'Delhi' AND Bonus IS NOT NULL;

(b) Write SQL queries for the following:

  1. Display EmpID, EName and Salary of the employees whose Salary is between 60000 and 70000.
  2. Display EName and Dept of the employees whose Dept is HR or Sales.
Answer

(i)

ENameCity
SeemaPune
UshaMumbai
VikasPune
YaminiMumbai

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)

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL

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;
EmpIDENameSalary
E105Vikas64000

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';
ENameDept
RaviSales
SeemaHR
UshaSales
WasimHR

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.

E2.19Practice5 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

(a) Write the output of the following queries:

  1. SELECT PName FROM PRODUCT WHERE Category = 'Electronics' AND Price >= 300;
  2. SELECT PName FROM PRODUCT WHERE Discount IS NULL;
  3. SELECT * FROM PRODUCT WHERE Category = 'Electronics';

(b) Write SQL queries for the following:

  1. Display PName and Brand of the products whose Brand is not Boat.
  2. Display PName and Discount of the products whose Discount is not NULL.
Answer

(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)

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0489010044MouseElectronicsLogitech2026-02-2065015
P0689010066EarphonesElectronicsBoat2026-03-0589920

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';
PNameBrand
NotebookClassmate
Pen DriveSanDisk
Geometry BoxCamlin
MouseLogitech
Water BottleMilton
Lunch BoxMilton

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;
PNameDiscount
Notebook5
Geometry Box10
Mouse15
Earphones20
Lunch Box8

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 =.)

E2.20Practice5 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

(a) Write the output of the following queries:

  1. SELECT PCode, Price, Price + 10 FROM PRODUCT;
  2. SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Home';
  3. SELECT PCode, PName, Price FROM PRODUCT WHERE Price BETWEEN 400 AND 500;

(b) Write SQL queries for the following:

  1. Display PName of the products whose Discount is not known (NULL).
  2. Display PName and Discount of the products whose Discount is not NULL.
Answer

(i)

PCodePricePrice + 10
P016070
P02450460
P03180190
P04650660
P05320330
P06899909
P07275285

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)

PNameCategory
NotebookStationery
Pen DriveElectronics
Geometry BoxStationery
MouseElectronics
EarphonesElectronics

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)

PCodePNamePrice
P02Pen Drive450

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;
PNameDiscount
Notebook5
Geometry Box10
Mouse15
Earphones20
Lunch Box8

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 =.)

E2.21Practice5 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

(a) Write the output of the following queries:

  1. SELECT Title, Subject FROM BOOK WHERE Subject = 'Computer' OR Subject = 'Science';
  2. SELECT Title, Publisher FROM BOOK WHERE Publisher <> 'NCERT';
  3. SELECT Title, Price FROM BOOK WHERE Price < 250 OR Member IS NULL;

(b) Write SQL queries for the following:

  1. Display Title of the books whose Publisher is NCERT and Member is not NULL.
  2. Display Title and Member of the books whose Member is not NULL.
Answer

(i)

TitleSubject
Informatics PracticesComputer
Physics Part 1Science
Python BasicsComputer
Chemistry Part 1Science
Learn SQLComputer

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)

TitlePublisher
Wings of FireUniversities
Python BasicsBPB
The Story of My ExperimentsPenguin
Learn SQLBPB

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)

TitlePrice
Informatics Practices210
Physics Part 1180
Python Basics350
Chemistry Part 1190
The Story of My Experiments250

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;
TitleMember
Informatics PracticesAsha
Wings of FireRavi
Chemistry Part 1Neha
Learn SQLKaran

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 =.)

E2.22Practice5 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

(a) Write the output of the following queries:

  1. SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';
  2. SELECT * FROM STUDENT WHERE Section = 'C';
  3. SELECT Name FROM STUDENT WHERE Phone IS NULL;

(b) Write SQL queries for the following:

  1. Display Name and Marks of all the students whose Marks is more than 60.
  2. Display Name of the students whose Gender is F and Phone is not NULL.
Answer

(i)

NameDOB
Bhavya2009-11-30
Divya2009-07-21
Farah2009-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)

RollNoAdmNoNameSectionGenderDOBMarksPhone
44534DivyaCF2009-07-21669810044444
74567GauravCM2010-02-28599810077777

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;
NameMarks
Aarav78
Bhavya92
Divya66
Eshan88

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 =.)

E2.23Practice5 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

(a) Write the output of the following queries:

  1. SELECT EName, Salary FROM EMPLOYEE WHERE Salary < 50000 OR Bonus IS NULL;
  2. SELECT EName FROM EMPLOYEE WHERE Dept = 'IT' AND Salary >= 40000;
  3. SELECT EName, DOJ FROM EMPLOYEE WHERE DOJ BETWEEN '2018-01-01' AND '2020-12-31';

(b) Write SQL queries for the following:

  1. Display EmpID, Salary and Salary increased by 10 for every employee.
  2. Display EName and City of the employees whose City is not Mumbai.
Answer

(i)

ENameSalary
Ravi42000
Seema58000
Usha36000
Wasim39000
Yamini81000

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)

ENameDOJ
Ravi2018-06-01
Seema2020-01-15
Vikas2019-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;
EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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';
ENameCity
RaviDelhi
SeemaPune
TarunDelhi
VikasPune
WasimDelhi

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.

E2.24Practice5 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

(a) Write the output of the following queries:

  1. SELECT EName, City FROM EMPLOYEE WHERE City <> 'Delhi';
  2. SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 70000;
  3. SELECT EName, Bonus FROM EMPLOYEE WHERE Bonus IS NOT NULL;

(b) Write SQL queries for the following:

  1. Display EName and Salary of all the employees whose Salary is more than 50000.
  2. Display EName and Dept of the employees whose Dept is IT or Sales.
Answer

(i)

ENameCity
SeemaPune
UshaMumbai
VikasPune
YaminiMumbai

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)

EmpIDENameSalary
E101Ravi42000
E102Seema58000
E105Vikas64000

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)

ENameBonus
Ravi3000
Tarun5000
Vikas4000
Wasim2000

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;
ENameSalary
Seema58000
Tarun75000
Vikas64000
Yamini81000

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';
ENameDept
RaviSales
TarunIT
UshaSales
VikasIT
YaminiIT

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.

E2.25Practice5 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

(a) Write the output of the following queries:

  1. SELECT PName, Fee FROM PATIENT WHERE Fee < 1000 OR Insurance IS NULL;
  2. SELECT PName FROM PATIENT WHERE Insurance IS NULL;
  3. SELECT * FROM PATIENT WHERE Ward = 'General';

(b) Write SQL queries for the following:

  1. Display PName and Ward of the patients whose Ward is not General.
  2. Display PName and Fee of all the patients whose Fee is more than 1000.
Answer

(i)

PNameFee
Nisha8000
Qasim9500
Rekha4500
Sahil900

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)

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
13323432343234OmGeneralDr. Rao2026-09-101200Star
17723472347234SahilGeneralDr. Rao2026-09-20900Star

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';
PNameWard
NishaICU
PoojaMaternity
QasimICU
RekhaMaternity

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;
PNameFee
Mohan1500
Nisha8000
Om1200
Pooja5000
Qasim9500
Rekha4500

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.

E2.26Practice5 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

(a) Write the output of the following queries:

  1. SELECT EName, Dept FROM EMPLOYEE WHERE Dept = 'Sales' OR Dept = 'IT';
  2. SELECT EName, Salary FROM EMPLOYEE WHERE Salary > 60000;
  3. SELECT EmpID, EName, Salary FROM EMPLOYEE WHERE Salary BETWEEN 40000 AND 60000;

(b) Write SQL queries for the following:

  1. Display EName of the employees whose City is Mumbai and Bonus is not NULL.
  2. Display all the details of the employees whose Dept is Sales.
Answer

(i)

ENameDept
RaviSales
TarunIT
UshaSales
VikasIT
YaminiIT

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)

ENameSalary
Tarun75000
Vikas64000
Yamini81000

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)

EmpIDENameSalary
E101Ravi42000
E102Seema58000

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';
EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL

Explanation: WHERE keeps only the rows where Dept is 'Sales': 2 of the 7 rows match (Ravi, Usha). SELECT then shows all the columns (*).

E2.27Practice5 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

(a) Write the output of the following queries:

  1. SELECT Name FROM STUDENT WHERE Gender = 'F' AND Phone IS NOT NULL;
  2. SELECT RollNo, Name, Marks FROM STUDENT WHERE Marks BETWEEN 60 AND 80;
  3. SELECT Name, DOB FROM STUDENT WHERE DOB BETWEEN '2009-06-01' AND '2009-12-31';

(b) Write SQL queries for the following:

  1. Display Name and Section of the students whose Section is A or B.
  2. Display RollNo, Marks and Marks increased by 10 for every student.
Answer

(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)

RollNoNameMarks
1Aarav78
4Divya66

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)

NameDOB
Bhavya2009-11-30
Divya2009-07-21
Farah2009-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';
NameSection
AaravA
BhavyaB
ChiragA
EshanB
FarahA

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;
RollNoMarksMarks + 10
17888
292102
34555
46676
58898
63141
75969

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.

E2.28Practice5 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

(a) Write the output of the following queries:

  1. SELECT Name, Section FROM STUDENT WHERE NOT Section = 'A';
  2. SELECT RollNo, Marks, Marks + 10 FROM STUDENT;
  3. SELECT Name FROM STUDENT WHERE Gender = 'F' AND Phone IS NOT NULL;

(b) Write SQL queries for the following:

  1. Display RollNo, Name and Marks of the students whose Marks is between 70 and 80.
  2. Display all the details of the students whose Section is A.
Answer

(i)

NameSection
BhavyaB
DivyaC
EshanB
GauravC

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)

RollNoMarksMarks + 10
17888
292102
34555
46676
58898
63141
75969

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;
RollNoNameMarks
1Aarav78

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';
RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
34523ChiragAM2010-01-05459810033333
64556FarahAF2009-09-09319810066666

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 (*).

E2.29Practice5 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

(a) Write the output of the following queries:

  1. SELECT PName FROM PATIENT WHERE Insurance IS NULL;
  2. SELECT PID, Fee, Fee + 10 FROM PATIENT;
  3. SELECT PName FROM PATIENT WHERE Doctor = 'Dr. Sen' AND Insurance IS NOT NULL;

(b) Write SQL queries for the following:

  1. Display PName and Fee of the patients whose Fee is less than 1000 or whose Insurance is NULL.
  2. Display PID, PName and Fee of the patients whose Fee is between 1000 and 4000.
Answer

(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)

PIDFeeFee + 10
1115001510
1280008010
1312001210
1450005010
1595009510
1645004510
17900910

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;
PNameFee
Nisha8000
Qasim9500
Rekha4500
Sahil900

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;
PIDPNameFee
11Mohan1500
13Om1200

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.

E2.30Practice5 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

(a) Write the output of the following queries:

  1. SELECT BookID, Price, Price + 10 FROM BOOK;
  2. SELECT Title FROM BOOK WHERE Member IS NULL;
  3. SELECT Title FROM BOOK WHERE Publisher = 'BPB' AND Member IS NOT NULL;

(b) Write SQL queries for the following:

  1. Display Title and Subject of the books whose Subject is Biography or Computer.
  2. Display Title and Publisher of the books whose Publisher is not BPB.
Answer

(i)

BookIDPricePrice + 10
201210220
202180190
203299309
204350360
205190200
206250260
207400410

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';
TitleSubject
Informatics PracticesComputer
Wings of FireBiography
Python BasicsComputer
The Story of My ExperimentsBiography
Learn SQLComputer

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';
TitlePublisher
Informatics PracticesNCERT
Physics Part 1NCERT
Wings of FireUniversities
Chemistry Part 1NCERT
The Story of My ExperimentsPenguin

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.

E2.31Practice5 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

(a) Write the output of the following queries:

  1. SELECT Title FROM BOOK WHERE Publisher = 'Penguin' AND Member IS NOT NULL;
  2. SELECT Title, Member FROM BOOK WHERE Member IS NOT NULL;
  3. SELECT BookID, Price, Price + 10 FROM BOOK;

(b) Write SQL queries for the following:

  1. Display Title of the books whose Member is not known (NULL).
  2. Display BookID, Title and Price of the books whose Price is between 200 and 350.
Answer

(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)

TitleMember
Informatics PracticesAsha
Wings of FireRavi
Chemistry Part 1Neha
Learn SQLKaran

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)

BookIDPricePrice + 10
201210220
202180190
203299309
204350360
205190200
206250260
207400410

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;
BookIDTitlePrice
201Informatics Practices210
203Wings of Fire299
204Python Basics350
206The Story of My Experiments250

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.

E2.32Practice5 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

(a) Write the output of the following queries:

  1. SELECT PName, Category FROM PRODUCT WHERE Category = 'Home' OR Category = 'Electronics';
  2. SELECT PName, Discount FROM PRODUCT WHERE Discount IS NOT NULL;
  3. SELECT PName, Category FROM PRODUCT WHERE NOT Category = 'Home';

(b) Write SQL queries for the following:

  1. Display all the details of the products whose Category is Home.
  2. Display PName of the products whose Category is Home and Price is at least 400.
Answer

(i)

PNameCategory
Pen DriveElectronics
MouseElectronics
Water BottleHome
EarphonesElectronics
Lunch BoxHome

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)

PNameDiscount
Notebook5
Geometry Box10
Mouse15
Earphones20
Lunch Box8

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)

PNameCategory
NotebookStationery
Pen DriveElectronics
Geometry BoxStationery
MouseElectronics
EarphonesElectronics

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';
PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0789010077Lunch BoxHomeMilton2025-12-182758

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.

E2.33Practice5 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

(a) Write the output of the following queries:

  1. SELECT Title, Subject FROM BOOK WHERE Subject = 'Science' OR Subject = 'Biography';
  2. SELECT Title, Member FROM BOOK WHERE Member IS NOT NULL;
  3. SELECT Title FROM BOOK WHERE Member IS NULL;

(b) Write SQL queries for the following:

  1. Display Title of the books whose Publisher is Penguin and Member is not NULL.
  2. Display Title and Price of all the books whose Price is more than 300.
Answer

(i)

TitleSubject
Physics Part 1Science
Wings of FireBiography
Chemistry Part 1Science
The Story of My ExperimentsBiography

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)

TitleMember
Informatics PracticesAsha
Wings of FireRavi
Chemistry Part 1Neha
Learn SQLKaran

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;
TitlePrice
Python Basics350
Learn SQL400

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.

E2.34Practice5 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

(a) Write the output of the following queries:

  1. SELECT Title FROM BOOK WHERE Publisher = 'NCERT' AND Member IS NOT NULL;
  2. SELECT Title FROM BOOK WHERE Member IS NULL;
  3. SELECT Title FROM BOOK WHERE Subject = 'Computer' AND Price >= 300;

(b) Write SQL queries for the following:

  1. Display all the details of the books whose Subject is Computer.
  2. Display Title and IssueDate of the books whose IssueDate is between '2026-07-01' and '2026-07-31'.
Answer

(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';
BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

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';
TitleIssueDate
Informatics Practices2026-07-03
Physics Part 12026-07-10
Chemistry Part 12026-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.

E2.35Practice5 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

(a) Write the output of the following queries:

  1. SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
  2. SELECT RollNo, Marks, Marks + 10 FROM STUDENT;
  3. SELECT * FROM STUDENT WHERE Section = 'C';

(b) Write SQL queries for the following:

  1. Display Name and Section of the students whose Section is A or C.
  2. Display Name of the students whose Gender is M and Phone is not NULL.
Answer

(i)

NamePhone
Aarav9810011111
Chirag9810033333
Divya9810044444
Farah9810066666
Gaurav9810077777

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)

RollNoMarksMarks + 10
17888
292102
34555
46676
58898
63141
75969

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)

RollNoAdmNoNameSectionGenderDOBMarksPhone
44534DivyaCF2009-07-21669810044444
74567GauravCM2010-02-28599810077777

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';
NameSection
AaravA
ChiragA
DivyaC
FarahA
GauravC

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 =.)

E2.36Practice5 marks

Consider the table PRODUCT given below.

Table: PRODUCT

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0289010022Pen DriveElectronicsSanDisk2025-08-15450NULL
P0389010033Geometry BoxStationeryCamlin2025-11-0218010
P0489010044MouseElectronicsLogitech2026-02-2065015
P0589010055Water BottleHomeMilton2025-05-30320NULL
P0689010066EarphonesElectronicsBoat2026-03-0589920
P0789010077Lunch BoxHomeMilton2025-12-182758

(a) Write the output of the following queries:

  1. SELECT PName, Category FROM PRODUCT WHERE Category = 'Electronics' OR Category = 'Home';
  2. SELECT * FROM PRODUCT WHERE Category = 'Stationery';
  3. SELECT PName FROM PRODUCT WHERE Discount IS NULL;

(b) Write SQL queries for the following:

  1. Display PName of the products whose Brand is Boat and Discount is not NULL.
  2. Display PCode, Price and Price increased by 10 for every product.
Answer

(i)

PNameCategory
Pen DriveElectronics
MouseElectronics
Water BottleHome
EarphonesElectronics
Lunch BoxHome

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)

PCodeBarcodePNameCategoryBrandMfgDatePriceDiscount
P0189010011NotebookStationeryClassmate2026-01-10605
P0389010033Geometry BoxStationeryCamlin2025-11-0218010

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;
PCodePricePrice + 10
P016070
P02450460
P03180190
P04650660
P05320330
P06899909
P07275285

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.

E2.37Practice5 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

(a) Write the output of the following queries:

  1. SELECT Title, Subject FROM BOOK WHERE NOT Subject = 'Computer';
  2. SELECT * FROM BOOK WHERE Subject = 'Computer';
  3. SELECT Title FROM BOOK WHERE Subject = 'Computer' AND Price >= 250;

(b) Write SQL queries for the following:

  1. Display Title of the books whose Publisher is BPB and Member is not NULL.
  2. Display BookID, Title and Price of the books whose Price is between 250 and 300.
Answer

(i)

TitleSubject
Physics Part 1Science
Wings of FireBiography
Chemistry Part 1Science
The Story of My ExperimentsBiography

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)

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

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;
BookIDTitlePrice
203Wings of Fire299
206The Story of My Experiments250

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.

E2.38Practice5 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

(a) Write the output of the following queries:

  1. SELECT Name, Gender FROM STUDENT WHERE Gender <> 'F';
  2. SELECT Name, Phone FROM STUDENT WHERE Phone IS NOT NULL;
  3. SELECT Name FROM STUDENT WHERE Phone IS NULL;

(b) Write SQL queries for the following:

  1. Display Name and DOB of the students whose DOB is between '2009-06-01' and '2009-12-31'.
  2. Display Name and Marks of the students whose Marks is less than 60 or whose Phone is NULL.
Answer

(i)

NameGender
AaravM
ChiragM
EshanM
GauravM

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)

NamePhone
Aarav9810011111
Chirag9810033333
Divya9810044444
Farah9810066666
Gaurav9810077777

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';
NameDOB
Bhavya2009-11-30
Divya2009-07-21
Farah2009-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;
NameMarks
Bhavya92
Chirag45
Eshan88
Farah31
Gaurav59

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 =.)

E2.39Practice5 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

(a) Write the output of the following queries:

  1. SELECT RollNo, Marks, Marks + 10 FROM STUDENT;
  2. SELECT Name FROM STUDENT WHERE Phone IS NULL;
  3. SELECT Name, Marks FROM STUDENT WHERE Marks > 70;

(b) Write SQL queries for the following:

  1. Display Name of the students whose Section is C and Marks is at least 70.
  2. Display Name and Section of the students whose Section is B or A.
Answer

(i)

RollNoMarksMarks + 10
17888
292102
34555
46676
58898
63141
75969

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)

NameMarks
Aarav78
Bhavya92
Eshan88

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';
NameSection
AaravA
BhavyaB
ChiragA
EshanB
FarahA

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.

E2.40Practice5 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

(a) Write the output of the following queries:

  1. SELECT Name, Marks FROM STUDENT WHERE Marks < 50 OR Phone IS NULL;
  2. SELECT Name FROM STUDENT WHERE Gender = 'F' AND Phone IS NOT NULL;
  3. SELECT Name FROM STUDENT WHERE Phone IS NULL;

(b) Write SQL queries for the following:

  1. Display RollNo, Name and Marks of the students whose Marks is between 50 and 60.
  2. Display Name and Phone of the students whose Phone is not NULL.
Answer

(i)

NameMarks
Bhavya92
Chirag45
Eshan88
Farah31

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;
RollNoNameMarks
7Gaurav59

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;
NamePhone
Aarav9810011111
Chirag9810033333
Divya9810044444
Farah9810066666
Gaurav9810077777

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 =.)

E2.41Practice5 marks

Consider the table BOOK given below.

Table: BOOK

BookIDISBNTitleSubjectPublisherIssueDatePriceMember
2019789352921485Informatics PracticesComputerNCERT2026-07-03210Asha
2029789352920112Physics Part 1ScienceNCERT2026-07-10180NULL
2039780143032311Wings of FireBiographyUniversities2026-06-21299Ravi
2049789386551009Python BasicsComputerBPB2026-08-01350NULL
2059789352925032Chemistry Part 1ScienceNCERT2026-07-15190Neha
2069780140449136The Story of My ExperimentsBiographyPenguin2026-05-30250NULL
2079789386551023Learn SQLComputerBPB2026-08-12400Karan

(a) Write the output of the following queries:

  1. SELECT Title, Subject FROM BOOK WHERE NOT Subject = 'Biography';
  2. SELECT Title, Price FROM BOOK WHERE Price < 200 OR Member IS NULL;
  3. SELECT Title, IssueDate FROM BOOK WHERE IssueDate BETWEEN '2026-07-01' AND '2026-07-31';

(b) Write SQL queries for the following:

  1. Display Title of the books whose Member is not known (NULL).
  2. Display Title of the books whose Subject is Biography and Price is at least 300.
Answer

(i)

TitleSubject
Informatics PracticesComputer
Physics Part 1Science
Python BasicsComputer
Chemistry Part 1Science
Learn SQLComputer

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)

TitlePrice
Physics Part 1180
Python Basics350
Chemistry Part 1190
The Story of My Experiments250

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)

TitleIssueDate
Informatics Practices2026-07-03
Physics Part 12026-07-10
Chemistry Part 12026-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.

E2.42Practice5 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

(a) Write the output of the following queries:

  1. SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
  2. SELECT EName FROM EMPLOYEE WHERE City = 'Mumbai' AND Bonus IS NOT NULL;
  3. SELECT EName FROM EMPLOYEE WHERE Bonus IS NULL;

(b) Write SQL queries for the following:

  1. Display EName and DOJ of the employees whose DOJ is between '2018-01-01' and '2020-12-31'.
  2. Display EName and Salary of all the employees whose Salary is more than 60000.
Answer

(i)

EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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';
ENameDOJ
Ravi2018-06-01
Seema2020-01-15
Vikas2019-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;
ENameSalary
Tarun75000
Vikas64000
Yamini81000

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.

E2.43Practice5 marks

Consider the table PATIENT given below.

Table: PATIENT

PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
11123412341234MohanGeneralDr. Rao2026-09-021500LIC
12223422342234NishaICUDr. Sen2026-09-058000NULL
13323432343234OmGeneralDr. Rao2026-09-101200Star
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
15523452345234QasimICUDr. Sen2026-09-159500NULL
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL
17723472347234SahilGeneralDr. Rao2026-09-20900Star

(a) Write the output of the following queries:

  1. SELECT PName, Fee FROM PATIENT WHERE Fee > 4000;
  2. SELECT PName, Ward FROM PATIENT WHERE NOT Ward = 'Maternity';
  3. SELECT PID, Fee, Fee + 10 FROM PATIENT;

(b) Write SQL queries for the following:

  1. Display all the details of the patients whose Ward is Maternity.
  2. Display PName of the patients whose Ward is Maternity and Fee is at least 4000.
Answer

(i)

PNameFee
Nisha8000
Pooja5000
Qasim9500
Rekha4500

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)

PNameWard
MohanGeneral
NishaICU
OmGeneral
QasimICU
SahilGeneral

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)

PIDFeeFee + 10
1115001510
1280008010
1312001210
1450005010
1595009510
1645004510
17900910

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';
PIDAadhaarPNameWardDoctorAdmitDateFeeInsurance
14423442344234PoojaMaternityDr. Iyer2026-09-125000LIC
16623462346234RekhaMaternityDr. Iyer2026-09-184500NULL

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.

E2.44Practice5 marks

Consider the table EMPLOYEE given below.

Table: EMPLOYEE

EmpIDEmailENameDeptCityDOJSalaryBonus
E101ravi@co.inRaviSalesDelhi2018-06-01420003000
E102seema@co.inSeemaHRPune2020-01-1558000NULL
E103tarun@co.inTarunITDelhi2016-09-20750005000
E104usha@co.inUshaSalesMumbai2021-03-1036000NULL
E105vikas@co.inVikasITPune2019-11-05640004000
E106wasim@co.inWasimHRDelhi2022-07-25390002000
E107yamini@co.inYaminiITMumbai2017-12-1281000NULL

(a) Write the output of the following queries:

  1. SELECT EName FROM EMPLOYEE WHERE Bonus IS NULL;
  2. SELECT EmpID, Salary, Salary + 10 FROM EMPLOYEE;
  3. SELECT EName, Bonus FROM EMPLOYEE WHERE Bonus IS NOT NULL;

(b) Write SQL queries for the following:

  1. Display EName and Dept of the employees whose Dept is not IT.
  2. Display EmpID, EName and Salary of the employees whose Salary is between 40000 and 70000.
Answer

(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)

EmpIDSalarySalary + 10
E1014200042010
E1025800058010
E1037500075010
E1043600036010
E1056400064010
E1063900039010
E1078100081010

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)

ENameBonus
Ravi3000
Tarun5000
Vikas4000
Wasim2000

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';
ENameDept
RaviSales
SeemaHR
UshaSales
WasimHR

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;
EmpIDENameSalary
E101Ravi42000
E102Seema58000
E105Vikas64000

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.

E2.45Practice5 marks

Consider the table STUDENT given below.

Table: STUDENT

RollNoAdmNoNameSectionGenderDOBMarksPhone
14501AaravAM2009-04-12789810011111
24512BhavyaBF2009-11-3092NULL
34523ChiragAM2010-01-05459810033333
44534DivyaCF2009-07-21669810044444
54545EshanBM2010-03-1788NULL
64556FarahAF2009-09-09319810066666
74567GauravCM2010-02-28599810077777

(a) Write the output of the following queries:

  1. SELECT * FROM STUDENT WHERE Section = 'B';
  2. SELECT Name FROM STUDENT WHERE Gender = 'M' AND Phone IS NOT NULL;
  3. SELECT Name FROM STUDENT WHERE Section = 'B' AND Marks >= 50;

(b) Write SQL queries for the following:

  1. Display Name of the students whose Phone is not known (NULL).
  2. Display Name and Section of the students whose Section is not B.
Answer

(i)

RollNoAdmNoNameSectionGenderDOBMarksPhone
24512BhavyaBF2009-11-3092NULL
54545EshanBM2010-03-1788NULL

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';
NameSection
AaravA
ChiragA
DivyaC
FarahA
GauravC

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.

E3SQL: create, insert, alter, update, delete5 marks · 45 questions
E3.1Practice5 marks

Write SQL commands for the following:

  1. Create the table STUDENT with the columns RollNo INT, Name VARCHAR(25), Section CHAR(1), Gender CHAR(1), DOB DATE, Marks INT, Phone VARCHAR(10). Make RollNo the primary key and Name NOT NULL.
  2. Insert the record (105, 'Eshan', 'B', 'M', '2010-03-17', 88, NULL).
  3. Add a column Grade of type CHAR(1).
  4. Increase the Marks by 5 for all the students whose Section is B.
  5. Delete the records whose Marks is less than 50.
Answer

(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.

E3.2Practice5 marks

Write SQL commands for the following:

  1. Create the table EMPLOYEE with the columns EmpID CHAR(4), EName VARCHAR(25), Dept VARCHAR(10), City VARCHAR(15), DOJ DATE, Salary INT, Bonus INT. Make EmpID the primary key and EName NOT NULL.
  2. Insert the record ('E153', 'Tarun', 'IT', 'Delhi', '2016-09-20', 75000, 5000).
  3. Add a column Grade of type CHAR(1).
  4. Increase the Salary by 5 for all the employees whose Dept is Sales.
  5. Delete the records whose Salary is less than 70000.
Answer

(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.

E3.3Practice5 marks

Write SQL commands for the following:

  1. Create the table PRODUCT with the columns PCode CHAR(4), PName VARCHAR(20), Category VARCHAR(12), Brand VARCHAR(12), MfgDate DATE, Price INT, Discount INT. Make PCode the primary key and PName NOT NULL.
  2. Insert the record ('P51', 'Notebook', 'Stationery', 'Classmate', '2026-01-10', 60, 5).
  3. Add a column Grade of type CHAR(1).
  4. Increase the Price by 5 for all the products whose Category is Stationery.
  5. Delete the records whose Price is less than 100.
Answer

(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.

E3.4Practice5 marks

Write SQL commands for the following:

  1. Create the table BOOK with the columns BookID INT, Title VARCHAR(30), Subject VARCHAR(12), Publisher VARCHAR(12), IssueDate DATE, Price INT, Member VARCHAR(15). Make BookID the primary key and Title NOT NULL.
  2. Insert the record (302, 'Physics Part 1', 'Science', 'NCERT', '2026-07-10', 180, NULL).
  3. Add a column Grade of type CHAR(1).
  4. Increase the Price by 5 for all the books whose Subject is Biography.
  5. Remove the table BOOK from the database.
Answer

(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.

E3.5Practice5 marks

Write SQL commands for the following:

  1. Create the table PATIENT with the columns PID INT, PName VARCHAR(20), Ward VARCHAR(12), Doctor VARCHAR(15), AdmitDate DATE, Fee INT, Insurance VARCHAR(10). Make PID the primary key and PName NOT NULL.
  2. Insert the record (113, 'Om', 'General', 'Dr. Rao', '2026-09-10', 1200, 'Star').
  3. Add a column Remarks of type VARCHAR(30).
  4. Increase the Fee by 5 for all the patients whose Ward is General.
  5. Remove the table PATIENT from the database.
Answer

(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.

E3.6Practice5 marks

Write SQL commands for the following:

  1. Create the table STUDENT with the columns RollNo INT, Name VARCHAR(25), Section CHAR(1), Gender CHAR(1), DOB DATE, Marks INT, Phone VARCHAR(10). Make RollNo the primary key and Name NOT NULL.
  2. Insert the record (101, 'Aarav', 'A', 'M', '2009-04-12', 78, '9810011111').
  3. Add a column Rating of type INT.
  4. Increase the Marks by 5 for all the students whose Section is B.
  5. Delete the records whose Marks is less than 50.
Answer

(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.

E3.7Practice5 marks

Write SQL commands for the following:

  1. Create the table EMPLOYEE with the columns EmpID CHAR(4), EName VARCHAR(25), Dept VARCHAR(10), City VARCHAR(15), DOJ DATE, Salary INT, Bonus INT. Make EmpID the primary key and EName NOT NULL.
  2. Insert the record ('E153', 'Tarun', 'IT', 'Delhi', '2016-09-20', 75000, 5000).
  3. Add a column Remarks of type VARCHAR(30).
  4. Increase the Salary by 5 for all the employees whose Dept is HR.
  5. Remove the table EMPLOYEE from the database.
Answer

(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.

E3.8Practice5 marks

Write SQL commands for the following:

  1. Create the table PRODUCT with the columns PCode CHAR(4), PName VARCHAR(20), Category VARCHAR(12), Brand VARCHAR(12), MfgDate DATE, Price INT, Discount INT. Make PCode the primary key and PName NOT NULL.
  2. Insert the record ('P57', 'Lunch Box', 'Home', 'Milton', '2025-12-18', 275, 8).
  3. Add a column Status of type VARCHAR(10).
  4. Increase the Price by 5 for all the products whose Category is Electronics.
  5. Delete the records whose Price is less than 400.
Answer

(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.

E3.9Practice5 marks

Write SQL commands for the following:

  1. Create the table BOOK with the columns BookID INT, Title VARCHAR(30), Subject VARCHAR(12), Publisher VARCHAR(12), IssueDate DATE, Price INT, Member VARCHAR(15). Make BookID the primary key and Title NOT NULL.
  2. Insert the record (303, 'Wings of Fire', 'Biography', 'Universities', '2026-06-21', 299, 'Ravi').
  3. Add a column Remarks of type VARCHAR(30).
  4. Increase the Price by 5 for all the books whose Subject is Computer.
  5. Remove the table BOOK from the database.
Answer

(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.

E3.10Practice5 marks

Write SQL commands for the following:

  1. Create the table PATIENT with the columns PID INT, PName VARCHAR(20), Ward VARCHAR(12), Doctor VARCHAR(15), AdmitDate DATE, Fee INT, Insurance VARCHAR(10). Make PID the primary key and PName NOT NULL.
  2. Insert the record (111, 'Mohan', 'General', 'Dr. Rao', '2026-09-02', 1500, 'LIC').
  3. Add a column Status of type VARCHAR(10).
  4. Increase the Fee by 5 for all the patients whose Ward is Maternity.
  5. Delete the records whose Fee is less than 6000.
Answer

(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.

E3.11Practice5 marks

Write SQL commands for the following:

  1. Create the table STUDENT with the columns RollNo INT, Name VARCHAR(25), Section CHAR(1), Gender CHAR(1), DOB DATE, Marks INT, Phone VARCHAR(10). Make RollNo the primary key and Name NOT NULL.
  2. Insert the record (105, 'Eshan', 'B', 'M', '2010-03-17', 88, NULL).
  3. Add a column Rating of type INT.
  4. Increase the Marks by 5 for all the students whose Section is B.
  5. Delete the records whose Marks is less than 50.
Answer

(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.

E3.12Practice5 marks

Write SQL commands for the following:

  1. Create the table EMPLOYEE with the columns EmpID CHAR(4), EName VARCHAR(25), Dept VARCHAR(10), City VARCHAR(15), DOJ DATE, Salary INT, Bonus INT. Make EmpID the primary key and EName NOT NULL.
  2. Insert the record ('E151', 'Ravi', 'Sales', 'Delhi', '2018-06-01', 42000, 3000).
  3. Add a column Grade of type CHAR(1).
  4. Increase the Salary by 5 for all the employees whose Dept is IT.
  5. Remove the table EMPLOYEE from the database.
Answer

(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.

E3.13Practice5 marks

Write SQL commands for the following:

  1. Create the table PRODUCT with the columns PCode CHAR(4), PName VARCHAR(20), Category VARCHAR(12), Brand VARCHAR(12), MfgDate DATE, Price INT, Discount INT. Make PCode the primary key and PName NOT NULL.
  2. Insert the record ('P56', 'Earphones', 'Electronics', 'Boat', '2026-03-05', 899, 20).
  3. Add a column Grade of type CHAR(1).
  4. Increase the Price by 5 for all the products whose Category is Electronics.
  5. Delete the records whose Price is less than 100.
Answer

(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.

E3.14Practice5 marks

Write SQL commands for the following:

  1. Create the table BOOK with the columns BookID INT, Title VARCHAR(30), Subject VARCHAR(12), Publisher VARCHAR(12), IssueDate DATE, Price INT, Member VARCHAR(15). Make BookID the primary key and Title NOT NULL.
  2. Insert the record (305, 'Chemistry Part 1', 'Science', 'NCERT', '2026-07-15', 190, 'Neha').
  3. Add a column Status of type VARCHAR(10).
  4. Increase the Price by 5 for all the books whose Subject is Biography.
  5. Delete the records whose Price is less than 300.
Answer

(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.

E3.15Practice5 marks

Write SQL commands for the following:

  1. Create the table PATIENT with the columns PID INT, PName VARCHAR(20), Ward VARCHAR(12), Doctor VARCHAR(15), AdmitDate DATE, Fee INT, Insurance VARCHAR(10). Make PID the primary key and PName NOT NULL.
  2. Insert the record (114, 'Pooja', 'Maternity', 'Dr. Iyer', '2026-09-12', 5000, 'LIC').
  3. Add a column Status of type VARCHAR(10).
  4. Increase the Fee by 5 for all the patients whose Ward is Maternity.
  5. Delete the records whose Fee is less than 1500.
Answer

(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.

E3.16Practice5 marks

Write SQL commands for the following:

  1. Create the table STUDENT with the columns RollNo INT, Name VARCHAR(25), Section CHAR(1), Gender CHAR(1), DOB DATE, Marks INT, Phone VARCHAR(10). Make RollNo the primary key and Name NOT NULL.
  2. Insert the record (101, 'Aarav', 'A', 'M', '2009-04-12', 78, '9810011111').
  3. Add a column Status of type VARCHAR(10).
  4. Increase the Marks by 5 for all the students whose Section is A.
  5. Remove the table STUDENT from the database.
Answer

(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.

E3.17Practice5 marks

Write SQL commands for the following:

  1. Create the table EMPLOYEE with the columns EmpID CHAR(4), EName VARCHAR(25), Dept VARCHAR(10), City VARCHAR(15), DOJ DATE, Salary INT, Bonus INT. Make EmpID the primary key and EName NOT NULL.
  2. Insert the record ('E156', 'Wasim', 'HR', 'Delhi', '2022-07-25', 39000, 2000).
  3. Add a column Remarks of type VARCHAR(30).
  4. Increase the Salary by 5 for all the employees whose Dept is Sales.
  5. Remove the table EMPLOYEE from the database.
Answer

(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.

E3.18Practice5 marks

Write SQL commands for the following:

  1. Create the table PRODUCT with the columns PCode CHAR(4), PName VARCHAR(20), Category VARCHAR(12), Brand VARCHAR(12), MfgDate DATE, Price INT, Discount INT. Make PCode the primary key and PName NOT NULL.
  2. Insert the record ('P52', 'Pen Drive', 'Electronics', 'SanDisk', '2025-08-15', 450, NULL).
  3. Add a column Grade of type CHAR(1).
  4. Increase the Price by 5 for all the products whose Category is Stationery.
  5. Remove the table PRODUCT from the database.
Answer

(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.

E3.19Practice5 marks

Write SQL commands for the following:

  1. Create the table BOOK with the columns BookID INT, Title VARCHAR(30), Subject VARCHAR(12), Publisher VARCHAR(12), IssueDate DATE, Price INT, Member VARCHAR(15). Make BookID the primary key and Title NOT NULL.
  2. Insert the record (305, 'Chemistry Part 1', 'Science', 'NCERT', '2026-07-15', 190, 'Neha').
  3. Add a column Remarks of type VARCHAR(30).
  4. Increase the Price by 5 for all the books whose Subject is Computer.
  5. Delete the records whose Price is less than 200.
Answer

(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.

E3.20Practice5 marks

Write SQL commands for the following:

  1. Create the table PATIENT with the columns PID INT, PName VARCHAR(20), Ward VARCHAR(12), Doctor VARCHAR(15), AdmitDate DATE, Fee INT, Insurance VARCHAR(10). Make PID the primary key and PName NOT NULL.
  2. Insert the record (115, 'Qasim', 'ICU', 'Dr. Sen', '2026-09-15', 9500, NULL).
  3. Add a column Status of type VARCHAR(10).
  4. Increase the Fee by 5 for all the patients whose Ward is Maternity.
  5. Delete the records whose Fee is less than 1500.
Answer

(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.

E3.21Practice5 marks

Write SQL commands for the following:

  1. Create the table STUDENT with the columns RollNo INT, Name VARCHAR(25), Section CHAR(1), Gender CHAR(1), DOB DATE, Marks INT, Phone VARCHAR(10). Make RollNo the primary key and Name NOT NULL.
  2. Insert the record (105, 'Eshan', 'B', 'M', '2010-03-17', 88, NULL).
  3. Add a column Remarks of type VARCHAR(30).
  4. Increase the Marks by 5 for all the students whose Section is A.
  5. Remove the table STUDENT from the database.
Answer

(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.

E3.22Practice5 marks

Write SQL commands for the following:

  1. Create the table EMPLOYEE with the columns EmpID CHAR(4), EName VARCHAR(25), Dept VARCHAR(10), City VARCHAR(15), DOJ DATE, Salary INT, Bonus INT. Make EmpID the primary key and EName NOT NULL.
  2. Insert the record ('E156', 'Wasim', 'HR', 'Delhi', '2022-07-25', 39000, 2000).
  3. Add a column Status of type VARCHAR(10).
  4. Increase the Salary by 5 for all the employees whose Dept is IT.
  5. Remove the table EMPLOYEE from the database.
Answer

(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.

E3.23Practice5 marks

Write SQL commands for the following:

  1. Create the table PRODUCT with the columns PCode CHAR(4), PName VARCHAR(20), Category VARCHAR(12), Brand VARCHAR(12), MfgDate DATE, Price INT, Discount INT. Make PCode the primary key and PName NOT NULL.
  2. Insert the record ('P56', 'Earphones', 'Electronics', 'Boat', '2026-03-05', 899, 20).
  3. Add a column Rating of type INT.
  4. Increase the Price by 5 for all the products whose Category is Home.
  5. Remove the table PRODUCT from the database.
Answer

(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.

E3.24Practice5 marks

Write SQL commands for the following:

  1. Create the table BOOK with the columns BookID INT, Title VARCHAR(30), Subject VARCHAR(12), Publisher VARCHAR(12), IssueDate DATE, Price INT, Member VARCHAR(15). Make BookID the primary key and Title NOT NULL.
  2. Insert the record (306, 'The Story of My Experiments', 'Biography', 'Penguin', '2026-05-30', 250, NULL).
  3. Add a column Remarks of type VARCHAR(30).
  4. Increase the Price by 5 for all the books whose Subject is Biography.
  5. Delete the records whose Price is less than 250.
Answer

(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.

E3.25Practice5 marks

Write SQL commands for the following:

  1. Create the table PATIENT with the columns PID INT, PName VARCHAR(20), Ward VARCHAR(12), Doctor VARCHAR(15), AdmitDate DATE, Fee INT, Insurance VARCHAR(10). Make PID the primary key and PName NOT NULL.
  2. Insert the record (115, 'Qasim', 'ICU', 'Dr. Sen', '2026-09-15', 9500, NULL).
  3. Add a column Rating of type INT.
  4. Increase the Fee by 5 for all the patients whose Ward is Maternity.
  5. Delete the records whose Fee is less than 1500.
Answer

(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.

E3.26Practice5 marks

Write SQL commands for the following:

  1. Create the table STUDENT with the columns RollNo INT, Name VARCHAR(25), Section CHAR(1), Gender CHAR(1), DOB DATE, Marks INT, Phone VARCHAR(10). Make RollNo the primary key and Name NOT NULL.
  2. Insert the record (101, 'Aarav', 'A', 'M', '2009-04-12', 78, '9810011111').
  3. Add a column Remarks of type VARCHAR(30).
  4. Increase the Marks by 5 for all the students whose Section is A.
  5. Remove the table STUDENT from the database.
Answer

(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.

E3.27Practice5 marks

Write SQL commands for the following:

  1. Create the table EMPLOYEE with the columns EmpID CHAR(4), EName VARCHAR(25), Dept VARCHAR(10), City VARCHAR(15), DOJ DATE, Salary INT, Bonus INT. Make EmpID the primary key and EName NOT NULL.
  2. Insert the record ('E151', 'Ravi', 'Sales', 'Delhi', '2018-06-01', 42000, 3000).
  3. Add a column Remarks of type VARCHAR(30).
  4. Increase the Salary by 5 for all the employees whose Dept is HR.
  5. Remove the table EMPLOYEE from the database.
Answer

(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.

E3.28Practice5 marks

Write SQL commands for the following:

  1. Create the table PRODUCT with the columns PCode CHAR(4), PName VARCHAR(20), Category VARCHAR(12), Brand VARCHAR(12), MfgDate DATE, Price INT, Discount INT. Make PCode the primary key and PName NOT NULL.
  2. Insert the record ('P52', 'Pen Drive', 'Electronics', 'SanDisk', '2025-08-15', 450, NULL).
  3. Add a column Remarks of type VARCHAR(30).
  4. Increase the Price by 5 for all the products whose Category is Electronics.
  5. Delete the records whose Price is less than 400.
Answer

(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.

E3.29Practice5 marks

Write SQL commands for the following:

  1. Create the table BOOK with the columns BookID INT, Title VARCHAR(30), Subject VARCHAR(12), Publisher VARCHAR(12), IssueDate DATE, Price INT, Member VARCHAR(15). Make BookID the primary key and Title NOT NULL.
  2. Insert the record (302, 'Physics Part 1', 'Science', 'NCERT', '2026-07-10', 180, NULL).
  3. Add a column Remarks of type VARCHAR(30).
  4. Increase the Price by 5 for all the books whose Subject is Computer.
  5. Delete the records whose Price is less than 250.
Answer

(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.

E3.30Practice5 marks

Write SQL commands for the following:

  1. Create the table PATIENT with the columns PID INT, PName VARCHAR(20), Ward VARCHAR(12), Doctor VARCHAR(15), AdmitDate DATE, Fee INT, Insurance VARCHAR(10). Make PID the primary key and PName NOT NULL.
  2. Insert the record (117, 'Sahil', 'General', 'Dr. Rao', '2026-09-20', 900, 'Star').
  3. Add a column Status of type VARCHAR(10).
  4. Increase the Fee by 5 for all the patients whose Ward is Maternity.
  5. Delete the records whose Fee is less than 1000.
Answer

(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.

E3.31Practice5 marks

Write SQL commands for the following:

  1. Create the table STUDENT with the columns RollNo INT, Name VARCHAR(25), Section CHAR(1), Gender CHAR(1), DOB DATE, Marks INT, Phone VARCHAR(10). Make RollNo the primary key and Name NOT NULL.
  2. Insert the record (106, 'Farah', 'A', 'F', '2009-09-09', 31, '9810066666').
  3. Add a column Rating of type INT.
  4. Increase the Marks by 5 for all the students whose Section is A.
  5. Remove the table STUDENT from the database.
Answer

(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.

E3.32Practice5 marks

Write SQL commands for the following:

  1. Create the table EMPLOYEE with the columns EmpID CHAR(4), EName VARCHAR(25), Dept VARCHAR(10), City VARCHAR(15), DOJ DATE, Salary INT, Bonus INT. Make EmpID the primary key and EName NOT NULL.
  2. Insert the record ('E152', 'Seema', 'HR', 'Pune', '2020-01-15', 58000, NULL).
  3. Add a column Rating of type INT.
  4. Increase the Salary by 5 for all the employees whose Dept is IT.
  5. Remove the table EMPLOYEE from the database.
Answer

(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.

E3.33Practice5 marks

Write SQL commands for the following:

  1. Create the table PRODUCT with the columns PCode CHAR(4), PName VARCHAR(20), Category VARCHAR(12), Brand VARCHAR(12), MfgDate DATE, Price INT, Discount INT. Make PCode the primary key and PName NOT NULL.
  2. Insert the record ('P52', 'Pen Drive', 'Electronics', 'SanDisk', '2025-08-15', 450, NULL).
  3. Add a column Grade of type CHAR(1).
  4. Increase the Price by 5 for all the products whose Category is Stationery.
  5. Remove the table PRODUCT from the database.
Answer

(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.

E3.34Practice5 marks

Write SQL commands for the following:

  1. Create the table BOOK with the columns BookID INT, Title VARCHAR(30), Subject VARCHAR(12), Publisher VARCHAR(12), IssueDate DATE, Price INT, Member VARCHAR(15). Make BookID the primary key and Title NOT NULL.
  2. Insert the record (301, 'Informatics Practices', 'Computer', 'NCERT', '2026-07-03', 210, 'Asha').
  3. Add a column Rating of type INT.
  4. Increase the Price by 5 for all the books whose Subject is Computer.
  5. Delete the records whose Price is less than 250.
Answer

(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.

E3.35Practice5 marks

Write SQL commands for the following:

  1. Create the table PATIENT with the columns PID INT, PName VARCHAR(20), Ward VARCHAR(12), Doctor VARCHAR(15), AdmitDate DATE, Fee INT, Insurance VARCHAR(10). Make PID the primary key and PName NOT NULL.
  2. Insert the record (112, 'Nisha', 'ICU', 'Dr. Sen', '2026-09-05', 8000, NULL).
  3. Add a column Remarks of type VARCHAR(30).
  4. Increase the Fee by 5 for all the patients whose Ward is ICU.
  5. Delete the records whose Fee is less than 1500.
Answer

(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.

E3.36Practice5 marks

Write SQL commands for the following:

  1. Create the table STUDENT with the columns RollNo INT, Name VARCHAR(25), Section CHAR(1), Gender CHAR(1), DOB DATE, Marks INT, Phone VARCHAR(10). Make RollNo the primary key and Name NOT NULL.
  2. Insert the record (105, 'Eshan', 'B', 'M', '2010-03-17', 88, NULL).
  3. Add a column Remarks of type VARCHAR(30).
  4. Increase the Marks by 5 for all the students whose Section is C.
  5. Remove the table STUDENT from the database.
Answer

(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.

E3.37Practice5 marks

Write SQL commands for the following:

  1. Create the table EMPLOYEE with the columns EmpID CHAR(4), EName VARCHAR(25), Dept VARCHAR(10), City VARCHAR(15), DOJ DATE, Salary INT, Bonus INT. Make EmpID the primary key and EName NOT NULL.
  2. Insert the record ('E154', 'Usha', 'Sales', 'Mumbai', '2021-03-10', 36000, NULL).
  3. Add a column Status of type VARCHAR(10).
  4. Increase the Salary by 5 for all the employees whose Dept is IT.
  5. Delete the records whose Salary is less than 50000.
Answer

(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.

E3.38Practice5 marks

Write SQL commands for the following:

  1. Create the table PRODUCT with the columns PCode CHAR(4), PName VARCHAR(20), Category VARCHAR(12), Brand VARCHAR(12), MfgDate DATE, Price INT, Discount INT. Make PCode the primary key and PName NOT NULL.
  2. Insert the record ('P51', 'Notebook', 'Stationery', 'Classmate', '2026-01-10', 60, 5).
  3. Add a column Grade of type CHAR(1).
  4. Increase the Price by 5 for all the products whose Category is Home.
  5. Remove the table PRODUCT from the database.
Answer

(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.

E3.39Practice5 marks

Write SQL commands for the following:

  1. Create the table BOOK with the columns BookID INT, Title VARCHAR(30), Subject VARCHAR(12), Publisher VARCHAR(12), IssueDate DATE, Price INT, Member VARCHAR(15). Make BookID the primary key and Title NOT NULL.
  2. Insert the record (301, 'Informatics Practices', 'Computer', 'NCERT', '2026-07-03', 210, 'Asha').
  3. Add a column Grade of type CHAR(1).
  4. Increase the Price by 5 for all the books whose Subject is Science.
  5. Delete the records whose Price is less than 350.
Answer

(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.

E3.40Practice5 marks

Write SQL commands for the following:

  1. Create the table PATIENT with the columns PID INT, PName VARCHAR(20), Ward VARCHAR(12), Doctor VARCHAR(15), AdmitDate DATE, Fee INT, Insurance VARCHAR(10). Make PID the primary key and PName NOT NULL.
  2. Insert the record (114, 'Pooja', 'Maternity', 'Dr. Iyer', '2026-09-12', 5000, 'LIC').
  3. Add a column Grade of type CHAR(1).
  4. Increase the Fee by 5 for all the patients whose Ward is ICU.
  5. Delete the records whose Fee is less than 4000.
Answer

(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.

E3.41Practice5 marks

Write SQL commands for the following:

  1. Create the table STUDENT with the columns RollNo INT, Name VARCHAR(25), Section CHAR(1), Gender CHAR(1), DOB DATE, Marks INT, Phone VARCHAR(10). Make RollNo the primary key and Name NOT NULL.
  2. Insert the record (103, 'Chirag', 'A', 'M', '2010-01-05', 45, '9810033333').
  3. Add a column Remarks of type VARCHAR(30).
  4. Increase the Marks by 5 for all the students whose Section is A.
  5. Remove the table STUDENT from the database.
Answer

(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.

E3.42Practice5 marks

Write SQL commands for the following:

  1. Create the table EMPLOYEE with the columns EmpID CHAR(4), EName VARCHAR(25), Dept VARCHAR(10), City VARCHAR(15), DOJ DATE, Salary INT, Bonus INT. Make EmpID the primary key and EName NOT NULL.
  2. Insert the record ('E154', 'Usha', 'Sales', 'Mumbai', '2021-03-10', 36000, NULL).
  3. Add a column Rating of type INT.
  4. Increase the Salary by 5 for all the employees whose Dept is HR.
  5. Delete the records whose Salary is less than 70000.
Answer

(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.

E3.43Practice5 marks

Write SQL commands for the following:

  1. Create the table PRODUCT with the columns PCode CHAR(4), PName VARCHAR(20), Category VARCHAR(12), Brand VARCHAR(12), MfgDate DATE, Price INT, Discount INT. Make PCode the primary key and PName NOT NULL.
  2. Insert the record ('P57', 'Lunch Box', 'Home', 'Milton', '2025-12-18', 275, 8).
  3. Add a column Rating of type INT.
  4. Increase the Price by 5 for all the products whose Category is Electronics.
  5. Remove the table PRODUCT from the database.
Answer

(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.

E3.44Practice5 marks

Write SQL commands for the following:

  1. Create the table BOOK with the columns BookID INT, Title VARCHAR(30), Subject VARCHAR(12), Publisher VARCHAR(12), IssueDate DATE, Price INT, Member VARCHAR(15). Make BookID the primary key and Title NOT NULL.
  2. Insert the record (304, 'Python Basics', 'Computer', 'BPB', '2026-08-01', 350, NULL).
  3. Add a column Status of type VARCHAR(10).
  4. Increase the Price by 5 for all the books whose Subject is Computer.
  5. Remove the table BOOK from the database.
Answer

(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.

E3.45Practice5 marks

Write SQL commands for the following:

  1. Create the table PATIENT with the columns PID INT, PName VARCHAR(20), Ward VARCHAR(12), Doctor VARCHAR(15), AdmitDate DATE, Fee INT, Insurance VARCHAR(10). Make PID the primary key and PName NOT NULL.
  2. Insert the record (113, 'Om', 'General', 'Dr. Rao', '2026-09-10', 1200, 'Star').
  3. Add a column Remarks of type VARCHAR(30).
  4. Increase the Fee by 5 for all the patients whose Ward is General.
  5. Delete the records whose Fee is less than 1000.
Answer

(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.

15

Flashcards for one-mark questions

Tap an option to check your answer at once; your score is saved

Quick quiz: 10 MCQs

Ten multiple-choice questions picked at random. Tap an option to answer. You get your score at the end.

16

Practice question papers

Twenty ready papers with blueprints and a random paper maker, all on the CBSE paper design (Class XI unit marks)

Twenty ready practice papers

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.

Or make a fresh random paper

Marking scheme, download and timer

Blueprint only:
03:00:00

Choose Paper 1 to Paper 20, or make a random paper. The blueprint and the paper open here.

17

Last-day checklist

Read this the evening before and at the exam centre gate

Before the paper

  • Write CREATE TABLE with PRIMARY KEY and NOT NULL from memory.
  • Write one SELECT each with BETWEEN, IS NULL, AND, OR.
  • Revise list and dictionary methods, and ndim, shape, size of NumPy.
  • Learn the trend cards and the cloud stack.

In the first 15 minutes

  • Mark the OR questions and choose the part you know.
  • Note the exact table and column names given in each SQL question.

While writing

  • SQL: semicolon at the end; quotes for text and dates.
  • Output: trace with a small table of values.
  • Programs: input, logic, output, one comment.
Marks katne wali galti
  • = NULL instead of IS NULL
  • DELETE and DROP mixed up
  • Missing int() with input()
  • Writing L = L.sort()
  • Degree and cardinality swapped