First commit
This commit is contained in:
commit
c1006502f2
13
README.MD
Normal file
13
README.MD
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Discount Calculator Project
|
||||||
|
|
||||||
|
This project was created as part of a recruitment task for Koding Next.
|
||||||
|
|
||||||
|
It is a python-based GUI app that calculates final price after applying discount.
|
||||||
|
|
||||||
|
The purpose of this project is to demonstrate practical skills in programming, problem solving, and basic web development.
|
||||||
|
|
||||||
|
# Notes
|
||||||
|
Since the task mentionied quantity as a possible input, but the example showed no such input, I created two versions of the app.
|
||||||
|
- `discalc.py` includes all three mentioned fields (price, quantity, discount).
|
||||||
|
- `discalc-noqty.py` is the one without quantity field.
|
||||||
|
Thank you for your understanding
|
||||||
47
discalc-noqty.py
Normal file
47
discalc-noqty.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import tkinter as tk
|
||||||
|
from tkinter import messagebox
|
||||||
|
|
||||||
|
def calculate():
|
||||||
|
try:
|
||||||
|
price = float(entry_price.get())
|
||||||
|
#quantity = int(entry_quantity.get())
|
||||||
|
rate = float(entry_rate.get())
|
||||||
|
|
||||||
|
if price < 0 or rate < 0: #price < 0 or quantity < 0 or rate < 0:
|
||||||
|
messagebox.showerror("Error", "Invalid input.", detail="Value cannot be negative.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if rate > 100:
|
||||||
|
messagebox.showerror("Error", "Invalid input.", detail="Discount rate cannot exceed 100%.")
|
||||||
|
return
|
||||||
|
|
||||||
|
#subtotal = price * quantity
|
||||||
|
discount = price * rate / 100 #subtotal * rate / 100
|
||||||
|
total = price - discount #subtotal - discount
|
||||||
|
|
||||||
|
result_var.set(f"Total: {total:,.2f}")
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
messagebox.showerror("Error", "Invalid input.", detail="Please enter numeric values. Fractions are allowed for price and discount rate.")
|
||||||
|
|
||||||
|
|
||||||
|
root = tk.Tk()
|
||||||
|
root.title("Discount Calculator")
|
||||||
|
root.geometry("280x250")
|
||||||
|
tk.Label(root, text="Price").pack(pady=5)
|
||||||
|
entry_price = tk.Entry(root, width=20)
|
||||||
|
entry_price.pack(pady=5)
|
||||||
|
|
||||||
|
# tk.Label(root, text="Quantity").pack(pady=5)
|
||||||
|
# entry_quantity = tk.Entry(root, width=20)
|
||||||
|
# entry_quantity.pack(pady=5)
|
||||||
|
tk.Label(root, text="Discount (%)").pack(pady=5)
|
||||||
|
entry_rate = tk.Entry(root, width=20)
|
||||||
|
entry_rate.pack(pady=5)
|
||||||
|
|
||||||
|
tk.Button(root, text="Calculate", command=calculate).pack(pady=10)
|
||||||
|
|
||||||
|
result_var = tk.StringVar()
|
||||||
|
tk.Label(root, textvariable=result_var).pack(pady=10)
|
||||||
|
|
||||||
|
root.mainloop()
|
||||||
47
discalc.py
Executable file
47
discalc.py
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
import tkinter as tk
|
||||||
|
from tkinter import messagebox
|
||||||
|
|
||||||
|
def calculate():
|
||||||
|
try:
|
||||||
|
price = float(entry_price.get())
|
||||||
|
quantity = int(entry_quantity.get())
|
||||||
|
rate = float(entry_rate.get())
|
||||||
|
|
||||||
|
if price < 0 or quantity < 0 or rate < 0:
|
||||||
|
messagebox.showerror("Error", "Invalid input.", detail="Value cannot be negative.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if rate > 100:
|
||||||
|
messagebox.showerror("Error", "Invalid input.", detail="Discount rate cannot exceed 100%.")
|
||||||
|
return
|
||||||
|
|
||||||
|
subtotal = price * quantity
|
||||||
|
discount = subtotal * rate / 100
|
||||||
|
total = subtotal - discount
|
||||||
|
|
||||||
|
result_var.set(f"Total: {total:,.2f}")
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
messagebox.showerror("Error", "Invalid input.", detail="Please enter numeric values. Fractions are allowed for price and discount rate.")
|
||||||
|
|
||||||
|
|
||||||
|
root = tk.Tk()
|
||||||
|
root.title("Discount Calculator")
|
||||||
|
root.geometry("280x300")
|
||||||
|
tk.Label(root, text="Price").pack(pady=5)
|
||||||
|
entry_price = tk.Entry(root, width=20)
|
||||||
|
entry_price.pack(pady=5)
|
||||||
|
|
||||||
|
tk.Label(root, text="Quantity").pack(pady=5)
|
||||||
|
entry_quantity = tk.Entry(root, width=20)
|
||||||
|
entry_quantity.pack(pady=5)
|
||||||
|
tk.Label(root, text="Discount (%)").pack(pady=5)
|
||||||
|
entry_rate = tk.Entry(root, width=20)
|
||||||
|
entry_rate.pack(pady=5)
|
||||||
|
|
||||||
|
tk.Button(root, text="Calculate", command=calculate).pack(pady=10)
|
||||||
|
|
||||||
|
result_var = tk.StringVar()
|
||||||
|
tk.Label(root, textvariable=result_var).pack(pady=10)
|
||||||
|
|
||||||
|
root.mainloop()
|
||||||
Loading…
x
Reference in New Issue
Block a user