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

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

Product comparison ক্যালকুলেটর (পাইথন)

 

Product comparison ক্যালকুলেটর (একই ক্যাটাগরির পণ্যের উপর বিভিন্ন ব্যাবসায়িক প্রতিষ্ঠান এর মূল্যছাড় এর উপর ভিত্তি করে সবচেয়ে কম মূল্য প্রদানকারী প্রতিষ্ঠান খুঁজে বের করবে)



import tkinter as tk

from tkinter import ttk


def compare():

    try:

        price1 = float(entry_price1.get())

        discount1 = float(entry_discount1.get()) / 100

        price2 = float(entry_price2.get())

        discount2 = float(entry_discount2.get()) / 100

        urban = urban_var.get()


        discounted_price1 = price1 * (1 - discount1)

        discounted_price2 = price2 * (1 - discount2)


        if entry_price3.get():

            price3 = float(entry_price3.get())

            discount3 = float(entry_discount3.get()) / 100

            discounted_price3 = price3 * (1 - discount3)

            if urban:

                discounted_price3 *= 1.1  # Assuming urban areas have a 10% markup


        if urban:

            discounted_price1 *= 1.1

            discounted_price2 *= 1.1


        if not entry_price3.get():

            if discounted_price1 < discounted_price2:

                comparison_result.set("Product 1 is the better deal with a price of Tk %.2f." % discounted_price1)

            elif discounted_price1 > discounted_price2:

                comparison_result.set("Product 2 is the better deal with a price of Tk %.2f." % discounted_price2)

            else:

                comparison_result.set("Both products have the same price.")

        else:

            if discounted_price1 < discounted_price2 and discounted_price1 < discounted_price3:

                comparison_result.set("Product 1 is the better deal with a price of Tk %.2f." % discounted_price1)

            elif discounted_price2 < discounted_price1 and discounted_price2 < discounted_price3:

                comparison_result.set("Product 2 is the better deal with a price of Tk %.2f." % discounted_price2)

            elif discounted_price3 < discounted_price1 and discounted_price3 < discounted_price2:

                comparison_result.set("Product 3 is the better deal with a price of Tk %.2f." % discounted_price3)

            else:

                comparison_result.set("All products have the same price.")

    except ValueError:

        comparison_result.set("Please enter valid values for all fields.")


root = tk.Tk()

root.title("Product Comparison Calculator")


label_instruction = ttk.Label(root, text="Enter the price and discount for each product:")

label_instruction.grid(row=0, column=0, columnspan=2, pady=10)


label_price1 = ttk.Label(root, text="Price_Product 1:")

label_price1.grid(row=1, column=0, padx=10, pady=5, sticky="e")

entry_price1 = ttk.Entry(root)

entry_price1.grid(row=1, column=1, padx=10, pady=5)


label_discount1 = ttk.Label(root, text="Discount (%) (Product 1):")

label_discount1.grid(row=2, column=0, padx=10, pady=5, sticky="e")

entry_discount1 = ttk.Entry(root)

entry_discount1.grid(row=2, column=1, padx=10, pady=5)


label_price2 = ttk.Label(root, text="Price_Product 2:")

label_price2.grid(row=3, column=0, padx=10, pady=5, sticky="e")

entry_price2 = ttk.Entry(root)

entry_price2.grid(row=3, column=1, padx=10, pady=5)


label_discount2 = ttk.Label(root, text="Discount (%) (Product 2):")

label_discount2.grid(row=4, column=0, padx=10, pady=5, sticky="e")

entry_discount2 = ttk.Entry(root)

entry_discount2.grid(row=4, column=1, padx=10, pady=5)


label_price3 = ttk.Label(root, text="Price_Product 3 (optional):")

label_price3.grid(row=5, column=0, padx=10, pady=5, sticky="e")

entry_price3 = ttk.Entry(root)

entry_price3.grid(row=5, column=1, padx=10, pady=5)


label_discount3 = ttk.Label(root, text="Discount (%) (Product 3) (optional):")

label_discount3.grid(row=6, column=0, padx=10, pady=5, sticky="e")

entry_discount3 = ttk.Entry(root)

entry_discount3.grid(row=6, column=1, padx=10, pady=5)


urban_var = tk.BooleanVar()

urban_checkbox = ttk.Checkbutton(root, text="Urban", variable=urban_var)

urban_checkbox.grid(row=7, column=0, columnspan=2, pady=5)


button_compare = ttk.Button(root, text="Compare", command=compare)

button_compare.grid(row=8, column=0, columnspan=2, pady=10)


comparison_result = tk.StringVar()

label_result = ttk.Label(root, textvariable=comparison_result)

label_result.grid(row=9, column=0, columnspan=2)


root.mainloop()