Electricity bill ক্যালকুলেটর (পাইথন) - SMH Amiri

সর্বশেষ লিখাসমূহ

Electricity bill ক্যালকুলেটর (পাইথন)

Electricity bill ক্যালকুলেটর ( বিদ্যুৎ বিলের ক্ষেত্রে ওয়াটের স্লাব/পরিসীমা অনুযায়ী বিলের পরিমাণ নির্ণয় হবে)



import tkinter as tk

from tkinter import messagebox


def calculate_bill():

    try:

        units_consumed = int(units_entry.get())

        is_business = business_var.get()

        

        # Electricity tariff rates

        tariff_rates = {

            "domestic": [(50, 3.50), (100, 4.00), (200, 5.50), (300, 6.50), (400, 7.50), (500, 8.00)],

            "business": [(50, 4.00), (100, 4.50), (200, 6.00), (300, 7.00), (400, 8.00), (500, 8.50)]

        }

        

        # Other charges

        demand_charge = 100 if is_business else 50

        minimum_bill = 150 if is_business else 100

        vat_rate = 0.15

        

        # Calculate bill

        total_bill = 0

        for i in range(len(tariff_rates["business"])):

            if units_consumed <= 0:

                break

            lower_limit, rate = tariff_rates["business"][i] if is_business else tariff_rates["domestic"][i]

            if units_consumed > lower_limit:

                units_on_this_tier = min(units_consumed - lower_limit, 100)

                total_bill += units_on_this_tier * rate

                units_consumed -= units_on_this_tier

        

        # Add other charges

        total_bill += demand_charge

        if total_bill < minimum_bill:

            total_bill = minimum_bill

        

        # Add VAT

        total_bill *= (1 + vat_rate)

        

        messagebox.showinfo("Electricity Bill", f"Total electricity bill: {total_bill:.2f}")

    except ValueError:

        messagebox.showerror("Error", "Please enter a valid number for units consumed.")


# GUI setup

root = tk.Tk()

root.title("Electricity Bill Calculator")


units_label = tk.Label(root, text="Units Consumed:")

units_label.grid(row=0, column=0, padx=5, pady=5)


units_entry = tk.Entry(root)

units_entry.grid(row=0, column=1, padx=5, pady=5)


business_var = tk.BooleanVar()

business_checkbutton = tk.Checkbutton(root, text="Business", variable=business_var)

business_checkbutton.grid(row=1, column=0, columnspan=2, padx=5, pady=5)


calculate_button = tk.Button(root, text="Calculate", command=calculate_bill)

calculate_button.grid(row=2, column=0, columnspan=2, padx=5, pady=5)


root.mainloop()