a script which can be used to calculate the amount of interest using the formula I=Pit
this is a very simple code,any suggestions are welcome
1 2 3 4 5 6 7 8 | print "all amounts should be in dollars!"
while True:
P=float(raw_input("enter Principal:"))
i=float(raw_input("enter Percentage of interest rate:"))
t=float(raw_input("enter Time(in years):"))
I=P*t*(i/100)
print "Interest is", I,"dollars"
|
there're some problems with the script,such as not being able to input divided amounts such as "8/12" which is specially needed in the "time in years" field,any advice?
Tags: accounting, interest
I think line7 show be changed to: I=P * (1 + i/100.0) ** t
you could set the t=int(raw_input("enter time(in months) :"))
set Interest=principal(t/12)interest
the (t/12) converts the time back to years, and since I is fload, it can easily accomodate the result