Welcome, guest | Sign In | My Account | Store | Cart

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, 8 lines
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?

2 comments

zhang long 15 years, 6 months ago  # | flag

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

Edwin Bosire 15 years, 5 months ago  # | flag

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

Created by Mahmoud Hossam on Thu, 9 Oct 2008 (MIT)
Python recipes (4591)
Mahmoud Hossam's recipes (1)

Required Modules

  • (none specified)

Other Information and Tasks