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?

zhang long 13 years, 1 month ago

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

Edwin Bosire 13 years, 1 month ago

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)

### Required Modules

• (none specified)