Python Programming Practices

Table of Contents

Exercise 9.1: Sum of Two Numbers

Description : Write a program that takes two numbers as input from the user and calculates their sum.
Syllabus Coverage : Problem-solving process (understanding the problem, defining inputs and outputs, implementation).
Aim : Introduce students to basic input/output operations and simple arithmetic computations in Python.

Exercise 9.2: Largest of Three Numbers

Description : Write a program that takes three numbers as input and determines the largest among them.
Syllabus Coverage : Control structures (selection using if-elif-else).
Aim : Teach students how to use conditional statements to solve decision-making problems.

Exercise 9.3: Factorial of a Number

Description : Write a program that calculates the factorial of a given number using a loop.
Syllabus Coverage : Control structures (repetition using for or while loops).
Aim : Introduce students to iterative programming and mathematical computations.

Exercise 9.4: Multiplication Table

Description : Write a program that generates the multiplication table of a given number up to 10.
Syllabus Coverage : Repetition control structure (for loop).
Aim : Reinforce the concept of loops and formatting output.

Exercise 9.5: Check if a Number is Prime

Description : Write a program that checks whether a given number is prime or not.
Syllabus Coverage : Nested control structures (loops and conditionals).
Aim : Teach students how to combine loops and conditionals to solve complex problems.

Exercise 9.6: Simple Calculator

Description : Write a program that acts as a simple calculator. The user should input two numbers and an operator (+, -, *, /), and the program should perform the corresponding operation.
Syllabus Coverage : Modularization (using functions), selection control structures.
Aim : Introduce students to modular programming and function usage.

Exercise 9.7: Fibonacci Series

Description : Write a program that generates the Fibonacci series up to a given number of terms.
Syllabus Coverage : Repetition control structure (for loop), sequence generation.
Aim : Teach students how to generate sequences using loops and lists.

Exercise 9.8: Search for a Number in a List

Description : Write a program that searches for a given number in a list using sequential search.
Syllabus Coverage : Searching techniques (sequential search).
Aim : Introduce students to searching algorithms and their implementation.

Exercise 9.9: Bubble Sort

Description : Write a program that sorts a list of numbers using the bubble sort algorithm.
Syllabus Coverage : Sorting techniques (bubble sort).
Aim : Teach students how to implement sorting algorithms.

Exercise 9.10: File Handling – Reading and Writing

Description : Write a program that reads data from a file, modifies it, and writes it back to another file.
Syllabus Coverage : File handling (basic file operations).
Aim : Introduce students to file input/output operations in Python.

Exercise 9.11: File Handling – Reading and Writing

Description : Write a program that reads data from a file, modifies it, and writes it back to another file.
Syllabus Coverage : File handling (basic file operations).
Aim : Introduce students to file input/output operations in Python.

Exercise 9.12: Managing Data in Databases

Description : Write a program that connects to a SQLite database, creates a table, inserts data, retrieves data, and updates or deletes records.
Syllabus Coverage : Managing data in databases (connecting, retrieving, adding, modifying, and deleting data).
Aim : Teach students how to interact with databases using SQL queries embedded in Python.

Exercise 9.13: Sequential Search

Description : Write a program that searches for a given number in a list using sequential search.
Syllabus Coverage : Searching techniques (sequential search).
Aim : Introduce students to searching algorithms and their implementation.

Exercise 9.14: Bubble Sort

Description : Write a program that sorts a list of numbers using the bubble sort algorithm.
Syllabus Coverage : Sorting techniques (bubble sort).
Aim : Teach students how to implement sorting algorithms.

Exercise 9.15: Working with Strings

Description : Write a program that takes a string as input and performs the following operations:

  • Convert the string to uppercase.
  • Count the number of vowels in the string.
  • Reverse the string.
    Syllabus Coverage : Primitive data types (strings), operators, and basic string manipulation.
    Aim : Introduce students to string handling and manipulation techniques in Python.

Exercise 9.16: Using Lists

Description : Write a program that creates a list of numbers, finds the largest and smallest numbers, and calculates the average.
Syllabus Coverage : Data structures (lists).
Aim : Teach students how to work with lists and perform common operations like finding min, max, and average.

Exercise 9.17: Using Tuples

Description : Write a program that creates a tuple of student names and prints the names in alphabetical order.
Syllabus Coverage : Data structures (tuples).
Aim : Introduce students to tuples and their immutability.

Exercise 9.18: Using Dictionaries

Description : Write a program that uses a dictionary to store student names and their marks. The program should allow the user to add new students and display all students with their marks.
Syllabus Coverage : Data structures (dictionaries).
Aim : Teach students how to use dictionaries to store and retrieve key-value pairs.

Exercise 9.19: Writing Functions

Description : Write a program that defines a function to calculate the area of a circle. The user should input the radius, and the function should return the area.
Syllabus Coverage : Sub-programs (functions).
Aim : Introduce students to writing reusable functions.

Exercise 9.20: Nested Loops

Description : Write a program that prints a multiplication table from 1 to 10 using nested loops.
Syllabus Coverage : Control structures (nested loops).
Aim : Teach students how to use nested loops for complex tasks.

Exercise 9.21: Exception Handling

Description : Write a program that asks the user to input two numbers and divides them. Handle the case where the user tries to divide by zero.
Syllabus Coverage : Error handling.
Aim : Introduce students to exception handling in Python.

Exercise 9.22: File Reading and Writing

Description : Write a program that reads a text file, counts the number of words, and writes the word count to another file.
Syllabus Coverage : File handling (reading and writing).
Aim : Teach students how to read from and write to files.

Exercise 9.23: Connecting to a Database

Description : Write a program that connects to a SQLite database, creates a table, inserts data, and retrieves it.
Syllabus Coverage : Managing data in databases.
Aim : Introduce students to database connectivity using Python.

Exercise 9.24: Sequential Search

Description : Write a program that searches for a given number in a list using sequential search.
Syllabus Coverage : Searching techniques (sequential search).
Aim : Introduce students to searching algorithms.


Exercise 9.25: Bubble Sort

Description : Write a program that sorts a list of numbers using the bubble sort algorithm.
Syllabus Coverage : Sorting techniques (bubble sort).
Aim : Teach students how to implement sorting algorithms.

Below are additional Python exercises that align with the syllabus and provide practical, hands-on coding experience. These exercises focus on key concepts such as file handling , database connectivity , data structures , functions , and algorithms . Each exercise includes a description, syllabus coverage, aim, and Python code

Exercise 9.26: Working with Files

Description : Write a program that reads a text file line by line and counts the number of lines, words, and characters in the file.
Syllabus Coverage : File handling (basic file operations).
Aim : Teach students how to process files and extract useful information.

Exercise 9.27: Using Dictionaries for Frequency Count

Description : Write a program that reads a text file and calculates the frequency of each word in the file using a dictionary.
Syllabus Coverage : Data structures (dictionaries).
Aim : Introduce students to dictionaries for counting and organizing data.

Exercise 9.28: Recursive Functions

Description : Write a program that calculates the factorial of a number using recursion.
Syllabus Coverage : Sub-programs (functions), recursion.
Aim : Teach students how to write recursive functions.

Exercise 9.29: Sorting a List of Dictionaries

Description : Write a program that sorts a list of dictionaries based on a specific key.
Syllabus Coverage : Data structures (lists, dictionaries), sorting techniques.
Aim : Introduce students to sorting complex data structures.

Exercise 9.30: Connecting to a Database and Querying Data

Description : Write a program that connects to a SQLite database, creates a table, inserts data, and retrieves it using SQL queries.
Syllabus Coverage : Managing data in databases.
Aim : Reinforce students’ understanding of database connectivity and SQL queries.

Exercise 9.31: Binary Search Algorithm

Description : Write a program that implements the binary search algorithm to find a target value in a sorted list.
Syllabus Coverage : Searching techniques (binary search).
Aim : Teach students an efficient searching algorithm.

Exercise 9.32: Handling JSON Data

Description : Write a program that reads a JSON file, modifies its contents, and writes the updated data back to the file.
Syllabus Coverage : File handling (JSON).
Aim : Introduce students to working with JSON data.

Exercise 9.33: Generating Random Numbers

Description : Write a program that generates a list of random numbers and finds the largest and smallest numbers.
Syllabus Coverage : Primitive data types, control structures.
Aim : Teach students how to use the random module and perform basic operations.

Exercise 9.34: Simulating a Simple Banking System

Description : Write a program that simulates a simple banking system where users can deposit, withdraw, and check their balance.
Syllabus Coverage : Control structures, functions, data structures.
Aim : Provide a real-world application of Python programming concepts.

Python is an incredibly versatile programming language that can be used for a wide range of applications beyond the scope of your syllabus. Below are some additional, advanced, or creative ideas that you can explore using Python, which go beyond the topics covered in your Grade 13 ICT syllabus. These ideas will help you deepen your understanding of Python and its real-world applications:

1. Web Scraping

What You Can Do : Extract data from websites for analysis or automation.

  • Example Use Case : Scrape news articles, product prices, or social media posts.
  • Libraries : BeautifulSoup, requests, Selenium.
  • Code Example :

2. Data Analysis and Visualization

What You Can Do : Analyze datasets and create visualizations like graphs, charts, and heatmaps.

  • Example Use Case : Analyze sales data, student performance, or weather patterns.
  • Libraries : pandas, matplotlib, seaborn, plotly.
  • Code Example :

3. Machine Learning

What You Can Do : Build predictive models for classification, regression, clustering, etc.

  • Example Use Case : Predict house prices, classify emails as spam or not, or recommend products.
  • Libraries : scikit-learn, tensorflow, keras.
  • Code Example :

4. Automation Scripts

What You Can Do : Automate repetitive tasks like file organization, email sending, or report generation.

  • Example Use Case : Organize files into folders based on their extensions.
  • Libraries : os, shutil, smtplib.
  • Code Example :

5. Building APIs

What You Can Do : Create RESTful APIs to serve data or interact with applications.

  • Example Use Case : Build an API to fetch weather data or user information.
  • Libraries : Flask, FastAPI.
  • Code Example :

6. Game Development

What You Can Do : Create simple games like Tic-Tac-Toe, Snake, or Pong.

  • Example Use Case : Develop a text-based adventure game or a graphical game.
  • Libraries : pygame.
  • Code Example :

7. Chatbots

What You Can Do : Build conversational agents for customer support or personal assistants.

  • Example Use Case : Create a chatbot to answer FAQs or provide recommendations.
  • Libraries : nltk, chatterbot, transformers.
  • Code Example :

8. Image Processing

What You Can Do : Manipulate images (resize, crop, apply filters) or perform object detection.

  • Example Use Case : Build a face detection system or watermark images.
  • Libraries : Pillow, opencv-python.
  • Code Example :

9. Natural Language Processing (NLP)

What You Can Do : Process and analyze text data (sentiment analysis, summarization).

  • Example Use Case : Analyze customer reviews or summarize long documents.
  • Libraries : nltk, spaCy, transformers.
  • Code Example :

10. IoT Integration

What You Can Do : Control IoT devices (lights, fans, sensors) using Python.

  • Example Use Case : Build a smart home system or monitor environmental data.
  • Libraries : RPi.GPIO (for Raspberry Pi), pyserial.
  • Code Example :

11. Blockchain Basics

What You Can Do : Simulate a basic blockchain or cryptocurrency system.

  • Example Use Case : Create a simple blockchain for educational purposes.
  • Libraries : hashlib.
  • Code Example :

12. GUI Applications

What You Can Do : Build desktop applications with graphical user interfaces.

  • Example Use Case : Create a calculator, to-do list, or file manager.
  • Libraries : tkinter, PyQt, Kivy.
  • Code Example :

13. Networking

What You Can Do : Build networked applications like chat servers or file transfer systems.

  • Example Use Case : Create a simple chat server and client.
  • Libraries : socket.
  • Code Example :

14. Cryptography

What You Can Do : Encrypt and decrypt messages for secure communication.

  • Example Use Case : Build a password manager or secure messaging app.
  • Libraries : cryptography.
  • Code Example :

Spread the love