A program that translates the whole high-level program at once into machine code is a
(d) compiler A compiler translates the whole program at once and reports all errors together.
Minimum Learning Support Material · CBSE 2026-27
Notes · Labs · Run-checked programs · 1423 solved questions · Flashcards · Quiz · Practice Paper Maker
Theory 70 marks, 3 hours, 37 questions in five sections
| Section | Questions | Marks each | Total | What comes |
|---|---|---|---|---|
| A | Q1 to Q21 | 1 | 21 | MCQ and True/False on all units; Q20 and Q21 are Assertion-Reason |
| B | Q22 to Q28 | 2 | 14 | Unit I (Q22), Python explain (Q23), output (Q24, Q27), error correction (Q26), society (Q25, Q28) |
| C | Q29 to Q31 | 3 | 9 | Society situations, program output, number or pattern program |
| D | Q32 to Q35 | 4 | 16 | Conversions and truth table, cyber case study, string program, list or dictionary program |
| E | Q36, Q37 | 5 | 10 | Long Python programs (lists, dictionaries, menus) |
One common blueprint for all twenty practice papers of this kit. Each cell shows the number of questions, with their marks in brackets.
| Unit | Sec A1 mark each1 m | Sec B2 marks each2 m | Sec C3 marks each3 m | Sec D4 marks each4 m | Sec E5 marks each5 m | Totalmarks |
|---|---|---|---|---|---|---|
| Unit IComputer Systems and Organisation | 4 (4) | 1 (2) | - | 1 (4) | - | 10 |
| Unit IIComputational Thinking and Programming-1 | 13 (13) | 4 (8) | 2 (6) | 2 (8) | 2 (10) | 45 |
| Unit IIISociety, Law and Ethics | 4 (4) | 2 (4) | 1 (3) | 1 (4) | - | 15 |
| Total | 21 (21) | 7 (14) | 3 (9) | 4 (16) | 2 (10) | 70 |
CBSE holds no board exam for Class XI, so it gives no Class XI sample paper. This design follows the CBSE Class XII Computer Science Sample Question Paper 2026-27 (37 questions, 70 marks, 3 hours), with the Class XI unit marks 10, 45 and 15. Schools may set their own design.
Internal choice (OR) is given in eight questions: Q23, Q26, Q27, Q28, Q30, Q31, Q34 and Q37.
Report file: at least 20 Python programs. Lab test: one program, marked on logic, documentation and code quality.
Where the 70 marks come from, easiest first
Python (Unit II) carries 45 of the 70 marks. But Units I and III are the quickest marks. Climb the ladder.
input() gives a string; use int() for numbers.// rounds down: -7 // 2 is -4.L.sort() returns None.CPU, memory, units, software, operating system
A computer is an electronic machine that takes data as input, processes it according to instructions (a program), stores it and gives the result as output.
In daily life: A kitchen: ingredients come in (input), the cook works on them (CPU), the shelf keeps things handy (memory), and the dish is served (output).
Tap each part of the Central Processing Unit.
Does: all calculations (+, -, ×, ÷) and comparisons (>, <, ==).
Example: working out 45 + 12 or checking marks >= 33.
Does: fetches each instruction, decodes it and tells the other parts what to do.
Example: like a traffic police officer directing the flow of data.
Are: tiny, fastest storage places inside the CPU.
Hold: the data and instruction being worked on right now.
Data bus: carries data both ways.
Address bus: carries the memory address, one way from the CPU.
Control bus: carries signals such as read and write.
Is: the CPU built on a single chip.
Speed: clock speed is measured in GHz; more cores do more work together.
In daily life: Like reading a recipe: read the step (fetch), understand it (decode), do it (execute), then the next step.
| Memory | Volatile? | Speed | Use |
|---|---|---|---|
| Registers | Yes | fastest | data being processed now |
| Cache | Yes | very fast | often-used data, between CPU and RAM |
| RAM | Yes | fast | programs and data being used |
| ROM | No | fast to read | boot instructions (firmware) |
| SSD / HDD | No | slow | files kept for long |
| Pen drive, DVD | No | slower | carrying and backup |
Units of memory
1 KB = 1024 bytes, 1 MB = 1024 KB, 1 GB = 1024 MB, 1 TB = 1024 GB, 1 PB = 1024 TB (then EB, ZB, YB).
| Type | What it does | Examples |
|---|---|---|
| Operating system | manages hardware and runs other programs | Windows, Linux, Android |
| Device driver | lets the OS use a device | printer driver |
| Utility software | maintains the computer | antivirus, disk cleanup, compression |
| Language translator | converts programs to machine code | compiler, interpreter, assembler |
| Application software | does a task for the user | word processor, Tally, browser |
Language translators
| Assembler | Compiler | Interpreter | |
|---|---|---|---|
| Converts | assembly to machine code | high-level to machine code, all at once | high-level, line by line |
| Errors | - | all listed together after translation | stops at the first error |
| Example | NASM | C, C++ | Python |
Tap: input, output or both?
Tap the type of software.
Types of memory chips
| Memory | Full form | Feature |
|---|---|---|
| SRAM | Static RAM | very fast, costly; used as cache |
| DRAM | Dynamic RAM | needs refreshing; used as main memory |
| PROM | Programmable ROM | written once by the user |
| EPROM | Erasable PROM | erased with ultraviolet light |
| EEPROM | Electrically Erasable PROM | erased electrically; flash memory is a kind of it |
Types of operating systems
| Type | Idea | Example use |
|---|---|---|
| Single-user | one user at a time | a home PC |
| Multi-user | many users share one computer | a server, bank system |
| Multitasking | many programs run together | music while typing |
| Real-time | responds within a fixed time | air-bag, traffic signals, missiles |
| Distributed | many computers work as one | cloud services |
| Mobile | made for phones and tablets | Android, iOS |
Hardware, software, firmware
Ports and connections
| Port | Used for |
|---|---|
| USB | pen drive, mouse, printer, phone |
| HDMI | monitor, projector, TV (video + audio) |
| Ethernet (RJ45) | wired network |
| Audio jack | headphones, microphone |
Speed order to remember: Registers > Cache > RAM > SSD > HDD. Cost per GB follows the same order.
Do not call the hard disk "memory" in answers; it is secondary storage. Memory means primary memory (RAM, ROM, cache).
Binary, octal, decimal, hexadecimal; ASCII, ISCII, Unicode
A number system is a way of writing numbers using a set of digits. The number of digits is its base (radix).
| System | Base | Digits | Example |
|---|---|---|---|
| Binary | 2 | 0, 1 | (1011)2 |
| Octal | 8 | 0 to 7 | (752)8 |
| Decimal | 10 | 0 to 9 | (945)10 |
| Hexadecimal | 16 | 0 to 9, A to F (A = 10 ... F = 15) | (3AF)16 |
Type a number and choose its base. See it in all four systems, with the division steps.
Tap a method to see a worked example.
Rule: divide by the base, write the remainder, divide the quotient again until it is 0; read the remainders from the bottom.
Example: 25 ÷ 2: remainders 1, 0, 0, 1, 1 → read up: (11001)₂.
Rule: multiply every digit by base raised to its position (from 0 at the right) and add.
Example: (1A)₁₆ = 1×16 + 10×1 = 26.
Rule: from the right, make groups of 3 bits; each group is one octal digit. Back: each octal digit becomes 3 bits.
Example: (101 110)₂ = (56)₈.
Rule: from the right, make groups of 4 bits; each group is one hex digit. Back: each hex digit becomes 4 bits.
Example: (1011 0111)₂ = (B7)₁₆.
Rule: octal → binary (3 bits each) → regroup in 4 bits → hex.
Example: (57)₈ = 101 111 = 0010 1111 = (2F)₁₆.
Place values
| Position | 3 | 2 | 1 | 0 |
|---|---|---|---|---|
| Binary | 8 | 4 | 2 | 1 |
| Octal | 512 | 64 | 8 | 1 |
| Hexadecimal | 4096 | 256 | 16 | 1 |
Encoding gives a unique number (code) to every character, so that text can be stored as binary.
| Scheme | Bits / bytes | Characters | Remember |
|---|---|---|---|
| ASCII | 7 bits | 128 | A = 65, a = 97, 0 = 48, space = 32 |
| ISCII | 8 bits | 256 | Indian scripts (Devanagari, Tamil ...) |
| Unicode UTF-8 | 1 to 4 bytes | all scripts | English letters take 1 byte; used on the web |
| UTF-16 | 2 or 4 bytes | all scripts | |
| UTF-32 | 4 bytes fixed | all scripts | simple but uses more space |
Type any text, even Hindi. See the code of each character, its binary, and the bytes it takes in UTF-8.
print(ord('A'), chr(97)) # 65 a Worked example: decimal 75 to all bases
| Base | Working | Answer |
|---|---|---|
| Binary | 75 → 37 r1, 18 r1, 9 r0, 4 r1, 2 r0, 1 r0, 0 r1 | (1001011)2 |
| Octal | 75 → 9 r3, 1 r1, 0 r1 | (113)8 |
| Hexadecimal | 75 → 4 r11 (B), 0 r4 | (4B)16 |
Worked example: (2F)₁₆ to decimal, octal and binary
(2F)16 = 2 x 16^1 + 15 x 16^0 = 32 + 15 = 47
(2F)16 = 0010 1111 (each hex digit is 4 bits)
= 101111 (drop the leading zeros)
= 101 111 (groups of 3)
= (57)8 Binary table of 0 to 15 (learn by heart)
| Dec | Bin | Oct | Hex | Dec | Bin | Oct | Hex |
|---|---|---|---|---|---|---|---|
| 0 | 0000 | 0 | 0 | 8 | 1000 | 10 | 8 |
| 1 | 0001 | 1 | 1 | 9 | 1001 | 11 | 9 |
| 2 | 0010 | 2 | 2 | 10 | 1010 | 12 | A |
| 3 | 0011 | 3 | 3 | 11 | 1011 | 13 | B |
| 4 | 0100 | 4 | 4 | 12 | 1100 | 14 | C |
| 5 | 0101 | 5 | 5 | 13 | 1101 | 15 | D |
| 6 | 0110 | 6 | 6 | 14 | 1110 | 16 | E |
| 7 | 0111 | 7 | 7 | 15 | 1111 | 17 | F |
ASCII codes to remember
| Character | Code | Character | Code |
|---|---|---|---|
| space | 32 | 0 to 9 | 48 to 57 |
| A to Z | 65 to 90 | a to z | 97 to 122 |
| a - A | 32 | chr(ord('a') - 32) | 'A' |
Check your conversion: convert the answer back to decimal. If you get the starting number, it is right.
Always write the base as a subscript, like (101)2. Without it, 101 could be decimal.
Gates, truth tables, laws, De Morgan
Boolean logic works with only two values: 1 (True) and 0 (False). The basic operations are NOT, AND and OR.
The six gates: symbol, expression and truth table
Y = A · B
| A | B | Y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Y is 1 only when both inputs are 1.
Y = A + B
| A | B | Y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Y is 0 only when both inputs are 0.
Y = Ā
| A | Y |
|---|---|
| 0 | 1 |
| 1 | 0 |
Y is the opposite of A.
Y = NOT(A · B)
| A | B | Y |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Opposite of AND: 0 only when both are 1.
Y = NOT(A + B)
| A | B | Y |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
Opposite of OR: 1 only when both are 0.
Y = A ⊕ B
| A | B | Y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Y is 1 when the inputs are different.
| A | B | A AND B | A OR B | A NAND B | A NOR B | A XOR B |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 |
Choose an expression. Rows where the output is 1 are coloured.
Logic circuit
Logic circuit
Logic circuit
Logic circuit
Logic circuit
Logic circuit
Logic circuit
Logic circuit
Logic circuit
Logic circuit
Logic circuit
Logic circuit
Draw the gates in the order Python would work it out: NOT first, then AND, then OR. Each gate output becomes an input of the next gate.
| A | B | C | Y = (A AND B) OR (NOT C) |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
In daily life: A room light (Y) is on if both switches A and B are on, or if the night sensor C is off.
| A | B | C | Y = NOT (A OR B) AND C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
| Law | AND form | OR form |
|---|---|---|
| Identity | A · 1 = A | A + 0 = A |
| Null | A · 0 = 0 | A + 1 = 1 |
| Idempotent | A · A = A | A + A = A |
| Complement | A · Ā = 0 | A + Ā = 1 |
| Involution | NOT (NOT A) = A | |
| De Morgan | NOT(A · B) = Ā + B̄ | NOT(A + B) = Ā · B̄ |
| A | B | A·B | NOT(A·B) | Ā | B̄ | Ā + B̄ |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 0 | 0 | 0 |
The columns NOT(A·B) and Ā + B̄ are the same in every row, so the law is proved.
Number of rows in a truth table = 2n for n inputs: 2 inputs → 4 rows, 3 inputs → 8 rows.
Work out NOT first, then AND, then OR, unless brackets say otherwise.
Read the rule and tap the gate.
All the laws of Boolean algebra
| Law | AND form | OR form |
|---|---|---|
| Commutative | A · B = B · A | A + B = B + A |
| Associative | (A · B) · C = A · (B · C) | (A + B) + C = A + (B + C) |
| Distributive | A · (B + C) = A·B + A·C | A + B·C = (A + B) · (A + C) |
| Absorption | A · (A + B) = A | A + A·B = A |
NAND as a universal gate
| To make | Using NAND only |
|---|---|
| NOT A | A NAND A |
| A AND B | (A NAND B) NAND (A NAND B) |
| A OR B | (A NAND A) NAND (B NAND B) |
More circuits to practise
| A | B | C | Y = (A OR B) AND (NOT C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
| A | B | C | Y = (A AND NOT B) OR (B AND C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
| A | B | Y = (A AND B) OR (NOT A AND NOT B) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Steps to draw a circuit: (1) find the innermost brackets, (2) put NOT gates first, (3) then AND gates, (4) the OR gate last gives Y.
A bubble (small circle) at the output means NOT. NAND = AND + bubble; NOR = OR + bubble.
Algorithm, flowchart, pseudocode, decomposition
Before writing code, we plan. Problem solving has four steps.
| Symbol | Name | Use |
|---|---|---|
| Oval | Terminal | Start / Stop |
| Parallelogram | Input / output | read or print |
| Rectangle | Process | calculation, assignment |
| Diamond | Decision | yes / no question |
| Arrow | Flow line | order of steps |
The same problem as pseudocode
INPUT N
IF N MOD 2 = 0 THEN
PRINT 'Even'
ELSE
PRINT 'Odd'
END IFTap a word.
Meaning: breaking a big problem into small parts.
Example: a library system: add books, issue, return, fine.
Meaning: dry-run the steps with sample input to check the output.
Example: try N = 7 and N = 10 in the even-odd algorithm.
Meaning: finding and removing errors (bugs).
Tip: print the values of variables inside the loop.
Meaning: choosing the one that uses less time and memory.
Example: adding 1 to n with a loop vs the formula n(n+1)/2.
Tap from first to last.
Worked algorithm: largest of three numbers
Step 1: Start Step 2: Input A, B, C Step 3: If A >= B and A >= C, then Big = A Step 4: Else if B >= C, then Big = B Step 5: Else Big = C Step 6: Print Big Step 7: Stop
Worked algorithm: sum of digits
INPUT N
SET S = 0
WHILE N > 0
D = N MOD 10
S = S + D
N = N DIV 10
END WHILE
PRINT S Dry run (verification) of the sum of digits for N = 352
| N | D = N MOD 10 | S | N DIV 10 |
|---|---|---|---|
| 352 | 2 | 2 | 35 |
| 35 | 5 | 7 | 3 |
| 3 | 3 | 10 | 0 |
Algorithm and program
| Algorithm | Program | |
|---|---|---|
| Written in | plain language, steps | a programming language |
| Runs on a computer? | No | Yes |
| Rules | no strict syntax | strict syntax |
Tap the steps in order.
Tokens, data types, operators, precedence, input, errors
Python is a free, open-source, high-level, interpreted language. It is easy to read, case sensitive, and runs on every platform.
>>>, see the answer at once, not saved| Kind | Operators | Example | Result |
|---|---|---|---|
| Arithmetic | + - * / // % ** | 17 // 5, 17 % 5, 2 ** 5 | 3, 2, 32 |
| Relational | == != > < >= <= | 5 != 3 | True |
| Logical | not and or | 5 > 3 and 2 > 4 | False |
| Assignment | = += -= *= /= //= %= **= | x = 5; x += 2 | x is 7 |
| Identity | is, is not | a is b | same object? |
| Membership | in, not in | 'a' in 'cat' | True |
Precedence: highest first
** goes right to left: 2 ** 3 ** 2 = 2 ** 9 = 512. Others of equal level go left to right.
print(17 + 5 * 2 // 3 - 2 ** 2) print(-17 // 5, -17 % 5) print(7 / 2, 7 // 2, 7.0 // 2) print(True + True, 5 > 3 > 1)
Output
16 -4 3 3.5 3 3.0 2 True
Input, output and type conversion
name = input('Name: ')
age = int(input('Age: '))
print('Hello', name, 'next year you will be', age + 1)
print(name, age, sep=' | ', end='!\n')Output
Name: Asha Age: 16 Hello Asha next year you will be 17 Asha | 16!
| Function | Does | Example |
|---|---|---|
int() | to integer | int('25') → 25, int(7.9) → 7 |
float() | to float | float('2.5') → 2.5 |
str() | to string | str(10) → "10" |
type() | gives the type | type(5.0) → <class 'float'> |
id() | identity (address) | id(x) |
| Error | When | Example |
|---|---|---|
| Syntax error | grammar is wrong; found before running | if x > 5 print(x) (no colon) |
| Runtime error (exception) | while running | 5 / 0 ZeroDivisionError; int("abc") ValueError |
| Logical error | runs but gives a wrong answer | average = a + b / 2 (brackets missing) |
Tap the right box.
Tap the kind of error.
Multiple assignment and swapping
a, b, c = 10, 20, 30 x = y = 5 a, b = b, a print(a, b, c, x, y)
Output
20 10 30 5 5
Mutable and immutable: watch the id()
x = 10 print(id(x) == id(10)) x = x + 1 # a new object is made print(x) L = [1, 2] old = id(L) L.append(3) # the same list changes print(L, id(L) == old)
Output
True 11 [1, 2, 3] True
Escape sequences
| Sequence | Meaning |
|---|---|
| \n | new line |
| \t | tab |
| \' | single quote |
| \\ | backslash |
Keywords of Python (35)
False None True and as assert async await break class continue def del elif else except finally for from global if import in is lambda nonlocal not or pass raise return try while with yield
Implicit and explicit conversion
a = 5
b = 2.5
print(a + b, type(a + b)) # implicit: int to float
print(int('7') + 3, float(4)) # explicitOutput
7.5 <class 'float'> 10 4.0
Common runtime errors
| Error | Example |
|---|---|
| ZeroDivisionError | 5 / 0 |
| ValueError | int('abc') |
| TypeError | '5' + 5 |
| NameError | print(total) before total is made |
| IndexError | [1, 2][5] |
| KeyError | {'a': 1}['b'] |
if-elif-else, for, while, range, break, continue, nested loops
Statements run in sequence unless we use selection (if) or iteration (loops). Python marks a block by indentation (4 spaces).
if marks >= 90:
grade = 'A'
elif marks >= 60:
grade = 'B'
else:
grade = 'C'for i in range(1, 6):
print(i, end=' ')
i = 1
while i <= 5:
print(i, end=' ')
i += 1Change start, stop and step. See the values the loop gets.
| Statement | Effect | Example output |
|---|---|---|
| break | leaves the loop at once | for i in range(1, 10): if i == 4: break → 1 2 3 |
| continue | skips to the next round | if i == 4: continue → 1 2 3 5 6 7 8 9 |
| pass | does nothing; a placeholder | if x > 0: pass |
| loop else | runs if no break happened | useful for "not found" |
Nested loops: a pattern
for i in range(1, 5):
for j in range(1, i + 1):
print(j, end=' ')
print()Output
1 1 2 1 2 3 1 2 3 4
Trace a loop: sum of digits of 4728
| n | n % 10 | s | n // 10 |
|---|---|---|---|
| 4728 | 8 | 8 | 472 |
| 472 | 2 | 10 | 47 |
| 47 | 7 | 17 | 4 |
| 4 | 4 | 21 | 0 |
Model programs with loops: factorial, prime check, Fibonacci, sum of digits, reverse, palindrome, Armstrong, GCD, patterns, series sums. All are in the question bank (C3) with sample runs.
A while loop needs a change inside it (like i += 1), or it never ends.
Loop with else: prime check
n = 29
for i in range(2, n):
if n % i == 0:
print(n, 'is not prime')
break
else:
print(n, 'is prime')Output
29 is prime
Trace a while loop: reverse of 1234
| n | n % 10 | rev = rev*10 + d | n // 10 |
|---|---|---|---|
| 1234 | 4 | 4 | 123 |
| 123 | 3 | 43 | 12 |
| 12 | 2 | 432 | 1 |
| 1 | 1 | 4321 | 0 |
Twelve model programs (all in C3, D3, D4 with sample runs)
| Program | Key idea |
|---|---|
| Factorial | f = f * i in a loop |
| Prime check | for-else with break |
| Fibonacci | a, b = b, a + b |
| Sum of digits | n % 10 and n // 10 |
| Palindrome number | reverse and compare |
| Armstrong | sum of cubes of digits |
| GCD and LCM | x, y = y, x % y |
| Patterns | nested loops, print(end=" ") |
| Series sum | term in a loop |
| Vowel count | if ch in "aeiou" |
| Linear search | for-else |
| Frequency | D[x] = D.get(x, 0) + 1 |
Number of times a loop runs: range(a, b) runs b - a times; range(a, b, s) runs about (b - a) / s times, rounded up.
Do not put a semicolon or brackets after for or if; only a colon.
Indexing, slicing, operators, methods, traversal
A string is a sequence of characters in quotes. Strings are immutable: they cannot be changed in place.
Top: positive index. Bottom: negative index.
Change the string and the start, stop and step. The chosen characters glow, numbered in order.
| Operation | Example | Result |
|---|---|---|
| Concatenation | 'KV' + 'S' | 'KVS' |
| Replication | 'Ha' * 3 | 'HaHaHa' |
| Membership | 'dr' in 'Kendriya' | True |
| Slicing | 'Kendriya'[2:5] | 'ndr' |
| Reverse | 'Kendriya'[::-1] | 'ayirdneK' |
| Comparison | 'apple' < 'banana' | True (by character codes) |
String methods
| Method | Example (s = "hello World") | Result |
|---|---|---|
| len(s) | len(s) | 11 |
| upper(), lower() | s.upper() | 'HELLO WORLD' |
| title(), capitalize() | s.title() | 'Hello World' |
| swapcase() | s.swapcase() | 'HELLO wORLD' |
| count(x) | s.count('o') | 2 |
| find(x) | s.find('o'), s.find('z') | 4, -1 |
| index(x) | s.index('W') | 6 (error if not found) |
| startswith(), endswith() | s.endswith('ld') | True |
| isalpha(), isdigit(), isalnum() | 'abc12'.isalnum() | True |
| islower(), isupper(), isspace() | ' '.isspace() | True |
| strip(), lstrip(), rstrip() | ' hi '.strip() | 'hi' |
| replace(a, b) | s.replace('l', 'L') | 'heLLo WorLd' |
| split() | s.split() | ['hello', 'World'] |
| partition(x) | s.partition(' ') | ('hello', ' ', 'World') |
| join() | '-'.join(['a', 'b']) | 'a-b' |
| ord(), chr() | ord('A'), chr(98) | 65, 'b' |
Traversing a string
s = 'Hello World 26'
u = l = d = 0
for ch in s:
if ch.isupper():
u += 1
elif ch.islower():
l += 1
elif ch.isdigit():
d += 1
print(u, l, d)Output
2 8 2
Tap the type of value returned.
String comparison
print('apple' < 'banana', 'Zoo' < 'ant', 'abc' == 'ABC')
print(ord('Z'), ord('a'))Output
True True False 90 97
Building a new string (strings cannot change)
s = 'computer'
new = ''
for ch in s:
if ch in 'aeiou':
new = new + ch.upper()
else:
new = new + ch
print(new)Output
cOmpUtEr
More methods with examples
| Method | Example | Result |
|---|---|---|
| center(w, ch) | 'KV'.center(6, '*') | '**KV**' |
| zfill(w) | '7'.zfill(3) | '007' |
| count with start | 'banana'.count('a', 2) | 2 |
| find from end | 'banana'.rfind('a') | 5 |
| split with limit | 'a,b,c'.split(',', 1) | ['a', 'b,c'] |
| isalnum on space | 'KV 88'.isalnum() | False |
Slice trick: s[::-1] reverses; s[::2] takes every second character; s[-3:] takes the last three.
A slice never gives an IndexError, but s[20] on a short string does.
Indexing, slicing, methods, nested lists, linear search
A list is an ordered, mutable collection written in [ ]. It can hold values of different types: [10, 'KV', 3.5, [1, 2]].
Type a value and tap a method. The list changes as Python would change it; the code is shown below.
| Method / function | Does | Returns |
|---|---|---|
| L.append(x) | adds x at the end | None |
| L.extend(L2) | adds every element of L2 | None |
| L.insert(i, x) | puts x at index i | None |
| L.remove(x) | deletes the first x (error if absent) | None |
| L.pop(i) | deletes the element at i (last if no i) | the deleted element |
| del L[i] | statement: deletes by index or slice | - |
| L.clear() | empties the list | None |
| L.index(x) | position of the first x | int |
| L.count(x) | how many times x occurs | int |
| L.sort(), L.sort(reverse=True) | sorts L itself | None |
| sorted(L) | sorted copy, L unchanged | new list |
| L.reverse() | reverses L itself | None |
| len, max, min, sum | functions on a list | value |
Copying a list
A = [1, 2, 3] B = A # same list, two names C = A.copy() # a new list A.append(4) print(B) print(C)
Output
[1, 2, 3, 4] [1, 2, 3]
Linear search
L = [12, 45, 7, 30]
x = 7
for i in range(len(L)):
if L[i] == x:
print('Found at index', i)
break
else:
print('Not found')Output
Found at index 2
L = [5, 2, 8]. Tap what the statement gives.
Nested list: rows and columns
M = [[1, 2, 3], [4, 5, 6]]
print(M[1][2], len(M), len(M[0]))
for row in M:
print(sum(row), end=' ')Output
6 2 3 6 15
Slicing changes a list
L = [10, 20, 30, 40, 50] L[1:3] = [7, 8, 9] print(L) del L[::2] print(L)
Output
[10, 7, 8, 9, 40, 50] [7, 9, 50]
Common list programs and the line that does the work
| Task | Key line |
|---|---|
| Sum, max, min | sum(L), max(L), min(L) |
| Count evens | if x % 2 == 0: c += 1 |
| Remove duplicates | if x not in new: new.append(x) |
| Reverse without reverse() | L[::-1] |
| Second largest | sorted(set(L))[-2] |
| Swap first and last | L[0], L[-1] = L[-1], L[0] |
Use L.copy() or L[:] to make a real copy. B = A only gives another name.
L.remove(x) removes only the first x. Use a loop to remove all.
Immutable sequences, key-value pairs, methods, counting
A tuple is an ordered, immutable sequence written in ( ). A one-element tuple needs a comma: (5,).
T = (10, 20, 30, 20) print(T[1:3], T.count(20), T.index(30)) a, b, c, d = T # unpacking print(a + d) T2 = T + (40,) # a new tuple print(len(T2), max(T2))
Output
(20, 30) 2 2 30 5 40
A dictionary stores key: value pairs in { }. Keys are unique and immutable; values can be anything. It is mutable.
D = {'Amit': 85, 'Bela': 92}. Add, change, get or delete a key.
| Method | Does | Example (D = {"a": 1, "b": 2}) |
|---|---|---|
| D[k] | value of k (KeyError if absent) | D["a"] → 1 |
| D[k] = v | adds or changes | D["c"] = 3 |
| D.get(k, d) | value or d (None) if absent | D.get("z", 0) → 0 |
| D.keys(), D.values(), D.items() | views of keys, values, pairs | list(D.items()) → [("a", 1), ("b", 2)] |
| D.update(E) | adds or changes the pairs of E | D.update({"b": 5}) |
| D.pop(k) | removes k, returns its value | D.pop("a") → 1 |
| D.popitem() | removes the last pair | ("b", 2) |
| del D[k] | deletes a key | del D["a"] |
| D.setdefault(k, v) | adds k with v only if absent | returns the value |
| dict.fromkeys(L, v) | new dict from keys in L | dict.fromkeys("ab", 0) → {"a": 0, "b": 0} |
| D.copy(), D.clear() | copy; empty | |
| len, sorted, max, min | work on the keys | sorted(D) → ["a", "b"] |
Counting with a dictionary
text = 'banana'
F = {}
for ch in text:
F[ch] = F.get(ch, 0) + 1
print(F)Output
{'b': 1, 'a': 3, 'n': 2} List, tuple, dictionary, string
| String | List | Tuple | Dictionary | |
|---|---|---|---|---|
| Brackets | ' ' | [ ] | ( ) | { } |
| Mutable? | No | Yes | No | Yes |
| Access by | index | index | index | key |
| Duplicates | yes | yes | yes | keys no, values yes |
Tuple functions
T = (8, 3, 9, 3) print(len(T), max(T), min(T), sum(T)) print(sorted(T), tuple(sorted(T))) print(T.count(3), T.index(9))
Output
4 9 3 23 [3, 3, 8, 9] (3, 3, 8, 9) 2 2
Traversing a dictionary in three ways
D = {'Amit': 85, 'Bela': 92}
for k in D:
print(k, D[k])
for v in D.values():
print(v, end=' ')
print()
for k, v in D.items():
print(k, '->', v)Output
Amit 85 Bela 92 85 92 Amit -> 85 Bela -> 92
Nested dictionary
S = {'Amit': {'Eng': 80, 'CS': 95}, 'Bela': {'Eng': 88, 'CS': 91}}
print(S['Bela']['CS'])
for name in S:
print(name, sum(S[name].values()))Output
91 Amit 175 Bela 179
To count anything (letters, words, marks), use D[x] = D.get(x, 0) + 1.
D[k] on a missing key gives KeyError; D.get(k) gives None.
math, random, statistics
A module is a file of ready Python functions. Import it, then use its functions.
import math # use as math.sqrt(16) from math import sqrt, pi # use as sqrt(16) import statistics as st # use as st.mean(L)
| Module | Function | Example | Result |
|---|---|---|---|
| math | pi, e | math.pi | 3.141592653589793 |
| math | sqrt(x) | math.sqrt(49) | 7.0 |
| math | ceil(x), floor(x) | math.ceil(4.2), math.floor(-4.2) | 5, -5 |
| math | pow(x, y) | math.pow(2, 3) | 8.0 |
| math | fabs(x) | math.fabs(-6) | 6.0 |
| math | sin, cos, tan (radians) | math.sin(0) | 0.0 |
| random | random() | random.random() | 0.0 ≤ value < 1.0 |
| random | randint(a, b) | random.randint(1, 6) | 1 to 6, both included |
| random | randrange(a, b, s) | random.randrange(0, 10, 2) | 0, 2, 4, 6 or 8 |
| statistics | mean(data) | mean([2, 4, 9]) | 5 |
| statistics | median(data) | median([7, 1, 5]) | 5 |
| statistics | mode(data) | mode([2, 3, 3, 8]) | 3 |
To find possible outputs, write the range each call can give. random.randint(1, 3) gives 1, 2 or 3; random.randrange(1, 3) gives only 1 or 2.
import random
L = ['red', 'blue', 'green', 'pink']
k = random.randint(1, 2)
for i in range(k, 4):
print(L[i], end='#')k can be 1 or 2. So the possible outputs are blue#green#pink# and green#pink#. An output that starts with red is not possible.
Four ways to import
| Statement | Call as |
|---|---|
| import math | math.sqrt(9) |
| import math as m | m.sqrt(9) |
| from math import sqrt | sqrt(9) |
| from math import * | sqrt(9), pi (all names) |
Statistics on one list
import statistics as st marks = [72, 85, 85, 90, 64] print(st.mean(marks), st.median(marks), st.mode(marks))
Output
79.2 85 85
random: possible outputs, worked
import random
AR = [20, 30, 40, 50, 60, 70]
lo = random.randint(1, 3)
hi = random.randint(2, 4)
for k in range(lo, hi + 1):
print(AR[k], end='#')lo can be 1, 2 or 3; hi can be 2, 3 or 4. The printing starts at index lo and ends at index hi. So 30#40#50# (lo = 1, hi = 3) is possible, but anything starting with 20 is not, because index 0 is never chosen.
Digital footprint, IPR, licences, cyber crime, IT Act, e-waste
Technology changes how we live. This unit is about using it safely, fairly and lawfully.
Tap to see each kind.
Is: data we leave knowingly.
Examples: posts, comments, e-mails, forms filled, photos uploaded.
Is: data collected without our knowledge.
Examples: browsing history, IP address, location, cookies.
Do: think before posting, keep accounts private, delete old accounts, use private browsing.
Why: colleges and employers may see it; it is hard to erase.
| Right | Protects | Example |
|---|---|---|
| Copyright | creative works: books, music, software, art | a novel, an app |
| Patent | new inventions | a new engine design |
| Trademark | brand names, logos, symbols | the logo of a company |
| Crime / threat | What it is |
|---|---|
| Hacking | unauthorised access; ethical hacking is done with permission |
| Phishing | fake messages or sites to steal passwords and bank details |
| Ransomware | locks files and demands money |
| Cyber bullying | harassing a person online |
| Cyber trolling | posting provocative comments to upset people |
| Identity theft | using another person’s identity to cheat |
| Virus / worm / Trojan | needs a host / spreads by itself / disguised as useful |
| Spyware / adware / keylogger | spies / shows ads / records keys |
Read the case and tap the threat.
Tap the right that protects it.
IT Act, 2000: important sections
| Section | Offence |
|---|---|
| 43 | damage to a computer or data without permission (penalty) |
| 66 | computer-related offences such as hacking |
| 66C | identity theft (misusing a password or signature) |
| 66D | cheating by personation using a computer |
| 66E | violation of privacy (capturing private images) |
| 67 | publishing obscene material electronically |
Malware at a glance
| Malware | Spreads by | Harm |
|---|---|---|
| Virus | infected files, needs a host | damages files |
| Worm | network, by itself | slows networks |
| Trojan | pretends to be useful | steals or opens a back door |
| Ransomware | attachments, links | locks files for money |
| Spyware | free apps, downloads | steals data |
| Adware | free software | unwanted ads |
Creative Commons licence parts
| Code | Meaning |
|---|---|
| BY | give credit to the creator |
| SA | share changed versions under the same licence |
| NC | no commercial use |
| ND | no changes (no derivatives) |
Safe password checklist
Answer case studies in this order: name the problem, why it is wrong or harmful, what to do.
Free software is about freedom, not price; freeware is free of cost but closed.
1423 questions in 21 types, in the order of the paper
Tap a type to open it. In Section A, tap an option to check yourself. Every output, sample run, conversion and truth table shown in the answers was produced by running the code or computing it.
A program that translates the whole high-level program at once into machine code is a
(d) compiler A compiler translates the whole program at once and reports all errors together.
The decimal equivalent of (101)₈ is
(a) 65 Multiply each digit by its place value (powers of 8) and add: 1×8^2 + 0×8^1 + 1×8^0 = 65.
What is the value of NOT A OR (B AND C) when A = 0, B = 0, C = 1?
(b) 1 Work out NOT first, then AND, then OR.
Small, very fast storage locations inside the CPU are called
(d) registers Registers are tiny storage places inside the CPU itself, so they are the fastest memory; they hold the data being worked on right now.
By De Morgan's law, NOT (A AND B) equals
(a) (NOT A) OR (NOT B) De Morgan: break the bar and change the sign. NOT (A AND B) = (NOT A) OR (NOT B). Check with A = 1, B = 0: left side NOT 0 = 1, right side 0 OR 1 = 1.
The hexadecimal equivalent of (10001101)₂ is
(d) 8D Make groups of 4 bits from the right and write each group as one hexadecimal digit: 1000 = 8, 1101 = D.
The binary equivalent of (303)₈ is
(a) 11000011 Write each octal digit as 3 bits: 3 = 011, 0 = 000, 3 = 011.
Which of these is an input device?
(b) Scanner A barcode reader sends the product code into the computer, so it is an input device.
The ASCII code of 'A' is 65. What is the ASCII code of 'D'?
(b) 68 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
Which digit is NOT valid in the octal number system?
(a) 8 Octal uses the digits 0 to 7.
What is the value of (NOT A) OR B when A = 1, B = 0?
(a) 0 Work out NOT first, then AND, then OR.
Which of these is the fastest memory?
(c) Register Speed order: registers > cache > RAM > secondary storage.
How many KB are there in 4 MBs?
(b) 4096 1 byte = 8 bits; 1 KB = 1024 bytes; 1 MB = 1024 KB; 1 GB = 1024 MB; 1 TB = 1024 GB.
The hexadecimal equivalent of (162)₁₀ is
(c) A2 Divide by 16 again and again and read the remainders from bottom to top: 162 ÷ 16 = 10 r 2; 10 ÷ 16 = 0 r A.
The octal equivalent of (10001101)₂ is
(d) 215 Make groups of 3 bits from the right and write each group as one octal digit: 010 = 2, 001 = 1, 101 = 5.
The ASCII code of 'A' is 65. What is the ASCII code of 'A'?
(d) 65 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
An assembler converts
(c) assembly language into machine language An assembler translates assembly language (mnemonics such as ADD, MOV) into machine language (0s and 1s).
What is the value of (A AND B) OR (NOT A AND NOT B) when A = 0, B = 0?
(b) 1 Work out NOT first, then AND, then OR.
NAND and NOR are called universal gates because
(c) any other gate can be made from them Using only NAND gates (or only NOR gates) we can build NOT, AND, OR and every other gate.
What is the value of (NOT A) AND (NOT B) when A = 0, B = 0?
(b) 1 Work out NOT first, then AND, then OR.
4 bits make one
(a) nibble 4 bits = 1 nibble, 8 bits = 1 byte.
The octal equivalent of (89)₁₀ is
(d) 131 Divide by 8 again and again and read the remainders from bottom to top: 89 ÷ 8 = 11 r 1; 11 ÷ 8 = 1 r 3; 1 ÷ 8 = 0 r 1.
The decimal equivalent of (10100110)₂ is
(c) 166 Multiply each digit by its place value (powers of 2) and add: 1×2^7 + 0×2^6 + 1×2^5 + 0×2^4 + 0×2^3 + 1×2^2 + 1×2^1 + 0×2^0 = 166.
The ASCII code of 'A' is 65. What is the ASCII code of 'B'?
(b) 66 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
The hexadecimal equivalent of (211)₁₀ is
(a) D3 Divide by 16 again and again and read the remainders from bottom to top: 211 ÷ 16 = 13 r 3; 13 ÷ 16 = 0 r D.
What is the value of (NOT A) OR B when A = 0, B = 0?
(b) 1 Work out NOT first, then AND, then OR.
What is the value of NOT A OR (B AND C) when A = 1, B = 0, C = 1?
(a) 0 Work out NOT first, then AND, then OR.
The octal equivalent of (68)₁₆ is
(a) 150 Go through binary: 68 = 0110 1000; regroup in 3 bits from the right: 001 = 1, 101 = 5, 000 = 0.
What is the value of (A AND NOT B) OR (B AND C) when A = 0, B = 1, C = 1?
(b) 1 Work out NOT first, then AND, then OR.
Which unit of the CPU performs arithmetic and logical operations?
(d) ALU ALU stands for Arithmetic Logic Unit.
The binary equivalent of (3A)₁₆ is
(c) 111010 Write each hexadecimal digit as 4 bits: 3 = 0011, A = 1010.
The decimal equivalent of (203)₈ is
(b) 131 Multiply each digit by its place value (powers of 8) and add: 2×8^2 + 0×8^1 + 3×8^0 = 131.
State True or False: Cache memory is faster than RAM.
(a) True Cache is made of fast SRAM and sits close to the CPU, so it is faster than RAM.
How many different characters can 7-bit ASCII represent?
(a) 128 2 to the power 7 = 128.
How many MB are there in 7 GBs?
(b) 7168 1 byte = 8 bits; 1 KB = 1024 bytes; 1 MB = 1024 KB; 1 GB = 1024 MB; 1 TB = 1024 GB.
The decimal equivalent of (360)₈ is
(c) 240 Multiply each digit by its place value (powers of 8) and add: 3×8^2 + 6×8^1 + 0×8^0 = 240.
What is the value of A AND (B OR C) when A = 1, B = 1, C = 0?
(b) 1 Work out NOT first, then AND, then OR.
In UTF-32, every character takes
(c) 4 bytes UTF-32 is a fixed-length encoding: every character uses 32 bits = 4 bytes.
The hexadecimal equivalent of (114)₁₀ is
(b) 72 Divide by 16 again and again and read the remainders from bottom to top: 114 ÷ 16 = 7 r 2; 7 ÷ 16 = 0 r 7.
In UTF-8, an English letter such as 'A' takes
(b) 1 byte UTF-8 uses 1 byte for the English (ASCII) characters and 2 to 4 bytes for other scripts.
The ASCII code of 'a' is 97. What is the ASCII code of 'z'?
(a) 122 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
Which gate gives 1 when its two inputs are different?
(b) XOR XOR (exclusive OR) gives 1 for inputs 0,1 and 1,0, and 0 when both inputs are the same.
The ASCII code of 'a' is 97. What is the ASCII code of 'w'?
(d) 119 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
The hexadecimal equivalent of (11010100)₂ is
(d) D4 Make groups of 4 bits from the right and write each group as one hexadecimal digit: 1101 = D, 0100 = 4.
The decimal equivalent of (334)₈ is
(b) 220 Multiply each digit by its place value (powers of 8) and add: 3×8^2 + 3×8^1 + 4×8^0 = 220.
The ASCII code of '0' is 48. What is the ASCII code of '5'?
(c) 53 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
What is the value of A AND (B OR C) when A = 0, B = 1, C = 0?
(a) 0 Work out NOT first, then AND, then OR.
The hexadecimal equivalent of (124)₈ is
(d) 54 Go through binary: 124 = 001 010 100; regroup in 4 bits from the right: 0101 = 5, 0100 = 4.
The hexadecimal equivalent of (1000011)₂ is
(a) 43 Make groups of 4 bits from the right and write each group as one hexadecimal digit: 0100 = 4, 0011 = 3.
The binary equivalent of (331)₈ is
(b) 11011001 Write each octal digit as 3 bits: 3 = 011, 3 = 011, 1 = 001.
A user interface where commands are typed is called
(b) command line interface (CLI) In a CLI the user types commands (as in the DOS or Linux terminal) instead of clicking icons.
Which gate has only one input?
(c) NOT NOT (inverter) has one input and gives its opposite: NOT 0 = 1, NOT 1 = 0.
The decimal equivalent of (336)₈ is
(c) 222 Multiply each digit by its place value (powers of 8) and add: 3×8^2 + 3×8^1 + 6×8^0 = 222.
What is the value of NOT A OR (B AND C) when A = 1, B = 0, C = 0?
(a) 0 Work out NOT first, then AND, then OR.
Which of these is an output device?
(c) Plotter A projector shows the computer's output on a big screen.
State True or False: UTF-8 and ASCII codes are the same for English letters.
(a) True UTF-8 keeps the 128 ASCII codes unchanged.
The decimal equivalent of (307)₈ is
(d) 199 Multiply each digit by its place value (powers of 8) and add: 3×8^2 + 0×8^1 + 7×8^0 = 199.
The decimal equivalent of (1001111)₂ is
(a) 79 Multiply each digit by its place value (powers of 2) and add: 1×2^6 + 0×2^5 + 0×2^4 + 1×2^3 + 1×2^2 + 1×2^1 + 1×2^0 = 79.
The hexadecimal equivalent of (243)₈ is
(a) A3 Go through binary: 243 = 010 100 011; regroup in 4 bits from the right: 1010 = A, 0011 = 3.
Which memory is volatile?
(b) RAM RAM loses its data when the power is switched off.
The hexadecimal equivalent of (73)₁₀ is
(a) 49 Divide by 16 again and again and read the remainders from bottom to top: 73 ÷ 16 = 4 r 9; 4 ÷ 16 = 0 r 4.
The ASCII code of 'a' is 97. What is the ASCII code of 'b'?
(c) 98 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
Which of these is system software?
(a) Operating system A device driver helps the operating system use a device, so it is system software.
The decimal equivalent of (74)₈ is
(a) 60 Multiply each digit by its place value (powers of 8) and add: 7×8^1 + 4×8^0 = 60.
The ASCII code of 'a' is 97. What is the ASCII code of 'n'?
(b) 110 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
What is the value of NOT (A OR B) AND C when A = 1, B = 1, C = 0?
(a) 0 Work out NOT first, then AND, then OR.
The hexadecimal equivalent of (11101100)₂ is
(b) EC Make groups of 4 bits from the right and write each group as one hexadecimal digit: 1110 = E, 1100 = C.
The hexadecimal equivalent of (132)₈ is
(b) 5A Go through binary: 132 = 001 011 010; regroup in 4 bits from the right: 0101 = 5, 1010 = A.
State True or False: ROM is a volatile memory.
(b) False ROM keeps its contents without power.
Windows, macOS and Ubuntu provide a
(d) graphical user interface (GUI) They show windows, icons, menus and a pointer, which is a graphical user interface.
How many bytes are there in 7 KBs?
(c) 7168 1 byte = 8 bits; 1 KB = 1024 bytes; 1 MB = 1024 KB; 1 GB = 1024 MB; 1 TB = 1024 GB.
A language made of 0s and 1s, which the computer understands directly, is
(a) machine language Machine language is binary code that the CPU can run without any translation.
What is the value of A AND B AND NOT C when A = 0, B = 0, C = 1?
(a) 0 Work out NOT first, then AND, then OR.
The decimal equivalent of (342)₈ is
(d) 226 Multiply each digit by its place value (powers of 8) and add: 3×8^2 + 4×8^1 + 2×8^0 = 226.
Software that lets the operating system talk to a printer is a
(a) device driver A device driver is system software that tells the OS how to control a particular device.
How many GB are there in 4 TBs?
(a) 4096 1 byte = 8 bits; 1 KB = 1024 bytes; 1 MB = 1024 KB; 1 GB = 1024 MB; 1 TB = 1024 GB.
How many bits are there in 3 bytes?
(c) 24 1 byte = 8 bits; 1 KB = 1024 bytes; 1 MB = 1024 KB; 1 GB = 1024 MB; 1 TB = 1024 GB.
A truth table for 3 inputs has
(c) 8 rows 2 to the power 3 = 8.
The binary equivalent of (119)₁₀ is
(d) 1110111 Divide by 2 again and again and read the remainders from bottom to top: 119 ÷ 2 = 59 r 1; 59 ÷ 2 = 29 r 1; 29 ÷ 2 = 14 r 1; 14 ÷ 2 = 7 r 0; 7 ÷ 2 = 3 r 1; 3 ÷ 2 = 1 r 1 ….
The base of the hexadecimal number system is
(d) 16 Hexadecimal uses 16 symbols: 0 to 9 and A to F, so its base is 16.
The octal equivalent of (11011110)₂ is
(a) 336 Make groups of 3 bits from the right and write each group as one octal digit: 011 = 3, 011 = 3, 110 = 6.
The decimal equivalent of (1001000)₂ is
(a) 72 Multiply each digit by its place value (powers of 2) and add: 1×2^6 + 0×2^5 + 0×2^4 + 1×2^3 + 0×2^2 + 0×2^1 + 0×2^0 = 72.
The ASCII code of 'A' is 65. What is the ASCII code of 'S'?
(a) 83 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
The binary equivalent of (364)₈ is
(d) 11110100 Write each octal digit as 3 bits: 3 = 011, 6 = 110, 4 = 100.
How many bits are there in 7 nibbles?
(b) 28 1 byte = 8 bits; 1 KB = 1024 bytes; 1 MB = 1024 KB; 1 GB = 1024 MB; 1 TB = 1024 GB.
Python uses which language translator?
(d) Interpreter Python code is run line by line by the Python interpreter.
The decimal equivalent of (277)₈ is
(c) 191 Multiply each digit by its place value (powers of 8) and add: 2×8^2 + 7×8^1 + 7×8^0 = 191.
The octal equivalent of (10000111)₂ is
(a) 207 Make groups of 3 bits from the right and write each group as one octal digit: 010 = 2, 000 = 0, 111 = 7.
The octal equivalent of (162)₁₀ is
(c) 242 Divide by 8 again and again and read the remainders from bottom to top: 162 ÷ 8 = 20 r 2; 20 ÷ 8 = 2 r 4; 2 ÷ 8 = 0 r 2.
The binary equivalent of (EF)₁₆ is
(c) 11101111 Write each hexadecimal digit as 4 bits: E = 1110, F = 1111.
The output of an AND gate is 1 only when
(b) all its inputs are 1 AND is like multiplication: 1 AND 1 = 1, and any 0 input gives 0.
The decimal equivalent of (31)₈ is
(d) 25 Multiply each digit by its place value (powers of 8) and add: 3×8^1 + 1×8^0 = 25.
In hexadecimal, the letter F stands for
(b) 15 A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.
Which of these is secondary memory?
(d) Solid State Drive An SSD stores data permanently outside the CPU; registers, cache and RAM are primary memory.
The decimal equivalent of (1101111)₂ is
(d) 111 Multiply each digit by its place value (powers of 2) and add: 1×2^6 + 1×2^5 + 0×2^4 + 1×2^3 + 1×2^2 + 1×2^1 + 1×2^0 = 111.
Software whose source code is available to all for use and change is called
(b) open source software Open source software shares its source code, so anyone can study, change and share it (e.g. Linux, Python).
The hexadecimal equivalent of (10011110)₂ is
(c) 9E Make groups of 4 bits from the right and write each group as one hexadecimal digit: 1001 = 9, 1110 = E.
The output of an OR gate is 0 only when
(d) all its inputs are 0 OR gives 1 if any input is 1, so it gives 0 only when every input is 0.
How many bytes are there in 5 KBs?
(a) 5120 1 byte = 8 bits; 1 KB = 1024 bytes; 1 MB = 1024 KB; 1 GB = 1024 MB; 1 TB = 1024 GB.
The decimal equivalent of (367)₈ is
(a) 247 Multiply each digit by its place value (powers of 8) and add: 3×8^2 + 6×8^1 + 7×8^0 = 247.
The binary equivalent of (111)₁₀ is
(d) 1101111 Divide by 2 again and again and read the remainders from bottom to top: 111 ÷ 2 = 55 r 1; 55 ÷ 2 = 27 r 1; 27 ÷ 2 = 13 r 1; 13 ÷ 2 = 6 r 1; 6 ÷ 2 = 3 r 0; 3 ÷ 2 = 1 r 1 ….
The octal equivalent of (1101111)₂ is
(d) 157 Make groups of 3 bits from the right and write each group as one octal digit: 001 = 1, 101 = 5, 111 = 7.
The hexadecimal equivalent of (55)₈ is
(c) 2D Go through binary: 55 = 101 101; regroup in 4 bits from the right: 0010 = 2, 1101 = D.
Which part of the CPU directs and controls the working of all other parts?
(c) Control Unit The Control Unit fetches and decodes instructions and sends control signals to all the units.
The decimal equivalent of (76)₈ is
(c) 62 Multiply each digit by its place value (powers of 8) and add: 7×8^1 + 6×8^0 = 62.
The octal equivalent of (22)₁₀ is
(c) 26 Divide by 8 again and again and read the remainders from bottom to top: 22 ÷ 8 = 2 r 6; 2 ÷ 8 = 0 r 2.
The ASCII code of 'a' is 97. What is the ASCII code of 'm'?
(c) 109 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
The instructions needed to start a computer (boot) are stored in
(d) ROM The start-up (BIOS / boot) program is kept in ROM because ROM does not lose data when the power is off.
How many bits are there in 2 nibbles?
(b) 8 1 byte = 8 bits; 1 KB = 1024 bytes; 1 MB = 1024 KB; 1 GB = 1024 MB; 1 TB = 1024 GB.
The hexadecimal equivalent of (273)₈ is
(b) BB Go through binary: 273 = 010 111 011; regroup in 4 bits from the right: 1011 = B, 1011 = B.
The smallest unit of data in a computer is
(d) bit A bit (binary digit) is a single 0 or 1, the smallest unit; 8 bits make a byte.
The hexadecimal equivalent of (56)₈ is
(c) 2E Go through binary: 56 = 101 110; regroup in 4 bits from the right: 0010 = 2, 1110 = E.
One binary digit is called a
(d) bit bit is short for binary digit: it is either 0 or 1.
What is the value of (A OR B) AND (NOT C) when A = 0, B = 0, C = 0?
(a) 0 Work out NOT first, then AND, then OR.
Which of these is NOT a function of an operating system?
(d) Writing letters for the user The OS manages processes, memory, files, devices and security; writing letters is the job of application software such as a word processor.
How many bits are there in 5 nibbles?
(a) 20 1 byte = 8 bits; 1 KB = 1024 bytes; 1 MB = 1024 KB; 1 GB = 1024 MB; 1 TB = 1024 GB.
The place value of the leftmost 1 in (1000)₂ is
(d) 8 Place values in binary are 8 4 2 1 from the left for 4 digits, so the leftmost 1 is worth 2³ = 8.
The octal equivalent of (201)₁₀ is
(b) 311 Divide by 8 again and again and read the remainders from bottom to top: 201 ÷ 8 = 25 r 1; 25 ÷ 8 = 3 r 1; 3 ÷ 8 = 0 r 3.
The ASCII code of 'a' is 97. What is the ASCII code of 'r'?
(b) 114 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
The binary equivalent of (5B)₁₆ is
(b) 1011011 Write each hexadecimal digit as 4 bits: 5 = 0101, B = 1011.
The hexadecimal equivalent of (204)₁₀ is
(a) CC Divide by 16 again and again and read the remainders from bottom to top: 204 ÷ 16 = 12 r C; 12 ÷ 16 = 0 r C.
The octal equivalent of (27)₁₆ is
(c) 47 Go through binary: 27 = 0010 0111; regroup in 3 bits from the right: 100 = 4, 111 = 7.
The hexadecimal equivalent of (167)₈ is
(b) 77 Go through binary: 167 = 001 110 111; regroup in 4 bits from the right: 0111 = 7, 0111 = 7.
The binary equivalent of (135)₈ is
(a) 1011101 Write each octal digit as 3 bits: 1 = 001, 3 = 011, 5 = 101.
The decimal equivalent of (105)₈ is
(a) 69 Multiply each digit by its place value (powers of 8) and add: 1×8^2 + 0×8^1 + 5×8^0 = 69.
State True or False: An interpreter translates and runs a program one line at a time.
(a) True An interpreter takes one line, translates it and runs it, then moves to the next line.
The octal equivalent of (57)₁₆ is
(c) 127 Go through binary: 57 = 0101 0111; regroup in 3 bits from the right: 001 = 1, 010 = 2, 111 = 7.
The ASCII code of 'A' is 65. What is the ASCII code of 'H'?
(b) 72 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
The output of a NOR gate is 1 when
(b) all inputs are 0 NOR = NOT OR. OR gives 0 only when all inputs are 0, so NOR gives 1 only then.
Antivirus, disk cleanup and file compression tools are examples of
(a) utility software Utility software keeps the computer healthy and safe; it is a kind of system software.
The octal equivalent of (78)₁₆ is
(c) 170 Go through binary: 78 = 0111 1000; regroup in 3 bits from the right: 001 = 1, 111 = 7, 000 = 0.
Which bus carries the address of the memory location?
(c) Address bus The address bus carries the address of the memory location; the data bus carries the data and the control bus carries signals.
The hexadecimal equivalent of (214)₈ is
(c) 8C Go through binary: 214 = 010 001 100; regroup in 4 bits from the right: 1000 = 8, 1100 = C.
The binary equivalent of (27)₁₀ is
(a) 11011 Divide by 2 again and again and read the remainders from bottom to top: 27 ÷ 2 = 13 r 1; 13 ÷ 2 = 6 r 1; 6 ÷ 2 = 3 r 0; 3 ÷ 2 = 1 r 1; 1 ÷ 2 = 0 r 1.
By De Morgan's law, NOT (A OR B) equals
(c) (NOT A) AND (NOT B) De Morgan: NOT (A OR B) = (NOT A) AND (NOT B). Check with A = 0, B = 0: left side NOT 0 = 1, right side 1 AND 1 = 1.
ISCII is an encoding scheme made for
(b) Indian scripts ISCII (Indian Script Code for Information Interchange) was made for Indian scripts such as Devanagari.
Which device works as both input and output?
(b) Touch screen A touch screen shows output and also takes our touch as input.
The binary equivalent of (40)₈ is
(c) 100000 Write each octal digit as 3 bits: 4 = 100, 0 = 000.
State True or False: The output of NAND is the opposite (NOT) of the output of AND.
(a) True NAND = NOT AND, so its output is always the opposite of AND for the same inputs.
What is the value of A AND (NOT B) when A = 0, B = 1?
(a) 0 Work out NOT first, then AND, then OR.
The octal equivalent of (6D)₁₆ is
(b) 155 Go through binary: 6D = 0110 1101; regroup in 3 bits from the right: 001 = 1, 101 = 5, 101 = 5.
The ASCII code of 'A' is 65. What is the ASCII code of 'E'?
(c) 69 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
How many bits are there in 6 nibbles?
(a) 24 1 byte = 8 bits; 1 KB = 1024 bytes; 1 MB = 1024 KB; 1 GB = 1024 MB; 1 TB = 1024 GB.
What is the value of A AND B AND NOT C when A = 0, B = 0, C = 0?
(a) 0 Work out NOT first, then AND, then OR.
How many MB are there in 5 GBs?
(b) 5120 1 byte = 8 bits; 1 KB = 1024 bytes; 1 MB = 1024 KB; 1 GB = 1024 MB; 1 TB = 1024 GB.
The binary equivalent of (CF)₁₆ is
(a) 11001111 Write each hexadecimal digit as 4 bits: C = 1100, F = 1111.
UTF-8 uses
(b) 1 to 4 bytes for a character UTF-8 is variable length: 1 byte for English characters, up to 4 bytes for other scripts and symbols.
The ASCII code of 'A' is 65. What is the ASCII code of 'K'?
(a) 75 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
The decimal equivalent of (E5)₁₆ is
(c) 229 Multiply each digit by its place value (powers of 16) and add: E×16^1 + 5×16^0 = 229.
What is the value of A XOR B when A = 1, B = 1?
(a) 0 Work out NOT first, then AND, then OR.
The ASCII code of 'A' is 65. What is the ASCII code of 'P'?
(d) 80 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
How many bytes are there in 3 KBs?
(d) 3072 1 byte = 8 bits; 1 KB = 1024 bytes; 1 MB = 1024 KB; 1 GB = 1024 MB; 1 TB = 1024 GB.
The hexadecimal equivalent of (11110011)₂ is
(c) F3 Make groups of 4 bits from the right and write each group as one hexadecimal digit: 1111 = F, 0011 = 3.
The ASCII code of 'a' is 97. What is the ASCII code of 'h'?
(a) 104 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
Which memory sits between the CPU and RAM to speed up processing?
(d) Cache memory Cache keeps the data the CPU uses most often, so the CPU need not wait for slower RAM.
The ASCII code of 'A' is 65. What is the ASCII code of 'C'?
(b) 67 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
The binary equivalent of (228)₁₀ is
(a) 11100100 Divide by 2 again and again and read the remainders from bottom to top: 228 ÷ 2 = 114 r 0; 114 ÷ 2 = 57 r 0; 57 ÷ 2 = 28 r 1; 28 ÷ 2 = 14 r 0; 14 ÷ 2 = 7 r 0; 7 ÷ 2 = 3 r 1 ….
The ASCII code of 'A' is 65. What is the ASCII code of 'G'?
(d) 71 Letters and digits have codes in order: 'A' = 65, 'a' = 97, '0' = 48.
The hexadecimal equivalent of (176)₈ is
(c) 7E Go through binary: 176 = 001 111 110; regroup in 4 bits from the right: 0111 = 7, 1110 = E.
Which encoding can represent characters of almost all the languages of the world?
(a) Unicode Unicode gives a unique code to the characters of almost every script, including Hindi, Tamil and Chinese.
Choosing one of two paths depending on a condition is called
(d) selection Selection (if ... else) picks one path according to a condition; sequence and iteration are the other two.
What does 'abc' * 0 give?
(d) an empty string '' Repeating a string 0 times gives the empty string ''.
Which statement skips the rest of the current loop round and goes to the next round?
(d) continue continue jumps to the next round of the loop.
math.floor(-4.1) gives
(b) -5 floor() gives the largest whole number not greater than the value; for -4.1 that is -5 (it moves down the number line).
Which method adds one element at the end of a list?
(d) append() L.append(5) adds 5 as the last element.
A list can contain
(b) elements of different types A list can hold any mix of types, e.g. [1, 'KV', 2.5, True].
What is the length of [1, [2, 3], 4]?
(d) 3 The inner list counts as one element: 1, [2, 3], 4.
Which statement does nothing and is used as a placeholder?
(b) pass pass is used where a statement is needed but nothing is to be done.
Which function gives the memory address (identity) of an object?
(b) id() id(x) gives the identity of the object x.
Which operator checks whether two names refer to the same object?
(a) is is checks identity (same object); == checks equal values.
A program runs but gives the wrong answer because of a wrong formula. This is a
(a) logical error A logical error gives no error message; the program runs but the result is wrong.
Which method removes an element by index and returns it?
(c) pop() L.pop(2) removes and returns the element at index 2.
The smallest individual unit of a Python program is a
(d) token Tokens: keywords, identifiers, literals, operators and punctuators.
list('KV') gives
(c) ['K', 'V'] list() makes one element from each character.
The default value of end in print() is
(b) a new line (\n) After printing, print() goes to a new line unless end is changed.
Which method checks if every character of a string is a digit?
(a) isdigit() '2026'.isdigit() is True; '20a6'.isdigit() is False.
Which of these is a valid identifier?
(c) total_marks It has letters and an underscore; it does not start with a digit, has no hyphen and is not a keyword.
Which function returns the median of a list?
(b) statistics.median() statistics.median([3, 1, 2]) sorts the values and gives the middle one: 2.
Accessing a key that is not in the dictionary with d[key] gives
(a) KeyError D['x'] for a missing key gives KeyError.
Which of these is immutable?
(b) tuple A tuple cannot be changed after it is made; lists, dictionaries and sets can be changed.
Which flowchart symbol is used for input and output?
(c) Parallelogram The parallelogram is used for input (read N) and output (print).
random.random() returns a float
(a) from 0.0 up to, but not including, 1.0 random.random() gives a float from 0.0 up to but not including 1.0, e.g. 0.3721.
Which of these is a valid string literal?
(b) '''KV''' Triple quotes ''' ... ''' (or """ ... """) make a valid string, which can also go over many lines.
Which data type is mutable?
(b) list A list can be changed in place (append, remove, L[0] = 5); strings and tuples cannot.
Which operator gives the remainder?
(d) % 17 % 5 gives 2, the remainder.
random.choice([3, 6, 9]) returns
(d) any one element of the list choice() picks any one element of the sequence at random.
s.partition('-') returns
(b) a tuple of three parts partition() splits at the first '-' and returns a tuple (before, '-', after); e.g. 'a-b-c'.partition('-') = ('a', '-', 'b-c').
The value None belongs to the data type
(d) NoneType None is the only value of the NoneType type.
Which method removes all the elements of a list?
(b) clear() L.clear() leaves an empty list [].
Which method adds all the elements of another list at the end?
(b) extend() L.extend([4, 5]) adds 4 and 5 one by one.
Which of these is a membership operator?
(a) in in checks whether a value is present: 3 in [1, 3] is True.
Which of these is a keyword in Python?
(b) elif sum, print and input are built-in functions, not keywords.
input() always returns a value of type
(c) str input() returns a string; use int() or float() to get a number.
Strings in Python are
(b) immutable Strings cannot be changed in place: s[0] = 'P' gives TypeError. Methods return new strings.
A comment in Python starts with
(a) # Everything after # on a line is ignored by Python.
Which statement deletes the elements from index 1 to 2 of L?
(b) del L[1:3] del L[1:3] deletes index 1 and 2 (the stop index 3 is not included).
The value of 5 > 3 and 3 > 1 is
(c) True Both conditions are True, so and gives True.
An error in the grammar of the code, such as a missing colon, is a
(c) syntax error Wrong grammar (syntax) is caught before the program runs.
Which method removes the first occurrence of a given value?
(a) remove() L.remove(10) deletes the first 10 in the list.
Finding and removing errors from a program is called
(a) debugging Debugging means finding and correcting errors (bugs).
The default separator (sep) in print() is
(d) a space print(1, 2) prints 1 2 with a space between.
Which statement ends the loop at once?
(a) break break stops the loop immediately.
Which method breaks a string into a list of words?
(b) split() 'I love KV'.split() gives ['I', 'love', 'KV'].
A step-by-step, finite set of instructions to solve a problem is
(d) an algorithm An algorithm is a finite list of clear steps that solves a problem.
d.update(e)
(b) adds the pairs of e to d, changing the values of common keys New keys are added and the values of existing keys are replaced.
State True or False: In Python, a variable must be declared with its type before use.
(b) False Python finds the type from the value given.
Breaking a complex problem into smaller sub-problems is called
(a) decomposition Decomposition breaks a big problem into small parts that are easier to solve.
The else part of a loop runs when
(d) the loop ends normally, without break The loop's else runs only if the loop was not stopped by break.
Which method removes spaces from both ends of a string?
(d) strip() ' KV '.strip() gives 'KV'; lstrip() and rstrip() remove from one side only.
Python program files are saved with the extension
(a) .py Python scripts are saved as name.py.
Which of these converts 65 into 'A'?
(b) chr(65) chr() gives the character of a code: chr(65) = 'A'; ord('A') = 65.
Which statement is used to write an empty if block?
(d) pass An empty block gives an error, so pass is written inside it.
Converting the type of a value by a function such as int() or float() is called
(c) explicit type conversion The programmer converts it on purpose, so it is explicit conversion.
Searching a list element by element from the start is called
(a) linear search Checking every element one after another is linear search.
Which method returns the value of a key, and None if the key is not present?
(d) get() D.get('x') returns None instead of giving KeyError.
A loop that never ends is called
(c) an infinite loop If the condition never becomes False, the loop runs for ever.
The output of print(10, 20, sep='-') is
(c) 10-20 sep='-' puts - between the values instead of a space.
Python marks a block of statements by
(a) indentation Python uses indentation (usually 4 spaces) to show which statements belong to a block.
The keys of a dictionary must be
(a) immutable and unique Keys must be immutable (numbers, strings, tuples) and unique; values can be anything.
Joining two strings with + is called
(c) concatenation 'KV' + 'S' = 'KVS': joining strings is concatenation.
Which of these is NOT a token?
(b) comment Comments are ignored by Python.
L.sort() and sorted(L) differ because
(a) sort() changes L, sorted() returns a new list L.sort() sorts the same list and returns None; sorted(L) makes a new sorted list and L stays the same.
State True or False: Dictionary keys can be repeated.
(b) False A new value for an existing key replaces the old value.
What is the result of 9 % 4 ** 2?
(c) 9 4 ** 2 = 16 first; 9 % 16 = 9.
'Hi' * 3 is an example of
(d) replication * repeats a string: 'Hi' * 3 = 'HiHiHi'. This is replication.
Which method returns all the key-value pairs of a dictionary?
(d) items() D.items() gives (key, value) pairs.
State True or False: math.sqrt(16) returns 4.0, a float.
(a) True math.sqrt() always returns a float, so sqrt(16) is 4.0.
Which method returns the position of a substring, and -1 if it is not found?
(b) find() 'KVS'.find('V') = 1 and 'KVS'.find('Z') = -1; index() would give an error instead.
bool(0) and bool('') give
(d) False and False 0 and the empty string are treated as False.
Which flowchart symbol shows a decision?
(c) Diamond The diamond holds a condition and has two exits, Yes and No.
Packing values into a tuple and taking them out into variables is called
(d) packing and unpacking T = 1, 2, 3 packs the values; a, b, c = T unpacks them.
s[-1] gives
(d) the last character of s Negative indexes count from the end: s[-1] is the last character.
index() is different from find() because index()
(c) gives an error when the substring is not found Both give the position, but index() raises ValueError when the substring is missing, while find() returns -1.
math.ceil(4.1) gives
(d) 5 ceil() gives the smallest whole number not less than the value, so 4.1 becomes 5.
Python is case sensitive. So Total and total are
(d) two different names Capital and small letters are different in Python names, so Total and total are two variables.
The value of math.pi to two decimal places is
(c) 3.14 math.pi = 3.141592653589793, which is 3.14 to two decimal places.
Which function converts the string '25' into the integer 25?
(b) int() int('25') gives 25; float('25') would give 25.0.
In Python, complex numbers are written as
(d) 3 + 4j Python uses j for the imaginary part: 3 + 4j.
Which module has the functions mean, median and mode?
(a) statistics import statistics, then statistics.mean(), statistics.median() and statistics.mode().
Which of these names is NOT valid?
(c) my-name A hyphen is not allowed in a name; Python reads it as minus.
The first step of problem solving is to
(b) analyse and understand the problem First understand the problem: what is given, what is wanted and any conditions; only then design the algorithm.
Checking an algorithm by working it out on paper with sample values is called
(b) dry run In a dry run we follow the steps by hand with sample values to check the result.
A tuple with one element is written as
(a) (5,) The comma makes it a tuple: (5,) is a tuple, but (5) is just the number 5.
State True or False: The = operator compares two values.
(b) False = assigns; == compares.
Which method makes a dictionary from a list of keys, with the same value for every key?
(c) dict.fromkeys() dict.fromkeys(['a', 'b'], 0) gives {'a': 0, 'b': 0}.
In 5 + 2.0, Python converts 5 to a float on its own. This is
(c) implicit type conversion Python converts it automatically, so it is implicit conversion.
tuple([1, 2]) gives
(a) (1, 2) tuple() converts the list into a tuple: (1, 2).
Repeating a set of steps again and again in an algorithm is called
(c) iteration Iteration means repetition, done with loops such as for and while.
Which operator is used for exponent (power)?
(a) ** 2 ** 3 gives 8; ^ is not power in Python.
A rectangle in a flowchart shows
(b) a process The rectangle is the process box, used for calculations such as sum = a + b.
Which of these is NOT allowed on a tuple?
(b) T.append(5) Tuples are immutable, so they have no append(); count(), index() and slicing are allowed.
range(5) gives the numbers
(c) 0, 1, 2, 3, 4 range(5) starts at 0 and stops before 5.
len({'a': 1, 'b': 2}) is
(c) 2 There are two key-value pairs.
Dividing a number by zero while the program runs gives a
(c) runtime error (ZeroDivisionError) The program starts but stops with ZeroDivisionError while running.
How many times does 'for i in range(3, 15, 4)' run?
(b) 3 i takes 3, 7 and 11.
An algorithm must end after a finite number of steps. This property is called
(d) finiteness Finiteness: an algorithm must stop after a fixed number of steps; an endless process is not an algorithm.
Which mode of Python runs one statement at a time with the >>> prompt?
(b) Interactive mode Interactive mode shows the >>> prompt and gives the result of each statement at once.
Python is a
(b) high-level, interpreted language Python is close to English (high level) and is run by an interpreter.
A while loop is called
(b) entry-controlled The condition is checked before each round (at the entry).
State True or False: L[1] = 10 is allowed on a list L of 3 elements.
(a) True Lists are mutable and index 1 exists in a 3-element list.
Which statement imports only the sqrt function from math?
(d) from math import sqrt from math import sqrt brings in only sqrt, which can then be used without writing math.
Writing the steps of an algorithm in simple English-like statements is called
(a) pseudocode Pseudocode is written like a program but in simple English, without the strict rules of a language.
State True or False: A while loop may not run even once.
(a) True If the condition is False at the start, the body is skipped.
Which loop is best when the number of repetitions is known?
(c) for for i in range(n) runs exactly n times.
'Hello'.replace('l', 'L', 1) gives
(a) 'HeLlo' The third argument 1 means replace only the first 'l', so 'Hello' becomes 'HeLlo'.
A loop inside another loop is called
(c) a nested loop The inner loop runs fully for every round of the outer loop.
random.randint(1, 6) can return
(a) 1, 2, 3, 4, 5 or 6 randint(a, b) includes both ends, so any of 1, 2, 3, 4, 5, 6 can come.
State True or False: s.upper() changes the string s itself.
(b) False Strings are immutable; upper() returns a new string.
The oval (terminal) symbol in a flowchart shows
(d) start or stop The oval marks where the flowchart starts and stops.
Which of these can be a dictionary key?
(a) (1, 2) A key must be immutable: numbers, strings and tuples can be keys; lists and dictionaries cannot.
The index of the first character of a string is
(a) 0 Indexing starts from 0, so s[0] is the first character.
What is the output of the following code?
print(17 + 5 * 4 // 2)
(b) 27 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(20 / 4, 20 // 4, 20 % 4)
(a) 5.0 5 0 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(-23 // 4, -23 % 4)
(b) -6 1 // rounds down towards minus infinity, so -23 // 4 is -6; the remainder takes the sign of the divisor.
What is the output of the following code?
print(0 or 5)
(c) 5 not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
print(type(float(7)))
(a) <class 'float'> The type of the result decides the class.
What is the output of the following code?
for i in range(0, 5, 1):
print(i, end=" ")(a) 0 1 2 3 4 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(0, -11, -2):
print(i, end=" ")(b) 0 -2 -4 -6 -8 -10 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
n = 49
count = 0
while n > 7:
n = n - 4
count += 1
print(count, n)(a) 11 5 Trace the loop: the condition is checked before every round.
What is the output of the following code?
for i in range(4, 13):
if i % 3 == 0:
continue
print(i, end=" ")(a) 4 5 7 8 10 11 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
x = 9 x *= 2 + 3 print(x)
(a) 45 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
print(float('9') * 2)(d) 18.0 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
marks = 78
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(d) A Only the first true condition of an if-elif chain runs.
What is the output of the following code?
c = 0
for i in range(1, 6):
for j in range(i):
c += j
print(c)(c) 20 The inner loop runs fully for every round of the outer loop.
What is the output of the following code?
print(14 - 5 // 2 ** 3)
(c) 14 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(7 + 5 * 3 % 3)
(d) 7 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(34 / 6, 34 // 6, 34 % 6)
(d) 5.666666666666667 5 4 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(not 1)
(b) False not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
print(type((7)))
(b) <class 'int'> The type of the result decides the class.
What is the output of the following code?
for i in range(0, 4, 1):
print(i, end=" ")(d) 0 1 2 3 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(5, 12, 1):
print(i, end=" ")(b) 5 6 7 8 9 10 11 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
n = 27
count = 0
while n > 6:
n = n - 9
count += 1
print(count, n)(a) 3 0 Trace the loop: the condition is checked before every round.
What is the output of the following code?
for i in range(1, 16):
if i % 3 == 0:
continue
print(i, end=" ")(c) 1 2 4 5 7 8 10 11 13 14 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
x = 3 x -= 2 x **= 2 print(x)
(c) 1 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
print(str(3) * 2)
(d) 33 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
marks = 49
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(b) C Only the first true condition of an if-elif chain runs.
What is the output of the following code?
c = 0
for i in range(4):
for j in range(4):
c += 1
print(c)(d) 16 The inner loop runs fully for every round of the outer loop.
What is the output of the following code?
print(23 - 5 // 3 ** 2)
(d) 23 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(7 + 6 // 5 * 3)
(d) 10 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(22 / 6, 22 // 6, 22 % 6)
(a) 3.6666666666666665 3 4 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(-21 // 6, -21 % 6)
(d) -4 3 // rounds down towards minus infinity, so -21 // 6 is -4; the remainder takes the sign of the divisor.
What is the output of the following code?
for i in range(2, 9, 2):
print(i, end=" ")(b) 2 4 6 8 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
n = 54
count = 0
while n > 7:
n = n - 6
count += 1
print(count, n)(b) 8 6 Trace the loop: the condition is checked before every round.
What is the output of the following code?
for i in range(2, 12):
if i % 6 == 0:
break
print(i, end=" ")(a) 2 3 4 5 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
x = 8 x -= 2 x **= 2 print(x)
(a) 36 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
print(str(8) * 2)
(d) 88 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
marks = 4
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(a) Fail Only the first true condition of an if-elif chain runs.
What is the output of the following code?
c = 0
for i in range(1, 5):
for j in range(i):
c += j
print(c)(a) 10 The inner loop runs fully for every round of the outer loop.
What is the output of the following code?
print(8 + 2 * 2 % 4)
(c) 8 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(22 + 6 * 4 ** 2)
(d) 118 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(-19 // 6, -19 % 6)
(a) -4 5 // rounds down towards minus infinity, so -19 // 6 is -4; the remainder takes the sign of the divisor.
What is the output of the following code?
print(7 > 5 and 12 < 10 or not 0)
(d) True not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
print(type('3' + '4'))(d) <class 'str'> The type of the result decides the class.
What is the output of the following code?
for i in range(2, 7, 2):
print(i, end=" ")(c) 2 4 6 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(1, -11, -2):
print(i, end=" ")(a) 1 -1 -3 -5 -7 -9 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
n = 35
count = 0
while n > 6:
n = n - 5
count += 1
print(count, n)(c) 6 5 Trace the loop: the condition is checked before every round.
What is the output of the following code?
for i in range(3, 12):
if i % 6 == 0:
break
print(i, end=" ")(c) 3 4 5 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
a = 4 b = a * 2 a = b - a b //= 3 print(a, b)
(d) 4 2 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
marks = 55
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(b) C Only the first true condition of an if-elif chain runs.
What is the output of the following code?
print(20 - 4 % 3 % 3)
(d) 19 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(27 - 6 * 2 ** 2)
(b) 3 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(42 / 3, 42 // 3, 42 % 3)
(c) 14.0 14 0 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(-19 // 5, -19 % 5)
(a) -4 1 // rounds down towards minus infinity, so -19 // 5 is -4; the remainder takes the sign of the divisor.
What is the output of the following code?
print(not 5 > 3 or 5 == 3 and 0)
(a) False not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
print(type(7 / 2))
(b) <class 'float'> The type of the result decides the class.
What is the output of the following code?
for i in range(5, -7, -2):
print(i, end=" ")(c) 5 3 1 -1 -3 -5 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(3, -8, -2):
print(i, end=" ")(b) 3 1 -1 -3 -5 -7 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
n = 38
count = 0
while n > 1:
n = n - 9
count += 1
print(count, n)(d) 5 -7 Trace the loop: the condition is checked before every round.
What is the output of the following code?
x = 10 x *= 2 + 3 print(x)
(b) 50 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
print(str(9) * 2)
(a) 99 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
marks = 7
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(c) Fail Only the first true condition of an if-elif chain runs.
What is the output of the following code?
print(16 - 6 % 4 * 3)
(a) 10 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(10 - 2 // 3 % 3)
(d) 10 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(56 / 9, 56 // 9, 56 % 9)
(d) 6.222222222222222 6 2 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
for i in range(1, 13, 2):
print(i, end=" ")(c) 1 3 5 7 9 11 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(6, 10, 2):
print(i, end=" ")(a) 6 8 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
n = 39
count = 0
while n > 7:
n = n - 4
count += 1
print(count, n)(a) 8 7 Trace the loop: the condition is checked before every round.
What is the output of the following code?
for i in range(3, 10):
if i % 2 == 0:
continue
print(i, end=" ")(c) 3 5 7 9 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
print(int(8.5), round(8.5))
(a) 8 8 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
marks = 12
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(c) Fail Only the first true condition of an if-elif chain runs.
What is the output of the following code?
print(13 + 6 * 2 ** 2)
(a) 37 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(28 - 5 // 2 % 2)
(b) 28 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(28 / 3, 28 // 3, 28 % 3)
(c) 9.333333333333334 9 1 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(-22 // 4, -22 % 4)
(d) -6 2 // rounds down towards minus infinity, so -22 // 4 is -6; the remainder takes the sign of the divisor.
What is the output of the following code?
print(6 and 9)
(a) 9 not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
print(type(7 // 2))
(b) <class 'int'> The type of the result decides the class.
What is the output of the following code?
for i in range(6, 12, 1):
print(i, end=" ")(a) 6 7 8 9 10 11 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(2, -10, -2):
print(i, end=" ")(a) 2 0 -2 -4 -6 -8 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
n = 43
count = 0
while n > 1:
n = n - 3
count += 1
print(count, n)(d) 14 1 Trace the loop: the condition is checked before every round.
What is the output of the following code?
for i in range(2, 13):
if i % 8 == 0:
break
print(i, end=" ")(a) 2 3 4 5 6 7 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
a = 9 b = 8 a += b b = a - b a = a - b print(a, b)
(c) 8 9 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
print(float('2') * 2)(d) 4.0 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
marks = 14
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(d) Fail Only the first true condition of an if-elif chain runs.
What is the output of the following code?
c = 0
for i in range(2):
for j in range(4):
c += 1
print(c)(b) 8 The inner loop runs fully for every round of the outer loop.
What is the output of the following code?
print(13 - 3 // 3 % 4)
(c) 12 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(26 + 2 * 5 * 4)
(c) 66 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(57 / 9, 57 // 9, 57 % 9)
(c) 6.333333333333333 6 3 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(not 0)
(a) True not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
print(type('7' * 2))(a) <class 'str'> The type of the result decides the class.
What is the output of the following code?
for i in range(1, 7, 3):
print(i, end=" ")(b) 1 4 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(1, -8, -2):
print(i, end=" ")(d) 1 -1 -3 -5 -7 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
n = 34
count = 0
while n > 7:
n = n - 6
count += 1
print(count, n)(d) 5 4 Trace the loop: the condition is checked before every round.
What is the output of the following code?
for i in range(1, 14):
if i % 3 == 0:
continue
print(i, end=" ")(d) 1 2 4 5 7 8 10 11 13 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
a, b = 8, 10 a, b = b, a + b print(a, b)
(c) 10 18 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
print(float('8') * 2)(d) 16.0 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
marks = 42
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(a) C Only the first true condition of an if-elif chain runs.
What is the output of the following code?
c = 0
for i in range(2):
for j in range(3):
c += 1
print(c)(d) 6 The inner loop runs fully for every round of the outer loop.
What is the output of the following code?
print(24 - 5 // 5 % 2)
(b) 23 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(30 + 4 // 2 ** 2)
(d) 31 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(20 / 8, 20 // 8, 20 % 8)
(b) 2.5 2 4 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(type(2 ** -1))
(b) <class 'float'> The type of the result decides the class.
What is the output of the following code?
for i in range(1, -6, -2):
print(i, end=" ")(c) 1 -1 -3 -5 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(0, 12, 3):
print(i, end=" ")(d) 0 3 6 9 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
n = 34
count = 0
while n > 2:
n = n - 9
count += 1
print(count, n)(c) 4 -2 Trace the loop: the condition is checked before every round.
What is the output of the following code?
for i in range(2, 14):
if i % 3 == 0:
continue
print(i, end=" ")(d) 2 4 5 7 8 10 11 13 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
a = 10 b = 8 a += b b = a - b a = a - b print(a, b)
(c) 8 10 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
print(21 + 4 * 3 * 2)
(a) 45 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(27 - 3 % 4 ** 3)
(b) 24 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(47 / 7, 47 // 7, 47 % 7)
(c) 6.714285714285714 6 5 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(-14 // 4, -14 % 4)
(d) -4 2 // rounds down towards minus infinity, so -14 // 4 is -4; the remainder takes the sign of the divisor.
What is the output of the following code?
print(9 < 6 < 15)
(a) False not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
print(type(7 % 2 == 1))
(c) <class 'bool'> The type of the result decides the class.
What is the output of the following code?
for i in range(0, -8, -1):
print(i, end=" ")(a) 0 -1 -2 -3 -4 -5 -6 -7 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(5, 12, 3):
print(i, end=" ")(d) 5 8 11 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
n = 47
count = 0
while n > 3:
n = n - 9
count += 1
print(count, n)(c) 5 2 Trace the loop: the condition is checked before every round.
What is the output of the following code?
for i in range(3, 15):
if i % 7 == 0:
break
print(i, end=" ")(d) 3 4 5 6 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
a = 2 b = 5 a += b b = a - b a = a - b print(a, b)
(a) 5 2 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
print(int('7') + 7, '7' + '7')(c) 14 77 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
What is the output of the following code?
marks = 81
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(a) A Only the first true condition of an if-elif chain runs.
What is the output of the following code?
print(7 + 3 % 3 // 4)
(b) 7 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(8 - 3 % 5 * 2)
(a) 2 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(16 / 5, 16 // 5, 16 % 5)
(d) 3.2 3 1 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(-13 // 6, -13 % 6)
(d) -3 5 // rounds down towards minus infinity, so -13 // 6 is -3; the remainder takes the sign of the divisor.
What is the output of the following code?
print(0 or 9)
(a) 9 not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
for i in range(1, 11, 2):
print(i, end=" ")(a) 1 3 5 7 9 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(2, 12, 2):
print(i, end=" ")(c) 2 4 6 8 10 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
n = 25
count = 0
while n > 6:
n = n - 3
count += 1
print(count, n)(c) 7 4 Trace the loop: the condition is checked before every round.
What is the output of the following code?
for i in range(3, 15):
if i % 6 == 0:
break
print(i, end=" ")(d) 3 4 5 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
x = 6 x -= 2 x **= 2 print(x)
(c) 16 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
marks = 15
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(d) Fail Only the first true condition of an if-elif chain runs.
What is the output of the following code?
print(30 + 5 * 4 // 4)
(a) 35 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(20 + 5 % 2 * 3)
(a) 23 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(29 / 8, 29 // 8, 29 % 8)
(a) 3.625 3 5 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
print(-25 // 4, -25 % 4)
(d) -7 3 // rounds down towards minus infinity, so -25 // 4 is -7; the remainder takes the sign of the divisor.
What is the output of the following code?
print(9 and 8)
(a) 8 not is applied first, then and, then or. and/or return one of the operands.
What is the output of the following code?
print(type(2 ** 3))
(d) <class 'int'> The type of the result decides the class.
What is the output of the following code?
for i in range(6, -6, -1):
print(i, end=" ")(d) 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(1, -6, -1):
print(i, end=" ")(a) 1 0 -1 -2 -3 -4 -5 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
n = 52
count = 0
while n > 4:
n = n - 9
count += 1
print(count, n)(b) 6 -2 Trace the loop: the condition is checked before every round.
What is the output of the following code?
for i in range(3, 12):
if i % 2 == 0:
continue
print(i, end=" ")(a) 3 5 7 9 11 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
a = 7 b = 6 a += b b = a - b a = a - b print(a, b)
(c) 6 7 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
marks = 74
if marks >= 75:
print("A")
elif marks >= 60:
print("B")
elif marks >= 33:
print("C")
else:
print("Fail")(c) B Only the first true condition of an if-elif chain runs.
What is the output of the following code?
print(8 + 6 % 3 % 3)
(c) 8 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(13 + 5 % 5 ** 2)
(c) 18 Python applies ** first, then *, /, //, % from left to right, then + and -.
What is the output of the following code?
print(32 / 3, 32 // 3, 32 % 3)
(b) 10.666666666666666 10 2 / always gives a float; // gives the quotient rounded down; % gives the remainder.
What is the output of the following code?
for i in range(1, 13, 1):
print(i, end=" ")(c) 1 2 3 4 5 6 7 8 9 10 11 12 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
for i in range(6, -2, -1):
print(i, end=" ")(a) 6 5 4 3 2 1 0 -1 range(start, stop, step) starts at start and stops before stop.
What is the output of the following code?
n = 36
count = 0
while n > 5:
n = n - 5
count += 1
print(count, n)(b) 7 1 Trace the loop: the condition is checked before every round.
What is the output of the following code?
for i in range(2, 12):
if i % 8 == 0:
break
print(i, end=" ")(b) 2 3 4 5 6 7 break leaves the loop; continue skips only the rest of that round.
What is the output of the following code?
a, b = 9, 6 a, b = b, a + b print(a, b)
(b) 6 15 In a, b = b, a + b the right side is worked out first, with the old values.
What is the output of the following code?
print(int(7.5), round(7.5))
(b) 7 8 round() rounds a .5 value to the nearest even number; int() cuts off the decimal part.
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randrange(3, 8), end=" ")(c) 3 7 6 random.randrange(3, 8) gives a whole number from 3 to 7 (the stop value 8 is left out).
What is the output of the following code?
s = "INFORMATION" print(s.isupper())
(c) True See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "INFORMATION" | s = 'INFORMATION' | |
| 2 | print(s.isupper()) | True⏎ |
What is the output of the following code?
s = "NOTEBOOK" print(s[:-4:-1])
(c) KOO A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
s = "Delhi-88"
print(s.split("i"))(c) ['Delh', '-88'] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Delhi-88" | s = 'Delhi-88' | |
| 2 | print(s.split("i")) | ['Delh', '-88']⏎ |
What is the output of the following code?
s = "Vidyalaya"
print(s.count("O"))(c) 0 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Vidyalaya" | s = 'Vidyalaya' | |
| 2 | print(s.count("O")) | 0⏎ |
What is the output of the following code?
import statistics data = [5, 3, 6, 3, 4, 3, 3] print(statistics.median(data))
(c) 3 mean is the average, median is the middle value after sorting, mode is the most common value.
What is the output of the following code?
L = [6, 7, 37, 29] L.insert(0, 44) print(L)
(a) [44, 6, 7, 37, 29] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [6, 7, 37, 29] | L = [6, 7, 37, 29] | |
| 2 | L.insert(0, 44) | L = [44, 6, 7, 37, 29] | |
| 3 | print(L) | [44, 6, 7, 37, 29]⏎ |
What is the output of the following code?
L = [38, 33, 27, 32] print(sum(L) // len(L))
(a) 32 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [38, 33, 27, 32] | L = [38, 33, 27, 32] | |
| 2 | print(sum(L) // len(L)) | 32⏎ |
What is the output of the following code?
s = "KV Shalimar Bagh"
print(s.count("o"))(b) 0 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "KV Shalimar Bagh" | s = 'KV Shalimar Bagh' | |
| 2 | print(s.count("o")) | 0⏎ |
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randint(2, 5), end=" ")(c) 5 2 4 random.randint(2, 5) gives a whole number from 2 to 5.
What is the output of the following code?
s = "Learning" print(s[0:-5])
(d) Lea A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
import math print(math.gcd(18, 12))
(c) 6 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | print(math.gcd(18, 12)) | 6⏎ |
What is the output of the following code?
import math print(math.fabs(25))
(c) 25.0 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | print(math.fabs(25)) | 25.0⏎ |
What is the output of the following code?
L = [18, 33, 28, 16, 25] L.extend([57, 58]) print(L)
(b) [18, 33, 28, 16, 25, 57, 58] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [18, 33, 28, 16, 25] | L = [18, 33, 28, 16, 25] | |
| 2 | L.extend([57, 58]) | L = [18, 33, 28, 16, 25, 57, 58] | |
| 3 | print(L) | [18, 33, 28, 16, 25, 57, 58]⏎ |
What is the output of the following code?
T = (25, 28, 1, 22, 5) print(T[1:4])
(d) (28, 1, 22) A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
s = "COMPUTER" print(s[-8:-4])
(c) COMP A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
s = "NOTEBOOK"
print(s.replace("n", "#"))(b) NOTEBOOK See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "NOTEBOOK" | s = 'NOTEBOOK' | |
| 2 | print(s.replace("n", "#")) | NOTEBOOK⏎ |
What is the output of the following code?
L = [15, 8, 22, 5] L.sort() print(L)
(a) [5, 8, 15, 22] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [15, 8, 22, 5] | L = [15, 8, 22, 5] | |
| 2 | L.sort() | L = [5, 8, 15, 22] | |
| 3 | print(L) | [5, 8, 15, 22]⏎ |
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randint(3, 5), end=" ")(b) 3 3 4 random.randint(3, 5) gives a whole number from 3 to 5.
What is the output of the following code?
L = [12, 20, 3, 10] print(max(L) - min(L))
(b) 17 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [12, 20, 3, 10] | L = [12, 20, 3, 10] | |
| 2 | print(max(L) - min(L)) | 17⏎ |
What is the output of the following code?
L = [5, 32, 16, 30] L[0] = 53 print(L)
(a) [53, 32, 16, 30] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [5, 32, 16, 30] | L = [5, 32, 16, 30] | |
| 2 | L[0] = 53 | L = [53, 32, 16, 30] | |
| 3 | print(L) | [53, 32, 16, 30]⏎ |
What is the output of the following code?
L = [4, 33, 11, 24, 25] print(L[::-2])
(c) [25, 11, 4] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [4, 33, 11, 24, 25] | L = [4, 33, 11, 24, 25] | |
| 2 | print(L[::-2]) | [25, 11, 4]⏎ |
What is the output of the following code?
import math print(math.floor(-7.8))
(c) -8 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | print(math.floor(-7.8)) | -8⏎ |
What is the output of the following code?
L = [25, 36, 6, 2, 27, 31] L.sort(reverse=True) print(L)
(c) [36, 31, 27, 25, 6, 2] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [25, 36, 6, 2, 27, 31] | L = [25, 36, 6, 2, 27, 31] | |
| 2 | L.sort(reverse=True) | L = [36, 31, 27, 25, 6, 2] | |
| 3 | print(L) | [36, 31, 27, 25, 6, 2]⏎ |
What is the output of the following code?
s = "Python"
print(s.find("n"))(b) 5 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Python" | s = 'Python' | |
| 2 | print(s.find("n")) | 5⏎ |
What is the output of the following code?
D = {'Esha': 97, 'Bela': 43, 'Dev': 54, 'Gita': 45}
D["Zoya"] = 99
print(len(D))(c) 5 A dictionary keeps key: value pairs; keys are unique.
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randrange(1, 5), end=" ")(c) 4 2 2 random.randrange(1, 5) gives a whole number from 1 to 4 (the stop value 5 is left out).
What is the output of the following code?
D = {'Dev': 78, 'Farid': 86, 'Amit': 74, 'Bela': 50}
D["Dev"] = 99
print(D)(a) {'Dev': 99, 'Farid': 86, 'Amit': 74, 'Bela': 50} A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
import statistics data = [2, 8, 1, 8, 8, 2, 8] print(statistics.median(data))
(b) 8 mean is the average, median is the middle value after sorting, mode is the most common value.
What is the output of the following code?
s = "keyboard" print(s[-7:-3:1])
(c) eybo A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
T = (6, 26, 3, 18, 4, 16) t = (6,) print(type(t))
(d) <class 'tuple'> A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
import statistics data = [1, 8, 7, 8, 9, 4, 1] print(statistics.median(data))
(d) 7 mean is the average, median is the middle value after sorting, mode is the most common value.
What is the output of the following code?
import statistics data = [1, 8, 2, 8, 5, 3, 2] print(statistics.median(data))
(c) 3 mean is the average, median is the middle value after sorting, mode is the most common value.
What is the output of the following code?
D = {'Esha': 51, 'Dev': 54, 'Amit': 56, 'Charu': 64}
print(list(D.values())[1])(a) 54 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
s = "KENDRIYA"
print(s.lstrip("K"))(a) ENDRIYA See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "KENDRIYA" | s = 'KENDRIYA' | |
| 2 | print(s.lstrip("K")) | ENDRIYA⏎ |
What is the output of the following code?
T = (25, 18, 22, 26) print(25 in T)
(d) True A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
T = (27, 20, 23, 3) print(len(T + (5,)))
(a) 5 A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
import math print(math.pow(2, 3))
(a) 8.0 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | print(math.pow(2, 3)) | 8.0⏎ |
What is the output of the following code?
import math print(math.sqrt(16))
(b) 4.0 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | print(math.sqrt(16)) | 4.0⏎ |
What is the output of the following code?
import math print(math.ceil(2.5), math.floor(2.5))
(b) 3 2 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | print(math.ceil(2.5), math.floor(2.5)) | 3 2⏎ |
What is the output of the following code?
s = "Delhi-88" print(s[6:-5:-2])
(d) 8i A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
T = (16, 19, 28, 27, 23) print(T.count(19))
(d) 1 A tuple is ordered like a list but cannot be changed.
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randint(1, 5), end=" ")(b) 4 5 3 random.randint(1, 5) gives a whole number from 1 to 5.
What is the output of the following code?
T = (21, 12, 25, 5) print(T.index(25))
(d) 2 A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
import statistics data = [3, 1, 1, 1, 2, 2, 8] print(statistics.mean(data))
(d) 2.5714285714285716 mean is the average, median is the middle value after sorting, mode is the most common value.
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randrange(4, 7), end=" ")(b) 4 4 4 random.randrange(4, 7) gives a whole number from 4 to 6 (the stop value 7 is left out).
What is the output of the following code?
L = [22, 20, 9, 35, 7, 34] print(L.pop(), L)
(d) 34 [22, 20, 9, 35, 7] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [22, 20, 9, 35, 7, 34] | L = [22, 20, 9, 35, 7, 34] | |
| 2 | print(L.pop(), L) | L = [22, 20, 9, 35, 7] | 34 [22, 20, 9, 35, 7]⏎ |
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randrange(4, 5), end=" ")(b) 4 4 4 random.randrange(4, 5) gives a whole number from 4 to 4 (the stop value 5 is left out).
What is the output of the following code?
L = [8, 19, 20, 23, 16, 10] print(len(L + [51]))
(c) 7 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [8, 19, 20, 23, 16, 10] | L = [8, 19, 20, 23, 16, 10] | |
| 2 | print(len(L + [51])) | 7⏎ |
What is the output of the following code?
D = {'Charu': 78, 'Amit': 56, 'Gita': 45, 'Dev': 48}
print(D.get("Zoya"))(a) None A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [19, 33, 5, 3, 15] print(max(L) - min(L))
(a) 30 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [19, 33, 5, 3, 15] | L = [19, 33, 5, 3, 15] | |
| 2 | print(max(L) - min(L)) | 30⏎ |
What is the output of the following code?
D = {'Dev': 65, 'Gita': 50, 'Bela': 41, 'Esha': 77}
D["Zoya"] = 99
print(len(D))(b) 5 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [24, 16, 22, 5, 21] L.insert(0, 53) print(L)
(b) [53, 24, 16, 22, 5, 21] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [24, 16, 22, 5, 21] | L = [24, 16, 22, 5, 21] | |
| 2 | L.insert(0, 53) | L = [53, 24, 16, 22, 5, 21] | |
| 3 | print(L) | [53, 24, 16, 22, 5, 21]⏎ |
What is the output of the following code?
import math print(math.fabs(-2.5))
(a) 2.5 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | print(math.fabs(-2.5)) | 2.5⏎ |
What is the output of the following code?
s = "Python" print(s[:-2:1])
(b) Pyth A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
import math print(int(math.sqrt(15)) ** 2)
(a) 9 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | print(int(math.sqrt(15)) ** 2) | 9⏎ |
What is the output of the following code?
D = {'Esha': 66, 'Amit': 76, 'Dev': 61, 'Gita': 75}
print(D.pop("Esha"), len(D))(b) 66 3 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [32, 17, 25, 23] print(sorted(L)[1])
(b) 23 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [32, 17, 25, 23] | L = [32, 17, 25, 23] | |
| 2 | print(sorted(L)[1]) | 23⏎ |
What is the output of the following code?
s = "Program" print(s.swapcase())
(b) pROGRAM See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Program" | s = 'Program' | |
| 2 | print(s.swapcase()) | pROGRAM⏎ |
What is the output of the following code?
import statistics data = [7, 5, 2, 5, 2] print(statistics.mode(data))
(b) 5 mean is the average, median is the middle value after sorting, mode is the most common value.
What is the output of the following code?
import statistics data = [7, 8, 9, 8, 4] print(statistics.median(data))
(d) 8 mean is the average, median is the middle value after sorting, mode is the most common value.
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randrange(1, 8), end=" ")(b) 2 3 1 random.randrange(1, 8) gives a whole number from 1 to 7 (the stop value 8 is left out).
What is the output of the following code?
L = [32, 23, 15, 14] print(sorted(L)[1])
(a) 15 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [32, 23, 15, 14] | L = [32, 23, 15, 14] | |
| 2 | print(sorted(L)[1]) | 15⏎ |
What is the output of the following code?
D = {'Charu': 84, 'Bela': 96, 'Esha': 88, 'Dev': 92}
print(D.get("Zoya"))(d) None A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
T = (5, 17, 2, 10) print(T.count(17))
(b) 1 A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
import math print(abs(7.8))
(b) 7.8 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | print(abs(7.8)) | 7.8⏎ |
What is the output of the following code?
D = {'Bela': 74, 'Dev': 77, 'Charu': 94, 'Esha': 84}
print(D.pop("Esha"), len(D))(d) 84 3 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
s = "Learning" print(s[0:2:1])
(b) Le A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
L = [25, 32, 27, 22] L.append(46) print(L)
(b) [25, 32, 27, 22, 46] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [25, 32, 27, 22] | L = [25, 32, 27, 22] | |
| 2 | L.append(46) | L = [25, 32, 27, 22, 46] | |
| 3 | print(L) | [25, 32, 27, 22, 46]⏎ |
What is the output of the following code?
s = "India is Great" print(s.split())
(a) ['India', 'is', 'Great'] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "India is Great" | s = 'India is Great' | |
| 2 | print(s.split()) | ['India', 'is', 'Great']⏎ |
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randint(4, 5), end=" ")(a) 5 5 4 random.randint(4, 5) gives a whole number from 4 to 5.
What is the output of the following code?
D = {'Esha': 94, 'Charu': 80, 'Dev': 73, 'Amit': 48}
print(list(D.values())[1])(d) 80 A dictionary keeps key: value pairs; keys are unique.
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randint(4, 8), end=" ")(b) 5 5 7 random.randint(4, 8) gives a whole number from 4 to 8.
What is the output of the following code?
s = "Monitor" print(s[-1::2])
(a) r A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
import statistics data = [9, 1, 7, 1, 5, 7, 7] print(statistics.mean(data))
(a) 5.285714285714286 mean is the average, median is the middle value after sorting, mode is the most common value.
What is the output of the following code?
s = "Save Water Save Life"
print("-".join(s.split()))(a) Save-Water-Save-Life See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Save Water Save Life" | s = 'Save Water Save Life' | |
| 2 | print("-".join(s.split())) | Save-Water-Save-Life⏎ |
What is the output of the following code?
import math print(math.floor(-25))
(d) -25 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | print(math.floor(-25)) | -25⏎ |
What is the output of the following code?
s = "Algorithm" print(len(s))
(d) 9 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Algorithm" | s = 'Algorithm' | |
| 2 | print(len(s)) | 9⏎ |
What is the output of the following code?
s = "INFORMATION"
print(s.lstrip("I"))(c) NFORMATION See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "INFORMATION" | s = 'INFORMATION' | |
| 2 | print(s.lstrip("I")) | NFORMATION⏎ |
What is the output of the following code?
s = "CBSE Exam 2027" print(s.upper())
(a) CBSE EXAM 2027 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "CBSE Exam 2027" | s = 'CBSE Exam 2027' | |
| 2 | print(s.upper()) | CBSE EXAM 2027⏎ |
What is the output of the following code?
import statistics data = [6, 2, 8, 2, 9, 1, 7] print(statistics.mode(data))
(b) 2 mean is the average, median is the middle value after sorting, mode is the most common value.
What is the output of the following code?
import statistics data = [3, 9, 6, 9, 9] print(statistics.mean(data))
(a) 7.2 mean is the average, median is the middle value after sorting, mode is the most common value.
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randint(2, 8), end=" ")(c) 3 8 4 random.randint(2, 8) gives a whole number from 2 to 8.
What is the output of the following code?
import statistics data = [5, 5, 7, 5, 6] print(statistics.mode(data))
(d) 5 mean is the average, median is the middle value after sorting, mode is the most common value.
What is the output of the following code?
s = "Vidyalaya" print(s[:-6:-1])
(a) ayala A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
L = [35, 19, 8, 24] L.insert(2, 51) print(L)
(a) [35, 19, 51, 8, 24] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [35, 19, 8, 24] | L = [35, 19, 8, 24] | |
| 2 | L.insert(2, 51) | L = [35, 19, 51, 8, 24] | |
| 3 | print(L) | [35, 19, 51, 8, 24]⏎ |
What is the output of the following code?
s = "Algorithm"
print(s.count("I"))(d) 0 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Algorithm" | s = 'Algorithm' | |
| 2 | print(s.count("I")) | 0⏎ |
What is the output of the following code?
L = [32, 11, 15, 1, 29] print(11 in L, 45 not in L)
(d) True True See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [32, 11, 15, 1, 29] | L = [32, 11, 15, 1, 29] | |
| 2 | print(11 in L, 45 not in L) | True True⏎ |
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randint(3, 6), end=" ")(b) 6 5 4 random.randint(3, 6) gives a whole number from 3 to 6.
What is the output of the following code?
D = {'Esha': 55, 'Gita': 96, 'Bela': 51, 'Farid': 56}
D["Bela"] = 99
print(D)(d) {'Esha': 55, 'Gita': 96, 'Bela': 99, 'Farid': 56} A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
s = "Program" print(s[-5:4])
(d) og A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
s = "Vidyalaya" print(s[4:])
(a) alaya A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
D = {'Charu': 89, 'Esha': 65, 'Farid': 94, 'Dev': 71}
print(len(D))(c) 4 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
D = {'Bela': 59, 'Dev': 68, 'Farid': 81, 'Charu': 60}
print(D.get("Zoya", 0))(a) 0 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
s = "Save Water Save Life" print(s.isupper())
(b) False See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Save Water Save Life" | s = 'Save Water Save Life' | |
| 2 | print(s.isupper()) | False⏎ |
What is the output of the following code?
s = "Science" print(s.title())
(d) Science See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Science" | s = 'Science' | |
| 2 | print(s.title()) | Science⏎ |
What is the output of the following code?
L = [23, 3, 17, 28, 9] L.insert(4, 60) print(L)
(c) [23, 3, 17, 28, 60, 9] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [23, 3, 17, 28, 9] | L = [23, 3, 17, 28, 9] | |
| 2 | L.insert(4, 60) | L = [23, 3, 17, 28, 60, 9] | |
| 3 | print(L) | [23, 3, 17, 28, 60, 9]⏎ |
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randint(1, 7), end=" ")(b) 2 6 5 random.randint(1, 7) gives a whole number from 1 to 7.
What is the output of the following code?
L = [35, 27, 31, 2] print(L[1:4])
(a) [27, 31, 2] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [35, 27, 31, 2] | L = [35, 27, 31, 2] | |
| 2 | print(L[1:4]) | [27, 31, 2]⏎ |
What is the output of the following code?
D = {'Esha': 72, 'Bela': 80, 'Amit': 85, 'Farid': 74}
print(list(D.values())[1])(a) 80 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [12, 1, 26, 6] print(L.pop(1), L)
(d) 1 [12, 26, 6] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [12, 1, 26, 6] | L = [12, 1, 26, 6] | |
| 2 | print(L.pop(1), L) | L = [12, 26, 6] | 1 [12, 26, 6]⏎ |
What is the output of the following code?
s = "Network"
print("-".join(s.split()))(b) Network See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Network" | s = 'Network' | |
| 2 | print("-".join(s.split())) | Network⏎ |
What is the output of the following code?
D = {'Gita': 46, 'Charu': 76, 'Bela': 52, 'Dev': 74}
print(sorted(D))(b) ['Bela', 'Charu', 'Dev', 'Gita'] A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
s = "keyboard" print(s[2:7])
(d) yboar A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
import math print(int(math.sqrt(30)) ** 2)
(b) 25 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | print(int(math.sqrt(30)) ** 2) | 25⏎ |
What is the output of the following code?
D = {'Dev': 53, 'Charu': 90, 'Amit': 72, 'Farid': 97}
print(max(D.values()))(a) 97 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
D = {'Dev': 40, 'Charu': 70, 'Amit': 67, 'Farid': 60}
del D["Charu"]
print(D)(a) {'Dev': 40, 'Amit': 67, 'Farid': 60} A dictionary keeps key: value pairs; keys are unique.
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randint(4, 7), end=" ")(a) 4 6 7 random.randint(4, 7) gives a whole number from 4 to 7.
What is the output of the following code?
s = "Hello World 2026" print(s.title())
(c) Hello World 2026 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Hello World 2026" | s = 'Hello World 2026' | |
| 2 | print(s.title()) | Hello World 2026⏎ |
What is the output of the following code?
T = (11, 9, 24, 10, 27, 5) print(max(T), min(T))
(b) 27 5 A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
s = "Data and Logic"
print(s.count("t"))(c) 1 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Data and Logic" | s = 'Data and Logic' | |
| 2 | print(s.count("t")) | 1⏎ |
What is the output of the following code?
D = {'Farid': 83, 'Charu': 44, 'Esha': 94, 'Gita': 82}
print(D.get("Zoya", 0))(a) 0 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [24, 17, 10, 11, 19] print(L[1:2])
(b) [17] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [24, 17, 10, 11, 19] | L = [24, 17, 10, 11, 19] | |
| 2 | print(L[1:2]) | [17]⏎ |
What is the output of the following code?
D = {'Amit': 87, 'Bela': 49, 'Dev': 66, 'Gita': 63}
print(D["Amit"])(d) 87 A dictionary keeps key: value pairs; keys are unique.
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randrange(2, 8), end=" ")(d) 2 2 7 random.randrange(2, 8) gives a whole number from 2 to 7 (the stop value 8 is left out).
What is the output of the following code?
T = (11, 1, 9, 8) t = (11) print(type(t))
(b) <class 'int'> A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
s = "CBSE Exam 2027"
print(s.find("BS"))(c) 1 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "CBSE Exam 2027" | s = 'CBSE Exam 2027' | |
| 2 | print(s.find("BS")) | 1⏎ |
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randrange(2, 5), end=" ")(d) 2 2 2 random.randrange(2, 5) gives a whole number from 2 to 4 (the stop value 5 is left out).
What is the output of the following code?
L = [26, 1, 33, 6] print(sum(L) // len(L))
(c) 16 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [26, 1, 33, 6] | L = [26, 1, 33, 6] | |
| 2 | print(sum(L) // len(L)) | 16⏎ |
What is the output of the following code?
import statistics data = [9, 2, 9, 2, 1] print(statistics.mean(data))
(b) 4.6 mean is the average, median is the middle value after sorting, mode is the most common value.
What is the output of the following code?
D = {'Gita': 47, 'Esha': 74, 'Bela': 94, 'Amit': 88}
print(D.pop("Bela"), len(D))(c) 94 3 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
s = "Vidyalaya" print(s.split())
(d) ['Vidyalaya'] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Vidyalaya" | s = 'Vidyalaya' | |
| 2 | print(s.split()) | ['Vidyalaya']⏎ |
What is the output of the following code?
s = "Keep Calm and Code"
print(s.startswith("Ke"))(b) True See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Keep Calm and Code" | s = 'Keep Calm and Code' | |
| 2 | print(s.startswith("Ke")) | True⏎ |
What is the output of the following code?
import statistics data = [7, 6, 4, 6, 1, 8, 1] print(statistics.median(data))
(c) 6 mean is the average, median is the middle value after sorting, mode is the most common value.
What is the output of the following code?
T = (18, 13, 8, 26, 12) print(T.index(8))
(d) 2 A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
D = {'Esha': 60, 'Bela': 69, 'Charu': 94, 'Amit': 42}
print(list(D.items())[0])(b) ('Esha', 60) A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
import statistics data = [4, 5, 4, 5, 6, 4, 8] print(statistics.median(data))
(c) 5 mean is the average, median is the middle value after sorting, mode is the most common value.
What is the output of the following code?
s = "Python"
print(s.replace("A", "#"))(d) Python See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Python" | s = 'Python' | |
| 2 | print(s.replace("A", "#")) | Python⏎ |
What is the output of the following code?
D = {'Charu': 80, 'Farid': 49, 'Bela': 62, 'Dev': 68}
print(max(D))(c) Farid A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
s = "DATABASE" print(s[1:-3:2])
(c) AA A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
D = {'Esha': 48, 'Charu': 52, 'Gita': 76, 'Dev': 43}
print(D.get("Zoya"))(d) None A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
T = (23, 18, 5, 10, 21, 3) print(T.index(5))
(b) 2 A tuple is ordered like a list but cannot be changed.
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randrange(3, 5), end=" ")(a) 3 4 4 random.randrange(3, 5) gives a whole number from 3 to 4 (the stop value 5 is left out).
What is the output of the following code?
s = "COMPUTER" print(s.capitalize())
(a) Computer See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "COMPUTER" | s = 'COMPUTER' | |
| 2 | print(s.capitalize()) | Computer⏎ |
What is the output of the following code?
D = {'Esha': 83, 'Farid': 44, 'Bela': 86, 'Amit': 55}
D["Farid"] = 99
print(D)(b) {'Esha': 83, 'Farid': 99, 'Bela': 86, 'Amit': 55} A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
import math print(math.factorial(4))
(b) 24 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | print(math.factorial(4)) | 24⏎ |
What is the output of the following code?
import math print(math.ceil(-2.5), math.floor(-2.5))
(c) -2 -3 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | print(math.ceil(-2.5), math.floor(-2.5)) | -2 -3⏎ |
What is the output of the following code?
L = [14, 5, 11, 2, 25] print(14 in L, 48 not in L)
(c) True True See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [14, 5, 11, 2, 25] | L = [14, 5, 11, 2, 25] | |
| 2 | print(14 in L, 48 not in L) | True True⏎ |
What is the output of the following code?
L = [1, 15, 11, 17, 24, 5] L.reverse() print(L)
(d) [5, 24, 17, 11, 15, 1] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [1, 15, 11, 17, 24, 5] | L = [1, 15, 11, 17, 24, 5] | |
| 2 | L.reverse() | L = [5, 24, 17, 11, 15, 1] | |
| 3 | print(L) | [5, 24, 17, 11, 15, 1]⏎ |
What is the output of the following code?
T = (15, 24, 10, 3, 13) print(max(T), min(T))
(c) 24 3 A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
L = [6, 36, 38, 31, 33, 25] L.append(47) print(L)
(a) [6, 36, 38, 31, 33, 25, 47] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [6, 36, 38, 31, 33, 25] | L = [6, 36, 38, 31, 33, 25] | |
| 2 | L.append(47) | L = [6, 36, 38, 31, 33, 25, 47] | |
| 3 | print(L) | [6, 36, 38, 31, 33, 25, 47]⏎ |
What is the output of the following code?
s = "NOTEBOOK" print(s.split())
(a) ['NOTEBOOK'] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "NOTEBOOK" | s = 'NOTEBOOK' | |
| 2 | print(s.split()) | ['NOTEBOOK']⏎ |
What is the output of the following code?
s = "Data and Logic"
print(s.replace("O", "#"))(b) Data and Logic See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Data and Logic" | s = 'Data and Logic' | |
| 2 | print(s.replace("O", "#")) | Data and Logic⏎ |
What is the output of the following code?
T = (14, 1, 26, 3, 28) print(T.index(26))
(c) 2 A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
s = "Science" print(s[-4:7])
(c) ence A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
L = [18, 24, 33, 19, 7, 20] print(7 in L, 45 not in L)
(a) True True See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [18, 24, 33, 19, 7, 20] | L = [18, 24, 33, 19, 7, 20] | |
| 2 | print(7 in L, 45 not in L) | True True⏎ |
What is the output of the following code?
s = "Keep Calm and Code" print(len(s))
(d) 18 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Keep Calm and Code" | s = 'Keep Calm and Code' | |
| 2 | print(len(s)) | 18⏎ |
What is the output of the following code?
D = {'Esha': 78, 'Dev': 53, 'Bela': 52, 'Gita': 70}
print(D.pop("Bela"), len(D))(c) 52 3 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
T = (26, 11, 10, 27, 19, 5) print(sum(T))
(b) 98 A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
s = "Keep Calm and Code"
print(s.count("n"))(c) 1 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Keep Calm and Code" | s = 'Keep Calm and Code' | |
| 2 | print(s.count("n")) | 1⏎ |
What is the output of the following code?
T = (5, 24, 15, 6) print(T.index(15))
(c) 2 A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
D = {'Farid': 63, 'Amit': 66, 'Dev': 48, 'Gita': 90}
print(sorted(D))(b) ['Amit', 'Dev', 'Farid', 'Gita'] A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
s = "Keep Calm and Code"
print(s.split("O"))(d) ['Keep Calm and Code'] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Keep Calm and Code" | s = 'Keep Calm and Code' | |
| 2 | print(s.split("O")) | ['Keep Calm and Code']⏎ |
What is the output of the following code?
s = "Monitor" print(s.capitalize())
(a) Monitor See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Monitor" | s = 'Monitor' | |
| 2 | print(s.capitalize()) | Monitor⏎ |
What is the output of the following code?
L = [38, 8, 10, 15, 39, 31] L.append([60, 61]) print(L)
(d) [38, 8, 10, 15, 39, 31, [60, 61]] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [38, 8, 10, 15, 39, 31] | L = [38, 8, 10, 15, 39, 31] | |
| 2 | L.append([60, 61]) | L = [38, 8, 10, 15, 39, 31, [60, 61]] | |
| 3 | print(L) | [38, 8, 10, 15, 39, 31, [60, 61]]⏎ |
What is the output of the following code?
s = "KV Shalimar Bagh" print(s.title())
(a) Kv Shalimar Bagh See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "KV Shalimar Bagh" | s = 'KV Shalimar Bagh' | |
| 2 | print(s.title()) | Kv Shalimar Bagh⏎ |
What is the output of the following code?
L = [8, 32, 2, 4, 16] print(L.pop(3), L)
(c) 4 [8, 32, 2, 16] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [8, 32, 2, 4, 16] | L = [8, 32, 2, 4, 16] | |
| 2 | print(L.pop(3), L) | L = [8, 32, 2, 16] | 4 [8, 32, 2, 16]⏎ |
What is the output of the following code?
L = [8, 9, 36, 6] L[0] = 44 print(L)
(a) [44, 9, 36, 6] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [8, 9, 36, 6] | L = [8, 9, 36, 6] | |
| 2 | L[0] = 44 | L = [44, 9, 36, 6] | |
| 3 | print(L) | [44, 9, 36, 6]⏎ |
What is the output of the following code?
L = [30, 39, 5, 33, 8] print(len(L + [53]))
(d) 6 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [30, 39, 5, 33, 8] | L = [30, 39, 5, 33, 8] | |
| 2 | print(len(L + [53])) | 6⏎ |
What is the output of the following code?
import statistics data = [1, 3, 2, 3, 2, 3, 4] print(statistics.median(data))
(d) 3 mean is the average, median is the middle value after sorting, mode is the most common value.
What is the output of the following code?
s = "Python" print(s.swapcase())
(a) pYTHON See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Python" | s = 'Python' | |
| 2 | print(s.swapcase()) | pYTHON⏎ |
What is the output of the following code?
D = {'Esha': 76, 'Amit': 77, 'Bela': 71, 'Dev': 78}
print(sorted(D))(d) ['Amit', 'Bela', 'Dev', 'Esha'] A dictionary keeps key: value pairs; keys are unique.
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randrange(1, 7), end=" ")(c) 1 3 2 random.randrange(1, 7) gives a whole number from 1 to 6 (the stop value 7 is left out).
What is the output of the following code?
D = {'Esha': 41, 'Charu': 62, 'Bela': 79, 'Gita': 53}
print("Esha" in D, 41 in D)(d) True False A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
T = (17, 4, 18, 28, 27, 12) print(17 in T)
(c) True A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
s = "Science" print(s[:-5:1])
(b) Sc A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
T = (17, 19, 26, 27, 23) print(len(T + (5,)))
(b) 6 A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
L = [30, 14, 36, 33, 13, 1] L.remove(14) print(L)
(a) [30, 36, 33, 13, 1] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [30, 14, 36, 33, 13, 1] | L = [30, 14, 36, 33, 13, 1] | |
| 2 | L.remove(14) | L = [30, 36, 33, 13, 1] | |
| 3 | print(L) | [30, 36, 33, 13, 1]⏎ |
What is the output of the following code?
s = "Vidyalaya"
print(s.lstrip("V"))(a) idyalaya See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Vidyalaya" | s = 'Vidyalaya' | |
| 2 | print(s.lstrip("V")) | idyalaya⏎ |
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randrange(4, 8), end=" ")(a) 5 5 4 random.randrange(4, 8) gives a whole number from 4 to 7 (the stop value 8 is left out).
What is the output of the following code?
D = {'Dev': 88, 'Bela': 82, 'Esha': 44, 'Gita': 81}
print(D["Gita"])(d) 81 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
D = {'Esha': 77, 'Charu': 47, 'Amit': 84, 'Bela': 70}
print(sorted(D))(b) ['Amit', 'Bela', 'Charu', 'Esha'] A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
s = "Python" print(s.upper())
(c) PYTHON See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Python" | s = 'Python' | |
| 2 | print(s.upper()) | PYTHON⏎ |
What is the output of the following code?
import math print(math.factorial(5))
(b) 120 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | print(math.factorial(5)) | 120⏎ |
What is the output of the following code?
s = "COMPUTER" print(s[6:4:-2])
(d) E A slice s[start:stop:step] stops before stop; a negative index counts from the end.
What is the output of the following code?
D = {'Bela': 70, 'Gita': 64, 'Farid': 42, 'Charu': 67}
print(D.get("Zoya", 0))(c) 0 A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
import math print(math.gcd(42, 20))
(d) 2 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 2 | print(math.gcd(42, 20)) | 2⏎ |
What is the output of the following code?
L = [20, 6, 16, 10, 22] print(16 in L, 52 not in L)
(d) True True See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [20, 6, 16, 10, 22] | L = [20, 6, 16, 10, 22] | |
| 2 | print(16 in L, 52 not in L) | True True⏎ |
What is the output of the following code?
L = [30, 4, 31, 35, 23, 37] del L[3] print(L)
(d) [30, 4, 31, 23, 37] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [30, 4, 31, 35, 23, 37] | L = [30, 4, 31, 35, 23, 37] | |
| 2 | del L[3] | L = [30, 4, 31, 23, 37] | |
| 3 | print(L) | [30, 4, 31, 23, 37]⏎ |
What is the output of the following code?
D = {'Bela': 90, 'Gita': 54, 'Amit': 82, 'Dev': 76}
print("Gita" in D, 54 in D)(d) True False A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
D = {'Amit': 50, 'Dev': 42, 'Charu': 51, 'Esha': 47}
del D["Dev"]
print(D)(a) {'Amit': 50, 'Charu': 51, 'Esha': 47} A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
D = {'Gita': 80, 'Charu': 60, 'Farid': 98, 'Esha': 55}
D["Charu"] = 99
print(D)(c) {'Gita': 80, 'Charu': 99, 'Farid': 98, 'Esha': 55} A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [14, 38, 27, 19, 32] del L[1] print(L)
(a) [14, 27, 19, 32] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [14, 38, 27, 19, 32] | L = [14, 38, 27, 19, 32] | |
| 2 | del L[1] | L = [14, 27, 19, 32] | |
| 3 | print(L) | [14, 27, 19, 32]⏎ |
What is the output of the following code?
T = (10, 24, 4, 7) print(10 in T)
(b) True A tuple is ordered like a list but cannot be changed.
What is the output of the following code?
D = {'Charu': 86, 'Gita': 47, 'Bela': 84, 'Farid': 80}
print(sorted(D))(c) ['Bela', 'Charu', 'Farid', 'Gita'] A dictionary keeps key: value pairs; keys are unique.
What is the output of the following code?
L = [13, 1, 9, 29, 25] L.extend([46, 47]) print(L)
(b) [13, 1, 9, 29, 25, 46, 47] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [13, 1, 9, 29, 25] | L = [13, 1, 9, 29, 25] | |
| 2 | L.extend([46, 47]) | L = [13, 1, 9, 29, 25, 46, 47] | |
| 3 | print(L) | [13, 1, 9, 29, 25, 46, 47]⏎ |
What is the output of the following code?
L = [31, 29, 18, 24, 6] print(L * 2)
(d) [31, 29, 18, 24, 6, 31, 29, 18, 24, 6] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [31, 29, 18, 24, 6] | L = [31, 29, 18, 24, 6] | |
| 2 | print(L * 2) | [31, 29, 18, 24, 6, 31, 29, 18, 24, 6]⏎ |
What is the output of the following code?
s = "India is Great"
print(s.find("nd"))(c) 1 See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "India is Great" | s = 'India is Great' | |
| 2 | print(s.find("nd")) | 1⏎ |
Which of these is a possible output of the code?
import random
for i in range(3):
print(random.randrange(2, 6), end=" ")(d) 4 4 2 random.randrange(2, 6) gives a whole number from 2 to 5 (the stop value 6 is left out).
What is the output of the following code?
s = "Program" print(s.split())
(c) ['Program'] See the working below.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Program" | s = 'Program' | |
| 2 | print(s.split()) | ['Program']⏎ |
Hacking done with permission, to find and fix the weak points of a system, is
(b) ethical hacking Ethical (white-hat) hackers test a system with the owner's permission to make it safer.
Spending too much time on screens can lead to
(b) eye strain and poor sleep Long screen time strains the eyes and disturbs sleep; take breaks (20-20-20 rule).
Which of these is open source software?
(b) Python Python's source code is free to use, change and share; it is open source.
Which of these reduces e-waste?
(c) Repairing and using devices longer Repairing and using devices for longer means fewer devices are thrown away.
GPL is a type of
(d) free and open source software licence The GNU General Public License is a free and open source (copyleft) licence.
Unwanted bulk e-mail sent to many users is
(b) spam Spam is unwanted e-mail sent in bulk, often advertisements or scams.
FOSS stands for
(d) Free and Open Source Software FOSS = Free and Open Source Software, e.g. Linux, LibreOffice, Python.
State True or False: The IT Act, 2000 deals with cyber crimes in India.
(a) True The Information Technology Act, 2000 deals with cyber crimes and electronic records in India.
State True or False: Deleting a post removes every copy of it from the Internet.
(b) False Copies and screenshots may remain; footprints are lasting.
Data protection means
(a) keeping personal data safe from misuse Data protection means keeping personal data safe from misuse, theft and loss.
Small text files stored by websites on the user's computer are
(d) cookies Cookies are small text files that websites save to remember your visit, login and preferences.
Which harmful metal is found in e-waste?
(b) Lead E-waste contains lead, mercury and cadmium, which harm health when burnt or dumped.
Which of these is a safe practice on a public computer?
(b) log out and close the browser after use Always log out and close the browser so the next user cannot open your accounts.
OTP stands for
(d) One-Time Password OTP = One-Time Password, a code that works only once, used for safe login and payments.
Which of these is personal data that should not be shared online?
(c) Aadhaar number An Aadhaar number identifies you and can be misused, so it must not be shared openly.
Which of these helps a visually challenged person use a computer?
(a) Screen reader A screen reader reads the text on the screen aloud.
Encryption is used to
(b) turn data into a secret code so others cannot read it Encryption turns data into a secret code; only a person with the key can read it.
A white-hat hacker is
(a) an ethical hacker White-hat hackers are ethical hackers who work with permission to improve security.
Which of these is NOT a good netiquette?
(a) Typing in ALL CAPITALS Typing in ALL CAPITALS looks like shouting, so it is bad netiquette.
Respecting others, not using bad language and not shouting (ALL CAPS) online is part of
(a) netiquette Netiquette is good manners on the Internet.
Software that secretly records what the user does and sends it to others is
(b) spyware Spyware spies on the user and sends the information to someone else without permission.
A digital signature is used to
(a) verify the identity of the sender of an electronic document A digital signature proves who sent an electronic document and that it was not changed.
Apache, MIT and BSD are examples of
(a) open source licences They are permissive open source licences: the code can be used and changed freely.
Which of these protects a new medicine formula?
(a) Patent A new invention such as a medicine formula is protected by a patent.
Which of these is NOT a cyber crime?
(d) Using a licensed copy of software Using a licensed (legally bought) copy of software is legal; the others are crimes.
A program that records keystrokes to steal passwords is a
(b) keylogger A keylogger secretly records every key pressed, to steal passwords and card numbers.
A virus needs a
(a) host program to spread A virus attaches itself to a host program or file and spreads when that file is run.
HTTPS in a website address shows that
(d) the connection is encrypted and secure The S stands for secure: data between the browser and the website is encrypted.
The best way to manage e-waste is to
(d) reduce, reuse and recycle Reduce (buy less), reuse (repair, donate) and recycle through authorised recyclers.
Fake e-mails that trick users into giving passwords or bank details are
(a) phishing Phishing uses fake messages that look real to steal passwords and bank details.
Using a copyrighted work without permission is
(a) copyright infringement Using someone's protected work without permission breaks the copyright law.
Which of these is personal identifiable information?
(b) Phone number A phone number can identify a person, so it is PII.
Software given free for a trial period, after which it must be bought, is
(d) shareware Shareware is free only for a trial period; then it must be bought.
Before sharing a photo of a friend online, you should
(c) take the friend's permission The friend has the right to privacy, so take permission first.
Good manners to follow while communicating online are called
(b) netiquette Netiquette = net + etiquette (good manners online).
A fake website that looks like a real one is an example of
(b) spoofing Spoofing makes something fake look like a trusted source.
Which of these is free and open source software?
(d) LibreOffice LibreOffice is free and its source code is open; the others are proprietary.
Software that is free to use but whose source code is not open is
(a) freeware Freeware costs nothing but its source code is not shared (e.g. Adobe Reader).
Using a fake identity of another person to cheat is
(c) identity theft Identity theft is pretending to be someone else using their personal details.
Unauthorised copying of a movie and uploading it online is
(d) piracy Making and sharing illegal copies of copyrighted content is piracy.
The Indian law that deals with cyber crime and electronic records is the
(d) IT Act, 2000 The Information Technology Act, 2000 (IT Act) is India's cyber law.
A message saying 'Forward this to 10 people or bad luck will come' is
(c) a chain message (spam) Chain messages spread fear to make people forward them; they are spam.
A common gender issue in computing is
(a) fewer girls choosing computer science Fewer girls choose computer science because of stereotypes and less encouragement.
Two-factor authentication means
(b) checking identity in two ways, such as a password and an OTP Two checks are used, such as a password you know and an OTP on your phone.
A word, logo or symbol that identifies a brand is protected by a
(b) trademark A trademark protects brand names, logos and symbols.
Keeping the operating system and antivirus updated helps to
(a) fix security holes Updates fix security holes that attackers could use.
Which of these is a sign of a secure payment page?
(c) https and a padlock in the address bar https and a padlock show that the connection is encrypted.
Which is the national helpline number for reporting cyber fraud in India?
(b) 1930 Dial 1930 (or visit cybercrime.gov.in) to report cyber fraud.
Making digital content usable by persons with disabilities is called
(d) inclusive design (accessibility) Accessibility (inclusive design) makes content usable by everyone, including persons with disabilities.
Software that detects and removes malware is
(b) antivirus Antivirus software scans for viruses and other malware and removes them.
Old mobile phones should be
(b) given to an authorised e-waste collector An authorised e-waste collector recycles them safely.
Proprietary software
(c) is owned by a company and its source code is not shared Proprietary software is owned by a company; users buy a licence but cannot see or change the code.
Footprints left knowingly, such as posts and comments, are
(a) active digital footprints Active digital footprints are left on purpose by the user.
Sending a fake message that looks like it is from a known contact is
(a) spoofing Spoofing fakes the sender so the message looks trusted.
Using someone else's work or ideas as your own, without giving credit, is
(a) plagiarism Plagiarism is presenting another person's work as your own.
State True or False: A Trojan horse copies itself to other computers on its own.
(b) False That is a worm; a Trojan needs the user to run it.
State True or False: Open source software can be studied and changed by users.
(a) True Its source code is open, so users can study, change and share it.
Malware that copies itself and spreads through a network on its own is a
(b) worm A worm spreads by itself through networks; it does not need a host file.
Malware that looks like a useful program but harms the computer is a
(a) Trojan horse Like the wooden horse of Troy, a Trojan looks useful but hides harmful code.
Public domain works
(c) can be used freely by anyone Works in the public domain have no copyright, so anyone can use them freely.
State True or False: Screen readers help visually challenged users.
(a) True Screen readers read the screen aloud for users who cannot see it.
Clicking a link in a message that says 'You won a prize, enter your bank details' can lead to
(d) phishing fraud Such fake prize messages are phishing; they steal bank details.
Which right lets a creator decide who may copy and share the work?
(c) Copyright Copyright gives the creator the right to decide who may copy and share the work.
Malware that locks the files of a victim and asks for money is
(b) ransomware Ransomware encrypts files and demands a ransom to unlock them.
Posting provocative comments to upset people online is
(d) cyber trolling Cyber trolling means posting provocative or insulting comments to upset people.
Cyber safety means
(a) using the Internet safely and responsibly Cyber safety is using the Internet safely and responsibly to protect yourself and your data.
The legal right over a new invention is a
(d) patent A patent gives the inventor the right over the invention for a fixed period.
Sending insulting or threatening messages to harass a person online is
(c) cyber bullying Cyber bullying is harassing or threatening someone online.
Teaching aids such as screen readers and Braille keyboards are called
(a) assistive technologies Assistive technologies help persons with disabilities use computers.
The difference in access to computers and the Internet between groups of people is the
(a) digital divide The digital divide is the gap between people who have access to technology and those who do not.
Discarded electronic devices such as old phones and computers are
(a) e-waste Thrown-away electronic devices are called e-waste.
Private browsing (incognito mode)
(b) does not save the history and cookies after the window is closed Incognito mode does not keep history and cookies after the window is closed; websites can still see your visit.
Creative Commons (CC) licences are mostly used for
(d) creative works such as images, music and articles CC licences let creators share images, music and articles on simple terms.
Data collected without the user knowing, such as the websites visited, forms
(a) passive digital footprints Passive footprints are collected without the user knowing, e.g. browsing history and location.
A strong password
(a) mixes capital and small letters, digits and symbols A strong password is long and mixes capital and small letters, digits and symbols.
Children should share personal problems faced online with
(c) parents or teachers Parents and teachers can guide and protect them.
The illegal copying and selling of software is
(d) software piracy Software piracy is copying or selling software without a licence.
An online fraud in which the attacker calls and pretends to be from a bank is
(a) vishing (voice phishing) Vishing = voice phishing: fraud done over a phone call.
A message that pretends to come from a trusted website and redirects to a fake one is
(c) a phishing link A phishing link takes the user to a fake site to steal details.
Captions on videos mainly help
(c) people with hearing impairment Captions show speech as text for people who cannot hear.
The trail of data a person leaves while using the Internet is a
(d) digital footprint Everything you do online leaves a digital footprint.
State True or False: Plagiarism is avoided by giving credit to the original source.
(a) True Citing the source gives credit to the creator, so it is not plagiarism.
Copyleft licences such as GPL require that
(d) changed versions are also shared under the same licence Copyleft means changed versions must be shared under the same free licence.
The IT Act, 2000 gives legal recognition to
(b) electronic records and digital signatures The IT Act makes electronic records and digital signatures legally valid.
The safest way to dispose of an old hard disk is to
(a) wipe the data and give it to an authorised recycler Wipe the data so it cannot be recovered, then give it to an authorised recycler.
State True or False: A strong password should be shared with close friends.
(b) False A password must never be shared, even with friends.
The legal right of a creator over a book, song or software is
(b) copyright Copyright protects creative works such as books, songs and software.
Software that shows unwanted advertisements is
(d) adware Adware shows unwanted advertisements.
Creations of the mind, such as inventions, books and designs, are called
(d) intellectual property Intellectual property means creations of the mind; it is protected by copyright, patent and trademark.
Recycling e-waste in an unsafe, informal way harms
(b) the health of workers and the environment Burning and acid-washing e-waste releases toxic fumes that harm workers and the environment.
Gender bias in technology can be reduced by
(c) giving equal access and encouragement to girls Equal access, role models and encouragement bring more girls into computing.
Which of these is an example of passive digital footprint?
(b) The location data saved by an app Location data saved by an app is collected without the user actively posting it.
Which of these is a right of a creator under copyright?
(b) To decide who may copy the work Copyright lets the creator decide who may copy, share or change the work.
The licence that lets anyone use a work, only with credit to the creator, is
(d) CC BY CC BY (Attribution) allows any use if the creator is credited.
Which agency in India handles the response to cyber security incidents?
(a) CERT-In CERT-In (Indian Computer Emergency Response Team) responds to cyber security incidents.
A firewall
(d) filters the traffic between a computer and the network A firewall checks the traffic between a computer and the network and blocks unsafe connections.
State True or False: E-waste can be safely thrown into ordinary garbage.
(b) False It contains toxic metals; give it to an authorised recycler.
Digital footprints can be used by employers and colleges to
(a) learn about a person's online behaviour They may look at your online behaviour, so post responsibly.
Breaking into a computer system without permission is
(b) hacking Unauthorised access to a computer is hacking (cracking), a cyber crime.
Which section of the IT Act deals with identity theft?
(c) 66C Section 66C of the IT Act punishes identity theft (misusing passwords, signatures).
Assertion (A): In Python, the expression 7 // 2 gives 3.
Reason (R): // is the floor division operator that gives the quotient rounded down.
(a) Both A and R are true and R is the correct explanation of A. R is the rule behind A: 7 / 2 = 3.5 and // rounds it down to 3.
Assertion (A): Python is called a dynamically typed language.
Reason (R): The type of a variable is decided by the value given to it while the program runs.
(a) Both A and R are true and R is the correct explanation of A. R is exactly what dynamic typing means: x = 5 makes x an int; later x = 'hi' makes it a str.
Assertion (A): A = 5 and a = 5 create two different variables.
Reason (R): Python is case sensitive.
(a) Both A and R are true and R is the correct explanation of A. Because Python is case sensitive (R), A and a are different names (A).
Assertion (A): The statement x = int('12.5') converts the string to the integer 12.
Reason (R): int() can convert any string to an integer.
(d) A is false but R is true. int('12.5') gives ValueError; a string with a decimal point cannot be passed to int().
Assertion (A): input() returns a string even when a number is typed.
Reason (R): int() is used to change the input to an integer.
(b) Both A and R are true but R is not the correct explanation of A. Both are true, but R does not explain why input() returns a string.
Assertion (A): The expression 2 3 2 gives 512.
Reason (R): The ** operator is evaluated from right to left.
(a) Both A and R are true and R is the correct explanation of A. 3 2 = 9 first, then 2 9 = 512.
Assertion (A): A comment is executed by the Python interpreter.
Reason (R): A comment starts with the symbol #.
(d) A is false but R is true. Comments are ignored by the interpreter.
Assertion (A): 5 + '5' gives an error in Python.
Reason (R): Python cannot add an integer and a string.
(a) Both A and R are true and R is the correct explanation of A. R explains A: an int and a str cannot be added, so TypeError comes.
Assertion (A): A logical error is reported by the interpreter.
Reason (R): A logical error gives a wrong result without any error message.
(d) A is false but R is true. A is false: the interpreter does not report logical errors. R is true: the program runs but gives a wrong result.
Assertion (A): The keyword 'True' can be used as a variable name.
Reason (R): Keywords have a special meaning in Python.
(d) A is false but R is true. Keywords cannot be used as identifiers.
Assertion (A): A for loop with range(1, 10, 2) runs 5 times.
Reason (R): range(1, 10, 2) gives 1, 3, 5, 7, 9.
(a) Both A and R are true and R is the correct explanation of A. The five values 1, 3, 5, 7, 9 in R are why the loop runs 5 times.
Assertion (A): The else block of a loop runs even after break.
Reason (R): break ends the loop at once.
(d) A is false but R is true. The loop else is skipped when break runs.
Assertion (A): A while loop is called an entry-controlled loop.
Reason (R): Its condition is checked before every round.
(a) Both A and R are true and R is the correct explanation of A. The condition is checked before each round (at the entry).
Assertion (A): Indentation is important in Python.
Reason (R): Python uses curly brackets to mark a block.
(c) A is true but R is false. Python uses indentation, not brackets.
Assertion (A): continue ends the loop at once.
Reason (R): continue skips the rest of the current round.
(d) A is false but R is true. A is false: break ends the loop. R is true: continue skips the rest of the current round only.
Assertion (A): Strings are immutable in Python.
Reason (R): s[0] = 'P' gives a TypeError.
(a) Both A and R are true and R is the correct explanation of A. R shows A: changing one character with s[0] = 'P' gives TypeError because strings cannot be changed.
Assertion (A): s.find('z') returns -1 when 'z' is not in s.
Reason (R): find() gives an error when the substring is not found.
(c) A is true but R is false. It is index() that gives an error.
Assertion (A): 'Hello'[1:4] gives 'ell'.
Reason (R): Slicing stops before the end index.
(a) Both A and R are true and R is the correct explanation of A. Slicing takes index 1, 2, 3 and stops before 4 (R), so the result is 'ell' (A).
Assertion (A): len('KV 88') is 5.
Reason (R): Spaces are counted as characters.
(a) Both A and R are true and R is the correct explanation of A. K, V, space, 8, 8 = 5 characters, because the space is counted (R).
Assertion (A): 'Python'.upper() changes the original string.
Reason (R): upper() returns a new string in capital letters.
(d) A is false but R is true. A is false: strings cannot be changed. R is true: upper() returns a new string.
Assertion (A): Lists are mutable.
Reason (R): Elements of a list can be changed after the list is made.
(a) Both A and R are true and R is the correct explanation of A. Mutable means changeable; R says list elements can be changed, e.g. L[0] = 9.
Assertion (A): L.append([4, 5]) increases the length of L by 2.
Reason (R): append() adds its argument as one element.
(d) A is false but R is true. The length increases by 1; extend() would add 2.
Assertion (A): L.sort() returns the sorted list.
Reason (R): sort() arranges the list in place.
(d) A is false but R is true. sort() returns None.
Assertion (A): L.pop() removes the last element of L.
Reason (R): pop() without an index works on the last position.
(a) Both A and R are true and R is the correct explanation of A. With no index, pop() works on the last position (R), so it removes the last element (A).
Assertion (A): Two lists can be joined with +.
Reason (R): + is the concatenation operator for lists.
(a) Both A and R are true and R is the correct explanation of A. + is the concatenation operator (R): [1, 2] + [3] gives [1, 2, 3].
Assertion (A): A tuple cannot be changed after it is created.
Reason (R): Tuples are immutable.
(a) Both A and R are true and R is the correct explanation of A. Tuples are immutable (R), which is why they cannot be changed (A).
Assertion (A): (5) is a tuple.
Reason (R): A tuple with one element needs a comma after the element.
(d) A is false but R is true. (5) is just the integer 5.
Assertion (A): A list can be a key of a dictionary.
Reason (R): Dictionary keys must be immutable.
(d) A is false but R is true. A list is mutable, so it cannot be a key.
Assertion (A): d.get('x') does not give an error when 'x' is not a key.
Reason (R): get() returns None for a missing key.
(a) Both A and R are true and R is the correct explanation of A. get() returns None for a missing key (R), so no KeyError comes (A).
Assertion (A): A dictionary can have two pairs with the same key.
Reason (R): Values in a dictionary can be repeated.
(d) A is false but R is true. Keys are unique; values may repeat.
Assertion (A): math.floor(-3.5) gives -4.
Reason (R): floor() gives the largest integer not greater than the number.
(a) Both A and R are true and R is the correct explanation of A. floor() takes the largest whole number not greater than -3.5 (R), which is -4 (A).
Assertion (A): random.randint(1, 5) can give 5.
Reason (R): randint() includes both the end points.
(a) Both A and R are true and R is the correct explanation of A. randint() includes both end points (R), so 5 is possible (A).
Assertion (A): statistics.mode([2, 3, 3, 5]) gives 3.
Reason (R): Mode is the value that occurs most often.
(a) Both A and R are true and R is the correct explanation of A. 3 occurs most often (R), so the mode is 3 (A).
Assertion (A): ASCII can represent Hindi letters.
Reason (R): ASCII has codes only for English letters, digits and symbols.
(d) A is false but R is true. A is false: ASCII has only 128 codes for English letters, digits and symbols (R is true).
Assertion (A): Unicode is used in web pages of many languages.
Reason (R): Unicode gives a unique code to the characters of almost every script.
(a) Both A and R are true and R is the correct explanation of A. Unicode gives every character of almost every script a code (R), so pages in many languages use it (A).
Assertion (A): NAND is called a universal gate.
Reason (R): All other gates can be built using only NAND gates.
(a) Both A and R are true and R is the correct explanation of A. All other gates can be built from NAND alone (R); that is what universal means (A).
Assertion (A): RAM is called volatile memory.
Reason (R): RAM loses its data when the power is switched off.
(a) Both A and R are true and R is the correct explanation of A. Volatile means it loses data without power (R), which is true of RAM (A).
Assertion (A): Cache memory makes a computer faster.
Reason (R): Cache keeps the data that the CPU uses often.
(a) Both A and R are true and R is the correct explanation of A. Cache keeps often-used data close to the CPU (R), so the CPU waits less (A).
Assertion (A): Phishing is a cyber crime.
Reason (R): Phishing tricks people into giving passwords and bank details.
(a) Both A and R are true and R is the correct explanation of A. Phishing tricks people into giving passwords and bank details (R), so it is a crime (A).
Assertion (A): E-waste is harmful when burnt.
Reason (R): Electronic devices contain lead and mercury.
(a) Both A and R are true and R is the correct explanation of A. Electronic devices contain lead and mercury (R), which give toxic fumes when burnt (A).
Assertion (A): Open source software is always free of cost.
Reason (R): In open source software the source code is available.
(d) A is false but R is true. Open source is about access to the code; it may still be sold.
Assertion (A): Active digital footprints are left knowingly.
Reason (R): Posts and comments are made by the user on purpose.
(a) Both A and R are true and R is the correct explanation of A. Posts and comments are made on purpose (R), which is what active footprints are (A).
Assertion (A): L = [1, 2] * 2 gives [1, 2, 1, 2].
Reason (R): * repeats the list.
(a) Both A and R are true and R is the correct explanation of A. * repeats the list (R), so [1, 2] appears twice (A).
Assertion (A): 'Python'[::-1] gives 'nohtyP'.
Reason (R): A step of -1 reads the string from the end.
(a) Both A and R are true and R is the correct explanation of A. A step of -1 reads from the last character to the first (R), giving the reversed string (A).
Assertion (A): L[1:3] = [7, 8, 9] is allowed for a list L of 5 elements.
Reason (R): A slice of a list can be replaced by any number of elements.
(a) Both A and R are true and R is the correct explanation of A. A slice can be replaced by any number of elements (R); the list just becomes longer (6 elements) (A).
Assertion (A): for i in range(5): print(i) prints the numbers 1 to 5.
Reason (R): range(5) starts from 0.
(d) A is false but R is true. It prints 0 to 4.
Assertion (A): The expression 10 / 2 gives 5.
Reason (R): The / operator always gives a float.
(d) A is false but R is true. 10 / 2 gives 5.0.
Assertion (A): len({'a': 1, 'b': 2, 'a': 3}) is 2.
Reason (R): A repeated key keeps only its last value.
(a) Both A and R are true and R is the correct explanation of A. The repeated key 'a' keeps only its last value (R), so only 2 keys remain (A).
Assertion (A): s.split() on 'KV Delhi' gives ['KV', 'Delhi'].
Reason (R): split() without an argument splits at any amount of white space.
(a) Both A and R are true and R is the correct explanation of A. split() with no argument splits at any amount of white space (R), so the extra space gives no empty string (A).
Assertion (A): math.ceil(-2.3) gives -3.
Reason (R): ceil() gives the smallest integer that is not less than the number.
(d) A is false but R is true. It gives -2.
Assertion (A): max([3, 'a', 5]) gives an error.
Reason (R): Python cannot compare an int and a str with >.
(a) Both A and R are true and R is the correct explanation of A. max() compares the elements; int and str cannot be compared (R), so TypeError comes (A).
Assertion (A): 'ab' in 'cabin' is True.
Reason (R): in checks whether one string is a part of another.
(a) Both A and R are true and R is the correct explanation of A. in checks whether one string is part of another (R); 'cabin' contains 'ab' (A).
Why are NAND and NOR called universal gates? Show NOT using NAND.
Because every other gate (AND, OR, NOT) can be built using only NAND gates, or only NOR gates. NOT A = A NAND A: join both inputs of a NAND gate to A.
Draw the truth table for the Boolean expression (NOT A) OR (NOT B).
| A | B | (NOT A) OR (NOT B) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
The output is 1 in 3 of the 4 rows.
Draw the truth table for the Boolean expression NOT (A OR B).
| A | B | NOT (A OR B) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
The output is 1 in 1 of the 4 rows.
Draw the truth table for the Boolean expression (A OR B) AND (NOT C).
| A | B | C | (A OR B) AND (NOT C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
The output is 1 in 3 of the 8 rows.
Draw the truth table for the Boolean expression (NOT A) AND (NOT B).
| A | B | (NOT A) AND (NOT B) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
The output is 1 in 1 of the 4 rows.
Convert: (i) (114)10 to hexadecimal (ii) (10000110)2 to hexadecimal
(i)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 114 | 2 |
| 16 | 7 | 7 |
Read the remainders from bottom to top: (72)16
(ii)
Make groups of 4 bits from the right: 1000 0110
1000 → 8 0110 → 6
So (10000110)2 = (86)16
State De Morgan's laws.
(i) NOT (A AND B) = (NOT A) OR (NOT B). (ii) NOT (A OR B) = (NOT A) AND (NOT B). In words: the complement of a product is the sum of the complements, and the complement of a sum is the product of the complements.
What is encoding? Name any three encoding schemes.
Encoding is the way of giving a unique code (number) to every character so that a computer can store it. Schemes: ASCII, ISCII, Unicode (UTF-8, UTF-16, UTF-32).
Convert: (i) (111100)2 to hexadecimal (ii) (109)10 to hexadecimal
(i)
Make groups of 4 bits from the right: 0011 1100
0011 → 3 1100 → C
So (111100)2 = (3C)16
(ii)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 109 | D |
| 16 | 6 | 6 |
Read the remainders from bottom to top: (6D)16
Draw the symbols and write the truth table of the XOR gate.
XOR gives 1 when the inputs are different. Truth table: 0 0 → 0; 0 1 → 1; 1 0 → 1; 1 1 → 0. Symbol: an OR gate with an extra curved line on the input side.
Truth table: 0 0 → 0, 0 1 → 1, 1 0 → 1, 1 1 → 0 (output is 1 only when the inputs are different). Expression: Y = A ⊕ B = A·B̄ + Ā·B.
Convert: (i) (11100100)2 to hexadecimal (ii) (210)8 to binary
(i)
Make groups of 4 bits from the right: 1110 0100
1110 → E 0100 → 4
So (11100100)2 = (E4)16
(ii)
Write each digit as 3 bits: 2 → 010 1 → 001 0 → 000
So (210)8 = (10001000)2
Convert: (i) (40)8 to decimal (ii) (D0)16 to decimal
(i)
(40)8 = 4 × 81 + 0 × 80 = 32 + 0 = 32
(ii)
(D0)16 = D × 161 + 0 × 160 = 208 + 0 = 208
Convert: (i) (111111)2 to decimal (ii) (11001000)2 to hexadecimal
(i)
(111111)2 = 1 × 25 + 1 × 24 + 1 × 23 + 1 × 22 + 1 × 21 + 1 × 20 = 32 + 16 + 8 + 4 + 2 + 1 = 63
(ii)
Make groups of 4 bits from the right: 1100 1000
1100 → C 1000 → 8
So (11001000)2 = (C8)16
Convert: (i) (210)8 to decimal (ii) (11111111)2 to hexadecimal
(i)
(210)8 = 2 × 82 + 1 × 81 + 0 × 80 = 128 + 8 + 0 = 136
(ii)
Make groups of 4 bits from the right: 1111 1111
1111 → F 1111 → F
So (11111111)2 = (FF)16
Convert: (i) (153)8 to hexadecimal (ii) (120)10 to hexadecimal
(i)
Write each digit as 3 bits: 1 → 001 5 → 101 3 → 011
So (153)8 = (1101011)2
Make groups of 4 bits from the right: 0110 1011
0110 → 6 1011 → B
So (1101011)2 = (6B)16
(ii)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 120 | 8 |
| 16 | 7 | 7 |
Read the remainders from bottom to top: (78)16
Name the three types of buses and what each carries.
Data bus: carries data. Address bus: carries the address of the memory location. Control bus: carries control signals such as read and write.
Convert: (i) (107)8 to hexadecimal (ii) (11100011)2 to octal
(i)
Write each digit as 3 bits: 1 → 001 0 → 000 7 → 111
So (107)8 = (1000111)2
Make groups of 4 bits from the right: 0100 0111
0100 → 4 0111 → 7
So (1000111)2 = (47)16
(ii)
Make groups of 3 bits from the right: 011 100 011
011 → 3 100 → 4 011 → 3
So (11100011)2 = (343)8
Draw the truth table for the Boolean expression (A AND NOT B) OR (B AND C).
| A | B | C | (A AND NOT B) OR (B AND C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
The output is 1 in 4 of the 8 rows.
Convert: (i) (131)10 to hexadecimal (ii) (A4)16 to octal
(i)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 131 | 3 |
| 16 | 8 | 8 |
Read the remainders from bottom to top: (83)16
(ii)
Write each digit as 4 bits: A → 1010 4 → 0100
So (A4)16 = (10100100)2
Make groups of 3 bits from the right: 010 100 100
010 → 2 100 → 4 100 → 4
So (10100100)2 = (244)8
Convert: (i) (266)8 to decimal (ii) (180)10 to octal
(i)
(266)8 = 2 × 82 + 6 × 81 + 6 × 80 = 128 + 48 + 6 = 182
(ii)
| Divide by | Number | Remainder |
|---|---|---|
| 8 | 180 | 4 |
| 8 | 22 | 6 |
| 8 | 2 | 2 |
Read the remainders from bottom to top: (264)8
Convert: (i) (246)8 to decimal (ii) (147)10 to hexadecimal
(i)
(246)8 = 2 × 82 + 4 × 81 + 6 × 80 = 128 + 32 + 6 = 166
(ii)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 147 | 3 |
| 16 | 9 | 9 |
Read the remainders from bottom to top: (93)16
Draw the truth table for the Boolean expression NOT (A OR B) AND C.
| A | B | C | NOT (A OR B) AND C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
The output is 1 in 1 of the 8 rows.
Convert: (i) (43)8 to binary (ii) (316)8 to decimal
(i)
Write each digit as 3 bits: 4 → 100 3 → 011
So (43)8 = (100011)2
(ii)
(316)8 = 3 × 82 + 1 × 81 + 6 × 80 = 192 + 8 + 6 = 206
Differentiate between UTF-8 and UTF-32.
UTF-8 is variable length: 1 to 4 bytes per character; English letters take 1 byte, so it saves space. UTF-32 is fixed length: every character takes 4 bytes.
Draw the truth table for the Boolean expression A AND B AND NOT C.
| A | B | C | A AND B AND NOT C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
The output is 1 in 1 of the 8 rows.
What is an operating system? Write any two of its functions.
The operating system is system software that manages the hardware and gives a platform for other programs. Functions: process management, memory management, file management, device management, user interface. (Any two.)
Draw the truth table for the Boolean expression NOT (A AND B).
| A | B | NOT (A AND B) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
The output is 1 in 3 of the 4 rows.
Draw the truth table for the Boolean expression (NOT A) OR B.
| A | B | (NOT A) OR B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
The output is 1 in 3 of the 4 rows.
Convert: (i) (233)10 to hexadecimal (ii) (365)8 to binary
(i)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 233 | 9 |
| 16 | 14 | E |
Read the remainders from bottom to top: (E9)16
(ii)
Write each digit as 3 bits: 3 → 011 6 → 110 5 → 101
So (365)8 = (11110101)2
Convert: (i) (216)8 to binary (ii) (142)10 to hexadecimal
(i)
Write each digit as 3 bits: 2 → 010 1 → 001 6 → 110
So (216)8 = (10001110)2
(ii)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 142 | E |
| 16 | 8 | 8 |
Read the remainders from bottom to top: (8E)16
Differentiate between ASCII and Unicode.
ASCII uses 7 bits and has 128 codes, only for English letters, digits and symbols. Unicode can represent the characters of almost all the scripts of the world (over a million code points) using UTF-8, UTF-16 or UTF-32.
Draw the truth table for the Boolean expression A AND (B OR C).
| A | B | C | A AND (B OR C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
The output is 1 in 3 of the 8 rows.
Convert: (i) (45)10 to hexadecimal (ii) (1001100)2 to octal
(i)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 45 | D |
| 16 | 2 | 2 |
Read the remainders from bottom to top: (2D)16
(ii)
Make groups of 3 bits from the right: 001 001 100
001 → 1 001 → 1 100 → 4
So (1001100)2 = (114)8
Differentiate between system software and application software with one example each.
System software runs and manages the computer: operating system, device drivers, utilities (e.g. Windows). Application software does a task for the user: word processing, billing, games (e.g. LibreOffice Writer).
Convert: (i) (198)10 to octal (ii) (A1)16 to octal
(i)
| Divide by | Number | Remainder |
|---|---|---|
| 8 | 198 | 6 |
| 8 | 24 | 0 |
| 8 | 3 | 3 |
Read the remainders from bottom to top: (306)8
(ii)
Write each digit as 4 bits: A → 1010 1 → 0001
So (A1)16 = (10100001)2
Make groups of 3 bits from the right: 010 100 001
010 → 2 100 → 4 001 → 1
So (10100001)2 = (241)8
Draw the truth table for the Boolean expression A AND (NOT B).
| A | B | A AND (NOT B) |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
The output is 1 in 1 of the 4 rows.
Convert: (i) (69)16 to octal (ii) (119)10 to binary
(i)
Write each digit as 4 bits: 6 → 0110 9 → 1001
So (69)16 = (1101001)2
Make groups of 3 bits from the right: 001 101 001
001 → 1 101 → 5 001 → 1
So (1101001)2 = (151)8
(ii)
| Divide by | Number | Remainder |
|---|---|---|
| 2 | 119 | 1 |
| 2 | 59 | 1 |
| 2 | 29 | 1 |
| 2 | 14 | 0 |
| 2 | 7 | 1 |
| 2 | 3 | 1 |
| 2 | 1 | 1 |
Read the remainders from bottom to top: (1110111)2
Convert: (i) (189)10 to octal (ii) (166)8 to decimal
(i)
| Divide by | Number | Remainder |
|---|---|---|
| 8 | 189 | 5 |
| 8 | 23 | 7 |
| 8 | 2 | 2 |
Read the remainders from bottom to top: (275)8
(ii)
(166)8 = 1 × 82 + 6 × 81 + 6 × 80 = 64 + 48 + 6 = 118
Differentiate between a compiler and an interpreter.
A compiler translates the whole program at once and lists all the errors together; the machine code can be run again without translating. An interpreter translates and runs one line at a time and stops at the first error. Python uses an interpreter.
What is cache memory? Why is it used?
Cache is a small, very fast memory between the CPU and RAM. It keeps the data and instructions the CPU uses often, so the CPU waits less and the computer works faster.
Convert: (i) (1010001)2 to decimal (ii) (1E)16 to binary
(i)
(1010001)2 = 1 × 26 + 0 × 25 + 1 × 24 + 0 × 23 + 0 × 22 + 0 × 21 + 1 × 20 = 64 + 0 + 16 + 0 + 0 + 0 + 1 = 81
(ii)
Write each digit as 4 bits: 1 → 0001 E → 1110
So (1E)16 = (11110)2
Convert: (i) (234)8 to decimal (ii) (350)8 to hexadecimal
(i)
(234)8 = 2 × 82 + 3 × 81 + 4 × 80 = 128 + 24 + 4 = 156
(ii)
Write each digit as 3 bits: 3 → 011 5 → 101 0 → 000
So (350)8 = (11101000)2
Make groups of 4 bits from the right: 1110 1000
1110 → E 1000 → 8
So (11101000)2 = (E8)16
Convert: (i) (133)10 to binary (ii) (206)10 to octal
(i)
| Divide by | Number | Remainder |
|---|---|---|
| 2 | 133 | 1 |
| 2 | 66 | 0 |
| 2 | 33 | 1 |
| 2 | 16 | 0 |
| 2 | 8 | 0 |
| 2 | 4 | 0 |
| 2 | 2 | 0 |
| 2 | 1 | 1 |
Read the remainders from bottom to top: (10000101)2
(ii)
| Divide by | Number | Remainder |
|---|---|---|
| 8 | 206 | 6 |
| 8 | 25 | 1 |
| 8 | 3 | 3 |
Read the remainders from bottom to top: (316)8
Convert: (i) (103)8 to binary (ii) (60)16 to octal
(i)
Write each digit as 3 bits: 1 → 001 0 → 000 3 → 011
So (103)8 = (1000011)2
(ii)
Write each digit as 4 bits: 6 → 0110 0 → 0000
So (60)16 = (1100000)2
Make groups of 3 bits from the right: 001 100 000
001 → 1 100 → 4 000 → 0
So (1100000)2 = (140)8
Convert: (i) (175)8 to decimal (ii) (37)10 to octal
(i)
(175)8 = 1 × 82 + 7 × 81 + 5 × 80 = 64 + 56 + 5 = 125
(ii)
| Divide by | Number | Remainder |
|---|---|---|
| 8 | 37 | 5 |
| 8 | 4 | 4 |
Read the remainders from bottom to top: (45)8
Draw the truth table for the Boolean expression (A OR NOT B) AND (B OR C).
| A | B | C | (A OR NOT B) AND (B OR C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
The output is 1 in 4 of the 8 rows.
Convert: (i) (83)10 to hexadecimal (ii) (11101010)2 to hexadecimal
(i)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 83 | 3 |
| 16 | 5 | 5 |
Read the remainders from bottom to top: (53)16
(ii)
Make groups of 4 bits from the right: 1110 1010
1110 → E 1010 → A
So (11101010)2 = (EA)16
Differentiate between RAM and ROM (any two points).
RAM is volatile: it loses data when the power is off; it can be read and written; it holds the programs being run. ROM is non-volatile; it can only be read; it holds the start-up (boot) instructions.
Draw the truth table for the Boolean expression NOT A OR (B AND C).
| A | B | C | NOT A OR (B AND C) |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
The output is 1 in 5 of the 8 rows.
Arrange in increasing order of speed: RAM, hard disk, registers, cache. Which of these are volatile?
Hard disk < RAM < cache < registers. RAM, cache and registers are volatile; the hard disk is not.
Convert: (i) (200)10 to hexadecimal (ii) (CF)16 to octal
(i)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 200 | 8 |
| 16 | 12 | C |
Read the remainders from bottom to top: (C8)16
(ii)
Write each digit as 4 bits: C → 1100 F → 1111
So (CF)16 = (11001111)2
Make groups of 3 bits from the right: 011 001 111
011 → 3 001 → 1 111 → 7
So (11001111)2 = (317)8
Convert: (i) (55)8 to hexadecimal (ii) (10001011)2 to decimal
(i)
Write each digit as 3 bits: 5 → 101 5 → 101
So (55)8 = (101101)2
Make groups of 4 bits from the right: 0010 1101
0010 → 2 1101 → D
So (101101)2 = (2D)16
(ii)
(10001011)2 = 1 × 27 + 0 × 26 + 0 × 25 + 0 × 24 + 1 × 23 + 0 × 22 + 1 × 21 + 1 × 20 = 128 + 0 + 0 + 0 + 8 + 0 + 2 + 1 = 139
Convert: (i) (111000)2 to decimal (ii) (253)8 to hexadecimal
(i)
(111000)2 = 1 × 25 + 1 × 24 + 1 × 23 + 0 × 22 + 0 × 21 + 0 × 20 = 32 + 16 + 8 + 0 + 0 + 0 = 56
(ii)
Write each digit as 3 bits: 2 → 010 5 → 101 3 → 011
So (253)8 = (10101011)2
Make groups of 4 bits from the right: 1010 1011
1010 → A 1011 → B
So (10101011)2 = (AB)16
What is an algorithm? Write two characteristics of a good algorithm.
An algorithm is a finite, step-by-step set of instructions to solve a problem. A good algorithm has: clear and unambiguous steps, defined input and output, a finite number of steps, and it is correct and efficient. (Any two.)
Differentiate between a flowchart and pseudocode.
A flowchart shows the steps of an algorithm as a picture with standard symbols joined by arrows. Pseudocode writes the steps in simple English-like statements, close to a program but without exact syntax.
Write an algorithm to find the larger of two numbers.
Step 1: Start. Step 2: Input A and B. Step 3: If A > B then print A, else print B. Step 4: Stop.
Write pseudocode to print the sum of the first N natural numbers.
INPUT N; SET sum = 0; FOR i = 1 TO N: sum = sum + i; END FOR; PRINT sum.
What is decomposition? Give an example.
Decomposition is breaking a big problem into smaller parts that are easier to solve. Example: a school result system is split into entering marks, calculating totals, finding grades and printing report cards.
Draw a flowchart to check whether a number is even or odd. (Describe the boxes.)
Oval Start → Parallelogram: input N → Diamond: N % 2 == 0? → Yes: parallelogram print 'Even'; No: parallelogram print 'Odd' → Oval Stop.
What is verification of an algorithm? Why is it needed?
Verification is checking that the algorithm gives the correct output for all valid inputs, by a dry run with sample values. It is needed to catch errors before the program is written.
Differentiate between interactive mode and script mode of Python.
Interactive mode: statements are typed one at a time at the >>> prompt and the result is shown at once; the work is not saved. Script mode: the program is written in a .py file, saved, and run as a whole.
What are tokens? Name the types of tokens in Python.
Tokens are the smallest units of a program. Types: keywords, identifiers, literals, operators and punctuators (delimiters).
Write any four rules for naming an identifier in Python.
It can have letters, digits and the underscore; it cannot start with a digit; it cannot be a keyword; it cannot have spaces or special symbols such as @, $, -; it is case sensitive.
Differentiate between mutable and immutable data types with examples.
Mutable objects can be changed in place after creation: list, dictionary. Immutable objects cannot be changed; a change creates a new object: int, float, str, tuple.
Differentiate between = and == in Python.
= is the assignment operator; it gives a value to a variable: x = 5. == is a relational operator; it compares two values and gives True or False: x == 5.
Differentiate between / and // with examples.
/ is true division and always gives a float: 7 / 2 = 3.5. // is floor division and gives the quotient rounded down: 7 // 2 = 3, -7 // 2 = -4.
What is type conversion? Explain its two kinds with an example each.
Changing a value from one data type to another. Implicit: done by Python on its own, e.g. 3 + 2.5 gives 5.5 (int to float). Explicit: done by the programmer using functions, e.g. int('25') gives 25.
Name the three types of errors with one example each.
Syntax error: wrong grammar, e.g. a missing colon after if. Runtime error: occurs while running, e.g. 5 / 0 gives ZeroDivisionError. Logical error: wrong output, e.g. using + in place of * in a formula.
What is the difference between a keyword and an identifier?
A keyword is a reserved word with a fixed meaning in Python (if, for, while, True). An identifier is a name given by the programmer to a variable, function, etc. (marks, total_1). A keyword cannot be used as an identifier.
What is a literal? Name any three kinds of literals.
A literal is a fixed data value written in the program. Kinds: numeric literals (10, 3.5), string literals ('KV'), Boolean literals (True, False), the special literal None, and collection literals ([1, 2]).
Explain the use of id() and type() functions with an example.
id(x) gives the identity (memory address) of the object x. type(x) gives the data type of x. Example: x = 5; type(x) gives <class 'int'>.
What is the difference between the is and == operators?
== checks whether two values are equal. is checks whether two names refer to the same object in memory. a = [1]; b = [1]: a == b is True but a is b is False.
Write the precedence of these operators from highest to lowest: +, **, not, *, and, <
** , then * , then + , then < , then not , then and.
Differentiate between break and continue.
break ends the loop at once and control goes to the statement after the loop. continue skips the rest of the current round and the loop goes to its next round.
Differentiate between a for loop and a while loop.
A for loop runs over a sequence or range; it is used when the number of rounds is known. A while loop runs as long as a condition is True; it is used when the number of rounds is not known in advance.
What is an infinite loop? Give an example.
A loop whose condition never becomes False, so it never ends. Example: i = 1; while i > 0: i = i + 1
Explain range() with its three parameters, using an example.
range(start, stop, step) gives numbers from start up to stop - 1, jumping by step. Default start is 0 and step is 1. range(2, 11, 3) gives 2, 5, 8.
What is the use of the else clause with a loop?
The else block of a loop runs after the loop ends normally, that is, when no break was executed. It is useful in searching: print 'not found' in the else block.
Rewrite using a while loop:
for i in range(10, 0, -2):
print(i)i = 10
while i > 0:
print(i)
i = i - 2Rewrite using a for loop:
n = 1
while n <= 15:
print(n * n)
n += 3for n in range(1, 16, 3):
print(n * n)Differentiate between find() and index() methods of a string.
Both return the lowest index where the substring is found. If it is not found, find() returns -1, but index() raises ValueError.
Differentiate between split() and partition().
split() breaks the string at every separator and returns a list of any length. partition() breaks it only at the first separator and returns a tuple of exactly three parts: before, separator, after.
What is meant by 'strings are immutable'? Give an example.
A string cannot be changed after it is created. s = 'Kite'; s[0] = 'B' gives TypeError. To change it, make a new string: s = 'B' + s[1:].
Explain any two of: isalnum(), isspace(), istitle(), endswith().
isalnum(): True if all characters are letters or digits. isspace(): True if all characters are white space. istitle(): True if every word starts with a capital letter. endswith(x): True if the string ends with x.
Differentiate between append() and extend().
append(x) adds x as one single element at the end; the length increases by 1. extend(L2) adds each element of L2 at the end; the length increases by len(L2).
Differentiate between remove() and pop().
remove(x) deletes the first element equal to x and returns nothing. pop(i) deletes the element at index i (the last one if no index is given) and returns it.
Differentiate between sort() and sorted().
L.sort() arranges L itself and returns None; it works only on lists. sorted(seq) returns a new sorted list and leaves the original unchanged; it works on any sequence.
Write the difference between a list and a string.
A list is mutable and can hold elements of any type. A string is immutable and holds only characters. Both support indexing, slicing, + and *.
What is a nested list? How is an element of it accessed?
A list inside another list. L = [[1, 2], [3, 4]]: L[1][0] gives 3 (row 1, item 0).
Differentiate between a list and a tuple.
A list is mutable, written in [ ], has methods like append and remove. A tuple is immutable, written in ( ), has only count and index. Tuples are faster and can be dictionary keys.
Differentiate between a list and a dictionary.
A list is an ordered sequence accessed by an integer index. A dictionary stores key: value pairs and is accessed by keys, which must be unique and immutable.
Differentiate between pop() and popitem() of a dictionary.
pop(key) removes the given key and returns its value. popitem() removes and returns the last inserted (key, value) pair.
What is tuple packing and unpacking? Give an example.
Packing: T = 10, 20, 30 puts the values in one tuple. Unpacking: a, b, c = T takes them out into three variables.
Explain keys(), values() and items() with an example.
D = {'a': 1, 'b': 2}. D.keys() gives dict_keys(['a', 'b']); D.values() gives dict_values([1, 2]); D.items() gives dict_items([('a', 1), ('b', 2)]).
Differentiate between import math and from math import sqrt.
import math loads the whole module; functions are called as math.sqrt(16). from math import sqrt brings only sqrt; it is called directly as sqrt(16).
Differentiate between random.randint() and random.randrange().
randint(a, b) returns a random integer from a to b, both included. randrange(a, b, step) returns a random value from range(a, b, step), so b is not included.
What is a module? Name any three built-in modules of Python with one function each.
A module is a file of Python code with functions and variables that can be imported and used. math: sqrt(); random: randint(); statistics: mean().
Write the use of: math.ceil(), math.fabs(), statistics.median().
ceil(x): smallest integer not less than x, ceil(4.2) = 5. fabs(x): absolute value as a float, fabs(-3) = 3.0. median(data): middle value of the sorted data.
Write the output of the following code.
for i in range(1, 5):
for j in range(i):
print(i, end="")
print()Output:
1 22 333 4444
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(1, 5): | i = 1 | |
| 2 | for j in range(i): | j = 0 | |
| 3 | print(i, end="") | 1 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 5): | i = 2 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 3 | print(i, end="") | 2 | |
| 2 | for j in range(i): | j = 1 | |
| 3 | print(i, end="") | 2 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 5): | i = 3 | |
| 2 | for j in range(i): | j = 0 | |
| 3 | print(i, end="") | 3 | |
| 2 | for j in range(i): | j = 1 |
… the same steps continue for the remaining values.
Write the output of the following code.
for i in range(1, 4):
for j in range(1, i + 1):
print(j * i, end=" ")
print()Output:
1 2 4 3 6 9
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(1, 4): | i = 1 | |
| 2 | for j in range(1, i + 1): | j = 1 | |
| 3 | print(j * i, end=" ") | 1 | |
| 2 | for j in range(1, i + 1): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 4): | i = 2 | |
| 2 | for j in range(1, i + 1): | loop ends (no more values) | |
| 3 | print(j * i, end=" ") | 2 | |
| 2 | for j in range(1, i + 1): | j = 2 | |
| 3 | print(j * i, end=" ") | 4 | |
| 2 | for j in range(1, i + 1): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 4): | i = 3 | |
| 2 | for j in range(1, i + 1): | j = 1 | |
| 3 | print(j * i, end=" ") | 3 | |
| 2 | for j in range(1, i + 1): | j = 2 |
… the same steps continue for the remaining values.
Write the output of the following code.
for i in range(1, 5):
for j in range(1, i + 1):
print(j * i, end=" ")
print()Output:
1 2 4 3 6 9 4 8 12 16
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(1, 5): | i = 1 | |
| 2 | for j in range(1, i + 1): | j = 1 | |
| 3 | print(j * i, end=" ") | 1 | |
| 2 | for j in range(1, i + 1): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 5): | i = 2 | |
| 2 | for j in range(1, i + 1): | loop ends (no more values) | |
| 3 | print(j * i, end=" ") | 2 | |
| 2 | for j in range(1, i + 1): | j = 2 | |
| 3 | print(j * i, end=" ") | 4 | |
| 2 | for j in range(1, i + 1): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 5): | i = 3 | |
| 2 | for j in range(1, i + 1): | j = 1 | |
| 3 | print(j * i, end=" ") | 3 | |
| 2 | for j in range(1, i + 1): | j = 2 |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'b': 4, 'a': 18, 'e': 3, 'c': 12}
total = 0
for k in D:
if D[k] > 4:
total += D[k]
print(k, end=" ")
print(total)Output:
a c 30
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'b': 4, 'a': 18, 'e': 3, 'c': 12} | D = {'b': 4, 'a': 18, 'e': 3, 'c': 12} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 4: | condition is False | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 4: | condition is True | |
| 5 | total += D[k] | total = 18 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 4: | condition is False | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 4: | condition is True | |
| 5 | total += D[k] | total = 30 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 30⏎ |
Write the output of the following code.
s = "learn code daily"
W = s.split()
W.reverse()
print(" ".join(W).title())Output:
Daily Code Learn
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "learn code daily" | s = 'learn code daily' | |
| 2 | W = s.split() | W = ['learn', 'code', 'daily'] | |
| 3 | W.reverse() | W = ['daily', 'code', 'learn'] | |
| 4 | print(" ".join(W).title()) | Daily Code Learn⏎ |
Write the output of the following code.
for i in range(1, 4):
for j in range(i):
print(i, end="")
print()Output:
1 22 333
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(1, 4): | i = 1 | |
| 2 | for j in range(i): | j = 0 | |
| 3 | print(i, end="") | 1 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 4): | i = 2 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 3 | print(i, end="") | 2 | |
| 2 | for j in range(i): | j = 1 | |
| 3 | print(i, end="") | 2 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 4): | i = 3 | |
| 2 | for j in range(i): | j = 0 | |
| 3 | print(i, end="") | 3 | |
| 2 | for j in range(i): | j = 1 |
… the same steps continue for the remaining values.
Write the output of the following code.
n = 75259
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
95257
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 75259 | n = 75259 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 | |
| 5 | s = s * 10 + d | s = 9 | |
| 6 | n = n // 10 | n = 7525 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 5 | |
| 5 | s = s * 10 + d | s = 95 | |
| 6 | n = n // 10 | n = 752 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 | |
| 5 | s = s * 10 + d | s = 952 | |
| 6 | n = n // 10 | n = 75 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 5 |
… the same steps continue for the remaining values.
Write the output of the following code.
s = "Learn Code Daily"
for ch in s:
if ch.isupper():
print(ch.lower(), end="")
elif ch == " ":
print("*", end="")
else:
print(ch.upper(), end="")Output:
lEARN*cODE*dAILY
Each upper-case letter becomes lower case, each space becomes the symbol, and every other character becomes upper case.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Learn Code Daily" | s = 'Learn Code Daily' | |
| 2 | for ch in s: | ch = 'L' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | l | |
| 2 | for ch in s: | ch = 'e' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | E | |
| 2 | for ch in s: | ch = 'a' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | A | |
| 2 | for ch in s: | ch = 'r' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | R |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'c': 7, 'b': 6, 'e': 4, 'a': 1}
total = 0
for k in D:
if D[k] > 10:
total += D[k]
print(k, end=" ")
print(total)Output:
0
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'c': 7, 'b': 6, 'e': 4, 'a': 1} | D = {'c': 7, 'b': 6, 'e': 4, 'a': 1} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 10: | condition is False | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 10: | condition is False | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 10: | condition is False | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 10: | condition is False | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 0⏎ |
Write the output of the following code.
D = {'b': 18, 'c': 19, 'd': 14, 'a': 15}
total = 0
for k in D:
if D[k] > 12:
total += D[k]
print(k, end=" ")
print(total)Output:
b c d a 66
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'b': 18, 'c': 19, 'd': 14, 'a': 15} | D = {'b': 18, 'c': 19, 'd': 14, 'a': 15} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 12: | condition is True | |
| 5 | total += D[k] | total = 18 | |
| 6 | print(k, end=" ") | b | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 12: | condition is True | |
| 5 | total += D[k] | total = 37 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 12: | condition is True | |
| 5 | total += D[k] | total = 51 | |
| 6 | print(k, end=" ") | d | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 12: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
x, y = 7, 11
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
14 10
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 7, 11 | x = 7, y = 11 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 14 | |
| 4 | y = y - 1 | y = 10 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 14 10⏎ |
Write the output of the following code.
L = [2, 8, 3, 3, 4, 2]
S = []
for x in L:
if x not in S:
S.append(x)
print(S, len(L) - len(S))Output:
[2, 8, 3, 4] 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [2, 8, 3, 3, 4, 2] | L = [2, 8, 3, 3, 4, 2] | |
| 2 | S = [] | S = [] | |
| 3 | for x in L: | x = 2 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [2] | |
| 3 | for x in L: | x = 8 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [2, 8] | |
| 3 | for x in L: | x = 3 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [2, 8, 3] | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | if x not in S: | condition is False | |
| 3 | for x in L: | x = 4 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [2, 8, 3, 4] |
… the same steps continue for the remaining values.
Write the output of the following code.
s = "KENDRIYA"
t = ""
for i in range(len(s)):
if i % 2 == 0:
t = t + s[i]
else:
t = s[i] + t
print(t)Output:
AIDEKNRY
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "KENDRIYA" | s = 'KENDRIYA' | |
| 2 | t = "" | t = '' | |
| 3 | for i in range(len(s)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | t = t + s[i] | t = 'K' | |
| 3 | for i in range(len(s)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | t = s[i] + t | t = 'EK' | |
| 3 | for i in range(len(s)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | t = t + s[i] | t = 'EKN' | |
| 3 | for i in range(len(s)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | t = s[i] + t | t = 'DEKN' | |
| 3 | for i in range(len(s)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
n = 78519
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
91587
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 78519 | n = 78519 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 | |
| 5 | s = s * 10 + d | s = 9 | |
| 6 | n = n // 10 | n = 7851 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 1 | |
| 5 | s = s * 10 + d | s = 91 | |
| 6 | n = n // 10 | n = 785 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 5 | |
| 5 | s = s * 10 + d | s = 915 | |
| 6 | n = n // 10 | n = 78 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 8 |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'d': 6, 'e': 8, 'c': 10, 'a': 13}
total = 0
for k in D:
if D[k] > 9:
total += D[k]
print(k, end=" ")
print(total)Output:
c a 23
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'d': 6, 'e': 8, 'c': 10, 'a': 13} | D = {'d': 6, 'e': 8, 'c': 10, 'a': 13} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 9: | condition is False | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 9: | condition is False | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 9: | condition is True | |
| 5 | total += D[k] | total = 10 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 9: | condition is True | |
| 5 | total += D[k] | total = 23 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 23⏎ |
Write the output of the following code.
x, y = 8, 21
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
32 19
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 8, 21 | x = 8, y = 21 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 16 | |
| 4 | y = y - 1 | y = 20 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 32 | |
| 4 | y = y - 1 | y = 19 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 32 19⏎ |
Write the output of the following code.
for i in range(1, 5):
print(" " * (4 - i) + "#" * i)Output:
# ## ### ####
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(1, 5): | i = 1 | |
| 2 | print(" " * (4 - i) + "#" * i) | #⏎ | |
| 1 | for i in range(1, 5): | i = 2 | |
| 2 | print(" " * (4 - i) + "#" * i) | ##⏎ | |
| 1 | for i in range(1, 5): | i = 3 | |
| 2 | print(" " * (4 - i) + "#" * i) | ###⏎ | |
| 1 | for i in range(1, 5): | i = 4 | |
| 2 | print(" " * (4 - i) + "#" * i) | ####⏎ | |
| 1 | for i in range(1, 5): | loop ends (no more values) |
Write the output of the following code.
T = (29, 39, 5, 9, 38) L = list(T) L.append(T[1] + T[2]) L.sort() print(L[:3], len(L))
Output:
[5, 9, 29] 6
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (29, 39, 5, 9, 38) | T = (29, 39, 5, 9, 38) | |
| 2 | L = list(T) | L = [29, 39, 5, 9, 38] | |
| 3 | L.append(T[1] + T[2]) | L = [29, 39, 5, 9, 38, 44] | |
| 4 | L.sort() | L = [5, 9, 29, 38, 39, 44] | |
| 5 | print(L[:3], len(L)) | [5, 9, 29] 6⏎ |
Write the output of the following code.
a = 3
b = 11
if a % 2 == 0 and b % 2 == 0:
print(a + b)
elif a % 2 == 0 or b > 20:
print(a * b)
else:
print(b - a)Output:
8
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | a = 3 | a = 3 | |
| 2 | b = 11 | b = 11 | |
| 3 | if a % 2 == 0 and b % 2 == 0: | condition is False | |
| 5 | elif a % 2 == 0 or b > 20: | condition is False | |
| 8 | print(b - a) | 8⏎ |
Write the output of the following code.
s = "India is Great"
for ch in s:
if ch.isupper():
print(ch.lower(), end="")
elif ch == " ":
print("#", end="")
else:
print(ch.upper(), end="")Output:
iNDIA#IS#gREAT
Each upper-case letter becomes lower case, each space becomes the symbol, and every other character becomes upper case.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "India is Great" | s = 'India is Great' | |
| 2 | for ch in s: | ch = 'I' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | i | |
| 2 | for ch in s: | ch = 'n' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | N | |
| 2 | for ch in s: | ch = 'd' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | D | |
| 2 | for ch in s: | ch = 'i' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | I |
… the same steps continue for the remaining values.
Write the output of the following code.
s = "Data and Logic"
W = s.split()
for w in W:
print(w[0] + str(len(w)), end=" ")Output:
D4 a3 L5
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Data and Logic" | s = 'Data and Logic' | |
| 2 | W = s.split() | W = ['Data', 'and', 'Logic'] | |
| 3 | for w in W: | w = 'Data' | |
| 4 | print(w[0] + str(len(w)), end=" ") | D4 | |
| 3 | for w in W: | w = 'and' | |
| 4 | print(w[0] + str(len(w)), end=" ") | a3 | |
| 3 | for w in W: | w = 'Logic' | |
| 4 | print(w[0] + str(len(w)), end=" ") | L5 | |
| 3 | for w in W: | loop ends (no more values) |
Write the output of the following code.
s = "cbse exam 2027"
W = s.split()
W.reverse()
print(" ".join(W).title())Output:
2027 Exam Cbse
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "cbse exam 2027" | s = 'cbse exam 2027' | |
| 2 | W = s.split() | W = ['cbse', 'exam', '2027'] | |
| 3 | W.reverse() | W = ['2027', 'exam', 'cbse'] | |
| 4 | print(" ".join(W).title()) | 2027 Exam Cbse⏎ |
Write the output of the following code.
L = [16, 9, 28, 24, 21, 17]
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] = L[i] // 3
else:
L[i] = L[i] * 2
print(L)Output:
[5, 18, 9, 8, 42, 34]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [16, 9, 28, 24, 21, 17] | L = [16, 9, 28, 24, 21, 17] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [5, 9, 28, 24, 21, 17] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [5, 18, 28, 24, 21, 17] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [5, 18, 9, 24, 21, 17] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [5, 18, 9, 8, 21, 17] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [5, 18, 9, 8, 42, 17] |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [20, 14, 12, 27, 10, 19]
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] = L[i] // 3
else:
L[i] = L[i] * 2
print(L)Output:
[6, 4, 4, 54, 3, 38]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [20, 14, 12, 27, 10, 19] | L = [20, 14, 12, 27, 10, 19] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [6, 14, 12, 27, 10, 19] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [6, 4, 12, 27, 10, 19] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [6, 4, 4, 27, 10, 19] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [6, 4, 4, 54, 10, 19] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [6, 4, 4, 54, 3, 19] |
… the same steps continue for the remaining values.
Write the output of the following code.
x, y = 9, 30
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
36 28
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 9, 30 | x = 9, y = 30 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 18 | |
| 4 | y = y - 1 | y = 29 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 36 | |
| 4 | y = y - 1 | y = 28 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 36 28⏎ |
Write the output of the following code.
n = 2287
s = 0
while n > 0:
d = n % 10
if d % 2 == 0:
s = s + d
n = n // 10
print(s)Output:
12
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 2287 | n = 2287 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 228 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 8 | |
| 5 | if d % 2 == 0: | condition is True | |
| 6 | s = s + d | s = 8 | |
| 7 | n = n // 10 | n = 22 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 | |
| 5 | if d % 2 == 0: | condition is True | |
| 6 | s = s + d | s = 10 | |
| 7 | n = n // 10 | n = 2 |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [26, 10, 27, 19, 23, 17]
for i in range(len(L)):
if L[i] % 5 == 0:
L[i] = L[i] // 3
else:
L[i] = L[i] * 2
print(L)Output:
[52, 3, 54, 38, 46, 34]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [26, 10, 27, 19, 23, 17] | L = [26, 10, 27, 19, 23, 17] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 10, 27, 19, 23, 17] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 5 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [52, 3, 27, 19, 23, 17] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 3, 54, 19, 23, 17] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 3, 54, 38, 23, 17] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 3, 54, 38, 46, 17] |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'b': 10, 'e': 18, 'a': 19, 'd': 12}
total = 0
for k in D:
if D[k] > 7:
total += D[k]
print(k, end=" ")
print(total)Output:
b e a d 59
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'b': 10, 'e': 18, 'a': 19, 'd': 12} | D = {'b': 10, 'e': 18, 'a': 19, 'd': 12} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 7: | condition is True | |
| 5 | total += D[k] | total = 10 | |
| 6 | print(k, end=" ") | b | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 7: | condition is True | |
| 5 | total += D[k] | total = 28 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 7: | condition is True | |
| 5 | total += D[k] | total = 47 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 7: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
s = "COMPUTER"
print(s.count("M"), s.find("ER"), s[2:6].upper())Output:
1 6 MPUT
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "COMPUTER" | s = 'COMPUTER' | |
| 2 | print(s.count("M"), s.find("ER"), s[2:6].upper()) | 1 6 MPUT⏎ |
Write the output of the following code.
s = "Program"
t = ""
for i in range(len(s)):
if i % 2 == 0:
t = t + s[i]
else:
t = s[i] + t
print(t)Output:
agrPorm
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Program" | s = 'Program' | |
| 2 | t = "" | t = '' | |
| 3 | for i in range(len(s)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | t = t + s[i] | t = 'P' | |
| 3 | for i in range(len(s)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | t = s[i] + t | t = 'rP' | |
| 3 | for i in range(len(s)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | t = t + s[i] | t = 'rPo' | |
| 3 | for i in range(len(s)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | t = s[i] + t | t = 'grPo' | |
| 3 | for i in range(len(s)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
s = "Monitor" print(s[1:5], s[-3:], s[::3])
Output:
onit tor Mir
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Monitor" | s = 'Monitor' | |
| 2 | print(s[1:5], s[-3:], s[::3]) | onit tor Mir⏎ |
Write the output of the following code.
L = [3, 9, 3, 1, 9, 9]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{3: 2, 9: 3, 1: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [3, 9, 3, 1, 9, 9] | L = [3, 9, 3, 1, 9, 9] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 1} | |
| 3 | for x in L: | x = 9 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 1, 9: 1} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 9: 1} | |
| 3 | for x in L: | x = 1 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 9: 1, 1: 1} | |
| 3 | for x in L: | x = 9 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 9: 2, 1: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 9: 3, 1: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {3: 2, 9: 3, 1: 1}⏎ |
Write the output of the following code.
s = "COMPUTER"
t = ""
for i in range(len(s)):
if i % 2 == 0:
t = t + s[i]
else:
t = s[i] + t
print(t)Output:
RTPOCMUE
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "COMPUTER" | s = 'COMPUTER' | |
| 2 | t = "" | t = '' | |
| 3 | for i in range(len(s)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | t = t + s[i] | t = 'C' | |
| 3 | for i in range(len(s)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | t = s[i] + t | t = 'OC' | |
| 3 | for i in range(len(s)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | t = t + s[i] | t = 'OCM' | |
| 3 | for i in range(len(s)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | t = s[i] + t | t = 'POCM' | |
| 3 | for i in range(len(s)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
x, y = 4, 25
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
32 22
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 4, 25 | x = 4, y = 25 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 8 | |
| 4 | y = y - 1 | y = 24 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 16 | |
| 4 | y = y - 1 | y = 23 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 32 | |
| 4 | y = y - 1 | y = 22 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 32 22⏎ |
Write the output of the following code.
L = [3, 21, 19, 10, 15, 27]
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] = L[i] // 3
else:
L[i] = L[i] * 2
print(L)Output:
[6, 42, 38, 3, 30, 54]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [3, 21, 19, 10, 15, 27] | L = [3, 21, 19, 10, 15, 27] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [6, 21, 19, 10, 15, 27] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [6, 42, 19, 10, 15, 27] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [6, 42, 38, 10, 15, 27] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [6, 42, 38, 3, 15, 27] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [6, 42, 38, 3, 30, 27] |
… the same steps continue for the remaining values.
Write the output of the following code.
s = "CBSE Exam 2027"
for ch in s:
if ch.isupper():
print(ch.lower(), end="")
elif ch == " ":
print("-", end="")
else:
print(ch.upper(), end="")Output:
cbse-eXAM-2027
Each upper-case letter becomes lower case, each space becomes the symbol, and every other character becomes upper case.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "CBSE Exam 2027" | s = 'CBSE Exam 2027' | |
| 2 | for ch in s: | ch = 'C' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | c | |
| 2 | for ch in s: | ch = 'B' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | b | |
| 2 | for ch in s: | ch = 'S' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | s | |
| 2 | for ch in s: | ch = 'E' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | e | |
| 2 | for ch in s: | ch = ' ' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
T = (25, 34, 10, 2, 27) print(T[1:3] + T[-1:], T.index(2))
Output:
(34, 10, 27) 3
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (25, 34, 10, 2, 27) | T = (25, 34, 10, 2, 27) | |
| 2 | print(T[1:3] + T[-1:], T.index(2)) | (34, 10, 27) 3⏎ |
Write the output of the following code.
D = {'c': 13, 'd': 15, 'e': 14, 'a': 19}
total = 0
for k in D:
if D[k] > 5:
total += D[k]
print(k, end=" ")
print(total)Output:
c d e a 61
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'c': 13, 'd': 15, 'e': 14, 'a': 19} | D = {'c': 13, 'd': 15, 'e': 14, 'a': 19} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 13 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 28 | |
| 6 | print(k, end=" ") | d | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 42 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 5: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
n = 17629
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
92671
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 17629 | n = 17629 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 | |
| 5 | s = s * 10 + d | s = 9 | |
| 6 | n = n // 10 | n = 1762 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 | |
| 5 | s = s * 10 + d | s = 92 | |
| 6 | n = n // 10 | n = 176 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 6 | |
| 5 | s = s * 10 + d | s = 926 | |
| 6 | n = n // 10 | n = 17 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 |
… the same steps continue for the remaining values.
Write the output of the following code.
n = 66407
s = 0
while n > 0:
d = n % 10
if d % 2 == 0:
s = s + d
n = n // 10
print(s)Output:
16
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 66407 | n = 66407 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 6640 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 0 | |
| 5 | if d % 2 == 0: | condition is True | |
| 7 | n = n // 10 | n = 664 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 4 | |
| 5 | if d % 2 == 0: | condition is True | |
| 6 | s = s + d | s = 4 | |
| 7 | n = n // 10 | n = 66 | |
| 3 | while n > 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'e': 9, 'd': 11, 'a': 16, 'c': 15}
total = 0
for k in D:
if D[k] > 7:
total += D[k]
print(k, end=" ")
print(total)Output:
e d a c 51
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'e': 9, 'd': 11, 'a': 16, 'c': 15} | D = {'e': 9, 'd': 11, 'a': 16, 'c': 15} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 7: | condition is True | |
| 5 | total += D[k] | total = 9 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 7: | condition is True | |
| 5 | total += D[k] | total = 20 | |
| 6 | print(k, end=" ") | d | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 7: | condition is True | |
| 5 | total += D[k] | total = 36 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 7: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
T = (47, 44, 37, 43, 33) L = list(T) L.append(T[1] + T[2]) L.sort() print(L[:3], len(L))
Output:
[33, 37, 43] 6
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (47, 44, 37, 43, 33) | T = (47, 44, 37, 43, 33) | |
| 2 | L = list(T) | L = [47, 44, 37, 43, 33] | |
| 3 | L.append(T[1] + T[2]) | L = [47, 44, 37, 43, 33, 81] | |
| 4 | L.sort() | L = [33, 37, 43, 44, 47, 81] | |
| 5 | print(L[:3], len(L)) | [33, 37, 43] 6⏎ |
Write the output of the following code.
D = {'d': 16, 'b': 12, 'a': 4, 'e': 9}
total = 0
for k in D:
if D[k] > 5:
total += D[k]
print(k, end=" ")
print(total)Output:
d b e 37
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'d': 16, 'b': 12, 'a': 4, 'e': 9} | D = {'d': 16, 'b': 12, 'a': 4, 'e': 9} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 16 | |
| 6 | print(k, end=" ") | d | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 28 | |
| 6 | print(k, end=" ") | b | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 5: | condition is False | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 37 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 37⏎ |
Write the output of the following code.
T = (47, 20, 32, 7, 4) print(T[1:3] + T[-1:], T.index(7))
Output:
(20, 32, 4) 3
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (47, 20, 32, 7, 4) | T = (47, 20, 32, 7, 4) | |
| 2 | print(T[1:3] + T[-1:], T.index(7)) | (20, 32, 4) 3⏎ |
Write the output of the following code.
for i in range(3, 0, -1):
print("*" * i)Output:
*** ** *
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(3, 0, -1): | i = 3 | |
| 2 | print("*" * i) | ***⏎ | |
| 1 | for i in range(3, 0, -1): | i = 2 | |
| 2 | print("*" * i) | **⏎ | |
| 1 | for i in range(3, 0, -1): | i = 1 | |
| 2 | print("*" * i) | *⏎ | |
| 1 | for i in range(3, 0, -1): | loop ends (no more values) |
Write the output of the following code.
a = 4
b = 18
if a % 2 == 0 and b % 2 == 0:
print(a + b)
elif a % 2 == 0 or b > 20:
print(a * b)
else:
print(b - a)Output:
22
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | a = 4 | a = 4 | |
| 2 | b = 18 | b = 18 | |
| 3 | if a % 2 == 0 and b % 2 == 0: | condition is True | |
| 4 | print(a + b) | 22⏎ |
Write the output of the following code.
n = 76794
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
49767
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 76794 | n = 76794 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 4 | |
| 5 | s = s * 10 + d | s = 4 | |
| 6 | n = n // 10 | n = 7679 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 | |
| 5 | s = s * 10 + d | s = 49 | |
| 6 | n = n // 10 | n = 767 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 | |
| 5 | s = s * 10 + d | s = 497 | |
| 6 | n = n // 10 | n = 76 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 6 |
… the same steps continue for the remaining values.
Write the output of the following code.
T = (11, 36, 34, 33, 43) L = list(T) L.append(T[1] + T[2]) L.sort() print(L[:3], len(L))
Output:
[11, 33, 34] 6
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (11, 36, 34, 33, 43) | T = (11, 36, 34, 33, 43) | |
| 2 | L = list(T) | L = [11, 36, 34, 33, 43] | |
| 3 | L.append(T[1] + T[2]) | L = [11, 36, 34, 33, 43, 70] | |
| 4 | L.sort() | L = [11, 33, 34, 36, 43, 70] | |
| 5 | print(L[:3], len(L)) | [11, 33, 34] 6⏎ |
Write the output of the following code.
a = 9
b = 10
if a % 2 == 0 and b % 2 == 0:
print(a + b)
elif a % 2 == 0 or b > 20:
print(a * b)
else:
print(b - a)Output:
1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | a = 9 | a = 9 | |
| 2 | b = 10 | b = 10 | |
| 3 | if a % 2 == 0 and b % 2 == 0: | condition is False | |
| 5 | elif a % 2 == 0 or b > 20: | condition is False | |
| 8 | print(b - a) | 1⏎ |
Write the output of the following code.
s = "Science"
t = ""
for i in range(len(s)):
if i % 2 == 0:
t = t + s[i]
else:
t = s[i] + t
print(t)Output:
cecSine
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Science" | s = 'Science' | |
| 2 | t = "" | t = '' | |
| 3 | for i in range(len(s)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | t = t + s[i] | t = 'S' | |
| 3 | for i in range(len(s)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | t = s[i] + t | t = 'cS' | |
| 3 | for i in range(len(s)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | t = t + s[i] | t = 'cSi' | |
| 3 | for i in range(len(s)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | t = s[i] + t | t = 'ecSi' | |
| 3 | for i in range(len(s)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
n = 22202
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
20222
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 22202 | n = 22202 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 | |
| 5 | s = s * 10 + d | s = 2 | |
| 6 | n = n // 10 | n = 2220 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 0 | |
| 5 | s = s * 10 + d | s = 20 | |
| 6 | n = n // 10 | n = 222 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 | |
| 5 | s = s * 10 + d | s = 202 | |
| 6 | n = n // 10 | n = 22 | |
| 3 | while n > 0: | condition is True | |
| 5 | s = s * 10 + d | s = 2022 |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [2, 7, 3, 2, 7, 9]
S = []
for x in L:
if x not in S:
S.append(x)
print(S, len(L) - len(S))Output:
[2, 7, 3, 9] 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [2, 7, 3, 2, 7, 9] | L = [2, 7, 3, 2, 7, 9] | |
| 2 | S = [] | S = [] | |
| 3 | for x in L: | x = 2 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [2] | |
| 3 | for x in L: | x = 7 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [2, 7] | |
| 3 | for x in L: | x = 3 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [2, 7, 3] | |
| 3 | for x in L: | x = 2 | |
| 4 | if x not in S: | condition is False | |
| 3 | for x in L: | x = 7 | |
| 4 | if x not in S: | condition is False | |
| 3 | for x in L: | x = 9 |
… the same steps continue for the remaining values.
Write the output of the following code.
n = 73711
s = 0
while n > 0:
d = n % 10
if d % 2 == 0:
s = s + d
n = n // 10
print(s)Output:
0
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 73711 | n = 73711 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 1 | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 7371 | |
| 3 | while n > 0: | condition is True | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 737 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 73 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 3 | |
| 5 | if d % 2 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code.
n = 60528
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
82506
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 60528 | n = 60528 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 8 | |
| 5 | s = s * 10 + d | s = 8 | |
| 6 | n = n // 10 | n = 6052 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 | |
| 5 | s = s * 10 + d | s = 82 | |
| 6 | n = n // 10 | n = 605 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 5 | |
| 5 | s = s * 10 + d | s = 825 | |
| 6 | n = n // 10 | n = 60 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 0 |
… the same steps continue for the remaining values.
Write the output of the following code.
n = 27491
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
19472
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 27491 | n = 27491 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 1 | |
| 5 | s = s * 10 + d | s = 1 | |
| 6 | n = n // 10 | n = 2749 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 | |
| 5 | s = s * 10 + d | s = 19 | |
| 6 | n = n // 10 | n = 274 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 4 | |
| 5 | s = s * 10 + d | s = 194 | |
| 6 | n = n // 10 | n = 27 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 |
… the same steps continue for the remaining values.
Write the output of the following code.
for i in range(1, 6):
for j in range(i):
print(i, end="")
print()Output:
1 22 333 4444 55555
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(1, 6): | i = 1 | |
| 2 | for j in range(i): | j = 0 | |
| 3 | print(i, end="") | 1 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 6): | i = 2 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 3 | print(i, end="") | 2 | |
| 2 | for j in range(i): | j = 1 | |
| 3 | print(i, end="") | 2 | |
| 2 | for j in range(i): | loop ends (no more values) | |
| 4 | print() | ⏎ | |
| 1 | for i in range(1, 6): | i = 3 | |
| 2 | for j in range(i): | j = 0 | |
| 3 | print(i, end="") | 3 | |
| 2 | for j in range(i): | j = 1 |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [25, 2, 8, 12, 4, 13]
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] = L[i] // 2
else:
L[i] = L[i] * 2
print(L)Output:
[50, 1, 4, 6, 2, 26]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [25, 2, 8, 12, 4, 13] | L = [25, 2, 8, 12, 4, 13] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [50, 2, 8, 12, 4, 13] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [50, 1, 8, 12, 4, 13] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [50, 1, 4, 12, 4, 13] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [50, 1, 4, 6, 4, 13] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [50, 1, 4, 6, 2, 13] |
… the same steps continue for the remaining values.
Write the output of the following code.
s = "Monitor"
print(s.count("n"), s.find("or"), s[2:6].upper())Output:
1 5 NITO
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Monitor" | s = 'Monitor' | |
| 2 | print(s.count("n"), s.find("or"), s[2:6].upper()) | 1 5 NITO⏎ |
Write the output of the following code.
s = "KV Shalimar Bagh"
W = s.split()
for w in W:
print(w[0] + str(len(w)), end=" ")Output:
K2 S8 B4
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "KV Shalimar Bagh" | s = 'KV Shalimar Bagh' | |
| 2 | W = s.split() | W = ['KV', 'Shalimar', 'Bagh'] | |
| 3 | for w in W: | w = 'KV' | |
| 4 | print(w[0] + str(len(w)), end=" ") | K2 | |
| 3 | for w in W: | w = 'Shalimar' | |
| 4 | print(w[0] + str(len(w)), end=" ") | S8 | |
| 3 | for w in W: | w = 'Bagh' | |
| 4 | print(w[0] + str(len(w)), end=" ") | B4 | |
| 3 | for w in W: | loop ends (no more values) |
Write the output of the following code.
s = "india is great"
W = s.split()
W.reverse()
print(" ".join(W).title())Output:
Great Is India
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "india is great" | s = 'india is great' | |
| 2 | W = s.split() | W = ['india', 'is', 'great'] | |
| 3 | W.reverse() | W = ['great', 'is', 'india'] | |
| 4 | print(" ".join(W).title()) | Great Is India⏎ |
Write the output of the following code.
L = [9, 5, 3, 4, 3, 7]
S = []
for x in L:
if x not in S:
S.append(x)
print(S, len(L) - len(S))Output:
[9, 5, 3, 4, 7] 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [9, 5, 3, 4, 3, 7] | L = [9, 5, 3, 4, 3, 7] | |
| 2 | S = [] | S = [] | |
| 3 | for x in L: | x = 9 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [9] | |
| 3 | for x in L: | x = 5 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [9, 5] | |
| 3 | for x in L: | x = 3 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [9, 5, 3] | |
| 3 | for x in L: | x = 4 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [9, 5, 3, 4] | |
| 3 | for x in L: | x = 3 | |
| 4 | if x not in S: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [21, 7, 16, 20, 14, 18]
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] = L[i] // 3
else:
L[i] = L[i] * 2
print(L)Output:
[42, 14, 5, 6, 4, 6]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [21, 7, 16, 20, 14, 18] | L = [21, 7, 16, 20, 14, 18] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [42, 7, 16, 20, 14, 18] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 2 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [42, 14, 16, 20, 14, 18] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [42, 14, 5, 20, 14, 18] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [42, 14, 5, 6, 14, 18] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 2 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [42, 14, 5, 6, 4, 18] |
… the same steps continue for the remaining values.
Write the output of the following code.
n = 2194
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
4912
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 2194 | n = 2194 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 4 | |
| 5 | s = s * 10 + d | s = 4 | |
| 6 | n = n // 10 | n = 219 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 | |
| 5 | s = s * 10 + d | s = 49 | |
| 6 | n = n // 10 | n = 21 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 1 | |
| 5 | s = s * 10 + d | s = 491 | |
| 6 | n = n // 10 | n = 2 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 2 |
… the same steps continue for the remaining values.
Write the output of the following code.
s = "NOTEBOOK"
print(s.count("T"), s.find("OK"), s[2:6].upper())Output:
1 6 TEBO
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "NOTEBOOK" | s = 'NOTEBOOK' | |
| 2 | print(s.count("T"), s.find("OK"), s[2:6].upper()) | 1 6 TEBO⏎ |
Write the output of the following code.
T = (7, 12, 4, 40, 1) L = list(T) L.append(T[1] + T[2]) L.sort() print(L[:3], len(L))
Output:
[1, 4, 7] 6
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (7, 12, 4, 40, 1) | T = (7, 12, 4, 40, 1) | |
| 2 | L = list(T) | L = [7, 12, 4, 40, 1] | |
| 3 | L.append(T[1] + T[2]) | L = [7, 12, 4, 40, 1, 16] | |
| 4 | L.sort() | L = [1, 4, 7, 12, 16, 40] | |
| 5 | print(L[:3], len(L)) | [1, 4, 7] 6⏎ |
Write the output of the following code.
D = {'a': 13, 'c': 2, 'e': 11, 'd': 18}
total = 0
for k in D:
if D[k] > 12:
total += D[k]
print(k, end=" ")
print(total)Output:
a d 31
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'a': 13, 'c': 2, 'e': 11, 'd': 18} | D = {'a': 13, 'c': 2, 'e': 11, 'd': 18} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 12: | condition is True | |
| 5 | total += D[k] | total = 13 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 12: | condition is False | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 12: | condition is False | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 12: | condition is True | |
| 5 | total += D[k] | total = 31 | |
| 6 | print(k, end=" ") | d | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 31⏎ |
Write the output of the following code.
s = "Python is Easy"
for ch in s:
if ch.isupper():
print(ch.lower(), end="")
elif ch == " ":
print("#", end="")
else:
print(ch.upper(), end="")Output:
pYTHON#IS#eASY
Each upper-case letter becomes lower case, each space becomes the symbol, and every other character becomes upper case.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Python is Easy" | s = 'Python is Easy' | |
| 2 | for ch in s: | ch = 'P' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | p | |
| 2 | for ch in s: | ch = 'y' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | Y | |
| 2 | for ch in s: | ch = 't' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | T | |
| 2 | for ch in s: | ch = 'h' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | H |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [6, 3, 3, 8, 2, 3]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{6: 1, 3: 3, 8: 1, 2: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [6, 3, 3, 8, 2, 3] | L = [6, 3, 3, 8, 2, 3] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 6 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 1} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 1, 3: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 1, 3: 2} | |
| 3 | for x in L: | x = 8 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 1, 3: 2, 8: 1} | |
| 3 | for x in L: | x = 2 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 1, 3: 2, 8: 1, 2: 1} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 1, 3: 3, 8: 1, 2: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {6: 1, 3: 3, 8: 1, 2: 1}⏎ |
Write the output of the following code.
s = "India is Great"
for ch in s:
if ch.isupper():
print(ch.lower(), end="")
elif ch == " ":
print("@", end="")
else:
print(ch.upper(), end="")Output:
iNDIA@IS@gREAT
Each upper-case letter becomes lower case, each space becomes the symbol, and every other character becomes upper case.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "India is Great" | s = 'India is Great' | |
| 2 | for ch in s: | ch = 'I' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | i | |
| 2 | for ch in s: | ch = 'n' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | N | |
| 2 | for ch in s: | ch = 'd' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | D | |
| 2 | for ch in s: | ch = 'i' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | I |
… the same steps continue for the remaining values.
Write the output of the following code.
s = "Python"
t = ""
for i in range(len(s)):
if i % 2 == 0:
t = t + s[i]
else:
t = s[i] + t
print(t)Output:
nhyPto
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Python" | s = 'Python' | |
| 2 | t = "" | t = '' | |
| 3 | for i in range(len(s)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | t = t + s[i] | t = 'P' | |
| 3 | for i in range(len(s)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | t = s[i] + t | t = 'yP' | |
| 3 | for i in range(len(s)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | t = t + s[i] | t = 'yPt' | |
| 3 | for i in range(len(s)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | t = s[i] + t | t = 'hyPt' | |
| 3 | for i in range(len(s)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
s = "India is Great"
for ch in s:
if ch.isupper():
print(ch.lower(), end="")
elif ch == " ":
print("*", end="")
else:
print(ch.upper(), end="")Output:
iNDIA*IS*gREAT
Each upper-case letter becomes lower case, each space becomes the symbol, and every other character becomes upper case.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "India is Great" | s = 'India is Great' | |
| 2 | for ch in s: | ch = 'I' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | i | |
| 2 | for ch in s: | ch = 'n' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | N | |
| 2 | for ch in s: | ch = 'd' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | D | |
| 2 | for ch in s: | ch = 'i' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | I |
… the same steps continue for the remaining values.
Write the output of the following code.
s = "keep calm and code"
W = s.split()
W.reverse()
print(" ".join(W).title())Output:
Code And Calm Keep
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "keep calm and code" | s = 'keep calm and code' | |
| 2 | W = s.split() | W = ['keep', 'calm', 'and', 'code'] | |
| 3 | W.reverse() | W = ['code', 'and', 'calm', 'keep'] | |
| 4 | print(" ".join(W).title()) | Code And Calm Keep⏎ |
Write the output of the following code.
s = "CBSE Exam 2027"
W = s.split()
for w in W:
print(w[0] + str(len(w)), end=" ")Output:
C4 E4 24
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "CBSE Exam 2027" | s = 'CBSE Exam 2027' | |
| 2 | W = s.split() | W = ['CBSE', 'Exam', '2027'] | |
| 3 | for w in W: | w = 'CBSE' | |
| 4 | print(w[0] + str(len(w)), end=" ") | C4 | |
| 3 | for w in W: | w = 'Exam' | |
| 4 | print(w[0] + str(len(w)), end=" ") | E4 | |
| 3 | for w in W: | w = '2027' | |
| 4 | print(w[0] + str(len(w)), end=" ") | 24 | |
| 3 | for w in W: | loop ends (no more values) |
Write the output of the following code.
L = [6, 6, 4, 3, 7, 8]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{6: 2, 4: 1, 3: 1, 7: 1, 8: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [6, 6, 4, 3, 7, 8] | L = [6, 6, 4, 3, 7, 8] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 6 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 2} | |
| 3 | for x in L: | x = 4 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 2, 4: 1} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 2, 4: 1, 3: 1} | |
| 3 | for x in L: | x = 7 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 2, 4: 1, 3: 1, 7: 1} | |
| 3 | for x in L: | x = 8 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {6: 2, 4: 1, 3: 1, 7: 1, 8: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {6: 2, 4: 1, 3: 1, 7: 1, 8: 1}⏎ |
Write the output of the following code.
s = "Learn Code Daily"
c = 0
for w in s.split():
if w[0] in "AEIOUaeiou":
c += 1
print(c, len(s.split()))Output:
0 3
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Learn Code Daily" | s = 'Learn Code Daily' | |
| 2 | c = 0 | c = 0 | |
| 3 | for w in s.split(): | w = 'Learn' | |
| 4 | if w[0] in "AEIOUaeiou": | condition is False | |
| 3 | for w in s.split(): | w = 'Code' | |
| 4 | if w[0] in "AEIOUaeiou": | condition is False | |
| 3 | for w in s.split(): | w = 'Daily' | |
| 4 | if w[0] in "AEIOUaeiou": | condition is False | |
| 3 | for w in s.split(): | loop ends (no more values) | |
| 6 | print(c, len(s.split())) | 0 3⏎ |
Write the output of the following code.
s = "Keep Calm and Code"
c = 0
for w in s.split():
if w[0] in "AEIOUaeiou":
c += 1
print(c, len(s.split()))Output:
1 4
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Keep Calm and Code" | s = 'Keep Calm and Code' | |
| 2 | c = 0 | c = 0 | |
| 3 | for w in s.split(): | w = 'Keep' | |
| 4 | if w[0] in "AEIOUaeiou": | condition is False | |
| 3 | for w in s.split(): | w = 'Calm' | |
| 4 | if w[0] in "AEIOUaeiou": | condition is False | |
| 3 | for w in s.split(): | w = 'and' | |
| 4 | if w[0] in "AEIOUaeiou": | condition is True | |
| 5 | c += 1 | c = 1 | |
| 3 | for w in s.split(): | w = 'Code' | |
| 4 | if w[0] in "AEIOUaeiou": | condition is False | |
| 3 | for w in s.split(): | loop ends (no more values) | |
| 6 | print(c, len(s.split())) | 1 4⏎ |
Write the output of the following code.
T = (45, 27, 44, 25, 29) L = list(T) L.append(T[1] + T[2]) L.sort() print(L[:3], len(L))
Output:
[25, 27, 29] 6
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (45, 27, 44, 25, 29) | T = (45, 27, 44, 25, 29) | |
| 2 | L = list(T) | L = [45, 27, 44, 25, 29] | |
| 3 | L.append(T[1] + T[2]) | L = [45, 27, 44, 25, 29, 71] | |
| 4 | L.sort() | L = [25, 27, 29, 44, 45, 71] | |
| 5 | print(L[:3], len(L)) | [25, 27, 29] 6⏎ |
Write the output of the following code.
s = "KV Shalimar Bagh"
for ch in s:
if ch.isupper():
print(ch.lower(), end="")
elif ch == " ":
print("-", end="")
else:
print(ch.upper(), end="")Output:
kv-sHALIMAR-bAGH
Each upper-case letter becomes lower case, each space becomes the symbol, and every other character becomes upper case.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "KV Shalimar Bagh" | s = 'KV Shalimar Bagh' | |
| 2 | for ch in s: | ch = 'K' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | k | |
| 2 | for ch in s: | ch = 'V' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | v | |
| 2 | for ch in s: | ch = ' ' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is True | |
| 6 | print("-", end="") | - | |
| 2 | for ch in s: | ch = 'S' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | s | |
| 2 | for ch in s: | ch = 'h' | |
| 3 | if ch.isupper(): | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code.
s = "keyboard"
print(s.count("y"), s.find("rd"), s[2:6].upper())Output:
1 6 YBOA
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "keyboard" | s = 'keyboard' | |
| 2 | print(s.count("y"), s.find("rd"), s[2:6].upper()) | 1 6 YBOA⏎ |
Write the output of the following code.
x, y = 6, 18
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
24 16
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 6, 18 | x = 6, y = 18 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 12 | |
| 4 | y = y - 1 | y = 17 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 24 | |
| 4 | y = y - 1 | y = 16 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 24 16⏎ |
Write the output of the following code.
L = [8, 7, 1, 2, 4, 7]
S = []
for x in L:
if x not in S:
S.append(x)
print(S, len(L) - len(S))Output:
[8, 7, 1, 2, 4] 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [8, 7, 1, 2, 4, 7] | L = [8, 7, 1, 2, 4, 7] | |
| 2 | S = [] | S = [] | |
| 3 | for x in L: | x = 8 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [8] | |
| 3 | for x in L: | x = 7 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [8, 7] | |
| 3 | for x in L: | x = 1 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [8, 7, 1] | |
| 3 | for x in L: | x = 2 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [8, 7, 1, 2] | |
| 3 | for x in L: | x = 4 | |
| 4 | if x not in S: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [3, 5, 6, 3, 1, 2]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{3: 2, 5: 1, 6: 1, 1: 1, 2: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [3, 5, 6, 3, 1, 2] | L = [3, 5, 6, 3, 1, 2] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 1} | |
| 3 | for x in L: | x = 5 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 1, 5: 1} | |
| 3 | for x in L: | x = 6 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 1, 5: 1, 6: 1} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 5: 1, 6: 1} | |
| 3 | for x in L: | x = 1 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 5: 1, 6: 1, 1: 1} | |
| 3 | for x in L: | x = 2 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {3: 2, 5: 1, 6: 1, 1: 1, 2: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {3: 2, 5: 1, 6: 1, 1: 1, 2: 1}⏎ |
Write the output of the following code.
T = (48, 20, 26, 27, 31) L = list(T) L.append(T[1] + T[2]) L.sort() print(L[:3], len(L))
Output:
[20, 26, 27] 6
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (48, 20, 26, 27, 31) | T = (48, 20, 26, 27, 31) | |
| 2 | L = list(T) | L = [48, 20, 26, 27, 31] | |
| 3 | L.append(T[1] + T[2]) | L = [48, 20, 26, 27, 31, 46] | |
| 4 | L.sort() | L = [20, 26, 27, 31, 46, 48] | |
| 5 | print(L[:3], len(L)) | [20, 26, 27] 6⏎ |
Write the output of the following code.
for i in range(4, 0, -1):
print("*" * i)Output:
**** *** ** *
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(4, 0, -1): | i = 4 | |
| 2 | print("*" * i) | ****⏎ | |
| 1 | for i in range(4, 0, -1): | i = 3 | |
| 2 | print("*" * i) | ***⏎ | |
| 1 | for i in range(4, 0, -1): | i = 2 | |
| 2 | print("*" * i) | **⏎ | |
| 1 | for i in range(4, 0, -1): | i = 1 | |
| 2 | print("*" * i) | *⏎ | |
| 1 | for i in range(4, 0, -1): | loop ends (no more values) |
Write the output of the following code.
s = "Network"
print(s.count("t"), s.find("rk"), s[2:6].upper())Output:
1 5 TWOR
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Network" | s = 'Network' | |
| 2 | print(s.count("t"), s.find("rk"), s[2:6].upper()) | 1 5 TWOR⏎ |
Write the output of the following code.
L = [5, 6, 2, 3, 5, 1]
S = []
for x in L:
if x not in S:
S.append(x)
print(S, len(L) - len(S))Output:
[5, 6, 2, 3, 1] 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [5, 6, 2, 3, 5, 1] | L = [5, 6, 2, 3, 5, 1] | |
| 2 | S = [] | S = [] | |
| 3 | for x in L: | x = 5 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [5] | |
| 3 | for x in L: | x = 6 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [5, 6] | |
| 3 | for x in L: | x = 2 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [5, 6, 2] | |
| 3 | for x in L: | x = 3 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [5, 6, 2, 3] | |
| 3 | for x in L: | x = 5 | |
| 4 | if x not in S: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code.
T = (9, 39, 4, 46, 19) L = list(T) L.append(T[1] + T[2]) L.sort() print(L[:3], len(L))
Output:
[4, 9, 19] 6
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (9, 39, 4, 46, 19) | T = (9, 39, 4, 46, 19) | |
| 2 | L = list(T) | L = [9, 39, 4, 46, 19] | |
| 3 | L.append(T[1] + T[2]) | L = [9, 39, 4, 46, 19, 43] | |
| 4 | L.sort() | L = [4, 9, 19, 39, 43, 46] | |
| 5 | print(L[:3], len(L)) | [4, 9, 19] 6⏎ |
Write the output of the following code.
L = [26, 15, 22, 18, 24, 12]
for i in range(len(L)):
if L[i] % 5 == 0:
L[i] = L[i] // 2
else:
L[i] = L[i] * 2
print(L)Output:
[52, 7, 44, 36, 48, 24]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [26, 15, 22, 18, 24, 12] | L = [26, 15, 22, 18, 24, 12] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 15, 22, 18, 24, 12] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 5 == 0: | condition is True | |
| 4 | L[i] = L[i] // 2 | L = [52, 7, 22, 18, 24, 12] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 7, 44, 18, 24, 12] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 7, 44, 36, 24, 12] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 7, 44, 36, 48, 12] |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'b': 15, 'd': 12, 'c': 9, 'a': 7}
total = 0
for k in D:
if D[k] > 5:
total += D[k]
print(k, end=" ")
print(total)Output:
b d c a 43
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'b': 15, 'd': 12, 'c': 9, 'a': 7} | D = {'b': 15, 'd': 12, 'c': 9, 'a': 7} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 15 | |
| 6 | print(k, end=" ") | b | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 27 | |
| 6 | print(k, end=" ") | d | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 5: | condition is True | |
| 5 | total += D[k] | total = 36 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 5: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [9, 8, 8, 8, 7, 9]
S = []
for x in L:
if x not in S:
S.append(x)
print(S, len(L) - len(S))Output:
[9, 8, 7] 3
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [9, 8, 8, 8, 7, 9] | L = [9, 8, 8, 8, 7, 9] | |
| 2 | S = [] | S = [] | |
| 3 | for x in L: | x = 9 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [9] | |
| 3 | for x in L: | x = 8 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [9, 8] | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | if x not in S: | condition is False | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | if x not in S: | condition is False | |
| 3 | for x in L: | x = 7 | |
| 4 | if x not in S: | condition is True | |
| 5 | S.append(x) | S = [9, 8, 7] | |
| 3 | for x in L: | x = 9 |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [26, 2, 6, 25, 8, 12]
for i in range(len(L)):
if L[i] % 5 == 0:
L[i] = L[i] // 3
else:
L[i] = L[i] * 2
print(L)Output:
[52, 4, 12, 8, 16, 24]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [26, 2, 6, 25, 8, 12] | L = [26, 2, 6, 25, 8, 12] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 2, 6, 25, 8, 12] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 4, 6, 25, 8, 12] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 4, 12, 25, 8, 12] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 5 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [52, 4, 12, 8, 8, 12] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [52, 4, 12, 8, 16, 12] |
… the same steps continue for the remaining values.
Write the output of the following code.
for i in range(1, 6):
print(" " * (5 - i) + "#" * i)Output:
# ## ### #### #####
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | for i in range(1, 6): | i = 1 | |
| 2 | print(" " * (5 - i) + "#" * i) | #⏎ | |
| 1 | for i in range(1, 6): | i = 2 | |
| 2 | print(" " * (5 - i) + "#" * i) | ##⏎ | |
| 1 | for i in range(1, 6): | i = 3 | |
| 2 | print(" " * (5 - i) + "#" * i) | ###⏎ | |
| 1 | for i in range(1, 6): | i = 4 | |
| 2 | print(" " * (5 - i) + "#" * i) | ####⏎ | |
| 1 | for i in range(1, 6): | i = 5 | |
| 2 | print(" " * (5 - i) + "#" * i) | #####⏎ | |
| 1 | for i in range(1, 6): | loop ends (no more values) |
Write the output of the following code.
D = {'b': 4, 'e': 3, 'd': 7, 'c': 13}
total = 0
for k in D:
if D[k] > 8:
total += D[k]
print(k, end=" ")
print(total)Output:
c 13
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'b': 4, 'e': 3, 'd': 7, 'c': 13} | D = {'b': 4, 'e': 3, 'd': 7, 'c': 13} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 8: | condition is False | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 8: | condition is False | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 8: | condition is False | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 8: | condition is True | |
| 5 | total += D[k] | total = 13 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 13⏎ |
Write the output of the following code.
s = "Delhi-88" print(s[1:5], s[-3:], s[::3])
Output:
elhi -88 Dh8
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Delhi-88" | s = 'Delhi-88' | |
| 2 | print(s[1:5], s[-3:], s[::3]) | elhi -88 Dh8⏎ |
Write the output of the following code.
L = [5, 1, 2, 5, 7, 6]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{5: 2, 1: 1, 2: 1, 7: 1, 6: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [5, 1, 2, 5, 7, 6] | L = [5, 1, 2, 5, 7, 6] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 5 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1} | |
| 3 | for x in L: | x = 1 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 1: 1} | |
| 3 | for x in L: | x = 2 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 1: 1, 2: 1} | |
| 3 | for x in L: | x = 5 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 2, 1: 1, 2: 1} | |
| 3 | for x in L: | x = 7 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 2, 1: 1, 2: 1, 7: 1} | |
| 3 | for x in L: | x = 6 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 2, 1: 1, 2: 1, 7: 1, 6: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {5: 2, 1: 1, 2: 1, 7: 1, 6: 1}⏎ |
Write the output of the following code.
n = 79101
s = 0
while n > 0:
d = n % 10
if d % 2 == 0:
s = s + d
n = n // 10
print(s)Output:
0
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 79101 | n = 79101 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 1 | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 7910 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 0 | |
| 5 | if d % 2 == 0: | condition is True | |
| 7 | n = n // 10 | n = 791 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 1 | |
| 5 | if d % 2 == 0: | condition is False | |
| 7 | n = n // 10 | n = 79 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [1, 9, 9, 8, 3, 6]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{1: 1, 9: 2, 8: 1, 3: 1, 6: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [1, 9, 9, 8, 3, 6] | L = [1, 9, 9, 8, 3, 6] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 1 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {1: 1} | |
| 3 | for x in L: | x = 9 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {1: 1, 9: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {1: 1, 9: 2} | |
| 3 | for x in L: | x = 8 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {1: 1, 9: 2, 8: 1} | |
| 3 | for x in L: | x = 3 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {1: 1, 9: 2, 8: 1, 3: 1} | |
| 3 | for x in L: | x = 6 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {1: 1, 9: 2, 8: 1, 3: 1, 6: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {1: 1, 9: 2, 8: 1, 3: 1, 6: 1}⏎ |
Write the output of the following code.
a = 2
b = 22
if a % 2 == 0 and b % 2 == 0:
print(a + b)
elif a % 2 == 0 or b > 20:
print(a * b)
else:
print(b - a)Output:
24
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | a = 2 | a = 2 | |
| 2 | b = 22 | b = 22 | |
| 3 | if a % 2 == 0 and b % 2 == 0: | condition is True | |
| 4 | print(a + b) | 24⏎ |
Write the output of the following code.
s = "Save Water Save Life"
for ch in s:
if ch.isupper():
print(ch.lower(), end="")
elif ch == " ":
print("*", end="")
else:
print(ch.upper(), end="")Output:
sAVE*wATER*sAVE*lIFE
Each upper-case letter becomes lower case, each space becomes the symbol, and every other character becomes upper case.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Save Water Save Life" | s = 'Save Water Save Life' | |
| 2 | for ch in s: | ch = 'S' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | s | |
| 2 | for ch in s: | ch = 'a' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | A | |
| 2 | for ch in s: | ch = 'v' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | V | |
| 2 | for ch in s: | ch = 'e' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | E |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [5, 2, 8, 8, 8, 7]
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print(F)Output:
{5: 1, 2: 1, 8: 3, 7: 1}Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [5, 2, 8, 8, 8, 7] | L = [5, 2, 8, 8, 8, 7] | |
| 2 | F = {} | F = {} | |
| 3 | for x in L: | x = 5 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1} | |
| 3 | for x in L: | x = 2 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 2: 1} | |
| 3 | for x in L: | x = 8 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 2: 1, 8: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 2: 1, 8: 2} | |
| 3 | for x in L: | loop ends (no more values) | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 2: 1, 8: 3} | |
| 3 | for x in L: | x = 7 | |
| 4 | F[x] = F.get(x, 0) + 1 | F = {5: 1, 2: 1, 8: 3, 7: 1} | |
| 3 | for x in L: | loop ends (no more values) | |
| 5 | print(F) | {5: 1, 2: 1, 8: 3, 7: 1}⏎ |
Write the output of the following code.
s = "Algorithm" print(s[1:5], s[-3:], s[::3])
Output:
lgor thm Aot
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Algorithm" | s = 'Algorithm' | |
| 2 | print(s[1:5], s[-3:], s[::3]) | lgor thm Aot⏎ |
Write the output of the following code.
D = {'e': 13, 'a': 18, 'c': 9, 'b': 2}
total = 0
for k in D:
if D[k] > 6:
total += D[k]
print(k, end=" ")
print(total)Output:
e a c 40
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'e': 13, 'a': 18, 'c': 9, 'b': 2} | D = {'e': 13, 'a': 18, 'c': 9, 'b': 2} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 6: | condition is True | |
| 5 | total += D[k] | total = 13 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 6: | condition is True | |
| 5 | total += D[k] | total = 31 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 6: | condition is True | |
| 5 | total += D[k] | total = 40 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 6: | condition is False | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 40⏎ |
Write the output of the following code.
x, y = 7, 10
while x < y:
x = x * 2
y = y - 1
print(x, y)Output:
14 9
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | x, y = 7, 10 | x = 7, y = 10 | |
| 2 | while x < y: | condition is True | |
| 3 | x = x * 2 | x = 14 | |
| 4 | y = y - 1 | y = 9 | |
| 2 | while x < y: | condition is False | |
| 5 | print(x, y) | 14 9⏎ |
Write the output of the following code.
n = 49478
s = 0
while n > 0:
d = n % 10
s = s * 10 + d
n = n // 10
print(s)Output:
87494
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 49478 | n = 49478 | |
| 2 | s = 0 | s = 0 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 8 | |
| 5 | s = s * 10 + d | s = 8 | |
| 6 | n = n // 10 | n = 4947 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 7 | |
| 5 | s = s * 10 + d | s = 87 | |
| 6 | n = n // 10 | n = 494 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 4 | |
| 5 | s = s * 10 + d | s = 874 | |
| 6 | n = n // 10 | n = 49 | |
| 3 | while n > 0: | condition is True | |
| 4 | d = n % 10 | d = 9 |
… the same steps continue for the remaining values.
Write the output of the following code.
s = "CBSE Exam 2027"
for ch in s:
if ch.isupper():
print(ch.lower(), end="")
elif ch == " ":
print("#", end="")
else:
print(ch.upper(), end="")Output:
cbse#eXAM#2027
Each upper-case letter becomes lower case, each space becomes the symbol, and every other character becomes upper case.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "CBSE Exam 2027" | s = 'CBSE Exam 2027' | |
| 2 | for ch in s: | ch = 'C' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | c | |
| 2 | for ch in s: | ch = 'B' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | b | |
| 2 | for ch in s: | ch = 'S' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | s | |
| 2 | for ch in s: | ch = 'E' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | e | |
| 2 | for ch in s: | ch = ' ' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'b': 7, 'a': 12, 'c': 1, 'd': 2}
total = 0
for k in D:
if D[k] > 8:
total += D[k]
print(k, end=" ")
print(total)Output:
a 12
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'b': 7, 'a': 12, 'c': 1, 'd': 2} | D = {'b': 7, 'a': 12, 'c': 1, 'd': 2} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 8: | condition is False | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 8: | condition is True | |
| 5 | total += D[k] | total = 12 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 8: | condition is False | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 8: | condition is False | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 12⏎ |
Write the output of the following code.
D = {'b': 7, 'c': 13, 'e': 15, 'a': 16}
total = 0
for k in D:
if D[k] > 9:
total += D[k]
print(k, end=" ")
print(total)Output:
c e a 44
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'b': 7, 'c': 13, 'e': 15, 'a': 16} | D = {'b': 7, 'c': 13, 'e': 15, 'a': 16} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 9: | condition is False | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 9: | condition is True | |
| 5 | total += D[k] | total = 13 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 9: | condition is True | |
| 5 | total += D[k] | total = 28 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | k = 'a' | |
| 4 | if D[k] > 9: | condition is True | |
| 5 | total += D[k] | total = 44 | |
| 6 | print(k, end=" ") | a | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 44⏎ |
Write the output of the following code.
s = "Data and Logic"
for ch in s:
if ch.isupper():
print(ch.lower(), end="")
elif ch == " ":
print("@", end="")
else:
print(ch.upper(), end="")Output:
dATA@AND@lOGIC
Each upper-case letter becomes lower case, each space becomes the symbol, and every other character becomes upper case.
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | s = "Data and Logic" | s = 'Data and Logic' | |
| 2 | for ch in s: | ch = 'D' | |
| 3 | if ch.isupper(): | condition is True | |
| 4 | print(ch.lower(), end="") | d | |
| 2 | for ch in s: | ch = 'a' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | A | |
| 2 | for ch in s: | ch = 't' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | T | |
| 2 | for ch in s: | ch = 'a' | |
| 3 | if ch.isupper(): | condition is False | |
| 5 | elif ch == " ": | condition is False | |
| 8 | print(ch.upper(), end="") | A |
… the same steps continue for the remaining values.
Write the output of the following code.
L = [29, 25, 22, 14, 27, 7]
for i in range(len(L)):
if L[i] % 5 == 0:
L[i] = L[i] // 3
else:
L[i] = L[i] * 2
print(L)Output:
[58, 8, 44, 28, 54, 14]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [29, 25, 22, 14, 27, 7] | L = [29, 25, 22, 14, 27, 7] | |
| 2 | for i in range(len(L)): | i = 0 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [58, 25, 22, 14, 27, 7] | |
| 2 | for i in range(len(L)): | i = 1 | |
| 3 | if L[i] % 5 == 0: | condition is True | |
| 4 | L[i] = L[i] // 3 | L = [58, 8, 22, 14, 27, 7] | |
| 2 | for i in range(len(L)): | i = 2 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [58, 8, 44, 14, 27, 7] | |
| 2 | for i in range(len(L)): | i = 3 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [58, 8, 44, 28, 27, 7] | |
| 2 | for i in range(len(L)): | i = 4 | |
| 3 | if L[i] % 5 == 0: | condition is False | |
| 6 | L[i] = L[i] * 2 | L = [58, 8, 44, 28, 54, 7] |
… the same steps continue for the remaining values.
Write the output of the following code.
D = {'c': 16, 'b': 12, 'e': 14, 'd': 2}
total = 0
for k in D:
if D[k] > 8:
total += D[k]
print(k, end=" ")
print(total)Output:
c b e 42
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | D = {'c': 16, 'b': 12, 'e': 14, 'd': 2} | D = {'c': 16, 'b': 12, 'e': 14, 'd': 2} | |
| 2 | total = 0 | total = 0 | |
| 3 | for k in D: | k = 'c' | |
| 4 | if D[k] > 8: | condition is True | |
| 5 | total += D[k] | total = 16 | |
| 6 | print(k, end=" ") | c | |
| 3 | for k in D: | k = 'b' | |
| 4 | if D[k] > 8: | condition is True | |
| 5 | total += D[k] | total = 28 | |
| 6 | print(k, end=" ") | b | |
| 3 | for k in D: | k = 'e' | |
| 4 | if D[k] > 8: | condition is True | |
| 5 | total += D[k] | total = 42 | |
| 6 | print(k, end=" ") | e | |
| 3 | for k in D: | k = 'd' | |
| 4 | if D[k] > 8: | condition is False | |
| 3 | for k in D: | loop ends (no more values) | |
| 7 | print(total) | 42⏎ |
Rewrite the code after removing the errors. Underline each correction.
x = input('Enter a number')
if x % 2 = 0
print('Even')
else
print('Odd')x = int(input('Enter a number'))
if x % 2 == 0:
print('Even')
else:
print('Odd')input() gives a string: use int(); use == to compare; colons are needed after if and else.
Rewrite the code after removing the errors. Underline each correction.
for i in range(1, 6)
sum = sum + i
print(Sum)sum = 0
for i in range(1, 6):
sum = sum + i
print(sum)sum must be given a starting value; colon after for; Python is case sensitive (Sum).
Rewrite the code after removing the errors. Underline each correction.
n = 5 while n > 0 print(n) n = n - 1
n = 5
while n > 0:
print(n)
n = n - 1Colon after while; the body must be indented.
Rewrite the code after removing the errors. Underline each correction.
s = 'Python' s[0] = 'J' print(s.Upper())
s = 'Python' s = 'J' + s[1:] print(s.upper())
Strings are immutable; make a new string. The method name is upper().
Rewrite the code after removing the errors. Underline each correction.
L = [10, 20, 30] L.add(40) print(L[4])
L = [10, 20, 30] L.append(40) print(L[3])
Lists have append(), not add(); after adding, the last index is 3.
Rewrite the code after removing the errors. Underline each correction.
T = (1, 2, 3) T[1] = 5 T.append(4) print(T)
T = (1, 2, 3) L = list(T) L[1] = 5 L.append(4) T = tuple(L) print(T)
Tuples are immutable; change a list copy and convert back.
Rewrite the code after removing the errors. Underline each correction.
D = {'a': 1, 'b': 2]
for k in D
print(k, D(k))D = {'a': 1, 'b': 2}
for k in D:
print(k, D[k])Close the dictionary with }; colon after for; values are accessed with D[k].
Rewrite the code after removing the errors. Underline each correction.
a = 10 b = '20' c = a + b print 'Sum =', c
a = 10
b = '20'
c = a + int(b)
print('Sum =', c)Convert b to int before adding; print is a function and needs brackets.
Rewrite the code after removing the errors. Underline each correction.
num = int(input('N: '))
if num > 0:
print('Positive')
elif num = 0:
print('Zero')
else if num < 0:
print('Negative')num = int(input('N: '))
if num > 0:
print('Positive')
elif num == 0:
print('Zero')
else:
print('Negative')Indent the body of if; use == ; Python uses elif or else, not 'else if'.
Rewrite the code after removing the errors. Underline each correction.
name = 'Kendriya'
for ch in Name:
if ch in 'aeiou'
count += 1
print(count)name = 'Kendriya'
count = 0
for ch in name:
if ch in 'aeiou':
count += 1
print(count)Name is not defined (case); colon after if; count needs a starting value.
Rewrite the code after removing the errors. Underline each correction.
L = [5, 3, 8] L = L.sort() print(L[0])
L = [5, 3, 8] L.sort() print(L[0])
sort() returns None; it sorts L in place, so do not assign its result.
Rewrite the code after removing the errors. Underline each correction.
import Math x = math.sqrt(25) print(x.floor)
import math x = math.sqrt(25) print(math.floor(x))
The module name is math (small m); floor is a function of math.
Rewrite the code after removing the errors. Underline each correction.
for i in range(5):
if i == 3:
Break
print(i)
else
print('done')for i in range(5):
if i == 3:
break
print(i)
else:
print('done')break is in small letters; colon after else.
Rewrite the code after removing the errors. Underline each correction.
Marks = 90
if Marks >= 90 and <= 100:
print('A1')Marks = 90
if Marks >= 90 and Marks <= 100:
print('A1')Each side of and must be a full condition (or write 90 <= Marks <= 100).
Rewrite the code after removing the errors. Underline each correction.
L = [1, 2, 3]
for i in range(len(L))
L[i] = L[i] * 2
print(l)L = [1, 2, 3]
for i in range(len(L)):
L[i] = L[i] * 2
print(L)Colon after for; print L, not l.
Rewrite the code after removing the errors. Underline each correction.
s = "Hello World'
w = s.split(' ')
print(len w)s = "Hello World"
w = s.split(' ')
print(len(w))The string must open and close with the same quote; len() needs brackets.
Rewrite the code after removing the errors. Underline each correction.
D = dict() D[1] = 'one' D.[2] = 'two' print(D.key())
D = dict() D[1] = 'one' D[2] = 'two' print(D.keys())
Use D[2] to add; the method is keys().
Rewrite the code after removing the errors. Underline each correction.
x = 5 y = 2 print(x ^ y, x ** y, x // y, x % y))
x = 5 y = 2 print(x ** y, x // y, x % y)
^ is not power in Python (it is bitwise XOR); one closing bracket too many.
Rewrite the code after removing the errors. Underline each correction.
i = 1
while i < 10:
if i % 2 = 0:
continue
print(i)
i =+ 1i = 1
while i < 10:
if i % 2 == 0:
i += 1
continue
print(i)
i += 1Use == to compare; =+ means 'assign +1', write += 1; i must change before continue, or the loop never ends.
Rewrite the code after removing the errors. Underline each correction.
num = [4, 5, 6] num.insert(10) num.remove(1) print(num.length)
num = [4, 5, 6] num.insert(0, 10) num.remove(4) print(len(num))
insert() needs an index and a value; remove() takes a value present in the list; length is found by len().
Rewrite the code after removing the errors. Underline each correction.
s = 'abc' print(s * 2 + 3)
s = 'abc' print(s * 2 + '3')
A string cannot be added to an integer; use '3'.
Rewrite the code after removing the errors. Underline each correction.
student = {'name' = 'Asha', 'age' = 16}
print(student[name])student = {'name': 'Asha', 'age': 16}
print(student['name'])Use : between key and value; the key is the string 'name'.
Rewrite the code after removing the errors. Underline each correction.
N = 4
for i in range(1, N+1):
for j in range(i)
print('*', end=' ')
print()N = 4
for i in range(1, N+1):
for j in range(i):
print('*', end=' ')
print()Colon after the inner for; keep the indentation consistent.
Rewrite the code after removing the errors. Underline each correction.
from random import * r = random.randint(1, 6) print(r)
import random r = random.randint(1, 6) print(r)
With 'from random import *' the name random is not available; import the module itself (or call randint directly).
Rewrite the code after removing the errors. Underline each correction.
1st_num = 10 second num = 20 print(1st_num + second num)
num1 = 10 second_num = 20 print(num1 + second_num)
An identifier cannot start with a digit or have a space.
Rewrite the code after removing the errors. Underline each correction.
L = [1, 2, 3] L[3] = 4 print(L)
L = [1, 2, 3] L.append(4) print(L)
Index 3 does not exist (IndexError); add a new element with append().
Rewrite the code after removing the errors. Underline each correction.
s = 'KV'
if s.isupper:
print(s.lower)s = 'KV'
if s.isupper():
print(s.lower())Methods must be called with brackets.
Rewrite the code after removing the errors. Underline each correction.
t = (10, 20, 30) a, b = t print(a + b)
t = (10, 20, 30) a, b, c = t print(a + b)
The number of variables must match the number of values when unpacking.
Rewrite the code after removing the errors. Underline each correction.
def = 5
for i in range(def):
print(i)d = 5
for i in range(d):
print(i)def is a keyword; it cannot be a variable name.
Rewrite the code after removing the errors. Underline each correction.
a = int(input('A: ')
b = float(input('B: '))
print('Total' + a + b)a = int(input('A: '))
b = float(input('B: '))
print('Total', a + b)Missing closing bracket; a string cannot be joined to numbers with +, use a comma.
Rewrite the code after removing the errors. Underline each correction.
marks = [70, 80, 90]
total = 0
for m in range(marks):
total += m
print(total / len[marks])marks = [70, 80, 90]
total = 0
for m in marks:
total += m
print(total / len(marks))Loop directly over the list (range needs a number); len() uses round brackets.
Rewrite the code after removing the errors. Underline each correction.
word = input('Word: ')
if word == word.reverse():
print('Palindrome')word = input('Word: ')
if word == word[::-1]:
print('Palindrome')Strings have no reverse() method; use the slice [::-1].
Rewrite the code after removing the errors. Underline each correction.
s = input('Enter: ')
for i in range(len(s))
if s[i].isupper:
print(s[i], end='')s = input('Enter: ')
for i in range(len(s)):
if s[i].isupper():
print(s[i], end='')Colon after for; isupper() must be called with brackets.
Rewrite the code after removing the errors. Underline each correction.
L = [3, 6, 9] L.insert(1) print(L.sort())
L = [3, 6, 9] L.insert(1, 4) L.sort() print(L)
insert() needs an index and a value; sort() returns None, so sort first and then print L.
Rewrite the code after removing the errors. Underline each correction.
D = {[1, 2]: 'a', 'b': 2}
print(D.items)D = {(1, 2): 'a', 'b': 2}
print(D.items())A list cannot be a key (it is mutable); use a tuple. items() needs brackets.
Rewrite the code after removing the errors. Underline each correction.
count = 0
for i in range(10):
if i % 3 == 0:
count = count + 1
print('Count:' count)count = 0
for i in range(10):
if i % 3 == 0:
count = count + 1
print('Count:', count)The body of if must be indented; a comma is needed between the items in print().
Rewrite the code after removing the errors. Underline each correction.
x = 10
y = 0
if y != 0:
print(x / y)
Else:
print('Cannot divide')x = 10
y = 0
if y != 0:
print(x / y)
else:
print('Cannot divide')Python is case sensitive: the keyword is else.
Rewrite the code after removing the errors. Underline each correction.
s = 'Data'
n = len(s)
for i in range(n, 0):
print(s[i])s = 'Data'
n = len(s)
for i in range(n - 1, -1, -1):
print(s[i])s[n] is out of range and range(n, 0) needs a negative step; go from n - 1 down to 0.
Rewrite the code after removing the errors. Underline each correction.
import math print(math.squareroot(81)) print(math.PI)
import math print(math.sqrt(81)) print(math.pi)
The function is sqrt() and the constant is pi in small letters.
Rewrite the code after removing the errors. Underline each correction.
T = 1, 2, 3 T += 4 print(T)
T = 1, 2, 3 T += (4,) print(T)
A tuple can be joined only with another tuple; write (4,).
What is a digital footprint? Differentiate between its two types.
The trail of data left by a person while using the Internet. Active: left knowingly, such as posts, comments, e-mails. Passive: collected without the user knowing, such as browsing history, location, cookies.
Write any four points of netiquette.
Be polite and respectful; do not use bad language or ALL CAPS (shouting); do not share others' personal data; respect copyright and give credit; do not spam; check facts before forwarding. (Any four.)
What is plagiarism? How can it be avoided?
Presenting someone else's work or ideas as one's own. Avoid it by giving credit (citation) to the source, using quotation marks for exact words, and writing in your own words.
Differentiate between copyright and patent.
Copyright protects creative works such as books, music, software and art; it is automatic on creation. Patent protects a new invention; it must be applied for and granted, for a limited period.
What is intellectual property? Name the three ways it is protected.
Creations of the mind such as inventions, books, music, designs and brand names. It is protected by copyright, patent and trademark.
Differentiate between free software and open source software.
Free software stresses the user's freedom to run, study, change and share the software. Open source software stresses that the source code is available and can be improved by anyone. Both are together called FOSS. Free software need not be free of cost.
Differentiate between proprietary software and FOSS with one example each.
Proprietary software is owned by a company; the code is secret and a licence must be bought: MS Office. FOSS has open code and can be used and shared freely: LibreOffice, Linux.
Differentiate between GPL and Creative Commons licences.
GPL is a copyleft licence for software: changed versions must also be shared under GPL. Creative Commons licences are for creative works (images, music, text); the creator chooses conditions such as attribution or no commercial use.
What is hacking? Differentiate between ethical and unethical hacking.
Getting unauthorised access to a computer or network. Ethical hacking is done with permission to find and fix weaknesses (white hat). Unethical hacking is done to steal or damage (black hat) and is a crime.
What is phishing? Write two ways to protect yourself from it.
A fraud in which fake e-mails, messages or websites trick people into giving passwords or bank details. Protection: do not click unknown links; check the website address (https and spelling); never share OTP or passwords; report the message.
What is ransomware? Write one way to stay safe from it.
Malware that locks or encrypts a victim's files and asks for money (ransom) to unlock them. Stay safe by keeping regular offline backups, updating the system and not opening unknown attachments.
Differentiate between a virus and a worm.
A virus attaches itself to a host program and spreads when that program is run. A worm is a standalone program that copies itself and spreads through networks on its own.
What is a Trojan horse? How is it different from a virus?
Malware that looks like a useful program but does harm, such as stealing data. Unlike a virus, it does not copy itself or infect other files.
Differentiate between adware and spyware.
Adware shows unwanted advertisements, often pop-ups. Spyware secretly collects information about the user, such as passwords and browsing, and sends it to others.
What is cyber bullying? Write two things a student should do if bullied online.
Using digital media to harass, threaten or insult a person. Do: not reply to the bully, block and report the account, keep screenshots as proof, and tell parents or teachers.
Write any four safety measures while using the Internet.
Use strong, different passwords; do not share personal details; use antivirus and keep software updated; use secure (https) sites; log out on shared computers; think before clicking links. (Any four.)
What is identity theft? Give an example.
Stealing someone's personal information and using it to pretend to be that person, usually to cheat. Example: using another person's Aadhaar and phone number to take a loan.
What is the IT Act, 2000? Write two of its provisions.
The Indian law on electronic transactions and cyber crime. It gives legal recognition to electronic records and digital signatures, and punishes offences such as hacking, identity theft and sending offensive messages.
What is e-waste? Why is it harmful?
Discarded electronic devices such as old phones, computers and batteries. It contains toxic metals like lead, mercury and cadmium which pollute soil and water and harm health when dumped or burnt.
Write any four ways to manage e-waste.
Reduce buying new devices; reuse or donate working devices; repair instead of replacing; recycle through authorised e-waste collectors; return to the company under take-back schemes. (Any four.)
What are cookies? Are they harmful?
Small text files that websites save on the user's computer to remember choices and login. They are not harmful by themselves, but third-party cookies can track the user and invade privacy.
What is the digital divide? Give two ways to reduce it.
The gap between people who have access to computers and the Internet and those who do not. Reduce it by setting up public computer centres, cheap Internet, digital literacy programmes, and content in local languages.
Write two gender issues related to the use of computers and their solutions.
Fewer girls choose computer science; girls get less access to devices at home. Solutions: encourage girls through role models and clubs, equal access to labs and devices, and safe online spaces.
How can technology help persons with disabilities? Give two examples.
Assistive technologies make computers usable for them: screen readers and Braille keyboards for the visually challenged, speech-to-text for those who cannot type, captions for the hearing impaired.
What is data protection? Write two ways to protect your personal data.
Keeping personal data safe from misuse and unauthorised access. Ways: share data only on trusted sites, use strong passwords and two-factor authentication, check app permissions, and do not post personal details publicly.
Differentiate between freeware and shareware.
Freeware is free to use for any time, but its code is closed. Shareware is free only for a trial period or with limited features; after that it must be bought.
What is a firewall? Why is it used?
A hardware or software system that checks the data coming into and going out of a computer or network, and blocks the traffic that breaks the security rules. It protects against hackers and malware.
What is software piracy? Why is it wrong?
Copying, using or selling software without a licence. It is wrong because it breaks copyright law, causes loss to the creators and may carry malware.
Differentiate between cyber trolling and cyber bullying.
Trolling is posting provocative or offensive comments to upset people and start arguments, often to anyone. Bullying targets a particular person again and again to harass or threaten.
Why should we think before posting something online? Give two reasons.
Because digital footprints are lasting: posts can be copied and found later, and may affect college admission or jobs. Posts can also hurt others or break the law.
Write any two differences between active and passive digital footprints with an example of each.
Active footprints are left on purpose (a post, a comment, an e-mail); passive ones are collected without our knowledge (IP address, location, browsing history). Active ones can be controlled directly; passive ones need privacy settings and care.
Why is it important to manage your digital footprint? Give two tips.
Because it is lasting and can be seen by colleges, employers and strangers, and can be misused. Tips: think before posting; set accounts to private; delete old accounts; do not overshare personal details.
What is a trademark? Give two examples.
A word, name, logo or symbol that identifies the goods or services of a company and separates them from others. Examples: the logos of Tata, Amul, Apple.
What is copyright infringement? Give two examples.
Using a copyrighted work without the owner's permission. Examples: downloading a movie from a pirate site; copying a textbook and selling it; using a paid font without a licence.
What is a software licence? Why is it needed?
A legal agreement that says how a software may be used, copied or shared. It protects the rights of the creator and tells the user what is allowed.
Write two advantages of open source software.
It is usually free of cost; its code can be studied and changed; bugs are fixed quickly by a large community; no dependence on one company. (Any two.)
What is the public domain? Give an example.
Works whose copyright has ended or was given up, so anyone can use them freely. Example: the works of Rabindranath Tagore and Shakespeare.
Differentiate between a virus and a Trojan horse.
A virus attaches to a file and spreads when that file is run; it copies itself. A Trojan horse looks like useful software, does harm, but does not copy itself.
What is spam? How can it be controlled?
Unwanted bulk messages, mostly advertisements, sent to many people. Control it by using spam filters, not sharing your e-mail publicly, and not replying to or clicking in spam.
Write two ways in which cyber crimes are different from ordinary crimes.
They are done through computers and networks; the criminal can be far away or in another country; evidence is digital and can be hidden; many people can be hit at once.
What is two-factor authentication? Why is it safer?
Logging in with two different checks, such as a password and an OTP sent to the phone. Even if the password is stolen, the account cannot be opened without the second factor.
Name any four types of malware.
Virus, worm, Trojan horse, ransomware, spyware, adware, keylogger. (Any four.)
What is a keylogger? How can it harm you?
A program or device that records every key pressed. It can steal passwords, card numbers and messages.
Write any two ways to identify a phishing e-mail.
It creates urgency or offers prizes; the sender address or link looks odd or misspelt; it asks for passwords, OTP or bank details; it has spelling mistakes; the link is not https.
Write two health hazards of excessive use of technology.
Eye strain; neck and back pain due to wrong posture; lack of sleep; Internet addiction and stress. (Any two.)
What is the role of CERT-In?
The Indian Computer Emergency Response Team is the national agency that responds to cyber security incidents, issues alerts and guides people and organisations to stay safe.
How does recycling of e-waste help the environment? Give two points.
It stops toxic metals from entering soil and water, and recovers useful metals like copper and gold, so less mining is needed.
What is privacy? Why should we protect it online?
The right to keep our personal information to ourselves. Online data can be misused for fraud, stalking, identity theft or unwanted ads, so it must be protected.
Explain any two points to be kept in mind while using social media.
Keep the account private and accept only known people; do not share location or personal details; think before posting; report abusive content; respect others' privacy.
Why should we not forward a message without checking it?
It may be fake news or a rumour that can cause panic, hurt people or break the law. Check it from a trusted source first.
What is ethical use of technology? Give two examples.
Using technology in a fair, legal and responsible way. Examples: using licensed software; giving credit to sources; respecting others' privacy online.
Explain 'think before you click' with an example.
Before opening a link or attachment, check who sent it and whether it is safe. Example: a message 'Claim your free recharge' may lead to a phishing site.
Differentiate between hacking and cracking.
Hacking in general means getting into a system, and may be ethical with permission. Cracking is breaking security for a bad purpose, such as stealing data or removing software protection; it is always illegal.
What is cyber stalking?
Following or watching a person online again and again, sending unwanted messages and collecting information about them, which makes them afraid. It is a crime.
Give two ways schools can make computer labs friendly for students with disabilities.
Install screen readers and magnifiers; provide adjustable desks and wheelchair access; use large keyboards or Braille keyboards; give captions on videos.
What does 'copyleft' mean?
A licence condition that lets anyone use, change and share the work, but requires that changed versions are shared under the same free terms. GPL is a copyleft licence.
Why is a digital signature used? Name the Act that recognises it in India.
To prove who sent an electronic document and that it was not changed on the way. The IT Act, 2000 gives it legal recognition.
Write two precautions to take while shopping online.
Use trusted sites with https; do not save card details on shared computers; use cash on delivery or secure payment options; check reviews and seller details.
What is a cyber cell? When should we contact it?
A police unit that investigates cyber crimes. Contact it (or cybercrime.gov.in, helpline 1930) when we face fraud, hacking, bullying or identity theft.
Why is password sharing unsafe even with friends?
The friend may misuse it knowingly or by mistake, or the password may leak from their device. You remain responsible for all actions done from your account.
Draw the logic circuit for the Boolean expression A AND (NOT B). Also write its truth table.
| A | B | Y = A AND (NOT B) |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Draw the logic circuit for the Boolean expression (NOT A) OR B. Also write its truth table.
| A | B | Y = (NOT A) OR B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Draw the logic circuit for the Boolean expression NOT (A AND B). Also write its truth table.
| A | B | Y = NOT (A AND B) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Draw the logic circuit for the Boolean expression NOT (A OR B). Also write its truth table.
| A | B | Y = NOT (A OR B) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
Draw the logic circuit for the Boolean expression (NOT A) AND (NOT B). Also write its truth table.
| A | B | Y = (NOT A) AND (NOT B) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
Draw the logic circuit for the Boolean expression (NOT A) OR (NOT B). Also write its truth table.
| A | B | Y = (NOT A) OR (NOT B) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Draw the logic circuit for the Boolean expression A XOR B. Also write its truth table.
| A | B | X | Y = A XOR B |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
Draw the logic circuit for the Boolean expression (A AND B) OR (NOT A AND NOT B). Also write its truth table.
| A | B | Y = (A AND B) OR (NOT A AND NOT B) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Draw the logic circuit for the Boolean expression (A AND B) OR C. Also write its truth table.
| A | B | C | Y = (A AND B) OR C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
Draw the logic circuit for the Boolean expression A AND (B OR C). Also write its truth table.
| A | B | C | Y = A AND (B OR C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
Draw the logic circuit for the Boolean expression (A OR B) AND (NOT C). Also write its truth table.
| A | B | C | Y = (A OR B) AND (NOT C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
Draw the logic circuit for the Boolean expression NOT A OR (B AND C). Also write its truth table.
| A | B | C | Y = NOT A OR (B AND C) |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
Draw the logic circuit for the Boolean expression (A AND NOT B) OR (B AND C). Also write its truth table.
| A | B | C | Y = (A AND NOT B) OR (B AND C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
Draw the logic circuit for the Boolean expression NOT (A OR B) AND C. Also write its truth table.
| A | B | C | Y = NOT (A OR B) AND C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
Draw the logic circuit for the Boolean expression (A OR NOT B) AND (B OR C). Also write its truth table.
| A | B | C | Y = (A OR NOT B) AND (B OR C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
Draw the logic circuit for the Boolean expression A AND B AND NOT C. Also write its truth table.
| A | B | C | Y = A AND B AND NOT C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
Write the Boolean expression for the output Y of this logic circuit.
Y = A AND (NOT B)
| A | B | Y = A AND (NOT B) |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Write the Boolean expression for the output Y of this logic circuit.
Y = (NOT A) OR B
| A | B | Y = (NOT A) OR B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Write the Boolean expression for the output Y of this logic circuit.
Y = NOT (A AND B)
| A | B | Y = NOT (A AND B) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Write the Boolean expression for the output Y of this logic circuit.
Y = NOT (A OR B)
| A | B | Y = NOT (A OR B) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
Write the Boolean expression for the output Y of this logic circuit.
Y = (NOT A) AND (NOT B)
| A | B | Y = (NOT A) AND (NOT B) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
Write the Boolean expression for the output Y of this logic circuit.
Y = (NOT A) OR (NOT B)
| A | B | Y = (NOT A) OR (NOT B) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Write the Boolean expression for the output Y of this logic circuit.
Y = A XOR B
| A | B | X | Y = A XOR B |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
Write the Boolean expression for the output Y of this logic circuit.
Y = (A AND B) OR (NOT A AND NOT B)
| A | B | Y = (A AND B) OR (NOT A AND NOT B) |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Write the Boolean expression for the output Y of this logic circuit.
Y = (A AND B) OR C
| A | B | C | Y = (A AND B) OR C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
Write the Boolean expression for the output Y of this logic circuit.
Y = A AND (B OR C)
| A | B | C | Y = A AND (B OR C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
Write the Boolean expression for the output Y of this logic circuit.
Y = (A OR B) AND (NOT C)
| A | B | C | Y = (A OR B) AND (NOT C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
Write the Boolean expression for the output Y of this logic circuit.
Y = NOT A OR (B AND C)
| A | B | C | Y = NOT A OR (B AND C) |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
Write the Boolean expression for the output Y of this logic circuit.
Y = (A AND NOT B) OR (B AND C)
| A | B | C | Y = (A AND NOT B) OR (B AND C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
Write the Boolean expression for the output Y of this logic circuit.
Y = NOT (A OR B) AND C
| A | B | C | Y = NOT (A OR B) AND C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
Write the Boolean expression for the output Y of this logic circuit.
Y = (A OR NOT B) AND (B OR C)
| A | B | C | Y = (A OR NOT B) AND (B OR C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
Write the Boolean expression for the output Y of this logic circuit.
Y = A AND B AND NOT C
| A | B | C | Y = A AND B AND NOT C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
Name the cyber crime in each case:
Name the type of malware:
Which licence or software type is it?
Which IPR protects it?
Active or passive digital footprint?
What should be done?
Ethical or unethical?
Name the term:
Identify the threat:
Suggest one safety measure for each:
Which law or rule applies?
Give one harmful effect of each:
Identify the crime:
Free/open source or proprietary?
Which is the right action?
Name the e-waste step:
Name the term:
Gender or disability issue, and one solution:
Name the type of software:
Identify the act:
Write the output of the following code. Show your working in short.
msg = "KV Shalimar Bagh"
new = ""
for i in range(len(msg)):
ch = msg[i]
if ch.isupper():
new = new + ch.lower()
elif ch.islower():
new = new + ch.upper()
elif ch.isdigit():
new = new + str(int(ch) + 1)
else:
new = new + "#"
print(new)
print(len(new), new.count("#"))Output:
kv#sHALIMAR#bAGH 16 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "KV Shalimar Bagh" | msg = 'KV Shalimar Bagh' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | ch = msg[i] | ch = 'K' | |
| 5 | if ch.isupper(): | condition is True | |
| 6 | new = new + ch.lower() | new = 'k' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | ch = msg[i] | ch = 'V' | |
| 5 | if ch.isupper(): | condition is True | |
| 6 | new = new + ch.lower() | new = 'kv' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 4 | ch = msg[i] | ch = ' ' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is False | |
| 9 | elif ch.isdigit(): | condition is False | |
| 12 | new = new + "#" | new = 'kv#' |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
msg = "Python is Easy"
new = ""
for i in range(len(msg)):
ch = msg[i]
if ch.isupper():
new = new + ch.lower()
elif ch.islower():
new = new + ch.upper()
elif ch.isdigit():
new = new + str(int(ch) + 1)
else:
new = new + "*"
print(new)
print(len(new), new.count("*"))Output:
pYTHON*IS*eASY 14 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "Python is Easy" | msg = 'Python is Easy' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | ch = msg[i] | ch = 'P' | |
| 5 | if ch.isupper(): | condition is True | |
| 6 | new = new + ch.lower() | new = 'p' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | ch = msg[i] | ch = 'y' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'pY' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 4 | ch = msg[i] | ch = 't' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'pYT' |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
T = (33, 25, 28, 26, 12, 10)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(10, 26, 25, 66, 56, 24) 3 10
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (33, 25, 28, 26, 12, 10) | T = (33, 25, 28, 26, 12, 10) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [66] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [25, 66] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [25, 66, 56] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [26, 25, 66, 56] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
msg = "India is Great"
new = ""
for i in range(len(msg)):
if i % 2 == 0:
new = new + msg[i].upper()
elif msg[i] in "aeiouAEIOU":
new = new + "*"
else:
new = new + msg[i - 1]
print(new)Output:
IID*AaIi R*Aa
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "India is Great" | msg = 'India is Great' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | new = new + msg[i].upper() | new = 'I' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 6 | elif msg[i] in "aeiouAEIOU": | condition is False | |
| 9 | new = new + msg[i - 1] | new = 'II' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | new = new + msg[i].upper() | new = 'IID' | |
| 3 | for i in range(len(msg)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 6 | elif msg[i] in "aeiouAEIOU": | condition is True | |
| 7 | new = new + "*" | new = 'IID*' |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
T = (12, 3, 30, 32, 16, 20)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(20, 32, 3, 24, 60, 32) 4 3
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (12, 3, 30, 32, 16, 20) | T = (12, 3, 30, 32, 16, 20) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [24] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [3, 24] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [3, 24, 60] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [32, 3, 24, 60] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
n = 4
for i in range(n):
s = ""
for j in range(i + 1):
s = s + chr(65 + i + j)
print(s)Output:
A BC CDE DEFG
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 4 | n = 4 | |
| 2 | for i in range(n): | i = 0 | |
| 3 | s = "" | s = '' | |
| 4 | for j in range(i + 1): | j = 0 | |
| 5 | s = s + chr(65 + i + j) | s = 'A' | |
| 4 | for j in range(i + 1): | loop ends (no more values) | |
| 6 | print(s) | A⏎ | |
| 2 | for i in range(n): | i = 1 | |
| 3 | s = "" | s = '' | |
| 4 | for j in range(i + 1): | loop ends (no more values) | |
| 5 | s = s + chr(65 + i + j) | s = 'B' | |
| 4 | for j in range(i + 1): | j = 1 | |
| 5 | s = s + chr(65 + i + j) | s = 'BC' | |
| 4 | for j in range(i + 1): | loop ends (no more values) | |
| 6 | print(s) | BC⏎ | |
| 2 | for i in range(n): | i = 2 |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
msg = "Learn Code Daily"
new = ""
for i in range(len(msg)):
if i % 2 == 0:
new = new + msg[i].upper()
elif msg[i] in "aeiouAEIOU":
new = new + "*"
else:
new = new + msg[i - 1]
print(new)Output:
L*AaNnC*D* A*Ll
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "Learn Code Daily" | msg = 'Learn Code Daily' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | new = new + msg[i].upper() | new = 'L' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 6 | elif msg[i] in "aeiouAEIOU": | condition is True | |
| 7 | new = new + "*" | new = 'L*' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | new = new + msg[i].upper() | new = 'L*A' | |
| 3 | for i in range(len(msg)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 6 | elif msg[i] in "aeiouAEIOU": | condition is False | |
| 9 | new = new + msg[i - 1] | new = 'L*Aa' |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
text = "CBSE Exam 2027"
D = {}
for ch in text.lower():
if ch.isalpha():
D[ch] = D.get(ch, 0) + 1
for k in sorted(D):
if D[k] > 1:
print(k, D[k])Output:
e 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | text = "CBSE Exam 2027" | text = 'CBSE Exam 2027' | |
| 2 | D = {} | D = {} | |
| 3 | for ch in text.lower(): | ch = 'c' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'c': 1} | |
| 3 | for ch in text.lower(): | ch = 'b' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'c': 1, 'b': 1} | |
| 3 | for ch in text.lower(): | ch = 's' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'c': 1, 'b': 1, 's': 1} | |
| 3 | for ch in text.lower(): | ch = 'e' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'c': 1, 'b': 1, 's': 1, 'e': 1} | |
| 3 | for ch in text.lower(): | ch = ' ' | |
| 4 | if ch.isalpha(): | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Bag': 20, 'Map': 80, 'Pen': 15, 'Ink': 10}
for item in stock:
if stock[item] < 51:
stock[item] += 10
stock["Glue"] = 7
del stock['Bag']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Map': 80, 'Pen': 25, 'Ink': 20, 'Glue': 7}
4 132Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 20, 'Map': 80, 'Pen': 15, 'Ink': 10} | stock = {'Bag': 20, 'Map': 80, 'Pen': 15, 'Ink': 10} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 51: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 30, 'Map': 80, 'Pen': 15, 'Ink': 10} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 51: | condition is False | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 51: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 30, 'Map': 80, 'Pen': 25, 'Ink': 10} | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 51: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 30, 'Map': 80, 'Pen': 25, 'Ink': 20} | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 7 | stock = {'Bag': 30, 'Map': 80, 'Pen': 25, 'Ink': 20, 'Glue': 7} | |
| 6 | del stock['Bag'] | stock = {'Map': 80, 'Pen': 25, 'Ink': 20, 'Glue': 7} | |
| 7 | print(stock) | {'Map': 80, 'Pen': 25, 'Ink': 20, 'Glue': 7}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 132⏎ |
Write the output of the following code. Show your working in short.
L = [19, 58, 39, 27, 22, 11]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::4], max(L) % 9)Output:
[77, 97, 66, 49, 33, 11] [77, 33] 7
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [19, 58, 39, 27, 22, 11] | L = [19, 58, 39, 27, 22, 11] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [77, 58, 39, 27, 22, 11] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [77, 97, 39, 27, 22, 11] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [77, 97, 66, 27, 22, 11] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [77, 97, 66, 49, 22, 11] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [77, 97, 66, 49, 33, 11] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [77, 97, 66, 49, 33, 11]⏎ | |
| 5 | print(L[::4], max(L) % 9) | [77, 33] 7⏎ |
Write the output of the following code. Show your working in short.
msg = "Vidyalaya"
new = ""
for i in range(len(msg)):
ch = msg[i]
if ch.isupper():
new = new + ch.lower()
elif ch.islower():
new = new + ch.upper()
elif ch.isdigit():
new = new + str(int(ch) + 1)
else:
new = new + "@"
print(new)
print(len(new), new.count("@"))Output:
vIDYALAYA 9 0
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "Vidyalaya" | msg = 'Vidyalaya' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | ch = msg[i] | ch = 'V' | |
| 5 | if ch.isupper(): | condition is True | |
| 6 | new = new + ch.lower() | new = 'v' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | ch = msg[i] | ch = 'i' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'vI' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 4 | ch = msg[i] | ch = 'd' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'vID' |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
T = (32, 2, 28, 39, 30, 18)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(18, 39, 2, 64, 56, 60) 3 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (32, 2, 28, 39, 30, 18) | T = (32, 2, 28, 39, 30, 18) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [64] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [2, 64] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [2, 64, 56] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [39, 2, 64, 56] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
n = 5
for i in range(1, n + 1):
print(" " * (n - i), end="")
for j in range(1, i + 1):
print(j, end="")
for j in range(i - 1, 0, -1):
print(j, end="")
print()Output:
1 121 12321 1234321 123454321
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 5 | n = 5 | |
| 2 | for i in range(1, n + 1): | i = 1 | |
| 3 | print(" " * (n - i), end="") | | |
| 4 | for j in range(1, i + 1): | j = 1 | |
| 5 | print(j, end="") | 1 | |
| 4 | for j in range(1, i + 1): | loop ends (no more values) | |
| 6 | for j in range(i - 1, 0, -1): | loop ends (no more values) | |
| 8 | print() | ⏎ | |
| 2 | for i in range(1, n + 1): | i = 2 | |
| 3 | print(" " * (n - i), end="") | | |
| 4 | for j in range(1, i + 1): | loop ends (no more values) | |
| 5 | print(j, end="") | 1 | |
| 4 | for j in range(1, i + 1): | j = 2 | |
| 5 | print(j, end="") | 2 | |
| 4 | for j in range(1, i + 1): | loop ends (no more values) | |
| 6 | for j in range(i - 1, 0, -1): | j = 1 |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
msg = "Data and Logic"
new = ""
for i in range(len(msg)):
ch = msg[i]
if ch.isupper():
new = new + ch.lower()
elif ch.islower():
new = new + ch.upper()
elif ch.isdigit():
new = new + str(int(ch) + 1)
else:
new = new + "*"
print(new)
print(len(new), new.count("*"))Output:
dATA*AND*lOGIC 14 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "Data and Logic" | msg = 'Data and Logic' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | ch = msg[i] | ch = 'D' | |
| 5 | if ch.isupper(): | condition is True | |
| 6 | new = new + ch.lower() | new = 'd' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | ch = msg[i] | ch = 'a' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'dA' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 4 | ch = msg[i] | ch = 't' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'dAT' |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [25, 56, 36, 49, 39, 47]
A, B = [], []
for x in L:
if x % 4 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[56, 36] [47, 39, 49, 25] [56, 36, 47, 39]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [25, 56, 36, 49, 39, 47] | L = [25, 56, 36, 49, 39, 47] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 25 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [25] | |
| 3 | for x in L: | x = 56 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [56] | |
| 3 | for x in L: | x = 36 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [56, 36] | |
| 3 | for x in L: | x = 49 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [49, 25] | |
| 3 | for x in L: | x = 39 | |
| 4 | if x % 4 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
a, b = 0, 1
for i in range(7):
print(a, end=" ")
a, b = b, a + b
print()
print(a + b)Output:
0 1 1 2 3 5 8 34
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | a, b = 0, 1 | a = 0, b = 1 | |
| 2 | for i in range(7): | i = 0 | |
| 3 | print(a, end=" ") | 0 | |
| 4 | a, b = b, a + b | a = 1 | |
| 2 | for i in range(7): | i = 1 | |
| 3 | print(a, end=" ") | 1 | |
| 4 | a, b = b, a + b | b = 2 | |
| 2 | for i in range(7): | i = 2 | |
| 3 | print(a, end=" ") | 1 | |
| 4 | a, b = b, a + b | a = 2, b = 3 | |
| 2 | for i in range(7): | i = 3 | |
| 3 | print(a, end=" ") | 2 | |
| 4 | a, b = b, a + b | a = 3, b = 5 | |
| 2 | for i in range(7): | i = 4 | |
| 3 | print(a, end=" ") | 3 | |
| 4 | a, b = b, a + b | a = 5, b = 8 |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [43, 5, 44, 49, 9, 37]
A, B = [], []
for x in L:
if x % 2 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[44] [37, 9, 49, 5, 43] [44, 37, 9]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [43, 5, 44, 49, 9, 37] | L = [43, 5, 44, 49, 9, 37] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 43 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [43] | |
| 3 | for x in L: | x = 5 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [5, 43] | |
| 3 | for x in L: | x = 44 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [44] | |
| 3 | for x in L: | x = 49 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [49, 5, 43] | |
| 3 | for x in L: | x = 9 | |
| 4 | if x % 2 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [12, 22, 29, 35, 46, 32]
A, B = [], []
for x in L:
if x % 4 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[12, 32] [46, 35, 29, 22] [12, 32, 46, 35]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [12, 22, 29, 35, 46, 32] | L = [12, 22, 29, 35, 46, 32] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 12 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [12] | |
| 3 | for x in L: | x = 22 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [22] | |
| 3 | for x in L: | x = 29 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [29, 22] | |
| 3 | for x in L: | x = 35 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [35, 29, 22] | |
| 3 | for x in L: | x = 46 | |
| 4 | if x % 4 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
msg = "DATABASE"
new = ""
for i in range(len(msg)):
ch = msg[i]
if ch.isupper():
new = new + ch.lower()
elif ch.islower():
new = new + ch.upper()
elif ch.isdigit():
new = new + str(int(ch) + 1)
else:
new = new + "#"
print(new)
print(len(new), new.count("#"))Output:
database 8 0
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "DATABASE" | msg = 'DATABASE' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | ch = msg[i] | ch = 'D' | |
| 5 | if ch.isupper(): | condition is True | |
| 6 | new = new + ch.lower() | new = 'd' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | ch = msg[i] | ch = 'A' | |
| 5 | if ch.isupper(): | condition is True | |
| 6 | new = new + ch.lower() | new = 'da' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 4 | ch = msg[i] | ch = 'T' | |
| 5 | if ch.isupper(): | condition is True | |
| 6 | new = new + ch.lower() | new = 'dat' | |
| 3 | for i in range(len(msg)): | i = 3 | |
| 4 | ch = msg[i] | ch = 'A' |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
text = "Keep Calm and Code"
D = {}
for ch in text.lower():
if ch.isalpha():
D[ch] = D.get(ch, 0) + 1
for k in sorted(D):
if D[k] > 1:
print(k, D[k])Output:
a 2 c 2 d 2 e 3
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | text = "Keep Calm and Code" | text = 'Keep Calm and Code' | |
| 2 | D = {} | D = {} | |
| 3 | for ch in text.lower(): | ch = 'k' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'k': 1} | |
| 3 | for ch in text.lower(): | ch = 'e' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'k': 1, 'e': 1} | |
| 3 | for ch in text.lower(): | loop ends (no more values) | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'k': 1, 'e': 2} | |
| 3 | for ch in text.lower(): | ch = 'p' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'k': 1, 'e': 2, 'p': 1} | |
| 3 | for ch in text.lower(): | ch = ' ' | |
| 4 | if ch.isalpha(): | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Map': 75, 'Bag': 85, 'Ink': 65, 'Book': 70}
for item in stock:
if stock[item] < 37:
stock[item] += 10
stock["Glue"] = 17
del stock['Bag']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Map': 75, 'Ink': 65, 'Book': 70, 'Glue': 17}
4 227Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Map': 75, 'Bag': 85, 'Ink': 65, 'Book': 70} | stock = {'Map': 75, 'Bag': 85, 'Ink': 65, 'Book': 70} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 37: | condition is False | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 37: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 37: | condition is False | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 37: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 17 | stock = {'Map': 75, 'Bag': 85, 'Ink': 65, 'Book': 70, 'Glue': 17} | |
| 6 | del stock['Bag'] | stock = {'Map': 75, 'Ink': 65, 'Book': 70, 'Glue': 17} | |
| 7 | print(stock) | {'Map': 75, 'Ink': 65, 'Book': 70, 'Glue': 17}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 227⏎ |
Write the output of the following code. Show your working in short.
a, b = 0, 1
for i in range(8):
print(a, end=" ")
a, b = b, a + b
print()
print(a + b)Output:
0 1 1 2 3 5 8 13 55
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | a, b = 0, 1 | a = 0, b = 1 | |
| 2 | for i in range(8): | i = 0 | |
| 3 | print(a, end=" ") | 0 | |
| 4 | a, b = b, a + b | a = 1 | |
| 2 | for i in range(8): | i = 1 | |
| 3 | print(a, end=" ") | 1 | |
| 4 | a, b = b, a + b | b = 2 | |
| 2 | for i in range(8): | i = 2 | |
| 3 | print(a, end=" ") | 1 | |
| 4 | a, b = b, a + b | a = 2, b = 3 | |
| 2 | for i in range(8): | i = 3 | |
| 3 | print(a, end=" ") | 2 | |
| 4 | a, b = b, a + b | a = 3, b = 5 | |
| 2 | for i in range(8): | i = 4 | |
| 3 | print(a, end=" ") | 3 | |
| 4 | a, b = b, a + b | a = 5, b = 8 |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
T = (11, 37, 8, 35, 27, 31)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(31, 35, 37, 22, 16, 54) 5 16
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (11, 37, 8, 35, 27, 31) | T = (11, 37, 8, 35, 27, 31) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [22] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [37, 22] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [37, 22, 16] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [35, 37, 22, 16] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [10, 18, 16, 12, 41, 6]
A, B = [], []
for x in L:
if x % 2 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[10, 18, 16, 12, 6] [41] [10, 18, 16, 12, 6, 41]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [10, 18, 16, 12, 41, 6] | L = [10, 18, 16, 12, 41, 6] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 10 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [10] | |
| 3 | for x in L: | x = 18 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [10, 18] | |
| 3 | for x in L: | x = 16 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [10, 18, 16] | |
| 3 | for x in L: | x = 12 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [10, 18, 16, 12] | |
| 3 | for x in L: | x = 41 | |
| 4 | if x % 2 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
msg = "KV Shalimar Bagh"
new = ""
for i in range(len(msg)):
if i % 2 == 0:
new = new + msg[i].upper()
elif msg[i] in "aeiouAEIOU":
new = new + "*"
else:
new = new + msg[i - 1]
print(new)Output:
KK H*L*M*RrB*Gg
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "KV Shalimar Bagh" | msg = 'KV Shalimar Bagh' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | new = new + msg[i].upper() | new = 'K' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 6 | elif msg[i] in "aeiouAEIOU": | condition is False | |
| 9 | new = new + msg[i - 1] | new = 'KK' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | new = new + msg[i].upper() | new = 'KK ' | |
| 3 | for i in range(len(msg)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 6 | elif msg[i] in "aeiouAEIOU": | condition is False | |
| 9 | new = new + msg[i - 1] | new = 'KK ' |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [51, 9, 54, 48, 38, 44]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::3], max(L) % 9)Output:
[60, 63, 102, 86, 82, 44] [60, 86] 3
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [51, 9, 54, 48, 38, 44] | L = [51, 9, 54, 48, 38, 44] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [60, 9, 54, 48, 38, 44] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [60, 63, 54, 48, 38, 44] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [60, 63, 102, 48, 38, 44] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [60, 63, 102, 86, 38, 44] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [60, 63, 102, 86, 82, 44] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [60, 63, 102, 86, 82, 44]⏎ | |
| 5 | print(L[::3], max(L) % 9) | [60, 86] 3⏎ |
Write the output of the following code. Show your working in short.
text = "Learn Code Daily"
D = {}
for ch in text.lower():
if ch.isalpha():
D[ch] = D.get(ch, 0) + 1
for k in sorted(D):
if D[k] > 1:
print(k, D[k])Output:
a 2 d 2 e 2 l 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | text = "Learn Code Daily" | text = 'Learn Code Daily' | |
| 2 | D = {} | D = {} | |
| 3 | for ch in text.lower(): | ch = 'l' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'l': 1} | |
| 3 | for ch in text.lower(): | ch = 'e' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'l': 1, 'e': 1} | |
| 3 | for ch in text.lower(): | ch = 'a' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'l': 1, 'e': 1, 'a': 1} | |
| 3 | for ch in text.lower(): | ch = 'r' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'l': 1, 'e': 1, 'a': 1, 'r': 1} | |
| 3 | for ch in text.lower(): | ch = 'n' | |
| 4 | if ch.isalpha(): | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [14, 50, 45, 26, 29, 56]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::2], max(L) % 7)Output:
[64, 95, 71, 55, 85, 56] [64, 71, 85] 4
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [14, 50, 45, 26, 29, 56] | L = [14, 50, 45, 26, 29, 56] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [64, 50, 45, 26, 29, 56] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [64, 95, 45, 26, 29, 56] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [64, 95, 71, 26, 29, 56] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [64, 95, 71, 55, 29, 56] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [64, 95, 71, 55, 85, 56] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [64, 95, 71, 55, 85, 56]⏎ | |
| 5 | print(L[::2], max(L) % 7) | [64, 71, 85] 4⏎ |
Write the output of the following code. Show your working in short.
text = "India is Great"
D = {}
for ch in text.lower():
if ch.isalpha():
D[ch] = D.get(ch, 0) + 1
for k in sorted(D):
if D[k] > 1:
print(k, D[k])Output:
a 2 i 3
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | text = "India is Great" | text = 'India is Great' | |
| 2 | D = {} | D = {} | |
| 3 | for ch in text.lower(): | ch = 'i' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'i': 1} | |
| 3 | for ch in text.lower(): | ch = 'n' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'i': 1, 'n': 1} | |
| 3 | for ch in text.lower(): | ch = 'd' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'i': 1, 'n': 1, 'd': 1} | |
| 3 | for ch in text.lower(): | ch = 'i' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'i': 2, 'n': 1, 'd': 1} | |
| 3 | for ch in text.lower(): | ch = 'a' | |
| 4 | if ch.isalpha(): | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
msg = "Function"
new = ""
for i in range(len(msg)):
ch = msg[i]
if ch.isupper():
new = new + ch.lower()
elif ch.islower():
new = new + ch.upper()
elif ch.isdigit():
new = new + str(int(ch) + 1)
else:
new = new + "#"
print(new)
print(len(new), new.count("#"))Output:
fUNCTION 8 0
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "Function" | msg = 'Function' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | ch = msg[i] | ch = 'F' | |
| 5 | if ch.isupper(): | condition is True | |
| 6 | new = new + ch.lower() | new = 'f' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | ch = msg[i] | ch = 'u' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'fU' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 4 | ch = msg[i] | ch = 'n' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'fUN' |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
msg = "Learning"
new = ""
for i in range(len(msg)):
if i % 2 == 0:
new = new + msg[i].upper()
elif msg[i] in "aeiouAEIOU":
new = new + "*"
else:
new = new + msg[i - 1]
print(new)Output:
L*AaN*Nn
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "Learning" | msg = 'Learning' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | new = new + msg[i].upper() | new = 'L' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 6 | elif msg[i] in "aeiouAEIOU": | condition is True | |
| 7 | new = new + "*" | new = 'L*' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | new = new + msg[i].upper() | new = 'L*A' | |
| 3 | for i in range(len(msg)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 6 | elif msg[i] in "aeiouAEIOU": | condition is False | |
| 9 | new = new + msg[i - 1] | new = 'L*Aa' |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
text = "Save Water Save Life"
D = {}
for ch in text.lower():
if ch.isalpha():
D[ch] = D.get(ch, 0) + 1
for k in sorted(D):
if D[k] > 1:
print(k, D[k])Output:
a 3 e 4 s 2 v 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | text = "Save Water Save Life" | text = 'Save Water Save Life' | |
| 2 | D = {} | D = {} | |
| 3 | for ch in text.lower(): | ch = 's' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'s': 1} | |
| 3 | for ch in text.lower(): | ch = 'a' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'s': 1, 'a': 1} | |
| 3 | for ch in text.lower(): | ch = 'v' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'s': 1, 'a': 1, 'v': 1} | |
| 3 | for ch in text.lower(): | ch = 'e' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'s': 1, 'a': 1, 'v': 1, 'e': 1} | |
| 3 | for ch in text.lower(): | ch = ' ' | |
| 4 | if ch.isalpha(): | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
msg = "Python is Easy"
new = ""
for i in range(len(msg)):
if i % 2 == 0:
new = new + msg[i].upper()
elif msg[i] in "aeiouAEIOU":
new = new + "#"
else:
new = new + msg[i - 1]
print(new)Output:
PPTtOo #SsE#Ss
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "Python is Easy" | msg = 'Python is Easy' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | new = new + msg[i].upper() | new = 'P' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 6 | elif msg[i] in "aeiouAEIOU": | condition is False | |
| 9 | new = new + msg[i - 1] | new = 'PP' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | new = new + msg[i].upper() | new = 'PPT' | |
| 3 | for i in range(len(msg)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 6 | elif msg[i] in "aeiouAEIOU": | condition is False | |
| 9 | new = new + msg[i - 1] | new = 'PPTt' |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
T = (30, 7, 29, 33, 39, 14)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(14, 33, 7, 60, 58, 78) 5 7
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (30, 7, 29, 33, 39, 14) | T = (30, 7, 29, 33, 39, 14) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [60] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [7, 60] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [7, 60, 58] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [33, 7, 60, 58] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [37, 22, 7, 16, 58, 34]
A, B = [], []
for x in L:
if x % 4 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[16] [34, 58, 7, 22, 37] [16, 34, 58]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [37, 22, 7, 16, 58, 34] | L = [37, 22, 7, 16, 58, 34] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 37 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [37] | |
| 3 | for x in L: | x = 22 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [22, 37] | |
| 3 | for x in L: | x = 7 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [7, 22, 37] | |
| 3 | for x in L: | x = 16 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [16] | |
| 3 | for x in L: | x = 58 | |
| 4 | if x % 4 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [25, 59, 44, 17, 27, 57]
A, B = [], []
for x in L:
if x % 2 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[44] [57, 27, 17, 59, 25] [44, 57, 27]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [25, 59, 44, 17, 27, 57] | L = [25, 59, 44, 17, 27, 57] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 25 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [25] | |
| 3 | for x in L: | x = 59 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [59, 25] | |
| 3 | for x in L: | x = 44 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [44] | |
| 3 | for x in L: | x = 17 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [17, 59, 25] | |
| 3 | for x in L: | x = 27 | |
| 4 | if x % 2 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Map': 45, 'Ruler': 30, 'Ink': 55, 'Pen': 35}
for item in stock:
if stock[item] < 49:
stock[item] += 10
stock["Glue"] = 13
del stock['Map']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Ruler': 40, 'Ink': 55, 'Pen': 45, 'Glue': 13}
4 153Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Map': 45, 'Ruler': 30, 'Ink': 55, 'Pen': 35} | stock = {'Map': 45, 'Ruler': 30, 'Ink': 55, 'Pen': 35} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 49: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Map': 55, 'Ruler': 30, 'Ink': 55, 'Pen': 35} | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 49: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Map': 55, 'Ruler': 40, 'Ink': 55, 'Pen': 35} | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 49: | condition is False | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 49: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Map': 55, 'Ruler': 40, 'Ink': 55, 'Pen': 45} | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 13 | stock = {'Map': 55, 'Ruler': 40, 'Ink': 55, 'Pen': 45, 'Glue': 13} | |
| 6 | del stock['Map'] | stock = {'Ruler': 40, 'Ink': 55, 'Pen': 45, 'Glue': 13} | |
| 7 | print(stock) | {'Ruler': 40, 'Ink': 55, 'Pen': 45, 'Glue': 13}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 153⏎ |
Write the output of the following code. Show your working in short.
T = (37, 5, 20, 39, 22, 21)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(21, 39, 5, 74, 40, 44) 3 5
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (37, 5, 20, 39, 22, 21) | T = (37, 5, 20, 39, 22, 21) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [74] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [5, 74] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [5, 74, 40] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [39, 5, 74, 40] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
T = (2, 22, 31, 28, 1, 19)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(19, 28, 22, 4, 62, 2) 4 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (2, 22, 31, 28, 1, 19) | T = (2, 22, 31, 28, 1, 19) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [4] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [22, 4] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [22, 4, 62] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [28, 22, 4, 62] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
T = (6, 16, 2, 30, 18, 8)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(8, 30, 16, 12, 4, 36) 5 4
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (6, 16, 2, 30, 18, 8) | T = (6, 16, 2, 30, 18, 8) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [12] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [16, 12] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [16, 12, 4] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [30, 16, 12, 4] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
T = (30, 33, 9, 36, 17, 19)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(19, 36, 33, 60, 18, 34) 3 18
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (30, 33, 9, 36, 17, 19) | T = (30, 33, 9, 36, 17, 19) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [60] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [33, 60] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [33, 60, 18] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [36, 33, 60, 18] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
T = (25, 39, 29, 12, 33, 26)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(26, 12, 39, 50, 58, 66) 5 12
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (25, 39, 29, 12, 33, 26) | T = (25, 39, 29, 12, 33, 26) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [50] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [39, 50] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [39, 50, 58] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [12, 39, 50, 58] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
msg = "DATABASE"
new = ""
for i in range(len(msg)):
if i % 2 == 0:
new = new + msg[i].upper()
elif msg[i] in "aeiouAEIOU":
new = new + "@"
else:
new = new + msg[i - 1]
print(new)Output:
D@T@B@S@
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "DATABASE" | msg = 'DATABASE' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | new = new + msg[i].upper() | new = 'D' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 6 | elif msg[i] in "aeiouAEIOU": | condition is True | |
| 7 | new = new + "@" | new = 'D@' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | new = new + msg[i].upper() | new = 'D@T' | |
| 3 | for i in range(len(msg)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 6 | elif msg[i] in "aeiouAEIOU": | condition is True | |
| 7 | new = new + "@" | new = 'D@T@' |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
text = "Practice makes Perfect"
D = {}
for ch in text.lower():
if ch.isalpha():
D[ch] = D.get(ch, 0) + 1
for k in sorted(D):
if D[k] > 1:
print(k, D[k])Output:
a 2 c 3 e 4 p 2 r 2 t 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | text = "Practice makes Perfect" | text = 'Practice makes Perfect' | |
| 2 | D = {} | D = {} | |
| 3 | for ch in text.lower(): | ch = 'p' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'p': 1} | |
| 3 | for ch in text.lower(): | ch = 'r' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'p': 1, 'r': 1} | |
| 3 | for ch in text.lower(): | ch = 'a' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'p': 1, 'r': 1, 'a': 1} | |
| 3 | for ch in text.lower(): | ch = 'c' | |
| 4 | if ch.isalpha(): | condition is True | |
| 5 | D[ch] = D.get(ch, 0) + 1 | D = {'p': 1, 'r': 1, 'a': 1, 'c': 1} | |
| 3 | for ch in text.lower(): | ch = 't' | |
| 4 | if ch.isalpha(): | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Bag': 50, 'Ruler': 15, 'Map': 80, 'Ink': 65}
for item in stock:
if stock[item] < 38:
stock[item] += 10
stock["Glue"] = 12
del stock['Ink']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Bag': 50, 'Ruler': 25, 'Map': 80, 'Glue': 12}
4 167Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 50, 'Ruler': 15, 'Map': 80, 'Ink': 65} | stock = {'Bag': 50, 'Ruler': 15, 'Map': 80, 'Ink': 65} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 38: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 50, 'Ruler': 25, 'Map': 80, 'Ink': 65} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 12 | stock = {'Bag': 50, 'Ruler': 25, 'Map': 80, 'Ink': 65, 'Glue': 12} | |
| 6 | del stock['Ink'] | stock = {'Bag': 50, 'Ruler': 25, 'Map': 80, 'Glue': 12} | |
| 7 | print(stock) | {'Bag': 50, 'Ruler': 25, 'Map': 80, 'Glue': 12}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 167⏎ |
Write the output of the following code. Show your working in short.
L = [37, 40, 12, 8, 50, 44]
A, B = [], []
for x in L:
if x % 4 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[40, 12, 8, 44] [50, 37] [40, 12, 8, 44, 50, 37]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [37, 40, 12, 8, 50, 44] | L = [37, 40, 12, 8, 50, 44] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 37 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [37] | |
| 3 | for x in L: | x = 40 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [40] | |
| 3 | for x in L: | x = 12 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [40, 12] | |
| 3 | for x in L: | x = 8 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [40, 12, 8] | |
| 3 | for x in L: | x = 50 | |
| 4 | if x % 4 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [44, 8, 57, 59, 10, 29]
A, B = [], []
for x in L:
if x % 3 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[57] [29, 10, 59, 8, 44] [57, 29, 10]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [44, 8, 57, 59, 10, 29] | L = [44, 8, 57, 59, 10, 29] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 44 | |
| 4 | if x % 3 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [44] | |
| 3 | for x in L: | x = 8 | |
| 4 | if x % 3 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [8, 44] | |
| 3 | for x in L: | x = 57 | |
| 4 | if x % 3 == 0: | condition is True | |
| 5 | A.append(x) | A = [57] | |
| 3 | for x in L: | x = 59 | |
| 4 | if x % 3 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [59, 8, 44] | |
| 3 | for x in L: | x = 10 | |
| 4 | if x % 3 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
T = (20, 29, 30, 19, 39, 32)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(32, 19, 29, 40, 60, 78) 5 19
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (20, 29, 30, 19, 39, 32) | T = (20, 29, 30, 19, 39, 32) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [40] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [29, 40] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [29, 40, 60] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [19, 29, 40, 60] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [19, 34, 21, 38, 58, 15]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::2], max(L) % 5)Output:
[53, 55, 59, 96, 73, 15] [53, 59, 73] 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [19, 34, 21, 38, 58, 15] | L = [19, 34, 21, 38, 58, 15] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 34, 21, 38, 58, 15] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 55, 21, 38, 58, 15] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 55, 59, 38, 58, 15] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 55, 59, 96, 58, 15] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 55, 59, 96, 73, 15] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [53, 55, 59, 96, 73, 15]⏎ | |
| 5 | print(L[::2], max(L) % 5) | [53, 59, 73] 1⏎ |
Write the output of the following code. Show your working in short.
T = (17, 18, 35, 3, 31, 23)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(23, 3, 18, 34, 70, 62) 4 3
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (17, 18, 35, 3, 31, 23) | T = (17, 18, 35, 3, 31, 23) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [34] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [18, 34] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [18, 34, 70] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [3, 18, 34, 70] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
msg = "Keep Calm and Code"
new = ""
for i in range(len(msg)):
ch = msg[i]
if ch.isupper():
new = new + ch.lower()
elif ch.islower():
new = new + ch.upper()
elif ch.isdigit():
new = new + str(int(ch) + 1)
else:
new = new + "@"
print(new)
print(len(new), new.count("@"))Output:
kEEP@cALM@AND@cODE 18 3
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "Keep Calm and Code" | msg = 'Keep Calm and Code' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | ch = msg[i] | ch = 'K' | |
| 5 | if ch.isupper(): | condition is True | |
| 6 | new = new + ch.lower() | new = 'k' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | ch = msg[i] | ch = 'e' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'kE' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'kEE' | |
| 3 | for i in range(len(msg)): | i = 3 |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
T = (16, 33, 9, 35, 14, 2)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(2, 35, 33, 32, 18, 28) 1 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (16, 33, 9, 35, 14, 2) | T = (16, 33, 9, 35, 14, 2) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [32] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [33, 32] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [33, 32, 18] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [35, 33, 32, 18] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [8, 45, 30, 23, 46, 42]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::4], max(L) % 5)Output:
[53, 75, 53, 69, 88, 42] [53, 88] 3
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [8, 45, 30, 23, 46, 42] | L = [8, 45, 30, 23, 46, 42] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 45, 30, 23, 46, 42] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 75, 30, 23, 46, 42] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 75, 53, 23, 46, 42] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 75, 53, 69, 46, 42] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [53, 75, 53, 69, 88, 42] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [53, 75, 53, 69, 88, 42]⏎ | |
| 5 | print(L[::4], max(L) % 5) | [53, 88] 3⏎ |
Write the output of the following code. Show your working in short.
msg = "keyboard"
new = ""
for i in range(len(msg)):
ch = msg[i]
if ch.isupper():
new = new + ch.lower()
elif ch.islower():
new = new + ch.upper()
elif ch.isdigit():
new = new + str(int(ch) + 1)
else:
new = new + "@"
print(new)
print(len(new), new.count("@"))Output:
KEYBOARD 8 0
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "keyboard" | msg = 'keyboard' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | ch = msg[i] | ch = 'k' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'K' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | ch = msg[i] | ch = 'e' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'KE' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 4 | ch = msg[i] | ch = 'y' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Pen': 50, 'Bag': 10, 'Ruler': 55, 'Map': 20}
for item in stock:
if stock[item] < 32:
stock[item] += 10
stock["Glue"] = 15
del stock['Ruler']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Pen': 50, 'Bag': 20, 'Map': 30, 'Glue': 15}
4 115Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Pen': 50, 'Bag': 10, 'Ruler': 55, 'Map': 20} | stock = {'Pen': 50, 'Bag': 10, 'Ruler': 55, 'Map': 20} | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 32: | condition is False | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 32: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Pen': 50, 'Bag': 20, 'Ruler': 55, 'Map': 20} | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 32: | condition is False | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 32: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Pen': 50, 'Bag': 20, 'Ruler': 55, 'Map': 30} | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 15 | stock = {'Pen': 50, 'Bag': 20, 'Ruler': 55, 'Map': 30, 'Glue': 15} | |
| 6 | del stock['Ruler'] | stock = {'Pen': 50, 'Bag': 20, 'Map': 30, 'Glue': 15} | |
| 7 | print(stock) | {'Pen': 50, 'Bag': 20, 'Map': 30, 'Glue': 15}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 115⏎ |
Write the output of the following code. Show your working in short.
L = [36, 16, 59, 19, 38, 10]
A, B = [], []
for x in L:
if x % 2 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[36, 16, 38, 10] [19, 59] [36, 16, 38, 10, 19, 59]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [36, 16, 59, 19, 38, 10] | L = [36, 16, 59, 19, 38, 10] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 36 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [36] | |
| 3 | for x in L: | x = 16 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [36, 16] | |
| 3 | for x in L: | x = 59 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [59] | |
| 3 | for x in L: | x = 19 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [19, 59] | |
| 3 | for x in L: | x = 38 | |
| 4 | if x % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Map': 65, 'Bag': 70, 'Ink': 50, 'Book': 20}
for item in stock:
if stock[item] < 53:
stock[item] += 10
stock["Glue"] = 14
del stock['Book']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Map': 65, 'Bag': 70, 'Ink': 60, 'Glue': 14}
4 209Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Map': 65, 'Bag': 70, 'Ink': 50, 'Book': 20} | stock = {'Map': 65, 'Bag': 70, 'Ink': 50, 'Book': 20} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 53: | condition is False | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 53: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 53: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Map': 65, 'Bag': 70, 'Ink': 60, 'Book': 20} | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 53: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Map': 65, 'Bag': 70, 'Ink': 60, 'Book': 30} | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 14 | stock = {'Map': 65, 'Bag': 70, 'Ink': 60, 'Book': 30, 'Glue': 14} | |
| 6 | del stock['Book'] | stock = {'Map': 65, 'Bag': 70, 'Ink': 60, 'Glue': 14} | |
| 7 | print(stock) | {'Map': 65, 'Bag': 70, 'Ink': 60, 'Glue': 14}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 209⏎ |
Write the output of the following code. Show your working in short.
msg = "Network"
new = ""
for i in range(len(msg)):
if i % 2 == 0:
new = new + msg[i].upper()
elif msg[i] in "aeiouAEIOU":
new = new + "*"
else:
new = new + msg[i - 1]
print(new)Output:
N*TtOoK
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "Network" | msg = 'Network' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | new = new + msg[i].upper() | new = 'N' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 6 | elif msg[i] in "aeiouAEIOU": | condition is True | |
| 7 | new = new + "*" | new = 'N*' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | new = new + msg[i].upper() | new = 'N*T' | |
| 3 | for i in range(len(msg)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 6 | elif msg[i] in "aeiouAEIOU": | condition is False | |
| 9 | new = new + msg[i - 1] | new = 'N*Tt' |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [32, 50, 7, 23, 56, 31]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::3], max(L) % 8)Output:
[82, 57, 30, 79, 87, 31] [82, 79] 7
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [32, 50, 7, 23, 56, 31] | L = [32, 50, 7, 23, 56, 31] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [82, 50, 7, 23, 56, 31] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [82, 57, 7, 23, 56, 31] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [82, 57, 30, 23, 56, 31] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [82, 57, 30, 79, 56, 31] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [82, 57, 30, 79, 87, 31] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [82, 57, 30, 79, 87, 31]⏎ | |
| 5 | print(L[::3], max(L) % 8) | [82, 79] 7⏎ |
Write the output of the following code. Show your working in short.
stock = {'Ink': 85, 'Pen': 60, 'Map': 45, 'Book': 80}
for item in stock:
if stock[item] < 38:
stock[item] += 10
stock["Glue"] = 9
del stock['Ink']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Pen': 60, 'Map': 45, 'Book': 80, 'Glue': 9}
4 194Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Ink': 85, 'Pen': 60, 'Map': 45, 'Book': 80} | stock = {'Ink': 85, 'Pen': 60, 'Map': 45, 'Book': 80} | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 38: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 9 | stock = {'Ink': 85, 'Pen': 60, 'Map': 45, 'Book': 80, 'Glue': 9} | |
| 6 | del stock['Ink'] | stock = {'Pen': 60, 'Map': 45, 'Book': 80, 'Glue': 9} | |
| 7 | print(stock) | {'Pen': 60, 'Map': 45, 'Book': 80, 'Glue': 9}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 194⏎ |
Write the output of the following code. Show your working in short.
n = 3
for i in range(n):
s = ""
for j in range(i + 1):
s = s + chr(65 + i + j)
print(s)Output:
A BC CDE
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 3 | n = 3 | |
| 2 | for i in range(n): | i = 0 | |
| 3 | s = "" | s = '' | |
| 4 | for j in range(i + 1): | j = 0 | |
| 5 | s = s + chr(65 + i + j) | s = 'A' | |
| 4 | for j in range(i + 1): | loop ends (no more values) | |
| 6 | print(s) | A⏎ | |
| 2 | for i in range(n): | i = 1 | |
| 3 | s = "" | s = '' | |
| 4 | for j in range(i + 1): | loop ends (no more values) | |
| 5 | s = s + chr(65 + i + j) | s = 'B' | |
| 4 | for j in range(i + 1): | j = 1 | |
| 5 | s = s + chr(65 + i + j) | s = 'BC' | |
| 4 | for j in range(i + 1): | loop ends (no more values) | |
| 6 | print(s) | BC⏎ | |
| 2 | for i in range(n): | i = 2 |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
T = (35, 3, 16, 19, 10, 1)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(1, 19, 3, 70, 32, 20) 3 1
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (35, 3, 16, 19, 10, 1) | T = (35, 3, 16, 19, 10, 1) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [70] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [3, 70] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [3, 70, 32] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [19, 3, 70, 32] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [49, 5, 21, 16, 31, 55]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::4], max(L) % 8)Output:
[54, 26, 37, 47, 86, 55] [54, 86] 6
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [49, 5, 21, 16, 31, 55] | L = [49, 5, 21, 16, 31, 55] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [54, 5, 21, 16, 31, 55] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [54, 26, 21, 16, 31, 55] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [54, 26, 37, 16, 31, 55] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [54, 26, 37, 47, 31, 55] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [54, 26, 37, 47, 86, 55] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [54, 26, 37, 47, 86, 55]⏎ | |
| 5 | print(L[::4], max(L) % 8) | [54, 86] 6⏎ |
Write the output of the following code. Show your working in short.
stock = {'Pen': 80, 'Map': 70, 'Ink': 45, 'Book': 60}
for item in stock:
if stock[item] < 50:
stock[item] += 10
stock["Glue"] = 9
del stock['Map']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Pen': 80, 'Ink': 55, 'Book': 60, 'Glue': 9}
4 204Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Pen': 80, 'Map': 70, 'Ink': 45, 'Book': 60} | stock = {'Pen': 80, 'Map': 70, 'Ink': 45, 'Book': 60} | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 50: | condition is False | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 50: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 50: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Pen': 80, 'Map': 70, 'Ink': 55, 'Book': 60} | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 50: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 9 | stock = {'Pen': 80, 'Map': 70, 'Ink': 55, 'Book': 60, 'Glue': 9} | |
| 6 | del stock['Map'] | stock = {'Pen': 80, 'Ink': 55, 'Book': 60, 'Glue': 9} | |
| 7 | print(stock) | {'Pen': 80, 'Ink': 55, 'Book': 60, 'Glue': 9}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 204⏎ |
Write the output of the following code. Show your working in short.
T = (20, 34, 33, 2, 15, 19)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(19, 2, 34, 40, 66, 30) 4 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (20, 34, 33, 2, 15, 19) | T = (20, 34, 33, 2, 15, 19) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [40] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [34, 40] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [34, 40, 66] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [2, 34, 40, 66] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [28, 43, 39, 44, 14, 47]
for i in range(1, len(L)):
L[i - 1] = L[i - 1] + L[i]
print(L)
print(L[::2], max(L) % 9)Output:
[71, 82, 83, 58, 61, 47] [71, 83, 61] 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [28, 43, 39, 44, 14, 47] | L = [28, 43, 39, 44, 14, 47] | |
| 2 | for i in range(1, len(L)): | i = 1 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [71, 43, 39, 44, 14, 47] | |
| 2 | for i in range(1, len(L)): | i = 2 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [71, 82, 39, 44, 14, 47] | |
| 2 | for i in range(1, len(L)): | i = 3 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [71, 82, 83, 44, 14, 47] | |
| 2 | for i in range(1, len(L)): | i = 4 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [71, 82, 83, 58, 14, 47] | |
| 2 | for i in range(1, len(L)): | i = 5 | |
| 3 | L[i - 1] = L[i - 1] + L[i] | L = [71, 82, 83, 58, 61, 47] | |
| 2 | for i in range(1, len(L)): | loop ends (no more values) | |
| 4 | print(L) | [71, 82, 83, 58, 61, 47]⏎ | |
| 5 | print(L[::2], max(L) % 9) | [71, 83, 61] 2⏎ |
Write the output of the following code. Show your working in short.
stock = {'Ink': 75, 'Book': 55, 'Bag': 45, 'Map': 10}
for item in stock:
if stock[item] < 52:
stock[item] += 10
stock["Glue"] = 12
del stock['Book']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Ink': 75, 'Bag': 55, 'Map': 20, 'Glue': 12}
4 162Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Ink': 75, 'Book': 55, 'Bag': 45, 'Map': 10} | stock = {'Ink': 75, 'Book': 55, 'Bag': 45, 'Map': 10} | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 52: | condition is False | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 52: | condition is False | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 52: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Ink': 75, 'Book': 55, 'Bag': 55, 'Map': 10} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 52: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Ink': 75, 'Book': 55, 'Bag': 55, 'Map': 20} | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 12 | stock = {'Ink': 75, 'Book': 55, 'Bag': 55, 'Map': 20, 'Glue': 12} | |
| 6 | del stock['Book'] | stock = {'Ink': 75, 'Bag': 55, 'Map': 20, 'Glue': 12} | |
| 7 | print(stock) | {'Ink': 75, 'Bag': 55, 'Map': 20, 'Glue': 12}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 162⏎ |
Write the output of the following code. Show your working in short.
msg = "Keep Calm and Code"
new = ""
for i in range(len(msg)):
ch = msg[i]
if ch.isupper():
new = new + ch.lower()
elif ch.islower():
new = new + ch.upper()
elif ch.isdigit():
new = new + str(int(ch) + 1)
else:
new = new + "*"
print(new)
print(len(new), new.count("*"))Output:
kEEP*cALM*AND*cODE 18 3
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "Keep Calm and Code" | msg = 'Keep Calm and Code' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | ch = msg[i] | ch = 'K' | |
| 5 | if ch.isupper(): | condition is True | |
| 6 | new = new + ch.lower() | new = 'k' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | ch = msg[i] | ch = 'e' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'kE' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'kEE' | |
| 3 | for i in range(len(msg)): | i = 3 |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Bag': 60, 'Pen': 45, 'Map': 40, 'Ink': 70}
for item in stock:
if stock[item] < 33:
stock[item] += 10
stock["Glue"] = 13
del stock['Ink']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Bag': 60, 'Pen': 45, 'Map': 40, 'Glue': 13}
4 158Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 60, 'Pen': 45, 'Map': 40, 'Ink': 70} | stock = {'Bag': 60, 'Pen': 45, 'Map': 40, 'Ink': 70} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 33: | condition is False | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 33: | condition is False | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 33: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 33: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 13 | stock = {'Bag': 60, 'Pen': 45, 'Map': 40, 'Ink': 70, 'Glue': 13} | |
| 6 | del stock['Ink'] | stock = {'Bag': 60, 'Pen': 45, 'Map': 40, 'Glue': 13} | |
| 7 | print(stock) | {'Bag': 60, 'Pen': 45, 'Map': 40, 'Glue': 13}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 158⏎ |
Write the output of the following code. Show your working in short.
T = (8, 15, 18, 9, 33, 28)
L = []
for i in range(len(T)):
if i % 2 == 0:
L.append(T[i] * 2)
else:
L.insert(0, T[i])
T2 = tuple(L)
print(T2)
print(T2.index(max(T2)), min(T2))Output:
(28, 9, 15, 16, 36, 66) 5 9
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | T = (8, 15, 18, 9, 33, 28) | T = (8, 15, 18, 9, 33, 28) | |
| 2 | L = [] | L = [] | |
| 3 | for i in range(len(T)): | i = 0 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [16] | |
| 3 | for i in range(len(T)): | i = 1 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [15, 16] | |
| 3 | for i in range(len(T)): | i = 2 | |
| 4 | if i % 2 == 0: | condition is True | |
| 5 | L.append(T[i] * 2) | L = [15, 16, 36] | |
| 3 | for i in range(len(T)): | i = 3 | |
| 4 | if i % 2 == 0: | condition is False | |
| 7 | L.insert(0, T[i]) | L = [9, 15, 16, 36] | |
| 3 | for i in range(len(T)): | i = 4 | |
| 4 | if i % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [51, 34, 6, 37, 15, 33]
A, B = [], []
for x in L:
if x % 2 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[34, 6] [33, 15, 37, 51] [34, 6, 33, 15]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [51, 34, 6, 37, 15, 33] | L = [51, 34, 6, 37, 15, 33] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 51 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [51] | |
| 3 | for x in L: | x = 34 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [34] | |
| 3 | for x in L: | x = 6 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [34, 6] | |
| 3 | for x in L: | x = 37 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [37, 51] | |
| 3 | for x in L: | x = 15 | |
| 4 | if x % 2 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [19, 27, 43, 15, 8, 46]
A, B = [], []
for x in L:
if x % 3 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[27, 15] [46, 8, 43, 19] [27, 15, 46, 8]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [19, 27, 43, 15, 8, 46] | L = [19, 27, 43, 15, 8, 46] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 19 | |
| 4 | if x % 3 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [19] | |
| 3 | for x in L: | x = 27 | |
| 4 | if x % 3 == 0: | condition is True | |
| 5 | A.append(x) | A = [27] | |
| 3 | for x in L: | x = 43 | |
| 4 | if x % 3 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [43, 19] | |
| 3 | for x in L: | x = 15 | |
| 4 | if x % 3 == 0: | condition is True | |
| 5 | A.append(x) | A = [27, 15] | |
| 3 | for x in L: | x = 8 | |
| 4 | if x % 3 == 0: | condition is False |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Bag': 35, 'Map': 50, 'Ruler': 40, 'Ink': 80}
for item in stock:
if stock[item] < 31:
stock[item] += 10
stock["Glue"] = 12
del stock['Ruler']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Bag': 35, 'Map': 50, 'Ink': 80, 'Glue': 12}
4 177Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 35, 'Map': 50, 'Ruler': 40, 'Ink': 80} | stock = {'Bag': 35, 'Map': 50, 'Ruler': 40, 'Ink': 80} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 31: | condition is False | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 31: | condition is False | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 31: | condition is False | |
| 2 | for item in stock: | item = 'Ink' | |
| 3 | if stock[item] < 31: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 12 | stock = {'Bag': 35, 'Map': 50, 'Ruler': 40, 'Ink': 80, 'Glue': 12} | |
| 6 | del stock['Ruler'] | stock = {'Bag': 35, 'Map': 50, 'Ink': 80, 'Glue': 12} | |
| 7 | print(stock) | {'Bag': 35, 'Map': 50, 'Ink': 80, 'Glue': 12}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 177⏎ |
Write the output of the following code. Show your working in short.
n = 4
for i in range(1, n + 1):
print(" " * (n - i), end="")
for j in range(1, i + 1):
print(j, end="")
for j in range(i - 1, 0, -1):
print(j, end="")
print()Output:
1 121 12321 1234321
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 4 | n = 4 | |
| 2 | for i in range(1, n + 1): | i = 1 | |
| 3 | print(" " * (n - i), end="") | | |
| 4 | for j in range(1, i + 1): | j = 1 | |
| 5 | print(j, end="") | 1 | |
| 4 | for j in range(1, i + 1): | loop ends (no more values) | |
| 6 | for j in range(i - 1, 0, -1): | loop ends (no more values) | |
| 8 | print() | ⏎ | |
| 2 | for i in range(1, n + 1): | i = 2 | |
| 3 | print(" " * (n - i), end="") | | |
| 4 | for j in range(1, i + 1): | loop ends (no more values) | |
| 5 | print(j, end="") | 1 | |
| 4 | for j in range(1, i + 1): | j = 2 | |
| 5 | print(j, end="") | 2 | |
| 4 | for j in range(1, i + 1): | loop ends (no more values) | |
| 6 | for j in range(i - 1, 0, -1): | j = 1 |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Bag': 85, 'Ruler': 30, 'Map': 25, 'Pen': 70}
for item in stock:
if stock[item] < 42:
stock[item] += 10
stock["Glue"] = 6
del stock['Ruler']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Bag': 85, 'Map': 35, 'Pen': 70, 'Glue': 6}
4 196Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 85, 'Ruler': 30, 'Map': 25, 'Pen': 70} | stock = {'Bag': 85, 'Ruler': 30, 'Map': 25, 'Pen': 70} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 42: | condition is False | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 42: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 85, 'Ruler': 40, 'Map': 25, 'Pen': 70} | |
| 2 | for item in stock: | item = 'Map' | |
| 3 | if stock[item] < 42: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 85, 'Ruler': 40, 'Map': 35, 'Pen': 70} | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 42: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 6 | stock = {'Bag': 85, 'Ruler': 40, 'Map': 35, 'Pen': 70, 'Glue': 6} | |
| 6 | del stock['Ruler'] | stock = {'Bag': 85, 'Map': 35, 'Pen': 70, 'Glue': 6} | |
| 7 | print(stock) | {'Bag': 85, 'Map': 35, 'Pen': 70, 'Glue': 6}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 196⏎ |
Write the output of the following code. Show your working in short.
n = 5
for i in range(n):
s = ""
for j in range(i + 1):
s = s + chr(65 + i + j)
print(s)Output:
A BC CDE DEFG EFGHI
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | n = 5 | n = 5 | |
| 2 | for i in range(n): | i = 0 | |
| 3 | s = "" | s = '' | |
| 4 | for j in range(i + 1): | j = 0 | |
| 5 | s = s + chr(65 + i + j) | s = 'A' | |
| 4 | for j in range(i + 1): | loop ends (no more values) | |
| 6 | print(s) | A⏎ | |
| 2 | for i in range(n): | i = 1 | |
| 3 | s = "" | s = '' | |
| 4 | for j in range(i + 1): | loop ends (no more values) | |
| 5 | s = s + chr(65 + i + j) | s = 'B' | |
| 4 | for j in range(i + 1): | j = 1 | |
| 5 | s = s + chr(65 + i + j) | s = 'BC' | |
| 4 | for j in range(i + 1): | loop ends (no more values) | |
| 6 | print(s) | BC⏎ | |
| 2 | for i in range(n): | i = 2 |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [39, 19, 40, 10, 56, 12]
A, B = [], []
for x in L:
if x % 4 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[40, 56, 12] [10, 19, 39] [40, 56, 12, 10, 19]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [39, 19, 40, 10, 56, 12] | L = [39, 19, 40, 10, 56, 12] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 39 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [39] | |
| 3 | for x in L: | x = 19 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [19, 39] | |
| 3 | for x in L: | x = 40 | |
| 4 | if x % 4 == 0: | condition is True | |
| 5 | A.append(x) | A = [40] | |
| 3 | for x in L: | x = 10 | |
| 4 | if x % 4 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [10, 19, 39] | |
| 3 | for x in L: | x = 56 | |
| 4 | if x % 4 == 0: | condition is True |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
stock = {'Bag': 30, 'Pen': 25, 'Ruler': 50, 'Book': 55}
for item in stock:
if stock[item] < 30:
stock[item] += 10
stock["Glue"] = 16
del stock['Ruler']
print(stock)
print(len(stock), sum(stock.values()))Output:
{'Bag': 30, 'Pen': 35, 'Book': 55, 'Glue': 16}
4 136Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | stock = {'Bag': 30, 'Pen': 25, 'Ruler': 50, 'Book': 55} | stock = {'Bag': 30, 'Pen': 25, 'Ruler': 50, 'Book': 55} | |
| 2 | for item in stock: | item = 'Bag' | |
| 3 | if stock[item] < 30: | condition is False | |
| 2 | for item in stock: | item = 'Pen' | |
| 3 | if stock[item] < 30: | condition is True | |
| 4 | stock[item] += 10 | stock = {'Bag': 30, 'Pen': 35, 'Ruler': 50, 'Book': 55} | |
| 2 | for item in stock: | item = 'Ruler' | |
| 3 | if stock[item] < 30: | condition is False | |
| 2 | for item in stock: | item = 'Book' | |
| 3 | if stock[item] < 30: | condition is False | |
| 2 | for item in stock: | loop ends (no more values) | |
| 5 | stock["Glue"] = 16 | stock = {'Bag': 30, 'Pen': 35, 'Ruler': 50, 'Book': 55, 'Glue': 16} | |
| 6 | del stock['Ruler'] | stock = {'Bag': 30, 'Pen': 35, 'Book': 55, 'Glue': 16} | |
| 7 | print(stock) | {'Bag': 30, 'Pen': 35, 'Book': 55, 'Glue': 16}⏎ | |
| 8 | print(len(stock), sum(stock.values())) | 4 136⏎ |
Write the output of the following code. Show your working in short.
msg = "India is Great"
new = ""
for i in range(len(msg)):
ch = msg[i]
if ch.isupper():
new = new + ch.lower()
elif ch.islower():
new = new + ch.upper()
elif ch.isdigit():
new = new + str(int(ch) + 1)
else:
new = new + "*"
print(new)
print(len(new), new.count("*"))Output:
iNDIA*IS*gREAT 14 2
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | msg = "India is Great" | msg = 'India is Great' | |
| 2 | new = "" | new = '' | |
| 3 | for i in range(len(msg)): | i = 0 | |
| 4 | ch = msg[i] | ch = 'I' | |
| 5 | if ch.isupper(): | condition is True | |
| 6 | new = new + ch.lower() | new = 'i' | |
| 3 | for i in range(len(msg)): | i = 1 | |
| 4 | ch = msg[i] | ch = 'n' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'iN' | |
| 3 | for i in range(len(msg)): | i = 2 | |
| 4 | ch = msg[i] | ch = 'd' | |
| 5 | if ch.isupper(): | condition is False | |
| 7 | elif ch.islower(): | condition is True | |
| 8 | new = new + ch.upper() | new = 'iND' |
… the same steps continue for the remaining values.
Write the output of the following code. Show your working in short.
L = [46, 33, 29, 10, 44, 36]
A, B = [], []
for x in L:
if x % 2 == 0:
A.append(x)
else:
B.insert(0, x)
print(A)
print(B)
print(A + B[:2])Output:
[46, 10, 44, 36] [29, 33] [46, 10, 44, 36, 29, 33]
Working (step by step)
| Line | Statement | Values after this step | Printed |
|---|---|---|---|
| 1 | L = [46, 33, 29, 10, 44, 36] | L = [46, 33, 29, 10, 44, 36] | |
| 2 | A, B = [], [] | A = [], B = [] | |
| 3 | for x in L: | x = 46 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [46] | |
| 3 | for x in L: | x = 33 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [33] | |
| 3 | for x in L: | x = 29 | |
| 4 | if x % 2 == 0: | condition is False | |
| 7 | B.insert(0, x) | B = [29, 33] | |
| 3 | for x in L: | x = 10 | |
| 4 | if x % 2 == 0: | condition is True | |
| 5 | A.append(x) | A = [46, 10] | |
| 3 | for x in L: | x = 44 | |
| 4 | if x % 2 == 0: | condition is True |
… the same steps continue for the remaining values.
Write a program to input a number and print its factorial.
n = int(input('Enter a number: '))
f = 1
for i in range(1, n + 1):
f = f * i
print('Factorial =', f)Sample run
Enter a number: 6 Factorial = 720
Write a program to input a number and find the sum of its digits.
n = int(input('Enter a number: '))
s = 0
while n > 0:
s = s + n % 10
n = n // 10
print('Sum of digits =', s)Sample run
Enter a number: 5274 Sum of digits = 18
Write a program to input a number and check whether it is a palindrome.
n = int(input('Enter a number: '))
temp = n
rev = 0
while temp > 0:
rev = rev * 10 + temp % 10
temp = temp // 10
if rev == n:
print(n, 'is a palindrome')
else:
print(n, 'is not a palindrome')Sample run
Enter a number: 12321 12321 is a palindrome
Write a program to input a number and check whether it is prime.
n = int(input('Enter a number: '))
if n < 2:
print(n, 'is not prime')
else:
for i in range(2, n):
if n % i == 0:
print(n, 'is not prime')
break
else:
print(n, 'is prime')Sample run
Enter a number: 29 29 is prime
Write a program to check whether a three-digit number is an Armstrong number.
n = int(input('Enter a 3-digit number: '))
temp = n
s = 0
while temp > 0:
d = temp % 10
s = s + d ** 3
temp = temp // 10
if s == n:
print(n, 'is an Armstrong number')
else:
print(n, 'is not an Armstrong number')Sample run
Enter a 3-digit number: 153 153 is an Armstrong number
Write a program to input two numbers and find their GCD (HCF) and LCM.
a = int(input('First number: '))
b = int(input('Second number: '))
x, y = a, b
while y != 0:
x, y = y, x % y
print('GCD =', x)
print('LCM =', a * b // x)Sample run
First number: 12 Second number: 18 GCD = 6 LCM = 36
Write a program to print the first n terms of the Fibonacci series.
n = int(input('How many terms? '))
a, b = 0, 1
for i in range(n):
print(a, end=' ')
a, b = b, a + bSample run
How many terms? 8 0 1 1 2 3 5 8 13
Write a program to input a number and print its multiplication table up to 10.
n = int(input('Enter a number: '))
for i in range(1, 11):
print(n, 'x', i, '=', n * i)Sample run
Enter a number: 7 7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49 7 x 8 = 56 7 x 9 = 63 7 x 10 = 70
Write a program to input a year and check whether it is a leap year.
y = int(input('Enter a year: '))
if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0:
print(y, 'is a leap year')
else:
print(y, 'is not a leap year')Sample run
Enter a year: 2024 2024 is a leap year
Write a program to input three numbers and print the largest.
a = int(input('A: '))
b = int(input('B: '))
c = int(input('C: '))
if a >= b and a >= c:
big = a
elif b >= c:
big = b
else:
big = c
print('Largest =', big)Sample run
A: 45 B: 72 C: 19 Largest = 72
Write a program to input marks out of 100 and print the grade: A (90 and above), B (75-89), C (50-74), D (33-49), E (below 33).
m = int(input('Marks: '))
if m >= 90:
g = 'A'
elif m >= 75:
g = 'B'
elif m >= 50:
g = 'C'
elif m >= 33:
g = 'D'
else:
g = 'E'
print('Grade', g)Sample run
Marks: 78 Grade B
Write a program to check whether a number is a perfect number (equal to the sum of its factors other than itself).
n = int(input('Enter a number: '))
s = 0
for i in range(1, n):
if n % i == 0:
s = s + i
if s == n:
print(n, 'is a perfect number')
else:
print(n, 'is not a perfect number')Sample run
Enter a number: 28 28 is a perfect number
Write a program to input a number and count its digits.
n = int(input('Enter a number: '))
count = 0
while n > 0:
count += 1
n = n // 10
print('Digits =', count)Sample run
Enter a number: 904512 Digits = 6
Write a program to print all prime numbers between 1 and n.
n = int(input('Up to: '))
for num in range(2, n + 1):
for i in range(2, num):
if num % i == 0:
break
else:
print(num, end=' ')Sample run
Up to: 30 2 3 5 7 11 13 17 19 23 29
Write a program to find the sum of even numbers and the sum of odd numbers from 1 to n.
n = int(input('Enter n: '))
even = odd = 0
for i in range(1, n + 1):
if i % 2 == 0:
even += i
else:
odd += i
print('Sum of even =', even)
print('Sum of odd =', odd)Sample run
Enter n: 10 Sum of even = 30 Sum of odd = 25
Write a program to input a number and print its reverse.
n = int(input('Enter a number: '))
rev = 0
while n > 0:
rev = rev * 10 + n % 10
n = n // 10
print('Reverse =', rev)Sample run
Enter a number: 37081 Reverse = 18073
Write a program to input the principal, rate and time and print the simple interest and compound interest.
p = float(input('Principal: '))
r = float(input('Rate: '))
t = float(input('Time: '))
si = p * r * t / 100
ci = p * (1 + r / 100) ** t - p
print('Simple interest =', round(si, 2))
print('Compound interest =', round(ci, 2))Sample run
Principal: 10000 Rate: 8 Time: 2 Simple interest = 1600.0 Compound interest = 1664.0
Write a program to convert a temperature in Celsius to Fahrenheit and Kelvin.
c = float(input('Celsius: '))
f = c * 9 / 5 + 32
k = c + 273.15
print('Fahrenheit =', f)
print('Kelvin =', k)Sample run
Celsius: 37 Fahrenheit = 98.6 Kelvin = 310.15
Write a program to input the three sides of a triangle and check whether it is equilateral, isosceles or scalene.
a = int(input('Side 1: '))
b = int(input('Side 2: '))
c = int(input('Side 3: '))
if a == b == c:
print('Equilateral')
elif a == b or b == c or a == c:
print('Isosceles')
else:
print('Scalene')Sample run
Side 1: 5 Side 2: 7 Side 3: 5 Isosceles
Write a program to find the sum of the squares of the first n natural numbers.
n = int(input('Enter n: '))
s = 0
for i in range(1, n + 1):
s = s + i * i
print('Sum of squares =', s)Sample run
Enter n: 6 Sum of squares = 91
Write a program to input n numbers and print their average, the largest and the smallest.
n = int(input('How many numbers? '))
total = 0
for i in range(n):
x = int(input('Number: '))
if i == 0:
big = small = x
big = max(big, x)
small = min(small, x)
total += x
print('Average =', total / n)
print('Largest =', big, 'Smallest =', small)Sample run
How many numbers? 4 Number: 15 Number: 42 Number: 8 Number: 23 Average = 22.0 Largest = 42 Smallest = 8
Write a program to print all the factors of a number and their count.
n = int(input('Enter a number: '))
count = 0
for i in range(1, n + 1):
if n % i == 0:
print(i, end=' ')
count += 1
print()
print('Number of factors =', count)Sample run
Enter a number: 36 1 2 3 4 6 9 12 18 36 Number of factors = 9
Write a program to check whether a number is a 'special number': the sum of the factorials of its digits equals the number (e.g. 145).
import math
n = int(input('Enter a number: '))
s = 0
for d in str(n):
s = s + math.factorial(int(d))
if s == n:
print(n, 'is a special number')
else:
print(n, 'is not a special number')Sample run
Enter a number: 145 145 is a special number
Write a program to input a number and print whether it is positive, negative or zero, and whether it is even or odd.
n = int(input('Enter a number: '))
if n > 0:
print('Positive')
elif n < 0:
print('Negative')
else:
print('Zero')
if n % 2 == 0:
print('Even')
else:
print('Odd')Sample run
Enter a number: -14 Negative Even
Write a program to print the following pattern for n rows (shown for n = 4):
* * * * * * * * * *
n = int(input('Rows: '))
for i in range(1, n + 1):
print('* ' * i)Sample run
Rows: 4 * * * * * * * * * *
Write a program to print the following pattern for n rows (shown for n = 4):
1 1 2 1 2 3 1 2 3 4
n = int(input('Rows: '))
for i in range(1, n + 1):
for j in range(1, i + 1):
print(j, end=' ')
print()Sample run
Rows: 4 1 1 2 1 2 3 1 2 3 4
Write a program to print the following pattern for n rows (shown for n = 4):
1 2 2 3 3 3 4 4 4 4
n = int(input('Rows: '))
for i in range(1, n + 1):
for j in range(i):
print(i, end=' ')
print()Sample run
Rows: 4 1 2 2 3 3 3 4 4 4 4
Write a program to print the following pattern for n rows (shown for n = 4):
A A B A B C A B C D
n = int(input('Rows: '))
for i in range(1, n + 1):
for j in range(i):
print(chr(65 + j), end=' ')
print()Sample run
Rows: 4 A A B A B C A B C D
Write a program to print the following pattern for n rows (shown for n = 4):
4 3 2 1 4 3 2 4 3 4
n = int(input('Rows: '))
for i in range(1, n + 1):
for j in range(n, i - 1, -1):
print(j, end=' ')
print()Sample run
Rows: 4 4 3 2 1 4 3 2 4 3 4
Write a program to print the following pattern for n rows (shown for n = 4):
* ** *** ****
n = int(input('Rows: '))
for i in range(1, n + 1):
print(' ' * (n - i) + '*' * i)Sample run
Rows: 4 * ** *** ****
Write a program to print the following pattern for n rows (shown for n = 4):
1 2 3 4 5 6 7 8 9 10
n = int(input('Rows: '))
k = 1
for i in range(1, n + 1):
for j in range(i):
print(k, end=' ')
k += 1
print()Sample run
Rows: 4 1 2 3 4 5 6 7 8 9 10
Write a program to print the following pattern for n rows (shown for n = 4):
1 2 3 4 1 2 3 1 2 1
n = int(input('Rows: '))
for i in range(n, 0, -1):
for j in range(1, i + 1):
print(j, end=' ')
print()Sample run
Rows: 4 1 2 3 4 1 2 3 1 2 1
Write a program to input the values needed and find the sum of the series: 1 + x + x² + x³ + ... + xⁿ
x = int(input('x: '))
n = int(input('n: '))
s = 0
for i in range(n + 1):
s = s + x ** i
print('Sum =', s)Sample run
x: 2 n: 5 Sum = 63
Write a program to input the values needed and find the sum of the series: 1 - x + x² - x³ + ... (n terms after 1, up to xⁿ)
x = int(input('x: '))
n = int(input('n: '))
s = 0
for i in range(n + 1):
s = s + (-1) ** i * x ** i
print('Sum =', s)Sample run
x: 3 n: 4 Sum = 61
Write a program to input the values needed and find the sum of the series: x - x²/2 + x³/3 - ... up to n terms
x = float(input('x: '))
n = int(input('n: '))
s = 0
for i in range(1, n + 1):
s = s + (-1) ** (i + 1) * x ** i / i
print('Sum =', round(s, 4))Sample run
x: 2 n: 4 Sum = -1.3333
Write a program to input the values needed and find the sum of the series: x + x²/2! + x³/3! + ... up to n terms
import math
x = float(input('x: '))
n = int(input('n: '))
s = 0
for i in range(1, n + 1):
s = s + x ** i / math.factorial(i)
print('Sum =', round(s, 4))Sample run
x: 2 n: 5 Sum = 6.2667
Write a program to input the values needed and find the sum of the series: 1 + 1/2 + 1/3 + ... + 1/n
n = int(input('n: '))
s = 0
for i in range(1, n + 1):
s = s + 1 / i
print('Sum =', round(s, 4))Sample run
n: 5 Sum = 2.2833
Write a program to input the values needed and find the sum of the series: 1² + 2² + 3² + ... + n² and 1³ + 2³ + ... + n³
n = int(input('n: '))
s2 = s3 = 0
for i in range(1, n + 1):
s2 += i ** 2
s3 += i ** 3
print('Sum of squares =', s2)
print('Sum of cubes =', s3)Sample run
n: 5 Sum of squares = 55 Sum of cubes = 225
Write a program to input the values needed and find the sum of the series: 1 + 2 + 4 + 8 + ... (n terms)
n = int(input('n: '))
term = 1
s = 0
for i in range(n):
s = s + term
term = term * 2
print('Sum =', s)Sample run
n: 6 Sum = 63
Write a program to input the values needed and find the sum of the series: 1 + 3 + 5 + ... (first n odd numbers)
n = int(input('n: '))
s = 0
for i in range(n):
s = s + (2 * i + 1)
print('Sum =', s)Sample run
n: 7 Sum = 49
(i) Convert (a) (10011011)2 to decimal and (b) (19E)16 to decimal. [2]
(ii) Draw the logic circuit and the truth table for (A AND B) OR C. [2]
(i) (a)
(10011011)2 = 1 × 27 + 0 × 26 + 0 × 25 + 1 × 24 + 1 × 23 + 0 × 22 + 1 × 21 + 1 × 20 = 128 + 0 + 0 + 16 + 8 + 0 + 2 + 1 = 155
(i) (b)
(19E)16 = 1 × 162 + 9 × 161 + E × 160 = 256 + 144 + 14 = 414
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A AND B) OR C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (463)8 to decimal and (b) (1C3)16 to decimal. [2]
(ii) Draw the logic circuit and the truth table for A AND (B OR C). [2]
(i) (a)
(463)8 = 4 × 82 + 6 × 81 + 3 × 80 = 256 + 48 + 3 = 307
(i) (b)
(1C3)16 = 1 × 162 + C × 161 + 3 × 160 = 256 + 192 + 3 = 451
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | A AND (B OR C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (543)8 to binary and (b) (101111100)2 to octal. [2]
(ii) Draw the logic circuit and the truth table for (A OR B) AND (NOT C). [2]
(i) (a)
Write each digit as 3 bits: 5 → 101 4 → 100 3 → 011
So (543)8 = (101100011)2
(i) (b)
Make groups of 3 bits from the right: 101 111 100
101 → 5 111 → 7 100 → 4
So (101111100)2 = (574)8
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A OR B) AND (NOT C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
(i) Convert (a) (472)8 to decimal and (b) (101010111)2 to decimal. [2]
(ii) Draw the logic circuit and the truth table for NOT A OR (B AND C). [2]
(i) (a)
(472)8 = 4 × 82 + 7 × 81 + 2 × 80 = 256 + 56 + 2 = 314
(i) (b)
(101010111)2 = 1 × 28 + 0 × 27 + 1 × 26 + 0 × 25 + 1 × 24 + 0 × 23 + 1 × 22 + 1 × 21 + 1 × 20 = 256 + 0 + 64 + 0 + 16 + 0 + 4 + 2 + 1 = 343
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | NOT A OR (B AND C) |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (527)8 to decimal and (b) (171)10 to hexadecimal. [2]
(ii) Draw the logic circuit and the truth table for (A AND NOT B) OR (B AND C). [2]
(i) (a)
(527)8 = 5 × 82 + 2 × 81 + 7 × 80 = 320 + 16 + 7 = 343
(i) (b)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 171 | B |
| 16 | 10 | A |
Read the remainders from bottom to top: (AB)16
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A AND NOT B) OR (B AND C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (100110000)2 to octal and (b) (10011110)2 to decimal. [2]
(ii) Draw the logic circuit and the truth table for NOT (A OR B) AND C. [2]
(i) (a)
Make groups of 3 bits from the right: 100 110 000
100 → 4 110 → 6 000 → 0
So (100110000)2 = (460)8
(i) (b)
(10011110)2 = 1 × 27 + 0 × 26 + 0 × 25 + 1 × 24 + 1 × 23 + 1 × 22 + 1 × 21 + 0 × 20 = 128 + 0 + 0 + 16 + 8 + 4 + 2 + 0 = 158
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | NOT (A OR B) AND C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
(i) Convert (a) (170)8 to binary and (b) (437)10 to hexadecimal. [2]
(ii) Draw the logic circuit and the truth table for (A OR NOT B) AND (B OR C). [2]
(i) (a)
Write each digit as 3 bits: 1 → 001 7 → 111 0 → 000
So (170)8 = (1111000)2
(i) (b)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 437 | 5 |
| 16 | 27 | B |
| 16 | 1 | 1 |
Read the remainders from bottom to top: (1B5)16
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A OR NOT B) AND (B OR C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (B5)16 to octal and (b) (462)8 to decimal. [2]
(ii) Draw the logic circuit and the truth table for A AND B AND NOT C. [2]
(i) (a)
Write each digit as 4 bits: B → 1011 5 → 0101
So (B5)16 = (10110101)2
Make groups of 3 bits from the right: 010 110 101
010 → 2 110 → 6 101 → 5
So (10110101)2 = (265)8
(i) (b)
(462)8 = 4 × 82 + 6 × 81 + 2 × 80 = 256 + 48 + 2 = 306
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | A AND B AND NOT C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
(i) Convert (a) (359)10 to binary and (b) (11101000)2 to decimal. [2]
(ii) Draw the logic circuit and the truth table for (A AND B) OR C. [2]
(i) (a)
| Divide by | Number | Remainder |
|---|---|---|
| 2 | 359 | 1 |
| 2 | 179 | 1 |
| 2 | 89 | 1 |
| 2 | 44 | 0 |
| 2 | 22 | 0 |
| 2 | 11 | 1 |
| 2 | 5 | 1 |
| 2 | 2 | 0 |
| 2 | 1 | 1 |
Read the remainders from bottom to top: (101100111)2
(i) (b)
(11101000)2 = 1 × 27 + 1 × 26 + 1 × 25 + 0 × 24 + 1 × 23 + 0 × 22 + 0 × 21 + 0 × 20 = 128 + 64 + 32 + 0 + 8 + 0 + 0 + 0 = 232
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A AND B) OR C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (13F)16 to decimal and (b) (1D0)16 to binary. [2]
(ii) Draw the logic circuit and the truth table for A AND (B OR C). [2]
(i) (a)
(13F)16 = 1 × 162 + 3 × 161 + F × 160 = 256 + 48 + 15 = 319
(i) (b)
Write each digit as 4 bits: 1 → 0001 D → 1101 0 → 0000
So (1D0)16 = (111010000)2
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | A AND (B OR C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (137)16 to decimal and (b) (1DF)16 to octal. [2]
(ii) Draw the logic circuit and the truth table for (A OR B) AND (NOT C). [2]
(i) (a)
(137)16 = 1 × 162 + 3 × 161 + 7 × 160 = 256 + 48 + 7 = 311
(i) (b)
Write each digit as 4 bits: 1 → 0001 D → 1101 F → 1111
So (1DF)16 = (111011111)2
Make groups of 3 bits from the right: 111 011 111
111 → 7 011 → 3 111 → 7
So (111011111)2 = (737)8
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A OR B) AND (NOT C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
(i) Convert (a) (11010001)2 to octal and (b) (372)8 to decimal. [2]
(ii) Draw the logic circuit and the truth table for NOT A OR (B AND C). [2]
(i) (a)
Make groups of 3 bits from the right: 011 010 001
011 → 3 010 → 2 001 → 1
So (11010001)2 = (321)8
(i) (b)
(372)8 = 3 × 82 + 7 × 81 + 2 × 80 = 192 + 56 + 2 = 250
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | NOT A OR (B AND C) |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (F2)16 to octal and (b) (464)10 to hexadecimal. [2]
(ii) Draw the logic circuit and the truth table for (A AND NOT B) OR (B AND C). [2]
(i) (a)
Write each digit as 4 bits: F → 1111 2 → 0010
So (F2)16 = (11110010)2
Make groups of 3 bits from the right: 011 110 010
011 → 3 110 → 6 010 → 2
So (11110010)2 = (362)8
(i) (b)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 464 | 0 |
| 16 | 29 | D |
| 16 | 1 | 1 |
Read the remainders from bottom to top: (1D0)16
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A AND NOT B) OR (B AND C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (298)10 to octal and (b) (1D9)16 to decimal. [2]
(ii) Draw the logic circuit and the truth table for NOT (A OR B) AND C. [2]
(i) (a)
| Divide by | Number | Remainder |
|---|---|---|
| 8 | 298 | 2 |
| 8 | 37 | 5 |
| 8 | 4 | 4 |
Read the remainders from bottom to top: (452)8
(i) (b)
(1D9)16 = 1 × 162 + D × 161 + 9 × 160 = 256 + 208 + 9 = 473
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | NOT (A OR B) AND C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
(i) Convert (a) (717)8 to hexadecimal and (b) (554)8 to decimal. [2]
(ii) Draw the logic circuit and the truth table for (A OR NOT B) AND (B OR C). [2]
(i) (a)
Write each digit as 3 bits: 7 → 111 1 → 001 7 → 111
So (717)8 = (111001111)2
Make groups of 4 bits from the right: 0001 1100 1111
0001 → 1 1100 → C 1111 → F
So (111001111)2 = (1CF)16
(i) (b)
(554)8 = 5 × 82 + 5 × 81 + 4 × 80 = 320 + 40 + 4 = 364
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A OR NOT B) AND (B OR C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (116)16 to octal and (b) (110111011)2 to hexadecimal. [2]
(ii) Draw the logic circuit and the truth table for A AND B AND NOT C. [2]
(i) (a)
Write each digit as 4 bits: 1 → 0001 1 → 0001 6 → 0110
So (116)16 = (100010110)2
Make groups of 3 bits from the right: 100 010 110
100 → 4 010 → 2 110 → 6
So (100010110)2 = (426)8
(i) (b)
Make groups of 4 bits from the right: 0001 1011 1011
0001 → 1 1011 → B 1011 → B
So (110111011)2 = (1BB)16
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | A AND B AND NOT C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
(i) Convert (a) (260)10 to binary and (b) (AB)16 to octal. [2]
(ii) Draw the logic circuit and the truth table for (A AND B) OR C. [2]
(i) (a)
| Divide by | Number | Remainder |
|---|---|---|
| 2 | 260 | 0 |
| 2 | 130 | 0 |
| 2 | 65 | 1 |
| 2 | 32 | 0 |
| 2 | 16 | 0 |
| 2 | 8 | 0 |
| 2 | 4 | 0 |
| 2 | 2 | 0 |
| 2 | 1 | 1 |
Read the remainders from bottom to top: (100000100)2
(i) (b)
Write each digit as 4 bits: A → 1010 B → 1011
So (AB)16 = (10101011)2
Make groups of 3 bits from the right: 010 101 011
010 → 2 101 → 5 011 → 3
So (10101011)2 = (253)8
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A AND B) OR C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (320)10 to binary and (b) (F9)16 to decimal. [2]
(ii) Draw the logic circuit and the truth table for A AND (B OR C). [2]
(i) (a)
| Divide by | Number | Remainder |
|---|---|---|
| 2 | 320 | 0 |
| 2 | 160 | 0 |
| 2 | 80 | 0 |
| 2 | 40 | 0 |
| 2 | 20 | 0 |
| 2 | 10 | 0 |
| 2 | 5 | 1 |
| 2 | 2 | 0 |
| 2 | 1 | 1 |
Read the remainders from bottom to top: (101000000)2
(i) (b)
(F9)16 = F × 161 + 9 × 160 = 240 + 9 = 249
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | A AND (B OR C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (110100010)2 to octal and (b) (235)8 to hexadecimal. [2]
(ii) Draw the logic circuit and the truth table for (A OR B) AND (NOT C). [2]
(i) (a)
Make groups of 3 bits from the right: 110 100 010
110 → 6 100 → 4 010 → 2
So (110100010)2 = (642)8
(i) (b)
Write each digit as 3 bits: 2 → 010 3 → 011 5 → 101
So (235)8 = (10011101)2
Make groups of 4 bits from the right: 1001 1101
1001 → 9 1101 → D
So (10011101)2 = (9D)16
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A OR B) AND (NOT C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
(i) Convert (a) (C0)16 to octal and (b) (326)10 to hexadecimal. [2]
(ii) Draw the logic circuit and the truth table for NOT A OR (B AND C). [2]
(i) (a)
Write each digit as 4 bits: C → 1100 0 → 0000
So (C0)16 = (11000000)2
Make groups of 3 bits from the right: 011 000 000
011 → 3 000 → 0 000 → 0
So (11000000)2 = (300)8
(i) (b)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 326 | 6 |
| 16 | 20 | 4 |
| 16 | 1 | 1 |
Read the remainders from bottom to top: (146)16
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | NOT A OR (B AND C) |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (10100111)2 to hexadecimal and (b) (5D)16 to octal. [2]
(ii) Draw the logic circuit and the truth table for (A AND NOT B) OR (B AND C). [2]
(i) (a)
Make groups of 4 bits from the right: 1010 0111
1010 → A 0111 → 7
So (10100111)2 = (A7)16
(i) (b)
Write each digit as 4 bits: 5 → 0101 D → 1101
So (5D)16 = (1011101)2
Make groups of 3 bits from the right: 001 011 101
001 → 1 011 → 3 101 → 5
So (1011101)2 = (135)8
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A AND NOT B) OR (B AND C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (6D)16 to decimal and (b) (110101111)2 to hexadecimal. [2]
(ii) Draw the logic circuit and the truth table for NOT (A OR B) AND C. [2]
(i) (a)
(6D)16 = 6 × 161 + D × 160 = 96 + 13 = 109
(i) (b)
Make groups of 4 bits from the right: 0001 1010 1111
0001 → 1 1010 → A 1111 → F
So (110101111)2 = (1AF)16
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | NOT (A OR B) AND C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
(i) Convert (a) (406)10 to hexadecimal and (b) (10011011)2 to hexadecimal. [2]
(ii) Draw the logic circuit and the truth table for (A OR NOT B) AND (B OR C). [2]
(i) (a)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 406 | 6 |
| 16 | 25 | 9 |
| 16 | 1 | 1 |
Read the remainders from bottom to top: (196)16
(i) (b)
Make groups of 4 bits from the right: 1001 1011
1001 → 9 1011 → B
So (10011011)2 = (9B)16
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A OR NOT B) AND (B OR C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (1010000)2 to hexadecimal and (b) (100010101)2 to octal. [2]
(ii) Draw the logic circuit and the truth table for A AND B AND NOT C. [2]
(i) (a)
Make groups of 4 bits from the right: 0101 0000
0101 → 5 0000 → 0
So (1010000)2 = (50)16
(i) (b)
Make groups of 3 bits from the right: 100 010 101
100 → 4 010 → 2 101 → 5
So (100010101)2 = (425)8
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | A AND B AND NOT C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
(i) Convert (a) (CB)16 to octal and (b) (430)8 to hexadecimal. [2]
(ii) Draw the logic circuit and the truth table for (A AND B) OR C. [2]
(i) (a)
Write each digit as 4 bits: C → 1100 B → 1011
So (CB)16 = (11001011)2
Make groups of 3 bits from the right: 011 001 011
011 → 3 001 → 1 011 → 3
So (11001011)2 = (313)8
(i) (b)
Write each digit as 3 bits: 4 → 100 3 → 011 0 → 000
So (430)8 = (100011000)2
Make groups of 4 bits from the right: 0001 0001 1000
0001 → 1 0001 → 1 1000 → 8
So (100011000)2 = (118)16
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A AND B) OR C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (101010101)2 to hexadecimal and (b) (A7)16 to decimal. [2]
(ii) Draw the logic circuit and the truth table for A AND (B OR C). [2]
(i) (a)
Make groups of 4 bits from the right: 0001 0101 0101
0001 → 1 0101 → 5 0101 → 5
So (101010101)2 = (155)16
(i) (b)
(A7)16 = A × 161 + 7 × 160 = 160 + 7 = 167
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | A AND (B OR C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (1AD)16 to binary and (b) (10101111)2 to hexadecimal. [2]
(ii) Draw the logic circuit and the truth table for (A OR B) AND (NOT C). [2]
(i) (a)
Write each digit as 4 bits: 1 → 0001 A → 1010 D → 1101
So (1AD)16 = (110101101)2
(i) (b)
Make groups of 4 bits from the right: 1010 1111
1010 → A 1111 → F
So (10101111)2 = (AF)16
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A OR B) AND (NOT C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
(i) Convert (a) (101011000)2 to decimal and (b) (E9)16 to octal. [2]
(ii) Draw the logic circuit and the truth table for NOT A OR (B AND C). [2]
(i) (a)
(101011000)2 = 1 × 28 + 0 × 27 + 1 × 26 + 0 × 25 + 1 × 24 + 1 × 23 + 0 × 22 + 0 × 21 + 0 × 20 = 256 + 0 + 64 + 0 + 16 + 8 + 0 + 0 + 0 = 344
(i) (b)
Write each digit as 4 bits: E → 1110 9 → 1001
So (E9)16 = (11101001)2
Make groups of 3 bits from the right: 011 101 001
011 → 3 101 → 5 001 → 1
So (11101001)2 = (351)8
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | NOT A OR (B AND C) |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (704)8 to binary and (b) (307)10 to octal. [2]
(ii) Draw the logic circuit and the truth table for (A AND NOT B) OR (B AND C). [2]
(i) (a)
Write each digit as 3 bits: 7 → 111 0 → 000 4 → 100
So (704)8 = (111000100)2
(i) (b)
| Divide by | Number | Remainder |
|---|---|---|
| 8 | 307 | 3 |
| 8 | 38 | 6 |
| 8 | 4 | 4 |
Read the remainders from bottom to top: (463)8
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A AND NOT B) OR (B AND C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (145)8 to binary and (b) (483)10 to binary. [2]
(ii) Draw the logic circuit and the truth table for NOT (A OR B) AND C. [2]
(i) (a)
Write each digit as 3 bits: 1 → 001 4 → 100 5 → 101
So (145)8 = (1100101)2
(i) (b)
| Divide by | Number | Remainder |
|---|---|---|
| 2 | 483 | 1 |
| 2 | 241 | 1 |
| 2 | 120 | 0 |
| 2 | 60 | 0 |
| 2 | 30 | 0 |
| 2 | 15 | 1 |
| 2 | 7 | 1 |
| 2 | 3 | 1 |
| 2 | 1 | 1 |
Read the remainders from bottom to top: (111100011)2
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | NOT (A OR B) AND C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
(i) Convert (a) (101001011)2 to hexadecimal and (b) (477)10 to hexadecimal. [2]
(ii) Draw the logic circuit and the truth table for (A OR NOT B) AND (B OR C). [2]
(i) (a)
Make groups of 4 bits from the right: 0001 0100 1011
0001 → 1 0100 → 4 1011 → B
So (101001011)2 = (14B)16
(i) (b)
| Divide by | Number | Remainder |
|---|---|---|
| 16 | 477 | D |
| 16 | 29 | D |
| 16 | 1 | 1 |
Read the remainders from bottom to top: (1DD)16
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | (A OR NOT B) AND (B OR C) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
(i) Convert (a) (B0)16 to decimal and (b) (101011110)2 to decimal. [2]
(ii) Draw the logic circuit and the truth table for A AND B AND NOT C. [2]
(i) (a)
(B0)16 = B × 161 + 0 × 160 = 176 + 0 = 176
(i) (b)
(101011110)2 = 1 × 28 + 0 × 27 + 1 × 26 + 0 × 25 + 1 × 24 + 1 × 23 + 1 × 22 + 1 × 21 + 0 × 20 = 256 + 0 + 64 + 0 + 16 + 8 + 4 + 2 + 0 = 350
(ii) Logic circuit:
Three variables give 23 = 8 rows.
| A | B | C | A AND B AND NOT C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
Sohan, a Class XI student, posts photos of his new phone with his home address on social media. A week later he gets an e-mail saying he has won a phone and must pay a small fee by clicking a link. He clicks it and his social media account is taken over; fake posts are made in his name.
A school is replacing 40 old computers, 10 printers and many batteries. The caretaker plans to dump them behind the school.
Meera wrote a story and posted it on her blog. Later she found that a magazine had printed it with another writer's name. A software company also copied her original app idea and design.
The computer teacher wants to set up a lab for 30 students with a low budget. She is choosing between MS Office and LibreOffice, and between Windows and Ubuntu Linux.
Karan, a Class XI student, gets messages every day in a gaming chat calling him names. The sender also shares his edited photo. Karan is upset and stops going to school.
A bank customer finds that all the files on her office computer are locked. A message asks her to pay money in cryptocurrency within 24 hours to unlock them. Earlier she had opened an e-mail attachment named invoice.exe.
A company says its new website is easy for everyone. But it has small text, no captions on videos, and images without descriptions. Very few women apply for its technical jobs.
Aditi uses the same password 'aditi2009' for all her accounts. She often uses free Wi-Fi at the mall and saves her passwords in the browser of the library computer.
Ravi notices that after visiting a shoe website, he sees shoe ads on every site. A new app on his phone also asks for access to his contacts, camera and location.
A student downloads a paid video editor for free from an unknown website. After installing it, his computer slows down, shows many ads, and his friends get strange messages from his e-mail.
In a village, many students do not have smartphones or Internet at home, so they miss online classes. The panchayat wants to help.
Nidhi used a photo from a website in her school poster. The photo had a CC BY-NC licence. She later printed and sold the posters at a fair.
A school wants students to make a digital magazine. Students use photos, music and articles from the Internet. Some copy articles word for word.
Ms. Gupta teaches a student who uses a wheelchair and another who has low vision. The school wants to make its computer lab and website inclusive.
An app that edits photos for free asks to read contacts, messages and location. Some months later, users of the app get spam calls and messages.
Rahul wants to share a program he wrote. He wants others to use and improve it, but he wants every improved version to also stay free and open.
An online game asks players to buy coins. A message on the game chat says, 'Get free coins: share your username and password here.' Some players lose their accounts.
The school's computers are on all night, monitors are very bright and many students sit for hours without breaks.
A student finds that his photo has been edited and posted on a fake page with mocking comments. Many classmates share it.
A company keeps the data of its customers. A hacker steals the names, phone numbers and card details of thousands of customers.
Write a program to input a string and check whether it is a palindrome (ignore the case).
s = input('Enter a string: ')
t = s.lower()
if t == t[::-1]:
print(s, 'is a palindrome')
else:
print(s, 'is not a palindrome')Sample run
Enter a string: Madam Madam is a palindrome
Write a program to input a sentence and count the number of words in it.
s = input('Enter a sentence: ')
words = s.split()
print('Number of words =', len(words))Sample run
Enter a sentence: Practice makes a person perfect Number of words = 5
Write a program to input a sentence and print the longest word and its length.
s = input('Enter a sentence: ')
longest = ''
for w in s.split():
if len(w) > len(longest):
longest = w
print('Longest word:', longest, 'with', len(longest), 'letters')Sample run
Enter a sentence: Computer science is wonderful Longest word: wonderful with 9 letters
Write a program to input a sentence and print the words that start with a vowel.
s = input('Enter a sentence: ')
for w in s.split():
if w[0] in 'aeiouAEIOU':
print(w)Sample run
Enter a sentence: An apple is on every table in India An apple is on every in India
Write a program to convert the first letter of every word to capital without using title().
s = input('Enter a sentence: ')
new = ''
for w in s.split():
new = new + w[0].upper() + w[1:] + ' '
print(new.strip())Sample run
Enter a sentence: keep calm and write code Keep Calm And Write Code
Write a program to replace every space in a string with a hyphen (-) without using replace().
s = input('Enter a string: ')
new = ''
for ch in s:
if ch == ' ':
new = new + '-'
else:
new = new + ch
print(new)Sample run
Enter a string: Save water save life Save-water-save-life
Write a program to print each word of a sentence in reverse, keeping the order of the words.
s = input('Enter a sentence: ')
result = []
for w in s.split():
result.append(w[::-1])
print(' '.join(result))Sample run
Enter a sentence: Python is fun nohtyP si nuf
Write a program to input a sentence and a word, and count how many times the word occurs (ignore the case).
s = input('Enter a sentence: ')
word = input('Word to count: ')
count = 0
for w in s.lower().split():
if w == word.lower():
count += 1
print(word, 'occurs', count, 'times')Sample run
Enter a sentence: The cat and the dog and THE bird Word to count: the the occurs 3 times
Write a program to remove all the vowels from a string.
s = input('Enter a string: ')
new = ''
for ch in s:
if ch not in 'aeiouAEIOU':
new = new + ch
print('Without vowels:', new)Sample run
Enter a string: Education is important Without vowels: dctn s mprtnt
Write a program to toggle the case of every letter in a string (without swapcase()).
s = input('Enter a string: ')
new = ''
for ch in s:
if ch.isupper():
new = new + ch.lower()
elif ch.islower():
new = new + ch.upper()
else:
new = new + ch
print(new)Sample run
Enter a string: Hello World 2026 hELLO wORLD 2026
Write a program to print the frequency of each character of a string, using a dictionary.
s = input('Enter a string: ')
freq = {}
for ch in s:
if ch != ' ':
freq[ch] = freq.get(ch, 0) + 1
for ch in freq:
print(ch, ':', freq[ch])Sample run
Enter a string: banana bread b : 2 a : 4 n : 2 r : 1 e : 1 d : 1
Write a program to input a string and print it in the reverse order of its words.
s = input('Enter a sentence: ')
words = s.split()
words.reverse()
print(' '.join(words))Sample run
Enter a sentence: I am learning Python Python learning am I
Write a program to input an e-mail ID and print the user name and the domain name.
email = input('Enter e-mail: ')
at = email.find('@')
if at == -1:
print('Invalid e-mail')
else:
print('User name:', email[:at])
print('Domain:', email[at + 1:])Sample run
Enter e-mail: asha.kumari@kvs.gov.in User name: asha.kumari Domain: kvs.gov.in
Write a program to check whether a password is valid: at least 8 characters with at least one capital letter, one digit and one special character.
pwd = input('Password: ')
up = dig = sp = 0
for ch in pwd:
if ch.isupper():
up += 1
elif ch.isdigit():
dig += 1
elif not ch.isalnum():
sp += 1
if len(pwd) >= 8 and up > 0 and dig > 0 and sp > 0:
print('Valid password')
else:
print('Invalid password')Sample run
Password: Kv@Delhi88 Valid password
Write a program to print the initials of a full name, e.g. 'Mohan Das Karamchand' gives 'M.D.K.'.
name = input('Full name: ')
init = ''
for w in name.split():
init = init + w[0].upper() + '.'
print(init)Sample run
Full name: mohan das karamchand M.D.K.
Write a program to print the name in short form: initials of all but the last word, then the last word, e.g. 'M. K. Gandhi'.
name = input('Full name: ')
w = name.split()
short = ''
for x in w[:-1]:
short = short + x[0].upper() + '. '
print(short + w[-1].title())Sample run
Full name: mohandas karamchand gandhi M. K. Gandhi
Write a program to input a string and print the characters at even positions and at odd positions separately.
s = input('Enter a string: ')
print('Even positions:', s[0::2])
print('Odd positions:', s[1::2])Sample run
Enter a string: COMPUTER Even positions: CMUE Odd positions: OPTR
Write a program to count the number of words that have more than four letters.
s = input('Enter a sentence: ')
count = 0
for w in s.split():
if len(w) > 4:
count += 1
print('Words longer than 4 letters:', count)Sample run
Enter a sentence: Every student should practise programs daily Words longer than 4 letters: 6
Write a program to input a string and a character, and print all the positions where the character occurs.
s = input('Enter a string: ')
c = input('Character: ')
for i in range(len(s)):
if s[i] == c:
print(i, end=' ')Sample run
Enter a string: programming Character: m 6 7
Write a program that inputs a string and creates a new string by moving every character one place in the alphabet (a becomes b, z becomes a). Other characters stay the same.
s = input('Enter a string: ')
new = ''
for ch in s:
if 'a' <= ch <= 'y' or 'A' <= ch <= 'Y':
new = new + chr(ord(ch) + 1)
elif ch == 'z':
new = new + 'a'
elif ch == 'Z':
new = new + 'A'
else:
new = new + ch
print(new)Sample run
Enter a string: Zebra crossing Afcsb dspttjoh
Write a program to check whether two strings are anagrams (have the same letters in a different order).
a = input('First word: ')
b = input('Second word: ')
if sorted(a.lower()) == sorted(b.lower()):
print('Anagrams')
else:
print('Not anagrams')Sample run
First word: Listen Second word: Silent Anagrams
Write a program to remove the duplicate characters from a string, keeping the first occurrence.
s = input('Enter a string: ')
new = ''
for ch in s:
if ch not in new:
new = new + ch
print(new)Sample run
Enter a string: programming progamin
Write a program to input a string and count the number of upper-case letters and lower-case letters in it.
s = input('Enter a string: ')
c1 = c2 = 0
for ch in s:
if ch.isupper():
c1 += 1
if ch.islower():
c2 += 1
print('Upper-case letters:', c1)
print('Lower-case letters:', c2)Sample run
Enter a string: Hello World 2026, KV Shalimar Bagh! Upper-case letters: 6 Lower-case letters: 18
Write a program to input a string and count the number of upper-case letters and digits in it.
s = input('Enter a string: ')
c1 = c2 = 0
for ch in s:
if ch.isupper():
c1 += 1
if ch.isdigit():
c2 += 1
print('Upper-case letters:', c1)
print('Digits:', c2)Sample run
Enter a string: Python 3.12 is EASY to Learn :) Upper-case letters: 6 Digits: 3
Write a program to input a string and count the number of upper-case letters and spaces in it.
s = input('Enter a string: ')
c1 = c2 = 0
for ch in s:
if ch.isupper():
c1 += 1
if ch == " ":
c2 += 1
print('Upper-case letters:', c1)
print('Spaces:', c2)Sample run
Enter a string: CBSE Exam on 15 March, all THE best! Upper-case letters: 9 Spaces: 7
Write a program to input a string and count the number of upper-case letters and vowels in it.
s = input('Enter a string: ')
c1 = c2 = 0
for ch in s:
if ch.isupper():
c1 += 1
if ch in "aeiouAEIOU":
c2 += 1
print('Upper-case letters:', c1)
print('Vowels:', c2)Sample run
Enter a string: I love India; Jai Hind 123 Upper-case letters: 4 Vowels: 9
Write a program to input a string and count the number of upper-case letters and special characters (not a letter, digit or space) in it.
s = input('Enter a string: ')
c1 = c2 = 0
for ch in s:
if ch.isupper():
c1 += 1
if not ch.isalnum() and ch != " ":
c2 += 1
print('Upper-case letters:', c1)
print('Special characters:', c2)Sample run
Enter a string: Hello World 2026, KV Shalimar Bagh! Upper-case letters: 6 Special characters: 2
Write a program to input a string and count the number of lower-case letters and digits in it.
s = input('Enter a string: ')
c1 = c2 = 0
for ch in s:
if ch.islower():
c1 += 1
if ch.isdigit():
c2 += 1
print('Lower-case letters:', c1)
print('Digits:', c2)Sample run
Enter a string: Python 3.12 is EASY to Learn :) Lower-case letters: 13 Digits: 3
Write a program to input a string and count the number of lower-case letters and spaces in it.
s = input('Enter a string: ')
c1 = c2 = 0
for ch in s:
if ch.islower():
c1 += 1
if ch == " ":
c2 += 1
print('Lower-case letters:', c1)
print('Spaces:', c2)Sample run
Enter a string: CBSE Exam on 15 March, all THE best! Lower-case letters: 16 Spaces: 7
Write a program to input a string and count the number of lower-case letters and vowels in it.
s = input('Enter a string: ')
c1 = c2 = 0
for ch in s:
if ch.islower():
c1 += 1
if ch in "aeiouAEIOU":
c2 += 1
print('Lower-case letters:', c1)
print('Vowels:', c2)Sample run
Enter a string: I love India; Jai Hind 123 Lower-case letters: 13 Vowels: 9
Write a program to input a string and count the number of lower-case letters and special characters (not a letter, digit or space) in it.
s = input('Enter a string: ')
c1 = c2 = 0
for ch in s:
if ch.islower():
c1 += 1
if not ch.isalnum() and ch != " ":
c2 += 1
print('Lower-case letters:', c1)
print('Special characters:', c2)Sample run
Enter a string: Hello World 2026, KV Shalimar Bagh! Lower-case letters: 18 Special characters: 2
Write a program to input a string and count the number of digits and spaces in it.
s = input('Enter a string: ')
c1 = c2 = 0
for ch in s:
if ch.isdigit():
c1 += 1
if ch == " ":
c2 += 1
print('Digits:', c1)
print('Spaces:', c2)Sample run
Enter a string: Python 3.12 is EASY to Learn :) Digits: 3 Spaces: 6
Write a program to input a string and count the number of digits and vowels in it.
s = input('Enter a string: ')
c1 = c2 = 0
for ch in s:
if ch.isdigit():
c1 += 1
if ch in "aeiouAEIOU":
c2 += 1
print('Digits:', c1)
print('Vowels:', c2)Sample run
Enter a string: CBSE Exam on 15 March, all THE best! Digits: 2 Vowels: 8
Write a program to input a string and count the number of digits and special characters (not a letter, digit or space) in it.
s = input('Enter a string: ')
c1 = c2 = 0
for ch in s:
if ch.isdigit():
c1 += 1
if not ch.isalnum() and ch != " ":
c2 += 1
print('Digits:', c1)
print('Special characters:', c2)Sample run
Enter a string: I love India; Jai Hind 123 Digits: 3 Special characters: 1
Write a program to input a string and count the number of spaces and vowels in it.
s = input('Enter a string: ')
c1 = c2 = 0
for ch in s:
if ch == " ":
c1 += 1
if ch in "aeiouAEIOU":
c2 += 1
print('Spaces:', c1)
print('Vowels:', c2)Sample run
Enter a string: Hello World 2026, KV Shalimar Bagh! Spaces: 5 Vowels: 7
Write a program to input a string and count the number of spaces and special characters (not a letter, digit or space) in it.
s = input('Enter a string: ')
c1 = c2 = 0
for ch in s:
if ch == " ":
c1 += 1
if not ch.isalnum() and ch != " ":
c2 += 1
print('Spaces:', c1)
print('Special characters:', c2)Sample run
Enter a string: Python 3.12 is EASY to Learn :) Spaces: 6 Special characters: 3
Write a program to input a string and count the number of vowels and special characters (not a letter, digit or space) in it.
s = input('Enter a string: ')
c1 = c2 = 0
for ch in s:
if ch in "aeiouAEIOU":
c1 += 1
if not ch.isalnum() and ch != " ":
c2 += 1
print('Vowels:', c1)
print('Special characters:', c2)Sample run
Enter a string: CBSE Exam on 15 March, all THE best! Vowels: 8 Special characters: 2
Write a program to input a string and display it after replacing each of its upper-case letters with "*".
s = input('Enter a string: ')
new = ''
for ch in s:
if ch.isupper():
new = new + '*'
else:
new = new + ch
print(new)Sample run
Enter a string: Python 3.12 is EASY to Learn :) *ython 3.12 is **** to *earn :)
Write a program to input a string and display it after replacing each of its lower-case letters with "*".
s = input('Enter a string: ')
new = ''
for ch in s:
if ch.islower():
new = new + '*'
else:
new = new + ch
print(new)Sample run
Enter a string: CBSE Exam on 15 March, all THE best! CBSE E*** ** 15 M****, *** THE ****!
Write a program to input a string and display it after replacing each of its digits with "*".
s = input('Enter a string: ')
new = ''
for ch in s:
if ch.isdigit():
new = new + '*'
else:
new = new + ch
print(new)Sample run
Enter a string: I love India; Jai Hind 123 I love India; Jai Hind ***
Write a program to input a string and display it after replacing each of its spaces with "*".
s = input('Enter a string: ')
new = ''
for ch in s:
if ch == " ":
new = new + '*'
else:
new = new + ch
print(new)Sample run
Enter a string: Hello World 2026, KV Shalimar Bagh! Hello*World*2026,*KV*Shalimar*Bagh!
Write a program to input a string and display it after replacing each of its vowels with "*".
s = input('Enter a string: ')
new = ''
for ch in s:
if ch in "aeiouAEIOU":
new = new + '*'
else:
new = new + ch
print(new)Sample run
Enter a string: Python 3.12 is EASY to Learn :) Pyth*n 3.12 *s **SY t* L**rn :)
Write a program to input a list of numbers and search for a number (linear search). Print its position or 'not found'.
L = eval(input('Enter a list: '))
x = int(input('Number to search: '))
for i in range(len(L)):
if L[i] == x:
print(x, 'found at index', i)
break
else:
print(x, 'not found')Sample run
Enter a list: [12, 45, 7, 30, 18] Number to search: 30 30 found at index 3
Write a program to input a list and swap the elements at even positions with the elements at odd positions: [1, 2, 3, 4] becomes [2, 1, 4, 3].
L = eval(input('Enter a list: '))
for i in range(0, len(L) - 1, 2):
L[i], L[i + 1] = L[i + 1], L[i]
print(L)Sample run
Enter a list: [10, 20, 30, 40, 50, 60] [20, 10, 40, 30, 60, 50]
Write a program to find the largest and the second largest element of a list without sorting.
L = eval(input('Enter a list: '))
first = second = None
for x in L:
if first is None or x > first:
second = first
first = x
elif x != first and (second is None or x > second):
second = x
print('Largest =', first)
print('Second largest =', second)Sample run
Enter a list: [34, 78, 12, 90, 56, 90] Largest = 90 Second largest = 78
Write a program to rotate the elements of a list one place to the left: [1, 2, 3, 4] becomes [2, 3, 4, 1].
L = eval(input('Enter a list: '))
first = L[0]
for i in range(len(L) - 1):
L[i] = L[i + 1]
L[-1] = first
print(L)Sample run
Enter a list: [5, 10, 15, 20, 25] [10, 15, 20, 25, 5]
Write a program to rotate the elements of a list one place to the right.
L = eval(input('Enter a list: '))
last = L[-1]
for i in range(len(L) - 1, 0, -1):
L[i] = L[i - 1]
L[0] = last
print(L)Sample run
Enter a list: [5, 10, 15, 20, 25] [25, 5, 10, 15, 20]
Write a program to remove the duplicate elements from a list.
L = eval(input('Enter a list: '))
new = []
for x in L:
if x not in new:
new.append(x)
print('Without duplicates:', new)Sample run
Enter a list: [3, 5, 3, 8, 5, 9, 3] Without duplicates: [3, 5, 8, 9]
Write a program to input a list and put the positive and the negative numbers into two separate lists.
L = eval(input('Enter a list: '))
pos, neg = [], []
for x in L:
if x >= 0:
pos.append(x)
else:
neg.append(x)
print('Positive:', pos)
print('Negative:', neg)Sample run
Enter a list: [12, -5, 0, 8, -17, 25] Positive: [12, 0, 8, 25] Negative: [-5, -17]
Write a program to find the frequency of each element of a list using a dictionary.
L = eval(input('Enter a list: '))
freq = {}
for x in L:
freq[x] = freq.get(x, 0) + 1
for k in freq:
print(k, 'occurs', freq[k], 'times')Sample run
Enter a list: [2, 7, 2, 9, 7, 2] 2 occurs 3 times 7 occurs 2 times 9 occurs 1 times
Write a program to input a list and replace every even element by its half and every odd element by its double.
L = eval(input('Enter a list: '))
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] = L[i] // 2
else:
L[i] = L[i] * 2
print(L)Sample run
Enter a list: [10, 7, 24, 3, 15] [5, 14, 12, 6, 30]
Write a program to print the cumulative sum of a list: [1, 2, 3] gives [1, 3, 6].
L = eval(input('Enter a list: '))
C = []
s = 0
for x in L:
s = s + x
C.append(s)
print(C)Sample run
Enter a list: [4, 6, 1, 9, 5] [4, 10, 11, 20, 25]
Write a program to input a tuple of numbers and print the maximum, the minimum, the sum and the mean.
T = eval(input('Enter a tuple: '))
print('Maximum =', max(T))
print('Minimum =', min(T))
print('Sum =', sum(T))
print('Mean =', sum(T) / len(T))Sample run
Enter a tuple: (45, 12, 78, 33, 52) Maximum = 78 Minimum = 12 Sum = 220 Mean = 44.0
Write a program to input a tuple and count how many times a given element occurs in it, without count().
T = eval(input('Enter a tuple: '))
x = int(input('Element: '))
c = 0
for v in T:
if v == x:
c += 1
print(x, 'occurs', c, 'times')Sample run
Enter a tuple: (4, 8, 4, 2, 4, 9) Element: 4 4 occurs 3 times
Write a program to create a dictionary of n students' roll numbers and names, and search for a roll number.
n = int(input('How many students? '))
D = {}
for i in range(n):
r = int(input('Roll no: '))
name = input('Name: ')
D[r] = name
r = int(input('Roll no to search: '))
if r in D:
print('Name:', D[r])
else:
print('Not found')Sample run
How many students? 3 Roll no: 1 Name: Asha Roll no: 2 Name: Bilal Roll no: 3 Name: Charu Roll no to search: 2 Name: Bilal
Write a program to count the frequency of each word in a sentence using a dictionary.
s = input('Enter a sentence: ')
D = {}
for w in s.lower().split():
D[w] = D.get(w, 0) + 1
print(D)Sample run
Enter a sentence: the sun and the moon and the stars
{'the': 3, 'sun': 1, 'and': 2, 'moon': 1, 'stars': 1}Write a program to create a dictionary of country names and their capitals, and print the capital of a country given by the user.
D = {'India': 'New Delhi', 'Japan': 'Tokyo', 'France': 'Paris', 'Kenya': 'Nairobi'}
c = input('Country: ')
print('Capital:', D.get(c, 'not in the list'))Sample run
Country: Japan Capital: Tokyo
Write a program to find the key with the largest value in a dictionary of items and prices.
D = eval(input('Enter a dictionary: '))
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Costliest item:', best, D[best])Sample run
Enter a dictionary: {'pen': 20, 'bag': 650, 'book': 280}
Costliest item: bag 650Write a program to input a list of numbers and print the numbers that are divisible by 3 but not by 5.
L = eval(input('Enter a list: '))
for x in L:
if x % 3 == 0 and x % 5 != 0:
print(x, end=' ')Sample run
Enter a list: [9, 15, 21, 30, 33, 40, 42] 9 21 33 42
Write a program to merge two lists and print the merged list in ascending order, without using + or extend().
A = eval(input('First list: '))
B = eval(input('Second list: '))
C = []
for x in A:
C.append(x)
for x in B:
C.append(x)
C.sort()
print(C)Sample run
First list: [8, 3, 5] Second list: [7, 1, 9] [1, 3, 5, 7, 8, 9]
Write a program to create a dictionary from two lists: one of names and one of marks. Print the names of the students who scored above 80.
names = eval(input('Names: '))
marks = eval(input('Marks: '))
D = {}
for i in range(len(names)):
D[names[i]] = marks[i]
print(D)
for k in D:
if D[k] > 80:
print(k)Sample run
Names: ['Anu', 'Bhanu', 'Chetan', 'Divya']
Marks: [78, 92, 85, 64]
{'Anu': 78, 'Bhanu': 92, 'Chetan': 85, 'Divya': 64}
Bhanu
ChetanWrite a program to input a list of words and print the words that are palindromes.
W = eval(input('Enter a list of words: '))
for w in W:
if w.lower() == w.lower()[::-1]:
print(w)Sample run
Enter a list of words: ['Level', 'tree', 'noon', 'civic', 'python'] Level noon civic
Write a program to input a list of numbers and create a new list that has the square of each odd number.
L = eval(input('Enter a list: '))
S = []
for x in L:
if x % 2 != 0:
S.append(x * x)
print(S)Sample run
Enter a list: [3, 8, 5, 10, 7] [9, 25, 49]
Write a program to find the sum of the elements at even indices and at odd indices of a list.
L = eval(input('Enter a list: '))
e = o = 0
for i in range(len(L)):
if i % 2 == 0:
e += L[i]
else:
o += L[i]
print('Sum at even indices =', e)
print('Sum at odd indices =', o)Sample run
Enter a list: [10, 3, 20, 7, 30, 1] Sum at even indices = 60 Sum at odd indices = 11
Write a menu-driven program for a list of numbers with these options: 1. Append a number, 2. Delete a number, 3. Display the list, 4. Sort the list, 5. Exit.
L = []
while True:
print('1.Append 2.Delete 3.Display 4.Sort 5.Exit')
ch = int(input('Choice: '))
if ch == 1:
L.append(int(input('Number: ')))
elif ch == 2:
x = int(input('Number to delete: '))
if x in L:
L.remove(x)
else:
print('Not in list')
elif ch == 3:
print(L)
elif ch == 4:
L.sort()
print('Sorted:', L)
elif ch == 5:
break
else:
print('Wrong choice')Sample run
1.Append 2.Delete 3.Display 4.Sort 5.Exit Choice: 1 Number: 30 1.Append 2.Delete 3.Display 4.Sort 5.Exit Choice: 1 Number: 10 1.Append 2.Delete 3.Display 4.Sort 5.Exit Choice: 1 Number: 20 1.Append 2.Delete 3.Display 4.Sort 5.Exit Choice: 3 [30, 10, 20] 1.Append 2.Delete 3.Display 4.Sort 5.Exit Choice: 2 Number to delete: 10 1.Append 2.Delete 3.Display 4.Sort 5.Exit Choice: 4 Sorted: [20, 30] 1.Append 2.Delete 3.Display 4.Sort 5.Exit Choice: 5
Write a menu-driven program to maintain a phone book (dictionary of name: phone) with options: 1. Add, 2. Search, 3. Delete, 4. Display all, 5. Exit.
book = {}
while True:
print('1.Add 2.Search 3.Delete 4.Display 5.Exit')
ch = int(input('Choice: '))
if ch == 1:
n = input('Name: ')
book[n] = input('Phone: ')
elif ch == 2:
n = input('Name: ')
print(book.get(n, 'Not found'))
elif ch == 3:
n = input('Name: ')
if n in book:
del book[n]
print('Deleted')
else:
print('Not found')
elif ch == 4:
for n in book:
print(n, book[n])
elif ch == 5:
breakSample run
1.Add 2.Search 3.Delete 4.Display 5.Exit Choice: 1 Name: Asha Phone: 98110 22334 1.Add 2.Search 3.Delete 4.Display 5.Exit Choice: 1 Name: Ravi Phone: 98990 55667 1.Add 2.Search 3.Delete 4.Display 5.Exit Choice: 2 Name: Ravi 98990 55667 1.Add 2.Search 3.Delete 4.Display 5.Exit Choice: 3 Name: Asha Deleted 1.Add 2.Search 3.Delete 4.Display 5.Exit Choice: 4 Ravi 98990 55667 1.Add 2.Search 3.Delete 4.Display 5.Exit Choice: 5
Write a menu-driven program for a stock dictionary (item: quantity): 1. Add or update an item, 2. Sell an item (reduce its quantity), 3. Show items with quantity below 5, 4. Exit.
stock = {'pen': 40, 'pencil': 3, 'eraser': 12}
while True:
print('1.Add/Update 2.Sell 3.Low stock 4.Exit')
ch = int(input('Choice: '))
if ch == 1:
it = input('Item: ')
stock[it] = stock.get(it, 0) + int(input('Quantity: '))
elif ch == 2:
it = input('Item: ')
q = int(input('Quantity: '))
if stock.get(it, 0) >= q:
stock[it] -= q
else:
print('Not enough stock')
elif ch == 3:
for it in stock:
if stock[it] < 5:
print(it, stock[it])
elif ch == 4:
break
print(stock)Sample run
1.Add/Update 2.Sell 3.Low stock 4.Exit
Choice: 1
Item: sharpener
Quantity: 6
{'pen': 40, 'pencil': 3, 'eraser': 12, 'sharpener': 6}
1.Add/Update 2.Sell 3.Low stock 4.Exit
Choice: 2
Item: pen
Quantity: 38
{'pen': 2, 'pencil': 3, 'eraser': 12, 'sharpener': 6}
1.Add/Update 2.Sell 3.Low stock 4.Exit
Choice: 3
pen 2
pencil 3
{'pen': 2, 'pencil': 3, 'eraser': 12, 'sharpener': 6}
1.Add/Update 2.Sell 3.Low stock 4.Exit
Choice: 4Write a menu-driven program for strings: 1. Count vowels, 2. Reverse the string, 3. Check palindrome, 4. Count words, 5. Exit. The string is input once at the start.
s = input('Enter a string: ')
while True:
print('1.Vowels 2.Reverse 3.Palindrome 4.Words 5.Exit')
ch = int(input('Choice: '))
if ch == 1:
c = 0
for x in s:
if x in 'aeiouAEIOU':
c += 1
print('Vowels:', c)
elif ch == 2:
print(s[::-1])
elif ch == 3:
print('Palindrome' if s.lower() == s.lower()[::-1] else 'Not a palindrome')
elif ch == 4:
print('Words:', len(s.split()))
elif ch == 5:
breakSample run
Enter a string: Never odd or even 1.Vowels 2.Reverse 3.Palindrome 4.Words 5.Exit Choice: 1 Vowels: 6 1.Vowels 2.Reverse 3.Palindrome 4.Words 5.Exit Choice: 2 neve ro ddo reveN 1.Vowels 2.Reverse 3.Palindrome 4.Words 5.Exit Choice: 3 Not a palindrome 1.Vowels 2.Reverse 3.Palindrome 4.Words 5.Exit Choice: 4 Words: 4 1.Vowels 2.Reverse 3.Palindrome 4.Words 5.Exit Choice: 5
Write a program to input the name and marks of 4 students and store them in a dictionary. Then:
n = int(input('How many students? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Marks: '))
# (i)
print('Names with marks more than 75:')
for k in D:
if D[k] > 75:
print(k, D[k])
# (ii)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest marks:', best, D[best])Sample run
How many students? 4 Name: Asha Marks: 88 Name: Bilal Marks: 64 Name: Charu Marks: 92 Name: Dev Marks: 47 Names with marks more than 75: Asha 88 Charu 92 Highest marks: Charu 92
Write a program to input the name and marks of 4 students and store them in a dictionary. Then:
n = int(input('How many students? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Marks: '))
# (i)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest marks:', best, D[best])
# (ii)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))Sample run
How many students? 4 Name: Asha Marks: 88 Name: Bilal Marks: 64 Name: Charu Marks: 92 Name: Dev Marks: 47 Highest marks: Charu 92 Total = 291 Average = 72.75
Write a program to input the name and marks of 4 students and store them in a dictionary. Then:
n = int(input('How many students? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Marks: '))
# (i)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))
# (ii)
for k in sorted(D):
print(k, D[k])Sample run
How many students? 4 Name: Asha Marks: 88 Name: Bilal Marks: 64 Name: Charu Marks: 92 Name: Dev Marks: 47 Total = 291 Average = 72.75 Asha 88 Bilal 64 Charu 92 Dev 47
Write a program to input the name and marks of 4 students and store them in a dictionary. Then:
n = int(input('How many students? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Marks: '))
# (i)
for k in sorted(D):
print(k, D[k])
# (ii)
c = 0
for k in D:
if D[k] < 75:
c += 1
print('Count with marks less than 75:', c)Sample run
How many students? 4 Name: Asha Marks: 88 Name: Bilal Marks: 64 Name: Charu Marks: 92 Name: Dev Marks: 47 Asha 88 Bilal 64 Charu 92 Dev 47 Count with marks less than 75: 2
Write a program to input the name and marks of 4 students and store them in a dictionary. Then:
n = int(input('How many students? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Marks: '))
# (i)
c = 0
for k in D:
if D[k] < 75:
c += 1
print('Count with marks less than 75:', c)
# (ii)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)Sample run
How many students? 4
Name: Asha
Marks: 88
Name: Bilal
Marks: 64
Name: Charu
Marks: 92
Name: Dev
Marks: 47
Count with marks less than 75: 2
{'Asha': 96.8, 'Bilal': 70.4, 'Charu': 101.2, 'Dev': 51.7}Write a program to input the name and salary of 4 employees and store them in a dictionary. Then:
n = int(input('How many employees? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Salary: '))
# (i)
print('Names with salary more than 50000:')
for k in D:
if D[k] > 50000:
print(k, D[k])
# (ii)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))Sample run
How many employees? 4 Name: Ravi Salary: 42000 Name: Seema Salary: 58000 Name: Tarun Salary: 36000 Name: Usha Salary: 61000 Names with salary more than 50000: Seema 58000 Usha 61000 Total = 197000 Average = 49250.0
Write a program to input the name and salary of 4 employees and store them in a dictionary. Then:
n = int(input('How many employees? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Salary: '))
# (i)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest salary:', best, D[best])
# (ii)
for k in sorted(D):
print(k, D[k])Sample run
How many employees? 4 Name: Ravi Salary: 42000 Name: Seema Salary: 58000 Name: Tarun Salary: 36000 Name: Usha Salary: 61000 Highest salary: Usha 61000 Ravi 42000 Seema 58000 Tarun 36000 Usha 61000
Write a program to input the name and salary of 4 employees and store them in a dictionary. Then:
n = int(input('How many employees? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Salary: '))
# (i)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))
# (ii)
c = 0
for k in D:
if D[k] < 50000:
c += 1
print('Count with salary less than 50000:', c)Sample run
How many employees? 4 Name: Ravi Salary: 42000 Name: Seema Salary: 58000 Name: Tarun Salary: 36000 Name: Usha Salary: 61000 Total = 197000 Average = 49250.0 Count with salary less than 50000: 2
Write a program to input the name and salary of 4 employees and store them in a dictionary. Then:
n = int(input('How many employees? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Salary: '))
# (i)
for k in sorted(D):
print(k, D[k])
# (ii)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)Sample run
How many employees? 4
Name: Ravi
Salary: 42000
Name: Seema
Salary: 58000
Name: Tarun
Salary: 36000
Name: Usha
Salary: 61000
Ravi 42000
Seema 58000
Tarun 36000
Usha 61000
{'Ravi': 46200.0, 'Seema': 63800.0, 'Tarun': 39600.0, 'Usha': 67100.0}Write a program to input the name and salary of 4 employees and store them in a dictionary. Then:
n = int(input('How many employees? '))
D = {}
for i in range(n):
k = input('Name: ')
D[k] = int(input('Salary: '))
# (i)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)
# (ii)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest salary:', best, D[best])Sample run
How many employees? 4
Name: Ravi
Salary: 42000
Name: Seema
Salary: 58000
Name: Tarun
Salary: 36000
Name: Usha
Salary: 61000
{'Ravi': 46200.0, 'Seema': 63800.0, 'Tarun': 39600.0, 'Usha': 67100.0}
Highest salary: Usha 67100.0Write a program to input the item and price of 4 items and store them in a dictionary. Then:
n = int(input('How many items? '))
D = {}
for i in range(n):
k = input('Item: ')
D[k] = int(input('Price: '))
# (i)
print('Items with price more than 300:')
for k in D:
if D[k] > 300:
print(k, D[k])
# (ii)
for k in sorted(D):
print(k, D[k])Sample run
How many items? 4 Item: Pen Price: 20 Item: Bag Price: 650 Item: Book Price: 280 Item: Lamp Price: 450 Items with price more than 300: Bag 650 Lamp 450 Bag 650 Book 280 Lamp 450 Pen 20
Write a program to input the item and price of 4 items and store them in a dictionary. Then:
n = int(input('How many items? '))
D = {}
for i in range(n):
k = input('Item: ')
D[k] = int(input('Price: '))
# (i)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest price:', best, D[best])
# (ii)
c = 0
for k in D:
if D[k] < 300:
c += 1
print('Count with price less than 300:', c)Sample run
How many items? 4 Item: Pen Price: 20 Item: Bag Price: 650 Item: Book Price: 280 Item: Lamp Price: 450 Highest price: Bag 650 Count with price less than 300: 2
Write a program to input the item and price of 4 items and store them in a dictionary. Then:
n = int(input('How many items? '))
D = {}
for i in range(n):
k = input('Item: ')
D[k] = int(input('Price: '))
# (i)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))
# (ii)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)Sample run
How many items? 4
Item: Pen
Price: 20
Item: Bag
Price: 650
Item: Book
Price: 280
Item: Lamp
Price: 450
Total = 1400
Average = 350.0
{'Pen': 22.0, 'Bag': 715.0, 'Book': 308.0, 'Lamp': 495.0}Write a program to input the item and price of 4 items and store them in a dictionary. Then:
n = int(input('How many items? '))
D = {}
for i in range(n):
k = input('Item: ')
D[k] = int(input('Price: '))
# (i)
for k in sorted(D):
print(k, D[k])
# (ii)
print('Items with price more than 300:')
for k in D:
if D[k] > 300:
print(k, D[k])Sample run
How many items? 4 Item: Pen Price: 20 Item: Bag Price: 650 Item: Book Price: 280 Item: Lamp Price: 450 Bag 650 Book 280 Lamp 450 Pen 20 Items with price more than 300: Bag 650 Lamp 450
Write a program to input the item and price of 4 items and store them in a dictionary. Then:
n = int(input('How many items? '))
D = {}
for i in range(n):
k = input('Item: ')
D[k] = int(input('Price: '))
# (i)
c = 0
for k in D:
if D[k] < 300:
c += 1
print('Count with price less than 300:', c)
# (ii)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest price:', best, D[best])Sample run
How many items? 4 Item: Pen Price: 20 Item: Bag Price: 650 Item: Book Price: 280 Item: Lamp Price: 450 Count with price less than 300: 2 Highest price: Bag 650
Write a program to input the player and runs of 4 players and store them in a dictionary. Then:
n = int(input('How many players? '))
D = {}
for i in range(n):
k = input('Player: ')
D[k] = int(input('Runs: '))
# (i)
print('Players with runs more than 50:')
for k in D:
if D[k] > 50:
print(k, D[k])
# (ii)
c = 0
for k in D:
if D[k] < 50:
c += 1
print('Count with runs less than 50:', c)Sample run
How many players? 4 Player: Rohit Runs: 74 Player: Virat Runs: 101 Player: Gill Runs: 38 Player: Pant Runs: 55 Players with runs more than 50: Rohit 74 Virat 101 Pant 55 Count with runs less than 50: 1
Write a program to input the player and runs of 4 players and store them in a dictionary. Then:
n = int(input('How many players? '))
D = {}
for i in range(n):
k = input('Player: ')
D[k] = int(input('Runs: '))
# (i)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest runs:', best, D[best])
# (ii)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)Sample run
How many players? 4
Player: Rohit
Runs: 74
Player: Virat
Runs: 101
Player: Gill
Runs: 38
Player: Pant
Runs: 55
Highest runs: Virat 101
{'Rohit': 81.4, 'Virat': 111.1, 'Gill': 41.8, 'Pant': 60.5}Write a program to input the player and runs of 4 players and store them in a dictionary. Then:
n = int(input('How many players? '))
D = {}
for i in range(n):
k = input('Player: ')
D[k] = int(input('Runs: '))
# (i)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))
# (ii)
print('Players with runs more than 50:')
for k in D:
if D[k] > 50:
print(k, D[k])Sample run
How many players? 4 Player: Rohit Runs: 74 Player: Virat Runs: 101 Player: Gill Runs: 38 Player: Pant Runs: 55 Total = 268 Average = 67.0 Players with runs more than 50: Rohit 74 Virat 101 Pant 55
Write a program to input the player and runs of 4 players and store them in a dictionary. Then:
n = int(input('How many players? '))
D = {}
for i in range(n):
k = input('Player: ')
D[k] = int(input('Runs: '))
# (i)
for k in sorted(D):
print(k, D[k])
# (ii)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest runs:', best, D[best])Sample run
How many players? 4 Player: Rohit Runs: 74 Player: Virat Runs: 101 Player: Gill Runs: 38 Player: Pant Runs: 55 Gill 38 Pant 55 Rohit 74 Virat 101 Highest runs: Virat 101
Write a program to input the player and runs of 4 players and store them in a dictionary. Then:
n = int(input('How many players? '))
D = {}
for i in range(n):
k = input('Player: ')
D[k] = int(input('Runs: '))
# (i)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)
# (ii)
for k in sorted(D):
print(k, D[k])Sample run
How many players? 4
Player: Rohit
Runs: 74
Player: Virat
Runs: 101
Player: Gill
Runs: 38
Player: Pant
Runs: 55
{'Rohit': 81.4, 'Virat': 111.1, 'Gill': 41.8, 'Pant': 60.5}
Gill 41.8
Pant 60.5
Rohit 81.4
Virat 111.1Write a program to input the title and copies of 4 books and store them in a dictionary. Then:
n = int(input('How many books? '))
D = {}
for i in range(n):
k = input('Title: ')
D[k] = int(input('Copies: '))
# (i)
print('Titles with copies more than 10:')
for k in D:
if D[k] > 10:
print(k, D[k])
# (ii)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)Sample run
How many books? 4
Title: Gitanjali
Copies: 12
Title: Godan
Copies: 5
Title: Malgudi Days
Copies: 9
Title: Wings of Fire
Copies: 15
Titles with copies more than 10:
Gitanjali 12
Wings of Fire 15
{'Gitanjali': 13.2, 'Godan': 5.5, 'Malgudi Days': 9.9, 'Wings of Fire': 16.5}Write a program to input the title and copies of 4 books and store them in a dictionary. Then:
n = int(input('How many books? '))
D = {}
for i in range(n):
k = input('Title: ')
D[k] = int(input('Copies: '))
# (i)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest copies:', best, D[best])
# (ii)
print('Titles with copies more than 10:')
for k in D:
if D[k] > 10:
print(k, D[k])Sample run
How many books? 4 Title: Gitanjali Copies: 12 Title: Godan Copies: 5 Title: Malgudi Days Copies: 9 Title: Wings of Fire Copies: 15 Highest copies: Wings of Fire 15 Titles with copies more than 10: Gitanjali 12 Wings of Fire 15
Write a program to input the title and copies of 4 books and store them in a dictionary. Then:
n = int(input('How many books? '))
D = {}
for i in range(n):
k = input('Title: ')
D[k] = int(input('Copies: '))
# (i)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))
# (ii)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest copies:', best, D[best])Sample run
How many books? 4 Title: Gitanjali Copies: 12 Title: Godan Copies: 5 Title: Malgudi Days Copies: 9 Title: Wings of Fire Copies: 15 Total = 41 Average = 10.25 Highest copies: Wings of Fire 15
Write a program to input the title and copies of 4 books and store them in a dictionary. Then:
n = int(input('How many books? '))
D = {}
for i in range(n):
k = input('Title: ')
D[k] = int(input('Copies: '))
# (i)
for k in sorted(D):
print(k, D[k])
# (ii)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))Sample run
How many books? 4 Title: Gitanjali Copies: 12 Title: Godan Copies: 5 Title: Malgudi Days Copies: 9 Title: Wings of Fire Copies: 15 Gitanjali 12 Godan 5 Malgudi Days 9 Wings of Fire 15 Total = 41 Average = 10.25
Write a program to input the title and copies of 4 books and store them in a dictionary. Then:
n = int(input('How many books? '))
D = {}
for i in range(n):
k = input('Title: ')
D[k] = int(input('Copies: '))
# (i)
c = 0
for k in D:
if D[k] < 10:
c += 1
print('Count with copies less than 10:', c)
# (ii)
for k in sorted(D):
print(k, D[k])Sample run
How many books? 4 Title: Gitanjali Copies: 12 Title: Godan Copies: 5 Title: Malgudi Days Copies: 9 Title: Wings of Fire Copies: 15 Count with copies less than 10: 2 Gitanjali 12 Godan 5 Malgudi Days 9 Wings of Fire 15
Write a program to input the city and population (lakh) of 4 cities and store them in a dictionary. Then:
n = int(input('How many cities? '))
D = {}
for i in range(n):
k = input('City: ')
D[k] = int(input('Population (lakh): '))
# (i)
print('Citys with population (lakh) more than 50:')
for k in D:
if D[k] > 50:
print(k, D[k])
# (ii)
print('Citys with population (lakh) more than 50:')
for k in D:
if D[k] > 50:
print(k, D[k])Sample run
How many cities? 4 City: Delhi Population (lakh): 190 City: Pune Population (lakh): 70 City: Jaipur Population (lakh): 40 City: Patna Population (lakh): 25 Citys with population (lakh) more than 50: Delhi 190 Pune 70 Citys with population (lakh) more than 50: Delhi 190 Pune 70
Write a program to input the city and population (lakh) of 4 cities and store them in a dictionary. Then:
n = int(input('How many cities? '))
D = {}
for i in range(n):
k = input('City: ')
D[k] = int(input('Population (lakh): '))
# (i)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest population (lakh):', best, D[best])
# (ii)
best = None
for k in D:
if best is None or D[k] > D[best]:
best = k
print('Highest population (lakh):', best, D[best])Sample run
How many cities? 4 City: Delhi Population (lakh): 190 City: Pune Population (lakh): 70 City: Jaipur Population (lakh): 40 City: Patna Population (lakh): 25 Highest population (lakh): Delhi 190 Highest population (lakh): Delhi 190
Write a program to input the city and population (lakh) of 4 cities and store them in a dictionary. Then:
n = int(input('How many cities? '))
D = {}
for i in range(n):
k = input('City: ')
D[k] = int(input('Population (lakh): '))
# (i)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))
# (ii)
total = 0
for k in D:
total += D[k]
print('Total =', total)
print('Average =', total / len(D))Sample run
How many cities? 4 City: Delhi Population (lakh): 190 City: Pune Population (lakh): 70 City: Jaipur Population (lakh): 40 City: Patna Population (lakh): 25 Total = 325 Average = 81.25 Total = 325 Average = 81.25
Write a program to input the city and population (lakh) of 4 cities and store them in a dictionary. Then:
n = int(input('How many cities? '))
D = {}
for i in range(n):
k = input('City: ')
D[k] = int(input('Population (lakh): '))
# (i)
for k in sorted(D):
print(k, D[k])
# (ii)
for k in sorted(D):
print(k, D[k])Sample run
How many cities? 4 City: Delhi Population (lakh): 190 City: Pune Population (lakh): 70 City: Jaipur Population (lakh): 40 City: Patna Population (lakh): 25 Delhi 190 Jaipur 40 Patna 25 Pune 70 Delhi 190 Jaipur 40 Patna 25 Pune 70
Write a program to input the city and population (lakh) of 4 cities and store them in a dictionary. Then:
n = int(input('How many cities? '))
D = {}
for i in range(n):
k = input('City: ')
D[k] = int(input('Population (lakh): '))
# (i)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)
# (ii)
for k in D:
D[k] = round(D[k] * 1.1, 1)
print(D)Sample run
How many cities? 4
City: Delhi
Population (lakh): 190
City: Pune
Population (lakh): 70
City: Jaipur
Population (lakh): 40
City: Patna
Population (lakh): 25
{'Delhi': 209.0, 'Pune': 77.0, 'Jaipur': 44.0, 'Patna': 27.5}
{'Delhi': 229.9, 'Pune': 84.7, 'Jaipur': 48.4, 'Patna': 30.3}Write a program to input a list of numbers. Then:
reverse().L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
R = []
for i in range(len(L) - 1, -1, -1):
R.append(L[i])
print('Reversed:', R)Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11] Sum = 111 Average = 15.857142857142858 Reversed: [11, 40, 9, 7, 22, 7, 15]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)Sample run
Enter a list of numbers: [5, 18, 29, 18, 3, 60, 13] Sum = 146 Average = 20.857142857142858 Even: 3 Odd: 4
Write a program to input a list of numbers. Then:
max() and min().L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2] Sum = 134 Average = 19.142857142857142 Largest: 41 Smallest: 2
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
avg = sum(L) / len(L)
print('Above average:', end=' ')
for x in L:
if x > avg:
print(x, end=' ')
print()Sample run
Enter a list of numbers: [23, 8, 17, 42, 8, 31, 12] Sum = 141 Average = 20.142857142857142 Above average: 23 42 31
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
print('Primes:', end=' ')
for x in L:
if x > 1:
for i in range(2, x):
if x % i == 0:
break
else:
print(x, end=' ')
print()Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11] Sum = 111 Average = 15.857142857142858 Primes: 7 7 11
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
E = L[::2]
print('Even-index elements:', E)Sample run
Enter a list of numbers: [5, 18, 29, 18, 3, 60, 13] Sum = 146 Average = 20.857142857142858 Even-index elements: [5, 29, 3, 13]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print('Frequency:', F)Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2]
Sum = 134 Average = 19.142857142857142
Frequency: {41: 1, 6: 2, 19: 1, 33: 1, 27: 1, 2: 1}Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
S = sorted(L, reverse=True)
print('Top three:', S[:3])Sample run
Enter a list of numbers: [23, 8, 17, 42, 8, 31, 12] Sum = 141 Average = 20.142857142857142 Top three: [42, 31, 23]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Sum =', sum(L), 'Average =', sum(L) / len(L))
# (ii)
x = L[0]
while x in L:
L.remove(x)
print('After removing', x, ':', L)Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11] Sum = 111 Average = 15.857142857142858 After removing 15 : [7, 22, 7, 9, 40, 11]
Write a program to input a list of numbers. Then:
max() and min().L = eval(input('Enter a list of numbers: '))
# (i)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)
# (ii)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11] Even: 2 Odd: 5 Largest: 40 Smallest: 7
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)
# (ii)
avg = sum(L) / len(L)
print('Above average:', end=' ')
for x in L:
if x > avg:
print(x, end=' ')
print()Sample run
Enter a list of numbers: [5, 18, 29, 18, 3, 60, 13] Even: 3 Odd: 4 Above average: 29 60
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)
# (ii)
print('Primes:', end=' ')
for x in L:
if x > 1:
for i in range(2, x):
if x % i == 0:
break
else:
print(x, end=' ')
print()Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2] Even: 3 Odd: 4 Primes: 41 19 2
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)
# (ii)
E = L[::2]
print('Even-index elements:', E)Sample run
Enter a list of numbers: [23, 8, 17, 42, 8, 31, 12] Even: 4 Odd: 3 Even-index elements: [23, 17, 8, 12]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)
# (ii)
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print('Frequency:', F)Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11]
Even: 2 Odd: 5
Frequency: {15: 1, 7: 2, 22: 1, 9: 1, 40: 1, 11: 1}Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)
# (ii)
S = sorted(L, reverse=True)
print('Top three:', S[:3])Sample run
Enter a list of numbers: [5, 18, 29, 18, 3, 60, 13] Even: 3 Odd: 4 Top three: [60, 29, 18]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
ev = od = 0
for x in L:
if x % 2 == 0:
ev += 1
else:
od += 1
print('Even:', ev, 'Odd:', od)
# (ii)
x = L[0]
while x in L:
L.remove(x)
print('After removing', x, ':', L)Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2] Even: 3 Odd: 4 After removing 41 : [6, 19, 33, 6, 27, 2]
Write a program to input a list of numbers. Then:
max() and min(), andL = eval(input('Enter a list of numbers: '))
# (i)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)
# (ii)
avg = sum(L) / len(L)
print('Above average:', end=' ')
for x in L:
if x > avg:
print(x, end=' ')
print()Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2] Largest: 41 Smallest: 2 Above average: 41 33 27
Write a program to input a list of numbers. Then:
max() and min(), andL = eval(input('Enter a list of numbers: '))
# (i)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)
# (ii)
print('Primes:', end=' ')
for x in L:
if x > 1:
for i in range(2, x):
if x % i == 0:
break
else:
print(x, end=' ')
print()Sample run
Enter a list of numbers: [23, 8, 17, 42, 8, 31, 12] Largest: 42 Smallest: 8 Primes: 23 17 31
Write a program to input a list of numbers. Then:
max() and min(), andL = eval(input('Enter a list of numbers: '))
# (i)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)
# (ii)
E = L[::2]
print('Even-index elements:', E)Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11] Largest: 40 Smallest: 7 Even-index elements: [15, 22, 9, 11]
Write a program to input a list of numbers. Then:
max() and min(), andL = eval(input('Enter a list of numbers: '))
# (i)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)
# (ii)
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print('Frequency:', F)Sample run
Enter a list of numbers: [5, 18, 29, 18, 3, 60, 13]
Largest: 60 Smallest: 3
Frequency: {5: 1, 18: 2, 29: 1, 3: 1, 60: 1, 13: 1}Write a program to input a list of numbers. Then:
max() and min(), andL = eval(input('Enter a list of numbers: '))
# (i)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)
# (ii)
S = sorted(L, reverse=True)
print('Top three:', S[:3])Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2] Largest: 41 Smallest: 2 Top three: [41, 33, 27]
Write a program to input a list of numbers. Then:
max() and min(), andL = eval(input('Enter a list of numbers: '))
# (i)
big = small = L[0]
for x in L:
if x > big:
big = x
if x < small:
small = x
print('Largest:', big, 'Smallest:', small)
# (ii)
x = L[0]
while x in L:
L.remove(x)
print('After removing', x, ':', L)Sample run
Enter a list of numbers: [23, 8, 17, 42, 8, 31, 12] Largest: 42 Smallest: 8 After removing 23 : [8, 17, 42, 8, 31, 12]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Primes:', end=' ')
for x in L:
if x > 1:
for i in range(2, x):
if x % i == 0:
break
else:
print(x, end=' ')
print()
# (ii)
E = L[::2]
print('Even-index elements:', E)Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2] Primes: 41 19 2 Even-index elements: [41, 19, 6, 2]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Primes:', end=' ')
for x in L:
if x > 1:
for i in range(2, x):
if x % i == 0:
break
else:
print(x, end=' ')
print()
# (ii)
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print('Frequency:', F)Sample run
Enter a list of numbers: [23, 8, 17, 42, 8, 31, 12]
Primes: 23 17 31
Frequency: {23: 1, 8: 2, 17: 1, 42: 1, 31: 1, 12: 1}Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Primes:', end=' ')
for x in L:
if x > 1:
for i in range(2, x):
if x % i == 0:
break
else:
print(x, end=' ')
print()
# (ii)
S = sorted(L, reverse=True)
print('Top three:', S[:3])Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11] Primes: 7 7 11 Top three: [40, 22, 15]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
print('Primes:', end=' ')
for x in L:
if x > 1:
for i in range(2, x):
if x % i == 0:
break
else:
print(x, end=' ')
print()
# (ii)
x = L[0]
while x in L:
L.remove(x)
print('After removing', x, ':', L)Sample run
Enter a list of numbers: [5, 18, 29, 18, 3, 60, 13] Primes: 5 29 3 13 After removing 5 : [18, 29, 18, 3, 60, 13]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
E = L[::2]
print('Even-index elements:', E)
# (ii)
F = {}
for x in L:
F[x] = F.get(x, 0) + 1
print('Frequency:', F)Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11]
Even-index elements: [15, 22, 9, 11]
Frequency: {15: 1, 7: 2, 22: 1, 9: 1, 40: 1, 11: 1}Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
E = L[::2]
print('Even-index elements:', E)
# (ii)
S = sorted(L, reverse=True)
print('Top three:', S[:3])Sample run
Enter a list of numbers: [5, 18, 29, 18, 3, 60, 13] Even-index elements: [5, 29, 3, 13] Top three: [60, 29, 18]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
E = L[::2]
print('Even-index elements:', E)
# (ii)
x = L[0]
while x in L:
L.remove(x)
print('After removing', x, ':', L)Sample run
Enter a list of numbers: [41, 6, 19, 33, 6, 27, 2] Even-index elements: [41, 19, 6, 2] After removing 41 : [6, 19, 33, 6, 27, 2]
Write a program to input a list of numbers. Then:
L = eval(input('Enter a list of numbers: '))
# (i)
S = sorted(L, reverse=True)
print('Top three:', S[:3])
# (ii)
x = L[0]
while x in L:
L.remove(x)
print('After removing', x, ':', L)Sample run
Enter a list of numbers: [15, 7, 22, 7, 9, 40, 11] Top three: [40, 22, 15] After removing 15 : [7, 22, 7, 9, 40, 11]
Tap an option to check your answer at once; your score is saved
Ten multiple-choice questions picked at random. Tap an option to answer. You get your score at the end.
Twenty ready papers with blueprints and a random paper maker, all on the CBSE paper design (Class XI unit marks)
Each paper has 37 questions for 70 marks in Sections A to E, with internal choices (OR) in Q23, Q26, Q27, Q28, Q30, Q31, Q34 and Q37. Unit marks are kept as in the syllabus: Unit I 10, Unit II 45, Unit III 15. Every paper opens with its chapter-wise blueprint. No question is repeated: the twenty papers use 900 different questions.
Downloads and printing work when this page is opened as an HTML file in a browser.
Choose Paper 1 to Paper 20, or make a random paper. The blueprint and the paper open here.
Read this the evening before and again at the exam centre gate
int() with input()L = L.sort()