test5.py (1189B)
1 from adpkg.finance import interest 2 3 if __name__ == '__main__': 4 print("--- Compound Interest Calculator ---") 5 6 while True: 7 try: 8 print("\nPlease provide the following details:") 9 prime_amount = input("Principal Amount (P): ") 10 rate_of_interest = input("Annual Interest Rate (%): ") 11 compounding_frequency = input("Times per year interest is compounded (n): ") 12 time_duration_str = input("Time Duration (e.g., '5y6m', '18m', '3y'): ") 13 14 calculated_interest = interest(prime_amount, time_duration_str, compounding_frequency, rate_of_interest) 15 16 if calculated_interest is not None: 17 print(f"\nCompound Interest earned is: {calculated_interest}") 18 else: 19 print("\nCalculation failed due to invalid input.") 20 21 except Exception as e: 22 print(f"\nAn unexpected error occurred: {e}") 23 24 check_again = input("\nDo you want to calculate another interest amount? (yes/no): ").lower() 25 if check_again != 'yes': 26 break 27 28 print("Exiting calculator. Goodbye!")