PROBLEM ANALYSIS CHART
1.1.1 Definition
A Problem Analysis Chart (PAC) is a tabular representation that breaks down a problem into its
fundamental components:
Input – The data required for the problem.
Process – The computational or logical steps needed to transform input into output.
Output – The expected result of the problem.
1.1.2 Components of Problem Analysis Chart (PAC)
Component Description Example
Problem Clearly defines what needs to be Find the area of a
Statement solved rectangle
Input Data values required from the user Length, Breadth
Operations or calculations Area = Length ×
Process
performed on input Breadth
Output Final result to be displayed Area of the rectangle
1.1.3 Steps to Construct a PAC
1. Identify the problem statement.
2. Determine all necessary inputs.
3. List the process steps needed to solve the problem.
4. Define the expected output.
5. Tabulate the above information into a PAC.
1.1.4 Example: PAC for Area of Rectangle
Proble
Find the Area of a Rectangle
m
Input Length, Breadth
Process Area = Length × Breadth
Output Area of the rectangle
1.1.5 Benefits of PAC
Provides clarity before coding.
Reduces logical errors by defining all inputs and outputs.
Acts as a bridge between problem statement and algorithm.
Helps beginners systematically approach programming problems.
1.1.6 Python Example Based on PAC
# Program to calculate area of rectangle using PAC
length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))
area = length * breadth
print("Area of rectangle:", area)
2. INTERACTIVE & SCRIPT MODE:
Python has two modes,
[Link] mode
2. Script mode
1. INTERACTIVE MODE:
In this mode, the user can type Python commands directly in the interpreter.
The prompt >>> indicates that the interpreter is ready for user input.
When an expression is typed after the prompt, the interpreter displays the result immediately.
Proper indentation is required while writing the code on the interpreter shell.
2. SCRIPT MODE:
Script mode is the standard mode.
In this mode, Python commands are saved in a file with the extension .py.
The saved file can then be executed repeatedly.
STEPS TO RUN PYTHON IN SCRIPT MODE:
Step 1: Open Python Shell by double-clicking the Python IDE.
Step 2: On the File Menu, click on New File option.
Step 3: Give some suitable file name with extension.
Step 4: A file will get opened and the type some programming code.
Step 5: Now run your code by clicking on Run Menu → Run Module (F5).
INDENTATION IN PYTHON
Indentation means the space at the beginning of a line of code.
In Python, indentation is mandatory and indicates a block of code.
Other programming languages like C/Java use curly braces { } to define blocks, but
Python indentation show the structure of the program.
The standard indentation is 4 spaces
EXAMPLE:
x = 10
if x > 5:
print("x is greater than 5")
print("This line is also inside the block")
print("This line is outside the block")
INDENTATION ERRORS:
If indentation is not used correctly, Python raises an indentation error.
Example: Error due to incorrect indentation
x = 10
if x > 5:
print("x is greater than 5") # ❌ IndentationError
Error Message:
IndentationError: expected an indented block
COMMENTS:
comments help programmers explain the logic, purpose, and functionality of code segments
without affecting execution.
Begin with the # symbol.
Python ignores comments during program execution.
Python provides two types of comments:
[Link]-Line Comments.
2. Multi-Line Comments
[Link]-Line Comments:
Example:
# This is a single-line comment
x = 10 # Assigning value 10 to variable x
print(x)
2. Multi-Line Comments:
Python does not have explicit multi-line comment syntax (like /* ... */ in C).
Instead, multi-line comments are created using triple quotes (''' ... ''' or """ ... """).
ERROR MESSAGES:
Errors occur when the Python interpreter fails to execute code correctly.
Python provides clear error messages that help identify the type and location of the problem.
Types of Errors:
1. Syntax Errors
2. Runtime Errors (Exceptions)
3. Logical Errors
1. Syntax Errors:
Syntax error occur Missing colon, wrong indentation
Eample:
if True
print("Hello") # Missing colon after if Error Message:
Error Message:
SyntaxError: expected ‘:’
2. Runtime Errors:
Occur while the program is running.
Example :
x = 10 / 0
Error Message:
ZeroDivisionError: division by zero
3. Logical Errors:
The program runs without crashing but produces incorrect results.
Hardest to detect since Python does not raise an error.
Example:
# Program to calculate average (wrong formula used)
marks = [80, 90, 70]
average = sum(marks) * len(marks) # Incorrect print("Average =", average)
VARIABLES AND RESERVED WORDS:
VARIABLE:
A variable is a name given to a memory location that holds a value.
Rules for Variable:
1. Must begin with a letter or underscore (_).
2. Cannot start with a digit.
3. Can contain letters, digits, and underscores.
4. Case-sensitive (Age and age are different).
5. Cannot use reserved keywords as variable names.
Variable Assignment
Python uses the = operator for assignment.
Multiple assignments are allowed in one line.
Examples:
x = 10 # Single assignment
a, b, c = 1, 2, 3 # Multiple assignment
y = z = 100 # Same value to multiple variables
RESERVED WORDS or KEYWORD:
Reserved words (or keywords) are predefined identifiers in Python with special meaning.
They are part of the Python language syntax and cannot be used as variable names.
List of Python Reserved Words (Python 3.10+)
DIFFERENCE BETWEEN VARIABLES AND RESERVED WORDS:
Aspect Variables Reserved Words
User-defined Predefined identifiers with special
Definition
names storing meaning
data
Flexibiliy Chosen by Fixed and cannot be changed
programmer
Example student, marks, count for, while, if, class
Store values, perform Define control flow, logic,
Usage
computations and structure
ARITHMETIC OPERATORS AND EXPRESSIONS
1. Addition (+)
The addition operator is used to add two operands and produce their sum.
Example: 5 + 3 = 8
2. Subtraction (-)
The subtraction operator calculates the difference between two operands.
Example: 10 - 4 = 6
3. Multiplication (*)
The multiplication operator returns the product of two operands.
Example: 7 * 3 = 21
4. Division (/)
The division operator divides the left operand by the right operand and returns a floating-
point result.
Example: 10 / 4 = 2.5
5. Floor Division (//)
The floor division operator divides two operands but discards the decimal part, returning the
largest integer less than or equal to the result.
Example: 10 // 4 = 2
6. Modulus (%)
The modulus operator returns the remainder of a division operation.
Example: 10 % 4 = 2
7. Exponentiation (**)
The exponentiation operator raises the first operand to the power of the second operand.
Example: 2 ** 3 = 8
Operator
Description Example Result
+ Addition 10 + 5 15
- Subtraction 10 - 5 5
* Multiplication 10 * 5 50
/ Division (float result) 10 / 3 3.333
// Floor Division 10 // 3 3
% Modulus (Remainder) 10 % 3 1
** Exponentiation (Power) 2 ** 3 8
Arithmetic Expressions:
An arithmetic expression is a combination of numbers, variables, and operators that produces a
numerical result.
Examples:
a = 10
b=3
expr1 = a + b # 13
expr2 = a – b # 7
expr3 = a * b + 2 # 32 expr4 = a / b # 3.333...
expr5 = a % b #1
expr6 = a ** b # 1000
Operator Precedence and Associativity
When multiple operators are used in a single expression, Python follows operator precedence rules.
Precedence Order (Highest to Lowest):
1. Parentheses ()
2. Exponentiation **
3. Multiplication, Division, Floor Division, Modulus *, /,
//, %
Addition, Subtraction +, -
Associativity:
Most operators are left-to-right associative (evaluated from left to right).
Exponentiation (**) is right-to-left associative.
Example:
result = 2 + 3 * 4 # 2 + (12) = 14
power = 2 ** 3 ** 2 # 2 ** (9) = 512
Applications of Arithmetic Operators
1. Engineering Calculations
2. Data Analysis
3. Control Systems processing.
4. Graphics and Game Development
5. Financial Applications
BUILT-IN FUNCTIONS:
Built-in functions that can be used directly without importing any external library.
Characteristics of Built-in Functions:
1. Available by default in Python (no need to import).
2. Can be used across different data types and applications.
3. Improve efficiency by reducing the need for manual implementation.
4. Often serve as building blocks for larger programs
Commonly Used Built-in Functions
Function Description Example Output
print() Displays output on the screen print("Hello") Hello
Reads user input as a string x = User
input()
input("Enter: ") input
Returns length of a
len() len("Python") 6
sequence
Displays the data type of a <class
type() type(10)
variable 'int'>
Converts a value to integer
int() int("5") 5
float() Converts a value to float float("3.2") 3.2
str() Converts a value to string str(25) "25"
Returns maximum value from a
max() max(4, 9, 2) 9
sequence
Returns minimum value from a
min() min(4, 9, 2) 2
sequence
abs() Returns absolute value abs(-7) 7
Rounds a number to nearest
round() integer or given decimals round(3.75, 1) 3.8
Returns sum of elements in a
sum() sum([1, 2, 3]) 6
sequence