This repository contains a series of Python practice exercises designed to teach and reinforce fundamental programming concepts. The exercises progressively introduce new topics, building upon previous ones.
These practices cover a range of essential Python fundamentals, including:
- 📝 Basic Syntax: Variables, data types (integers, floats, strings), operators.
- 📥 Input/Output: Getting user input (
input()
) and displaying output (print()
), formatted strings (f-strings). - 🔄 Control Flow:
- Conditional statements (
if
,elif
,else
). - Loops (
while
).
- Conditional statements (
- 📋 Data Structures:
- Lists (creation, appending, accessing elements, iterating).
- 🔧 Functions: Defining and calling functions, passing arguments, returning values.
- 📦 Modules: Creating and importing custom modules to organize code.
- 📂 File I/O: Reading from and writing to text files (
.txt
,.csv
). ⚠️ Error Handling: Usingtry...except
blocks to handle potential errors (e.g.,ValueError
).- ✅ Input Validation: Writing functions to ensure user input meets specific criteria (ranges, types, lengths).
- 🗂️ Code Organization: Using configuration files (
_config.py
) for constants.
- 🛠️ Task: Basic calculations (gross pay, discounts).
- 📌 Concepts: Variables, basic data types,
input()
,print()
, arithmetic operations.
- 🛠️ Task: Calculate costs with tiered discounts and sales tax.
- 📌 Concepts: Constants,
if
/elif
/else
statements for decision making, formatted output.
- 🛠️ Task: Process multiple sales transactions, accumulating totals until a sentinel value is entered.
- 📌 Concepts:
while
loops for repetition.- Accumulators (summing totals).
- Basic
try...except
for numeric input validation. - Nested loops/conditionals.
- 🛠️ Task: Refactor Practice_03 using functions and modules.
- 📌 Concepts:
- Defining functions.
- Creating and importing modules (
_module.py
). - Using configuration files (
_config.py
). - Global variables for accumulators.
- Modular code design.
- 🛠️ Task: Create and read a sequential data file (one piece of data per line).
- 📌 Concepts:
- File I/O (
open()
,with open()
,'w'
,'r'
). - Writing (
write()
) and reading (readline()
) files line by line. - String manipulation (
rstrip()
). - Sequential file processing logic.
- File I/O (
- 🛠️ Task: Process sales data for multiple salespeople using lists. Calculate statistics (min, max, average) and sort sales data without using built-in functions.
- 📌 Concepts:
- Lists (creation, appending).
- List iteration.
- Implementing custom logic for finding min/max values and sorting (e.g., bubble sort).
🎯 How to Use for Learning
- 👀 Study the Code: Read through the Python files (
.py
) in each practice folder, starting fromPractice_0
. Pay attention to the comments and structure. ▶️ Run the Code: Execute the main script (e.g.,Practice_07.py
) to see how it works. Provide input as prompted.- 🔍 Understand the Logic: Trace the execution flow. How do the loops, conditionals, and functions work together? How is data validated and processed?
- 📂 Examine Supporting Files: Look at the
_module.py
and_config.py
files in later practices to understand how code is organized. Review the OIP/Pseudo Code files (.txt
,.docx
) for the planning steps. - ✏️ Modify and Experiment: Change parts of the code to see what happens. Try different inputs. Add new features or validation rules.
- 🛠️ Replicate: Try to solve the problem described in the comments or OIP/Pseudo Code yourself before looking at the provided solution.
These exercises provide a practical way to grasp core Python concepts through building small, focused applications.