The hint given in the question has a mistake. The formula (P*(1+R/N)^NT) will give us amount, not compound interest.
Program:
#Defining the function
def calculate (p, r, t, n=1) :
#calculation the amount
amount = p * (1 + r/(n * 100))**(n * t)
#calculating the compound interest and rounding it off to 2 decimal places
ci = round(amount - p, 2)
#displaying the value of the compound interest
print( "The compound interest will be " , ci)
#asking the principal, rate and time
p = float(input( "Enter the principal amount : " ) )
r = float(input( "Enter the rate of interest : " ) )
t = float(input( "Enter total time : " ) )
n = int(input( "Number of times the interest is compounded in a year\n(e.g. Enter 1 for yearly, 2 for half-yearly) : " ) )
if(n > 365) :
calculate (p, r, t ,n)
else :
print("Maximum number of times an interest is compounded can not be more than 365")
Output:
Enter the principal amount : 10000
Enter the rate of interest : 8
Enter total time : 5
Number of times the interest is compounded in a year
(e.g. Enter 1 for yearly, 2 to half-yearly ) : 4
The compound interest will be 4859.47