Madrid_datalady
Madrid_datalady

Reputation: 79

ValueError with input and trying to convert input value into int

I am a beginner, so please bear with me. I am trying to solve a very simple question but am getting a consistent error with the input and int commands. The problem I am trying to solve is the following:

You have a debt of 50k€. You compare different deposits and the most profitable one is a deposit with a 6% annual compound interest. How much money should you invest in that deposit to have 50k€ in N years?

My code is:

FV=50000   #future value of the deposit is 50,000 euros
I=0.06     #the interest rate of the deposit is 6%
N=input("number of months:")
N=int(N)
print(FV/(1+I)**N)
print("I should invest", FV/(1+I)**N, "euros to have", FV, " euros in", N, 
"months with interest", I)

But the kernel stops running and executing after the third line (input command) and when I manually hit Enter to get a newline, I get a ValueError code that says:

ValueError: invalid literal for int() with base 10: ''

Can someone tell me why I am getting this error? And where am I wrong in solving the problem? Thanks in advance.

Upvotes: 0

Views: 180

Answers (1)

Paritosh Singh
Paritosh Singh

Reputation: 6246

The code seems to work fine. i am going to add a couple of print statements that may help make things clearer. See if this helps.

FV=50000   #future value of the deposit is 50,000 euros
I=0.06     #the interest rate of the deposit is 6%
print("I am a computer program, i am about to ask you for an input. please enter something and then press enter")
N=input("number of years:")
if N != '': #can be replaced with if N:
    print("you have entered-",N)
else:
    print("that is an empty string")
N=int(N)
print(FV/(1+I)**N)
print("I should invest", FV/(1+I)**N, "euros to have", FV, " euros in", N, 
"years with interest", I)

Upvotes: 2

Related Questions