2
2
def __init__(self):
self.history = []
def add_bill(self):
description = input("Enter description for the bill: ").strip()
currency = input("Enter currency (e.g., Rs., $, €): ").strip()
# Bill amount
while True:
try:
bill = float(input(f"Total bill? {currency}"))
if bill <= 0: raise ValueError
break
except ValueError:
print("Enter a valid bill amount.")
# Tip percentage
while True:
try:
tip = int(input("Tip percentage? "))
if tip < 0: raise ValueError
break
except ValueError:
print("Enter a valid tip percentage.")
# Number of people
while True:
try:
people = int(input("How many people? "))
if people <= 0: raise ValueError
break
except ValueError:
print("Enter a valid number of people.")
def show_history(self):
if not self.history:
print("No bills recorded yet.")
return
for i, record in enumerate(self.history, 1):
print(f"\nBill {i}: {record['description']}")
print(f"Total: {record['currency']}{record['bill']:.2f}, Tip:
{record['currency']}{record['total_bill']:.2f}")
print(f"Each pays: {record['currency']}
{record['bill_per_person']:.2f}")
for name, expense in record["individual_expenses"].items():
print(f"{name}: {record['currency']}{expense:.2f}")
def run(self):
while True:
print("\n--- Menu ---")
print("1. Add bill")
print("2. View history")
print("3. Exit")
choice = input("Choice (1/2/3): ").strip()
if choice == "1": self.add_bill()
elif choice == "2": self.show_history()
elif choice == "3": break
else: print("Invalid choice.")