Friday, 14 August 2026

Today Learn Python Tuples for a Simple Tax Analyzer Report




Python tuples can be useful for storing simple accounting records in a structured way. In this example, each expense is stored as a tuple containing four items:

("Entertainment", 8000, 4000, "Entertainment")

The structure is:

(Expense Name, Accounting Amount, Tax Deductible, Category)

Several expenses can then be stored together:

expenses = (
    ("Staff Salary", 50000, 50000, "Operating"),
    ("Office Rental", 24000, 24000, "Operating"),
    ("Entertainment", 8000, 4000, "Entertainment"),
    ("Income Tax", 12000, 0, "Tax"),
)

Python can process these tuples to calculate the deductible and non-deductible portions of the expenses.

From Net Profit to Adjusted Income

The tax analyzer starts with Net Profit from the financial 'Profit and Loss' statement.

For example:

Net Profit                  RM32,000
Add: Non-Deductible         RM29,000
                            --------
Adjusted Income             RM61,000

The basic idea is that certain expenses recorded in the financial accounts may not be deductible for tax purposes. These amounts are therefore added back to accounting profit to arrive at a simplified Adjusted Income (Adjusted Income is only for tax report, financial report 'Profit and Loss' statement only come to net profit).

The Python program automatically performs this calculation and produces:

The overall workflow is:

Accounting Expenses
        ↓
     Tuples
        ↓
 Python Tax Analyzer
        ↓
     Net Profit
        ↓
Tax Adjustments
        ↓
  Adjusted Income

This example demonstrates how a simple Python data structure such as a tuple can be combined with accounting knowledge to automate repetitive tax-analysis work.



Python code by Chatgpt

# ============================================================

# ACCOUNTING & TAX ANALYZER

# Net Profit to Adjusted Income

# Using Python Tuples

# ============================================================


import pandas as pd

import matplotlib.pyplot as plt



# ------------------------------------------------------------

# 1. ACCOUNTING EXPENSE DATA

# ------------------------------------------------------------

# Tuple structure:

# (Expense Name, Accounting Amount, Tax Deductible, Category)


expenses = (

    ("Staff Salary", 50000, 50000, "Operating"),

    ("Office Rental", 24000, 24000, "Operating"),

    ("Audit Fee", 5000, 5000, "Professional"),

    ("Entertainment", 8000, 4000, "Entertainment"),

    ("Income Tax", 12000, 0, "Tax"),

    ("Staff Training", 6000, 6000, "Training"),

    ("Donation", 3000, 0, "Donation"),

    ("Depreciation", 10000, 0, "Depreciation"),

)



# ------------------------------------------------------------

# 2. NET PROFIT

# ------------------------------------------------------------

# Assume net profit is obtained from the financial statements.


net_profit = 32000



# ------------------------------------------------------------

# 3. TOTAL ACCOUNTING EXPENSES

# ------------------------------------------------------------


total_expenses = sum(

    amount

    for name, amount, deductible, category in expenses

)



# ------------------------------------------------------------

# 4. TOTAL TAX-DEDUCTIBLE EXPENSES

# ------------------------------------------------------------


total_deductible = sum(

    deductible

    for name, amount, deductible, category in expenses

)



# ------------------------------------------------------------

# 5. NON-DEDUCTIBLE EXPENSES

# ------------------------------------------------------------


total_non_deductible = sum(

    amount - deductible

    for name, amount, deductible, category in expenses

)



# ------------------------------------------------------------

# 6. ADJUSTED INCOME

# ------------------------------------------------------------

# Simplified tax adjustment:

#

# Adjusted Income =

# Net Profit + Non-Deductible Expenses


adjusted_income = (

    net_profit + total_non_deductible

)



# ------------------------------------------------------------

# 7. CREATE DATAFRAME

# ------------------------------------------------------------


df = pd.DataFrame(

    expenses,

    columns=[

        "Expense",

        "Accounting Amount",

        "Tax Deductible",

        "Category"

    ]

)


df["Non-Deductible"] = (

    df["Accounting Amount"]

    - df["Tax Deductible"]

)



# ------------------------------------------------------------

# 8. DISPLAY EXPENSE ANALYSIS

# ------------------------------------------------------------


print("=" * 60)

print("          ACCOUNTING & TAX ANALYZER")

print("=" * 60)


display(df)


# ------------------------------------------------------------

# 14. FINAL REPORT

# ------------------------------------------------------------


print("\n" + "=" * 60)

print("              TAX REPORT")

print("=" * 60)


print(f"""

Net Profit                  RM {net_profit:,.2f}


Add: Non-Deductible

Expenses                    RM {total_non_deductible:,.2f}


Adjusted Income             RM {adjusted_income:,.2f}

""")


print("=" * 60)

print("Analysis completed.")

print("=" * 60)


No comments:

Post a Comment