-1

I am trying to write a code for myself that will give me an answer for simple interest, I will use same concept and later make compound interest. I am having trouble with my rate. when I do it as a percentage like

r = int(input("rate %: ") 

and I type 5.4 it does not work so I tried it in a decimal form like this

 r = int(input("Rate 0."))

i get the same answer at end if i do 0.045 and 0.45 so how do i fix this problem

here is my entire code

while True:
    while True:
            print('Working out for SIMPLE INTEREST')
            p = int(input("Principl:"))
            r = int(input("Rate 0."))
            t = int(input("Time yrs:"))
            i = p*r
            i = i*t
            a = p + i
            print("Interest = " + str(i))
            print("Accumalated = " + str(a))
            print(str(p) + ' x ' + str(r) + ' x ' + str(t) + ' = ' + str(i) + ' | ' + str(p) + ' + ' + str(i) + ' = ' + str(a))
shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90
Zac
  • 1
  • 2

3 Answers3

3

int converts the input string to an integer, which is a whole number like 4 or 5. For 5.4, you want a floating point number, which you can make using the float function:

r = float(input("rate %: "))

(For professional usage, you might even consider the arbitrary-precision decimal package, but it's probably overkill in your situation.)

Thomas
  • 174,939
  • 50
  • 355
  • 478
  • Please help with another question i have https://stackoverflow.com/questions/49235379/how-to-remove-a-number-from-a-list-that-has-a-range-between-two-numbers – Zac Mar 12 '18 at 12:54
0

Here the solution for Python program to calculate Simple Interest using Single Inheritance.

class SimpleInterest:
    def __init__(self,principle,years,roi):
        self.principle = principle
        self.years = years
        self.roi = roi

class Interest(SimpleInterest):
    def calulate(self):
        si = (self.principle*self.years*self.roi)/100
        return si
    
principle = int(input())
years = int(input())
roi = int(input())

o = Interest(principle,years,roi)
si = o.calulate()
print("Principle amount:",principle)
print("No.Of.Years:",years)
print("Rate of interest:",roi)
print("Simple Interest:",si)
Yash Mehta
  • 2,025
  • 3
  • 9
  • 20
-3

It is because int does not support decimal numbers

So change int(input('something...')) to input('sonething...')