diff --git a/compound_interest.py b/compound_interest.py index 9673a7a0..06892c10 100644 --- a/compound_interest.py +++ b/compound_interest.py @@ -2,6 +2,7 @@ # Do not use this in production. Sample purpose only. # Author: Upkar Lidder (IBM) +# Updated by HamzaIDM # Input: # p, principal amount @@ -10,15 +11,26 @@ # Output: # compound interest = p * (1 + r/100)^t - +import sys def compound_interest(p, t, r): return p * (pow((1 + r / 100), t)) +def main(): -if __name__ == "__main__": - p = float(input("Enter the principal amount: ")) - t = float(input("Enter the time period: ")) - r = float(input("Enter the rate of interest: ")) + # for speed + read = sys.stdin.readline + write = sys.stdout.write + + write("Enter the principal amount: ") + p = float(read()) + write("Enter the time period: ") + t = float(read()) + write("Enter the interest rate: ") + r = float(read()) - print("The compound interest is {:.2f}".format(compound_interest(p, t, r))) + print(f"The compound interest is {compound_interest(p, t, r):.2f}") + + +if __name__ == "__main__": + main() \ No newline at end of file