I am writing a program that calculates the compound interest using the formula: P(1 + i)n
The principal, interest and number of years are obtained from the user input.
I have written the following method:
def is_valid_entries(principle, int_rate, years): try: #Convert the inputs from string to respective data type principal_float = float(principle) rate_float = float(int_rate) years_int = int(years) if not (0 < rate_float < 1.0): return False, "The interest rate must be between 0.00 to 1.00" return True, (principal_float, rate_float, years_int) except ValueError: return False, "Could not convert data to the appropriate data type" except: return False, "Unknown error" However, my issue is I want to be very specific when i report exception. For instance, if there's a conversion error on principal, I want to report that there's an error in converting the principal and the same logic follows with interest rate and years. Please let me know how this can be done in exception handling or if there's a better way to write this.
raiseinstead ofreturn... I don't see how it solves your problem...