0

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.

4
  • What happens when you input a number and hit enter? Just hitting enter will input ''. Commented Nov 11, 2018 at 17:30
  • 2
    When there is a prompt, you should enter number. If you press enter without number, empty string is read which is invalid literal for int(). Commented Nov 11, 2018 at 17:34
  • I don´t understand your question, timgeb. I hit Enter in the kernel in order to get a newline, because the kernel stops executing after the third line of code, but I don´t know what number to enter since I don´t know the value of N (number of months), which is part of what I´m trying to solve for... Commented Nov 11, 2018 at 17:41
  • 1
    The kernal doesnt "stop", it is waiting for you to input N. you aren't solving for a value of N, N is being provided here. you are trying to solve for the initial investment with some value of N that needs to be provided. When you press enter however, you just feed it an empty string, which causes int(N) to fail because it is int('') Commented Nov 11, 2018 at 17:43

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much, Paritosh! I understand now and it worked... Also, N should be "number of years", not "number of months", since the interest rate is annual, so I changed that. Thank you, your explanations was really helpful!
Glad to help. Welcome to programming, don't be afraid to experiment with things and use lots of print statements whenever stuck! :) @Madrid_datalady
@Madrid_datalady if the question is solved, please accept the answer by clicking the green checkmark to say thank you to Paritosh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.