MASENO UNIVERSITY
SCHOOL OF PUBLIC HEALTH AND COMMUNITY DEVELOPMENT (S P H C D)
DEPARTMENT OF PUBLIC HEALTH
HEALTH RECORDS AND INFORMATION MANAGEMENT PROGRAM
Python Programming Teaching Manual for Students
Prepared for Computer and Health Records and Information
Management Students
Table of Contents
1. Introduction to Python Programming
2. Learning Objectives
3. Requirements for the Computer Laboratory
4. Installing Python
5. Introduction to Python Environment
6. Writing Your First Python Program
7. Python Syntax and Rules
8. Variables and Data Types
9. Operators in Python
10. Input and Output Statements
11. Conditional Statements
12. Loops in Python
13. Functions in Python
14. Lists, Tuples, Sets, and Dictionaries
15. String Manipulation
16. File Handling in Python
17. Exception Handling
18. Introduction to Object-Oriented Programming
19. Python Modules and Libraries
20. Practical Laboratory Exercises
21. Mini Projects
22. Assessment Activities
23. Laboratory Rules and Best Practices
24. Revision Questions
25. References
1|Page
1. Introduction to Python Programming
What is Python?
Python is a high-level, interpreted, and easy-to-learn programming language widely
used in:
Software development
Data analysis
Artificial intelligence
Web development
Health informatics
Automation
Cybersecurity
Python is popular because of its:
Simple syntax
Readability
Large community support
Powerful libraries
Cross-platform compatibility
Importance of Learning Python
Python helps students to:
Develop programming skills
Solve real-world problems
Automate repetitive tasks
Analyze data
Build applications
Prepare for careers in technology and health informatics
2. Learning Objectives
At the end of this training, students should be able to: 1. Explain basic programming
concepts. 2. Install and configure Python. 3. Write and execute Python programs. 4.
Use variables and data types. 5. Apply operators and expressions. 6. Use decision-
making statements. 7. Implement loops and functions. 8. Work with files and
exceptions. 9. Develop simple Python applications. 10. Demonstrate programming
competency in the computer laboratory.
2|Page
3. Requirements for the Computer Laboratory
Hardware Requirements
Students should have access to:
Desktop or laptop computers
Reliable power supply
Internet connection
Projector for demonstrations
Software Requirements
Required software includes:
Python Interpreter
Python IDE (IDLE, VS Code, PyCharm, or Jupyter Notebook)
Web browser
Recommended Python Version
Python 3.x is recommended.
4. Installing Python
Steps for Installing Python
Windows
1. Visit the official Python website.
2. Download Python 3.x installer.
3. Run the installer.
4. Select “Add Python to PATH.”
5. Complete installation.
Linux
Use terminal commands:
sudo apt update
sudo apt install python3
MacOS
1. Download Python from the official website.
2. Install using the package installer.
3|Page
Verifying Installation
Open terminal or command prompt and type:
python --version
or
python3 --version
5. Introduction to Python Environment
Python IDLE
Python IDLE is the default Python Integrated Development Environment.
Features of IDLE
Code editor
Python shell
Syntax highlighting
Easy execution of programs
Opening Python IDLE
1. Click Start Menu.
2. Search for Python IDLE.
3. Open the application.
Running Python Programs
Programs can be executed:
In the interactive shell
Using script files
6. Writing Your First Python Program
Example Program
print("Hello World")
Explanation
print() displays output on the screen.
Text inside quotation marks is called a string.
4|Page
Practical Exercise
Write a program that prints:
Your name
Course
Registration number
7. Python Syntax and Rules
Basic Rules
Python is case-sensitive.
Indentation is important.
Statements end automatically at new lines.
Comments begin with #.
Example
# This is a comment
print("Python Programming")
Naming Rules
Variable names:
Must start with a letter or underscore
Cannot contain spaces
Should be meaningful
8. Variables and Data Types
Variables
Variables store data.
Example
name = "John"
age = 20
Data Types
Common data types include:
Integer (int)
Float (float)
5|Page
String (str)
Boolean (bool)
Example
x = 10
price = 50.5
student = "Mary"
is_active = True
Practical Exercise
Create variables for:
Student name
Age
Course
Fee balance
9. Operators in Python
Arithmetic Operators
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
** Power
Example
x = 10
y = 5
print(x + y)
Comparison Operators
Operator Meaning
== Equal to
!= Not equal to
> Greater than
< Less than
6|Page
Logical Operators
and
or
not
10. Input and Output Statements
User Input
name = input("Enter your name: ")
print(name)
Converting Input
age = int(input("Enter age: "))
Practical Exercise
Write a program that: 1. Accepts student marks. 2. Calculates total marks. 3. Displays
results.
11. Conditional Statements
if Statement
age = 18
if age >= 18:
print("Adult")
if…else Statement
marks = 40
if marks >= 50:
print("Pass")
else:
print("Fail")
if…elif…else Statement
score = 75
if score >= 80:
print("A")
elif score >= 70:
print("B")
else:
print("C")
7|Page
Practical Exercise
Develop a grading system.
12. Loops in Python
for Loop
for i in range(5):
print(i)
while Loop
count = 1
while count <= 5:
print(count)
count += 1
break Statement
for i in range(10):
if i == 5:
break
continue Statement
for i in range(5):
if i == 2:
continue
print(i)
Practical Exercise
Write a program to display numbers from 1–100.
13. Functions in Python
Definition
Functions are reusable blocks of code.
Example
def greet():
print("Welcome")
greet()
8|Page
Function with Parameters
def add(x, y):
return x + y
print(add(5, 3))
Advantages of Functions
Reusability
Easier debugging
Better organization
Practical Exercise
Create a function to calculate area of a rectangle.
14. Lists, Tuples, Sets, and Dictionaries
Lists
students = ["John", "Mary", "James"]
print(students)
Tuples
numbers = (1, 2, 3)
Sets
items = {1, 2, 3}
Dictionaries
student = {
"name": "John",
"age": 20
}
Practical Exercise
Store student records using dictionaries.
15. String Manipulation
String Operations
name = "Python"
print([Link]())
9|Page
print([Link]())
print(len(name))
Concatenation
first = "John"
last = "Doe"
print(first + " " + last)
Practical Exercise
Create a program to format student names.
16. File Handling in Python
Opening Files
file = open("[Link]", "r")
Reading Files
content = [Link]()
print(content)
Writing Files
file = open("[Link]", "w")
[Link]("Python Programming")
Closing Files
[Link]()
Practical Exercise
Create a file to store student records.
17. Exception Handling
Definition
Exceptions are runtime errors.
Example
try:
x = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero")
10 | P a g e
Importance
Prevents program crashes
Improves reliability
Practical Exercise
Handle invalid user input.
18. Introduction to Object-Oriented Programming
Classes and Objects
class Student:
def __init__(self, name):
[Link] = name
student1 = Student("John")
print([Link])
Concepts of OOP
Class
Object
Encapsulation
Inheritance
Polymorphism
Practical Exercise
Create a Student class.
19. Python Modules and Libraries
Importing Modules
import math
print([Link](25))
Common Libraries
math
random
datetime
pandas
numpy
11 | P a g e
Practical Exercise
Generate random numbers using Python.
0. Practical Laboratory Exercises
Exercise 1
Write a program that:
Accepts two numbers
Adds them
Displays the result
Exercise 2
Develop a student grading system.
Exercise 3
Create a simple calculator.
Exercise 4
Develop a program to store student records.
Exercise 5
Create a menu-driven application.
21. Mini Projects
Project 1: Student Management System
Features:
Add students
Display records
Search students
Project 2: Hospital Billing System
Features:
Enter patient details
Calculate bill
Display receipt
12 | P a g e
Project 3: Attendance Register
Features:
Mark attendance
Save records
Generate summary
22. Assessment Activities
Continuous Assessment
Students will be assessed through:
Practical exercises
Quizzes
Assignments
Group work
Practical Examination
Students may be required to:
Write programs
Debug errors
Demonstrate coding skills
Explain program logic
23. Laboratory Rules and Best Practices
Computer Laboratory Rules
Students should:
Arrive on time.
Avoid food and drinks in the lab.
Handle equipment carefully.
Save work regularly.
Follow instructor guidance.
Programming Best Practices
Use meaningful variable names.
Comment code appropriately.
Test programs regularly.
13 | P a g e
Maintain proper indentation.
Debug systematically.
24. Revision Questions
1. Define Python programming.
2. Explain advantages of Python.
3. Differentiate variables and constants.
4. Explain data types in Python.
5. Describe conditional statements.
6. Differentiate for loop and while loop.
7. Explain functions in Python.
8. Define object-oriented programming.
9. Explain exception handling.
10. Discuss importance of Python in health informatics.
25. References
1. Python Official Documentation.
2. Introduction to Python Programming Textbooks.
3. W3Schools Python Tutorials.
4. Real Python Learning Resources.
5. Open-source Python Learning Materials.
Appendix A: Sample Practical Timetable
Week Topic Practical Activity
1 Introduction to Python Installation and setup
2 Variables and Data Types Simple programs
3 Operators and Input Calculations
4 Conditional Statements Grading system
5 Loops Number generation
6 Functions Function development
7 Data Structures Student records
8 File Handling File storage
9 Exception Handling Error management
10 Mini Projects Project presentation
14 | P a g e
Appendix B: Instructor Notes
Teaching Methods
Recommended teaching methods include:
Demonstrations
Hands-on coding practice
Pair programming
Group discussions
Project-based learning
Suggested Evaluation Criteria
Assess students based on:
Program accuracy
Coding style
Problem-solving ability
Practical skills
Participation
Conclusion
Python programming provides students with essential digital and problem-solving skills
applicable in many fields including health informatics, data analysis, and software
development.
Through regular practical sessions in the computer laboratory, students will develop
confidence in writing programs, debugging errors, and developing simple applications
using Python.
15 | P a g e