-1

With my basic interest calculator I keep getting the error

 r = int(raw_input("What is the rate of growth?\n=> "))
 ValueError: invalid literal for int() with base 10: '.52'

the numbers I am using are principal of 20,000 Rate of 52% (.052 is what I put in) compoundings are Semiannually with 3 periods

    import math

    p = int(raw_input("what is the principal value?\n=> "))
    r = int(raw_input("What is the rate of growth?\n=> "))
    c = int(raw_input("How many compoundings per periods are taking place? 
    \n=> "))
    t = int(raw_input("How mant periods are taking place?\n=>  "))

    number = str(p*(1+r/c)**c*t)
    print(number)

edit: sorry for crappy variables it is what is on my homework ;)

  • Possible duplicate of [Python input processing when input is a float or string](https://stackoverflow.com/questions/35144721/python-input-processing-when-input-is-a-float-or-string) – ivan_pozdeev Apr 18 '19 at 23:29
  • 1
    How is this a duplicate of that post? – Alec Apr 18 '19 at 23:51

2 Answers2

3

No; that's a contradiction: an int does not have a decimal point. .052 is not an int; it's a float. Use the proper conversion:

rate = float(raw_input("What is the rate of growth?\n=> "))

Also, use meaningful variable names; single-letter variables tend to gang up and bite you later.

Prune
  • 76,765
  • 14
  • 60
  • 81
2

Why are you casting the input string as an int if you want a float?

Change

r = int(raw_input("What is the rate of growth?\n=> "))

to

r = float(raw_input("What is the rate of growth?\n=> "))
Alec
  • 8,529
  • 8
  • 37
  • 63