Sunday, 11 January 2026

Chapter 8 Strings . Chapter 9 Lists . Chapter 10 Tuples & Dictionary

 πŸ”€ Strings

  • Definition: Sequence of characters enclosed in quotes.
  • Example: str1 = "Hello" → "Hello"

πŸ“‹ Lists

  • Definition: Ordered, mutable collection enclosed in square brackets.
  • Example: list1 = [10, 20, 30] → [10, 20, 30]

πŸ”— Tuples

  • Definition: Ordered, immutable collection enclosed in parentheses.
  • Example: tuple1 = (1, 2, 3) → (1, 2, 3)

πŸ“– Dictionaries

  • Definition: Unordered collection of key–value pairs enclosed in curly braces.
  • Example: dict1 = {'Math': 90, 'Sci': 85} → {'Math': 90, 'Sci': 85}

⚙️ Key Properties

  • Strings: Indexed, immutable.
    Example → "python"[0] → 'p'

  • Lists: Indexed, mutable.
    Example → list1[2] = 35 → [10, 20, 35]

  • Tuples: Indexed, immutable (but can hold mutable objects).
    Example → (7, 8, [55, 66])[2][1] = 100 → (7, 8, [55, 100])

  • Dictionaries: Keys unique, values mutable.
    Example → dict1['Math'] = 95 → {'Math': 95, 'Sci': 85}


➕ Operators

  • Concatenation (+): "hi"+"bye" → "hibye"[1]+[2] → [1,2](1,)+(2,) → (1,2)
  • Repetition ():"ha"*3 → "hahaha"[3]*2 → [3,3](4,)*3 → (4,4,4)
  • Membership (in / not in): "a" in "cat" → True10 in [2,4,6] → False

✂️ Slicing

  • Strings: "computer"[1:5] → "ompu"
  • Lists: [2,4,6,8,10][2:4] → [6,8]
  • Tuples: (10,20,30,40)[1:3] → (20,30)

πŸ”„Traversal

  • For loop:

    for ch in "code": print(ch)
    # c o d e
    
  • While loop:

    i=0; s="hi"
    while i<len(s): print(s[i]); i+=1
    # h i
    

πŸ› ️ Common Methods

Strings

  • len("hi") → 2
  • "hello".upper() → "HELLO"
  • "HELLO".lower() → "hello"
  • "hello world".split() → ['hello','world']

Lists

  • list1.append(5) → [10,20,5]
  • list1.remove(20) → [10,5]
  • list1.sort() → [5,10]

Tuples

  • (10,20,10).count(10) → 2
  • (10,20,30).index(20) → 1

Dictionaries

  • dict1.keys() → ['Math','Sci']
  • dict1.values() → [90,85]
  • dict1.get('Math') → 90

NOTE

Strings , Lists , Tuples & Dictionary begins with Position Zero in forward direction

Strings , Lists , Tuples & Dictionary begins with Position -1 in Reverse  direction

Royale in Forward Reading
R is Position Zero
e is Position Five

Python in Reverse Reading
R is Position -6
e is Position -1

Comparison Table




 πŸŽ― Mnemonic for Brackets

Think of the phrase:
“Quotes, Squares, Circles, Curly”

  • Quotes → Strings
    "Hello" → Characters are always spoken in quotes

  • Squares → Lists
    [1,2,3] → Lists are like boxes (square shelves) where items can be changed

  • Circles → Tuples
    (1,2,3) → Tuples are round plates — once served, you can’t change the food

  • Curly → Dictionaries
    {'key': 'value'} → Curly braces look like locks protecting key–value pairs

🧠 Quick Memory Trick

“Quotes talk, Squares store, Circles stay, Curly connect.”

  • Quotes talk → Strings are words/characters.
  • Squares store → Lists store items flexibly.
  • Circles stay → Tuples stay fixed.
  • Curly connect → Dictionaries connect keys to values.




Thursday, 8 January 2026

I PU Python 50 Marks Package

 

Chapter 1: Computer System

πŸ”Ή Data Transfer in Computer System

  • Data moves between CPU, primary memory, and secondary memory using buses.
  • Types of buses:
    • Data Bus: Transfers actual data (bi‑directional).
    • Address Bus: Transfers memory addresses (uni‑directional).
    • Control Bus: Transfers control signals (uni‑directional).
  • Memory Controller: Manages flow of data into/out of main memory.

πŸ”Ή Data vs Information

  • Data: Raw, unorganized facts (not sufficient for decision‑making).
  • Information: Organized, contextual, meaningful data (sufficient for decision‑making).

πŸ”Ή Types of Data

  • Structured Data: Organized in predefined format (tables, databases).
  • Unstructured Data: No fixed format (audio, video, text docs, social media posts).
  • Semi‑structured Data: Loosely organized with tags/markers (XML, JSON, CSV, emails).

πŸ”Ή Data Handling

  • Data Capturing: Gathering data from sources (keyboard, sensors, social media).
  • Data Storage: Saving data in files/databases; requires large servers in organizations.
  • Data Retrieval: Fetching stored data for processing; speed is crucial.
  • Data Deletion & Recovery: Deleted data can sometimes be recovered if not overwritten.

πŸ”Ή Microprocessors

  • Definition: CPU implemented on a single chip.
  • Built on integrated circuits with millions of transistors.
  • Can process millions of instructions per millisecond.
  • Generations:
    • 1st (1971–73): 4/8 bit, Intel 8080.
    • 2nd (1974–78): 8 bit, Intel 8085.
    • 3rd (1979–80): 16 bit, Intel 8086.
    • 4th (1981–95): 32 bit, Intel 80386.
    • 5th (1995–present): 64 bit, multicore (Pentium, Xeon).

Specifications:

  • Word Size: Bits processed at a time (8, 16, 32, 64).
  • Memory Size: Max memory supported (up to exabytes today).
  • Clock Speed: Pulses per second (Hz → GHz).
  • Cores: Units inside CPU (dual‑core, quad‑core, octa‑core).

πŸ”Ή Microcontrollers

  • Definition: Small computing device with CPU, RAM, ROM, I/O ports on one chip.
  • Used for specific tasks (washing machines, remotes, microwaves).
  • Automates repetitive tasks without human intervention.

πŸ”Ή Programming Tools

  • Low‑level language: Machine language (0s and 1s), Assembly language.
  • High‑level language: Human‑readable (Python, C, C++).
  • Language Translators:
    • Compiler: Converts whole program at once.
    • Interpreter: Converts line by line.
    • Assembler: Converts assembly language to machine code.
  • Program Development Tools:
    • Text Editor: Write source code.
    • IDE: Integrated environment with editor, compiler, debugger.

πŸ”Ή Software

  • Definition: Set of instructions that operate hardware.
  • Types:
    • System Software: OS, device drivers, utilities.
    • Programming Tools: Compilers, interpreters, IDEs.
    • Application Software: General purpose (MS Word, Photoshop) or customized (school ERP).
  • Software Usage Types:
    • Freeware, Open Source, Proprietary, Shareware.

πŸ”Ή Operating System Interfaces

  • Command‑based: Text commands (MS‑DOS, Unix).
  • GUI: Icons, menus (Windows, Mac).
  • Touch‑based: Smartphones, tablets.
  • Voice‑based: Siri, Cortana.
  • Gesture‑based: Gaming, medical devices.

πŸ”Ή Functions of Operating System

  • Process Management: Handles multiple tasks.
  • Memory Management: Allocates/frees memory.
  • File Management: Creates, updates, deletes files.
  • Device Management: Controls I/O devices via drivers.

πŸ“– Key Definitions (Exam‑Ready)

  • Computer System: Electronic device that processes data into information.
  • Data Bus: Bi‑directional bus carrying data between CPU and memory.
  • Address Bus: Uni‑directional bus carrying memory addresses.
  • Control Bus: Uni‑directional bus carrying control signals.
  • Data: Raw, unorganized facts.
  • Information: Organized, meaningful data.
  • Structured Data: Data stored in predefined format (tables).
  • Unstructured Data: Data without fixed format (audio, video, text).
  • Semi‑structured Data: Data with loose structure and tags (XML, JSON).
  • Microprocessor: CPU on a single chip performing arithmetic, logic, and control.
  • Microcontroller: CPU + memory + I/O on one chip for specific tasks.
  • Compiler: Translates entire program into machine code.
  • Interpreter: Translates one line at a time.
  • Assembler: Converts assembly language into machine code.
  • System Software: Software managing hardware (OS, drivers).
  • Application Software: Software for user tasks (Word, Photoshop).
  • Operating System (OS): Main system software managing hardware, memory, files, and processes.

  

Chapter 4: Introduction to Problem Solving

πŸ”Ή Problem Solving Process

  • Analyzing the problem: Identify inputs, outputs, and core functionalities.
  • Developing an algorithm: Write step‑by‑step instructions in natural language.
  • Coding: Convert algorithm into program using high‑level language.
  • Testing & Debugging: Ensure correctness through unit, integration, system, and acceptance testing.

πŸ”Ή Algorithm

  • Definition: A finite sequence of precise steps to solve a problem and produce output.
  • Characteristics:
    • Precision – steps clearly defined.
    • Uniqueness – each step has a unique result.
    • Finiteness – must stop after finite steps.
    • Input – accepts data.
    • Output – produces result.

πŸ”Ή Representation of Algorithms

  • Flowchart: Visual diagram using symbols (terminator, process, decision, input/output, arrows).
  • Pseudocode: Human‑readable, non‑formal description using keywords (INPUT, COMPUTE, PRINT, IF/ELSE, WHILE).

πŸ”Ή Flow of Control

  • Sequence: Steps executed one after another.
  • Selection: Conditional branching (if‑else).
  • Repetition: Loops/iteration (while, for).

πŸ”Ή Verification of Algorithms

  • Dry Run: Simulate algorithm with sample inputs to check correctness.
  • Helps identify missing details or incorrect steps.

πŸ”Ή Comparison of Algorithms

  • Time Complexity: Processing time required.
  • Space Complexity: Memory required.
  • Efficient algorithms minimize both.

πŸ”Ή Coding

  • Writing algorithm in programming language (Python, C, C++).
  • Source code translated into machine code using compiler/interpreter.
  • Syntax rules must be followed.

πŸ”Ή Decomposition

  • Breaking complex problems into smaller sub‑problems.
  • Each sub‑problem solved separately, then integrated.
  • Saves time and effort, allows teamwork.

πŸ“– Key Definitions (Exam‑Friendly)

  • Problem Solving: Identifying a problem, designing an algorithm, coding, and testing/debugging.
  • Algorithm: Finite sequence of precise steps to achieve desired output.
  • Flowchart: Diagrammatic representation of algorithm using symbols and arrows.
  • Pseudocode: Human‑readable representation of algorithm, not executable by computer.
  • Sequence: Execution of steps one after another.
  • Selection: Conditional branching (if‑else).
  • Repetition: Looping through steps until condition is met.
  • Dry Run: Manual simulation of algorithm with sample inputs to verify correctness.
  • Time Complexity: Measure of time taken by an algorithm.
  • Space Complexity: Measure of memory used by an algorithm.
  • Decomposition: Breaking a complex problem into smaller manageable sub‑problems.


πŸ”Ή Flowchart Symbols

Symbol

Name

Function

Oval

Start/End (Terminator)

Indicates beginning or end of algorithm.

Rectangle

Process (Action)

Represents a step or computation.

Diamond

Decision

Represents a condition check (Yes/No, True/False).

Parallelogram

Input/Output

Represents data input or output.

Arrow

Connector

Shows direction/flow of control.


πŸ”Ή Pseudocode Keywords

  • INPUT → Accept data from user.
  • OUTPUT / PRINT → Display result.
  • COMPUTE → Perform calculation.
  • IF / ELSE → Conditional branching.
  • WHILE / FOR → Looping (repetition).
  • TRUE / FALSE → Boolean values for decisions.
  • INCREMENT / DECREMENT → Increase or decrease variable value.

  • Always start and end flowcharts with oval symbols.
  • Use decision diamonds for conditions (odd/even, age categories).
  • Pseudocode is not executable, but must be clear and logical.
  • Keep pseudocode indented and structured for readability.

 

Part A – Match the Pseudocode with Flowchart Symbols

  1. INPUT num → ?
  2. COMPUTE sum = num1 + num2 → ?
  3. IF num MOD 2 == 0 THEN → ?
  4. PRINT result → ?
  5. Start / End → ?

Part B – Fill in the Blanks

  • The diamond symbol in a flowchart is used for __________.
  • The rectangle symbol represents __________.
  • The parallelogram symbol is used for __________.
  • The oval symbol indicates __________.
  • The arrow symbol shows __________.

✅ Answer Key

Part A
1 → Parallelogram (Input/Output)
2 → Rectangle (Process)
3 → Diamond (Decision)
4 → Parallelogram (Input/Output)
5 → Oval (Terminator)

Part B

  • Decision
  • Process/Action
  • Input or Output
  • Start/End
  • Flow direction

Sample 2/3/5 Answers

πŸ”Ή 2 Marks Questions

  1. Algorithm: A finite sequence of precise steps to solve a problem.
    • Characteristics: Precision, Finiteness. (1+1 marks)
  2. Flowchart vs Pseudocode:
    • Flowchart: Visual diagram using symbols.
    • Pseudocode: Human‑readable text description. (1+1 marks)
  3. Dry Run: Manual simulation of algorithm with sample inputs to verify correctness.
    • Importance: Detects errors/missing steps before coding. (1+1 marks)
  4. Pseudocode for square of a number:
    • INPUT num
    • COMPUTE square = num * num
    • PRINT square

5.       

    • Time: Processing time taken by algorithm.
    • Space: Memory used by algorithm. (1+1 marks)

πŸ”Ή 3 Marks Questions

  1. Steps in problem solving:
    • Analyze problem (inputs/outputs).
    • Develop algorithm.
    • Code in programming language. (1+1+1 marks)
  2. Flowchart for odd/even check:
    • Input number → Decision (num mod 2 == 0?) → Print “Even” / “Odd”. (Diagram + explanation = 3 marks)
  3. Pseudocode for rectangle area & perimeter:

INPUT length, breadth

COMPUTE Area = length * breadth

PRINT Area

COMPUTE Perim = 2 * (length + breadth)

PRINT Perim

  1. Flow of control types:
    • Sequence: Steps executed one after another.
    • Selection: Conditional branching (if‑else).
    • Repetition: Looping until condition met. (1+1+1 marks)
  2. Decomposition: Breaking complex problem into smaller sub‑problems.
    • Example: Railway reservation system (train info, booking, billing). (2+1 marks)

πŸ”Ή 5 Marks Questions

  1. Algorithm & Flowchart for average of 5 numbers:
    • Initialize count=0, sum=0.
    • Loop 5 times: Input number, add to sum, increment count.
    • Compute average = sum/5.
    • Print average. (Steps + diagram = 5 marks)
  2. Types of software testing:
    • Unit testing: individual components.
    • Integration testing: combined modules.
    • System testing: whole system.
    • Acceptance testing: user requirements. (1+1+1+2 marks)
  3. Flowchart vs Pseudocode comparison:
    • Flowchart: Visual, easy for non‑programmers, shows flow clearly.
    • Pseudocode: Textual, easier to modify, closer to coding.
    • Both useful; pseudocode better for programmers, flowchart better for non‑programmers. (5 marks)
  4. Age categorization pseudocode:

INPUT Age

IF Age < 13 THEN PRINT "Child"

ELSE IF Age < 20 THEN PRINT "Teenager"

ELSE PRINT "Adult"

  1. Dry run example:
    • Algorithm to add times (hours + minutes).
    • Input T1=4h50m, T2=2h20m → initial result 6h70m (incorrect).
    • Correction: If minutes ≥ 60, add 1 hour and subtract 60 from minutes.
    • Verified result = 7h10m. (Explanation + correction = 5 marks)

  

I PU Lab Exercise with Simpler Solutions

1)Write a program to swap two numbers using a third variable.

Solution

a = int(input( ))

b = int(input())

temp = a 

a = b 

b = temp

print("  After swapping  "  ,   a,b)

Inputs to be entered during execution 

3

2

Output

After swapping: 2  3

2) Write a program to enter two integers and perform all arithmetic operations on them.

Solution

a = int(input( ))

b = int(input( ))

print(a + b, a - b, a * b, a / b, a % b, a // b, a ** b)

Inputs to be entered during execution

3

2

Output:

5 1 6 1.5 1 1 9

3. Write a Python program to accept length and width of a rectangle and compute its perimeter and area.

Solution

length = float(input( ))

width = float(input( ))

perimeter = 2 * (length + width)

area = length * width

print(" Perimeter ", perimeter , " Area ", area)

Inputs to be entered during execution

3

2

Output:

Perimeter  10.0  Area  6.0

4. Write a Python program to calculate the amount payable if money has been lent on simple interest. Principal or money lent = P, Rate of interest = R% per annum and Time = T years. Then Simple Interest (SI) = (P x R x T)/ 100. Amount payable = Principal + SI. P, R and T are given as input to the program

Solution

P = float(input( ))

R = float(input( ))

T = float(input( ))

print(" Simple Interest  ", (P * R * T) / 100 , " Amount Payable  " , P + (P * R * T) / 100)

Inputs to be entered during execution

1000 

10

1

Output

Simple Interest: 100.0 Amount Payable: 1100.0

5. Write a Python program to find the largest among three numbers.

Solution

a = float(input( ))

b = float(input( ))

c = float(input(  ))

if a >= b and a >= c:

    largest = a

elif b >= a and b >= c:

    largest = b

else:

    largest = c

print("The largest number is:", largest)

Inputs to be entered during execution

3

2

1

Output:

The largest number is: 3.0

6.Write a program that takes the name and age of the user as input and displays a message whether the user is eligible to apply for a driving license or not. (the eligible age is 18 years).

Solution

name = input( )

age = int(input( ) )

if age >= 18:

    print(name , " Eligible to apply for a driving license. " )

else:

    print(name , " Not eligible to apply for a driving license. " )


Inputs to be entered during execution

•  Name = "A"

•  Age = 18

Output:

A , you are eligible to apply for a driving license.

Inputs to be entered during execution

•  Name = "B"

•  Age = 17

Output:

B , you are not eligible to apply for a driving license.

7. Write a program that prints minimum and maximum of five numbers entered by the user.

Solution

minimum = None

maximum = None

for i in range(5):

    num = float(input(  ))

    if minimum is None or num < minimum:

        minimum = num

    if maximum is None or num > maximum:

        maximum = num

print(" Minimum  " , minimum)

print(" Maximum  " , maximum)

Inputs to be entered during execution

5

4

3

2

1

Output:

Minimum: 1.0

Maximum: 5.0

8. Write a program to find the grade of a student when grades are allocated as given in the table below. Percentage of Marks Grade Above 90% A,80% to 90% B,70% to 80% C, 60% to 70% D Below 60% E Percentage of the marks obtained by the student is input to the program.

Solution

percentage = float(input(  ))

if percentage > 90:

    grade = "A"

elif percentage >= 80:

    grade = "B"

elif percentage >= 70:

    grade = "C"

elif percentage >= 60:

    grade = "D"

else:

    grade = "E"

print( " Grade  " , grade)

Inputs to be entered during execution

Enter the percentage of marks: 95

Output:

Grade: A

Inputs to be entered during execution

Enter the percentage of marks: 50

Output:

Grade: E

9. Write a function to print the table of a given number. The number has to be entered by the user. 

Solution

def table(n):

    for i in range(1, 11):

        print(n, "x", i, "=", n*i)


num = int(input( ) )

table(num)

Inputs to be entered during execution

num = 3

Output:

3 x 1 = 3

3 x 2 = 6

3 x 3 = 9

3 x 4 = 12

3 x 5 = 15

3 x 6 = 18

3 x 7 = 21

3 x 8 = 24

3 x 9 = 27

3 x 10 = 30

10.Write a program to find the sum of digits of an integer number, input by the user. 

Solution

num = int(input(  ) )

s = 0

while num > 0:

    s = s + num % 10

    num = num // 10

print(s)

Inputs to be entered during execution

num = 121

Output:

3

11.Write a program to check whether an input number is a palindrome or not. 

Solution

num = input(  )

if num == num[::-1]:

    print("Palindrome")

else:

    print("Not Palindrome")

Inputs to be entered during execution

121

Output:

Palindrome

Inputs to be entered during execution

123

Output:

Not Palindrome

12.Write a program to print the following patterns: 

1 2 3 4 5 

1 2 3 4 

1 2 3 

1 2 

1

Solution

for i in range(5, 0, -1):

    for j in range(1, i+1):

        print(j, end=" ")

    print( )

Inputs to be entered during execution

5 is the input value which is mentioned in the program already.

Output:

Output pattern will be printed as given in the question.

13. Write a program that uses a user defined function that accepts name and gender (as M for Male, F for Female) and prefixes Mr/Ms on the basis of the gender. 

Solution

def prefix(name, gender):

    if gender == 'M':

        print("Mr", name)

    elif gender == 'F':

        print("Ms", name)

n = input( "Enter name: ")

g = input("Enter gender (M/F): ")

prefix(n, g)

Inputs to be entered during execution

Enter name: ABC

Enter gender (M/F): M

Output

Mr ABC

Inputs to be entered during execution

Enter name: XYZ

Enter gender (M/F): F

Output

Mr XYZ

14.Write a program that has a user defined function to accept the coefficients of a quadratic equation in variables and calculates its determinant. For example : if the coefficients are stored in the variables a,b,c then calculate determinant as b2-4ac. Write the appropriate condition to check determinants on positive, zero and negative and output appropriate result.

Solution

def determinant(a, b, c):

    d = b**2 - 4*a*c

    if d > 0:

        print("Positive determinant")

    elif d == 0:

        print("Zero determinant")

    else:

        print("Negative determinant")

a = int(input("Enter a: "))

b = int(input("Enter b: "))

c = int(input("Enter c: "))

determinant(a, b, c) 

Inputs to be entered during execution

Enter a: 1

Enter b: 2

Enter c: 1

Calculation: d=b^2-4ac=2^2-4(1)(1)=4-4=0

Output

Zero determinant

Inputs to be entered during execution

Enter a: 1

Enter b: 3

Enter c: 1

Calculation: d=3^2-4(1)(1)=9-4=5

Output

Positive determinant

15.Write a program that has a user defined function to accept 2 numbers as parameters, if number 1 is less than number 2 then numbers are swapped and returned, i.e., number 2 is returned in place of number1 and number 1 is reformed in place of number 2, otherwise the same order is returned. 

Solution

def swap(x, y):

    if x < y:

        x, y = y, x

    return x, y

a = int(input("Enter first number: "))

b = int(input("Enter second number: "))

a, b = swap(a, b)

print(a, b)

Inputs to be entered during execution

Enter first number: 2

Enter second number: 5

Since 2 < 5, they are swapped.

Output

5 2

Inputs to be entered during execution

Enter first number: 5

Enter second number: 2

Since 5 > 2 , they are not swapped.

Output

5 2


🎀 Viva Voce Quick Reference Guide

πŸ”Ή Basics

Q: Why is indentation important in Python? 

A: Indentation defines code blocks. Without proper indentation, Python raises errors because it cannot group statements correctly.

Q: What is the difference between = and ==? 

A: = is the assignment operator (stores a value in a variable). == is the comparison operator (checks equality between two values).

Q: What is the role of input() and print()? 

A: input() takes user input as a string. print() displays output to the screen.

________________________________________

πŸ”Ή Control Structures

Q: What is the difference between if, if else, and if elif else? 

A:

if: executes block only if condition is true.

if else: executes one block if true, another if false.

if elif else: checks multiple conditions sequentially.

Q: What is the difference between for and while loops? 

A:

for: used when the number of iterations is known in advance.

while: used when iterations depend on a condition being true.

Q: What does the break statement do? 

A: It immediately exits the loop, skipping all remaining iterations.

Q: What does the continue statement do? 

A: It skips the current iteration and continues with the next one.

________________________________________

πŸ”Ή Functions

Q: Why do we use functions in Python? 

A: Functions make code reusable, organized, and easier to debug.

Q: What is the difference between a function definition and a function call? 

A:

Definition: writing the function logic (def myfunc():).

Call: executing the function (myfunc()).

________________________________________

πŸ”Ή Data Types & Operators

Q: Name Python’s basic data types. 

A: int, float, str, bool.

Q: What is the difference between / and //? 

A: / gives float division, // gives integer (floor) division.

________________________________________

πŸ”Ή Common Programs

Q: How do you check if a number is a palindrome? 

A: Convert to string and compare with its reverse (num == num[::-1]).

Q: How do you find the largest among three numbers? 

A: Use nested if or if elif else to compare values.

________________________________________