import tkinter as tk def validate_numeric_input(P): """Validate that input is a positive number or empty.""" if P == "": return True # Allow empty input try: value = float(P) return value >= 0 except ValueError: return False def format_currency(value): """Format a number as currency with two decimal places.""" return f"${value:,.2f}" def calculate_dividend_income(amount, quantity, frequency, days): """Calculate total dividend income over the given period.""" # Map frequency to number of payments per year freq_map = {"Monthly": 12, "Quarterly": 4, "Annually": 1} payments_per_year = freq_map.get(frequency, 0) if payments_per_year == 0: return 0 # Invalid frequency # Calculate the number of payments within the given days payments = (days / 365) * payments_per_year return amount * quantity * payments