0% found this document useful (0 votes)
2 views12 pages

Course Module

The document outlines key concepts in Python programming, including control flow statements, data structures, functions, modules, and file handling. It provides examples and learning outcomes for each module, emphasizing the importance of these concepts in building interactive applications and managing data. Additionally, it lists textbooks and maps course outcomes to program outcomes.

Uploaded by

Santhi Sri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views12 pages

Course Module

The document outlines key concepts in Python programming, including control flow statements, data structures, functions, modules, and file handling. It provides examples and learning outcomes for each module, emphasizing the importance of these concepts in building interactive applications and managing data. Additionally, it lists textbooks and maps course outcomes to program outcomes.

Uploaded by

Santhi Sri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Department of Computer Applications

Module 1: Control Flow Statements

Control flow statements are used to make decisions and repeat tasks based on
conditions. They help the program flow dynamically rather than linearly.

These are essential to solve logical problems and build interactive applications.

Control flow statements dictate the order of execution in a Python program. Key
constructs include:

• if, if-else, if-elif-else: Conditional execution based on Boolean


expressions.

• while Loop: Repeats a block of code as long as a condition is true.

• for Loop: Iterates over a sequence (e.g., list, range).

• break and continue: Alters loop execution (break exits, continue skips to
the next iteration).
Department of Computer Applications
Department of Computer Applications

Example for nested if

marks = int(input("Enter your marks (0-100): "))

if marks >= 90:

grade = "A"

elif marks >= 80:

grade = "B"

elif marks >= 70:

grade = "C"

elif marks >= 60:

grade = "D"

else:

grade = "F"

print(f"Your grade is: {grade}")

Example for While Loop

count = 5

while count > 0:

print(count)

count -= 1 # Decrement count by 1


Department of Computer Applications

Statement Use Example Effect


if Single condition check if x > 0: Runs block if condition is true
if x > 0: ... else:
if-else Two-way decision Runs one of two blocks
...
if-elif-else Multiple conditions if... elif... else: Runs first true block
for Loop over a sequence for i in range(5): Repeats block fixed times
while Loop with a condition while x < 5: Repeats while condition is true
break Exit the loop early if x == 3: break Stops the loop immediately
Skip current loop if x == 2: Skips rest and goes to next
continue
iteration continue loop
Do nothing No action, used to keep
pass if x > 0: pass
(placeholder) structure

Learning Outcome:

Students will understand how to control the logic of the program, implement
conditions and loops, and solve decision-based problems.
Department of Computer Applications

Module 2 : Data Structures

Python provides four fundamental built-in data structures: lists, tuples, sets,
and dictionaries. Each has unique characteristics and is suited for different
purposes.

• List: Ordered, mutable collection ([1, 2, 3]).

• Tuple: Ordered, immutable collection ((1, 2, 3)).

• Set: Unordered, mutable collection of unique elements ({1, 2, 3}).

• Dictionary: Key-value pairs ({"name": "Ram", "age": 22}).


Department of Computer Applications
Example

Structure Type Properties Access Example Output


my_list List Ordered, Mutable my_list[1] 2
my_tuple Tuple Ordered, Immutable my_tuple[0] 1
Unordered, No
my_set Set my_set after add(3) {1, 2, 3}
Duplicates, Mutable
Key-Value, Unordered,
my_dict Dictionary my_dict["name"] Ram
Mutable

Learning Outcome:

Students will understand how to store, access, and manage data using Python’s
built-in data structures such as lists, tuples, sets, and dictionaries, and apply the
appropriate structure based on the nature of the problem.
Department of Computer Applications

Module 3 : Functions and Modules

Functions allow us to group a set of instructions into a single block which


can be reused. Python also supports modules to organize code into multiple files
for better readability and structure.

Key Concepts:

• Function: A reusable block of code defined using the def keyword.


• Arguments: Values passed to the function.
• Return: Sends a result back to the caller.
• Module: A file containing Python definitions and functions, which can be
imported using import.
Department of Computer Applications

Examples for Function

def greet(name): # Function definition

print(f"Hello, {name}!")

greet("Siva") # Function call

Output:

Hello, Siva!

Examples for Module

File: math_operations.py

def add(a, b):

return a + b

def subtract(a, b):

return a - b

Importing a Module

import math_operations

sum_result = math_operations.add(5, 3)

diff_result = math_operations.subtract(5,
3)

print(sum_result)

print(diff_result)
Department of Computer Applications

Concept Purpose Syntax / Example Key Point


def Define a function def greet(): Creates a reusable block of code
Function call Run the function greet() Executes the function
Input values to the
Parameters def add(a, b): Accepts input values
function
return Send output back return a + b Returns a value to the caller
Use ready-made
Built-in Modules import math Provides extra functionality
Python libraries
Create your own
Custom Module math_operations.py Organize your own functions
module (file)
Load a module into import Gives access to external
import
your script math_operations functions
Import specific
Access specific items without full
from-import functions from a from math import sqrt
module
module
Use function from Syntax:
Module function call math.sqrt(25)
imported module module_name.function_name()

Learning Outcome:

Students will understand how to define and use functions to avoid repetitive
code, and how to organize large programs using modules and libraries. This
helps in building clean, readable, and modular Python programs.
Department of Computer Applications

Module 4: File Handling in Python

Python provides built-in functions to create, read, write, and update files.
File handling is essential for storing data permanently and interacting with text,
binary, and CSV files.

Mode Description

'r' Read mode (default) – Opens file for reading only

'w' Write mode – Creates a new file or overwrites if it exists

'a' Append mode – Adds content to the end of the file

'b' Binary mode – Used for binary files (e.g., images, audio)

'x' Create mode – Creates a new file, raises error if it exists


Department of Computer Applications

Example

# Writing to a file

with open("data.txt", "w") as file:

file.write("Hello, Python!")

# Reading from a file

with open("data.txt", "r") as file:

content = file.read()

print(content)

Output: Hello, Python!

Concept Function / Syntax Purpose


Opens a file in specified mode (e.g.,
Open a file open("file.txt", "r")
read)
Write to a file file.write("text") Writes data to a file
Read from file file.read() Reads the entire content
Read line-by- file.readline() /
Reads one line / all lines into a list
line file.readlines()
Append to file open("file.txt", "a") Adds content to the end of the file
File modes 'r', 'w', 'a', 'b', 'x' Define the operation type
Context
with open(...) as file: Auto-closes file safely after operation
manager
Close file file.close() Manually closes the file
Department of Computer Applications
Learning Outcome:
Students will learn to read, write, and manage files in Python using appropriate
modes and safe handling techniques.

TEXT BOOKS:

1. Introduction to Programming Using Python, Y. Daniel Liang, Pearson.

2. Gowrishankar S, Veena A., Introduction to Python Programming, CRC Press.


3. Python Programming, S Sridhar, J Indumathi, V M Hariharan, 2ndEdition,
Pearson, 2024

Mapping with Programme Outcomes (POs)

Course Outcome (CO) Programme Outcome (PO) Mapping

CO1 PO1, PO2


CO2 PO1, PO4
CO3 PO1, PO3
CO4 PO2, PO4, PO6
CO5 PO3, PO7

You might also like