ActiveState Code

Recipe 576533: script for calculating simple interest


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

Python
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"

Discussion

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?

Comments

  1. 1. At 1:19 a.m. on 9 oct 2008, zhang long said:

    I think line7 show be changed to: I=P * (1 + i/100.0) ** t

  2. 2. At 1:05 p.m. on 25 oct 2008, Edwin Bosire said:

    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

Sign in to comment