PYTHON
UNIT – 2
CONTROL STRUCTURE
Unit Outcomes
● Understand control structures in Python
● Learn decision-making and loop control
● Understand break, continue and pass
What are Control Structures?
● Control structures regulate the order of execution
● Python supports:
- Sequential
- Selection
- Looping
Selection Statements
● if statement
● if…else statement
● if…elif…else statement
Looping
● while loop
● for loop
● Nested loop
Loop Control
● break
● continue
● pass
Range Function
● range(stop)
● range(start, stop)
● range(start, stop, step)
● Used mostly with loops
Input / Output
● input() → Accept input from user
● print() → Display result to user
Indentation
● Indentation defines block of code
● No use of braces like {}, instead spacing is used
● Must be consistent
Python Programs
● Example: Check even or odd
● Example: Find largest among three numbers
Python Programs
● Example: Print multiplication table
● Example: Display Fibonacci sequence
Python Programs
● Example: Prime number check
● Example: Factorial using loop
Control Flow
● Sequential
● Selection (Decision Making)
● Looping (Iteration)
Errors and Exception Handling
● Syntax Errors
● Logical Errors
● Runtime Errors
● Exception Handling using try...except
Building Blocks
● Expressions
● Statements
● Blocks
● Functions
File Handling
● open()
● read()
● write()
● close()
● Modes: r, w, a, b
Client-Server Programming
● Server listens for connection
● Client initiates connection
● Uses socket module
● send(), recv() for communication
Virtualization
● Running multiple OS instances
● Uses software like VirtualBox, VMware
● Improves flexibility & isolation
Thank You
Thank You :)
?