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.
python jupyter-notebook
add a comment |
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.
python jupyter-notebook
What happens when you input a number and hit enter? Just hitting enter will input''.
– timgeb
Nov 11 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 forint().
– Austin
Nov 11 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...
– Madrid_datalady
Nov 11 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('')
– Paritosh Singh
Nov 11 at 17:43
add a comment |
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.
python jupyter-notebook
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.
python jupyter-notebook
python jupyter-notebook
edited Nov 11 at 17:30
snakecharmerb
9,50532247
9,50532247
asked Nov 11 at 17:29
Madrid_datalady
386
386
What happens when you input a number and hit enter? Just hitting enter will input''.
– timgeb
Nov 11 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 forint().
– Austin
Nov 11 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...
– Madrid_datalady
Nov 11 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('')
– Paritosh Singh
Nov 11 at 17:43
add a comment |
What happens when you input a number and hit enter? Just hitting enter will input''.
– timgeb
Nov 11 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 forint().
– Austin
Nov 11 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...
– Madrid_datalady
Nov 11 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('')
– Paritosh Singh
Nov 11 at 17:43
What happens when you input a number and hit enter? Just hitting enter will input
''.– timgeb
Nov 11 at 17:30
What happens when you input a number and hit enter? Just hitting enter will input
''.– timgeb
Nov 11 at 17:30
2
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().– Austin
Nov 11 at 17:34
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().– Austin
Nov 11 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...
– Madrid_datalady
Nov 11 at 17:41
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...
– Madrid_datalady
Nov 11 at 17:41
1
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('')
– Paritosh Singh
Nov 11 at 17:43
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('')
– Paritosh Singh
Nov 11 at 17:43
add a comment |
1 Answer
1
active
oldest
votes
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)
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!
– Madrid_datalady
Nov 11 at 17:54
Glad to help. Welcome to programming, don't be afraid to experiment with things and use lots of print statements whenever stuck! :) @Madrid_datalady
– Paritosh Singh
Nov 11 at 17:56
@Madrid_datalady if the question is solved, please accept the answer by clicking the green checkmark to say thank you to Paritosh.
– timgeb
Nov 11 at 19:26
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251332%2fvalueerror-with-input-and-trying-to-convert-input-value-into-int%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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)
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!
– Madrid_datalady
Nov 11 at 17:54
Glad to help. Welcome to programming, don't be afraid to experiment with things and use lots of print statements whenever stuck! :) @Madrid_datalady
– Paritosh Singh
Nov 11 at 17:56
@Madrid_datalady if the question is solved, please accept the answer by clicking the green checkmark to say thank you to Paritosh.
– timgeb
Nov 11 at 19:26
add a comment |
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)
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!
– Madrid_datalady
Nov 11 at 17:54
Glad to help. Welcome to programming, don't be afraid to experiment with things and use lots of print statements whenever stuck! :) @Madrid_datalady
– Paritosh Singh
Nov 11 at 17:56
@Madrid_datalady if the question is solved, please accept the answer by clicking the green checkmark to say thank you to Paritosh.
– timgeb
Nov 11 at 19:26
add a comment |
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)
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)
edited Nov 11 at 17:56
answered Nov 11 at 17:48
Paritosh Singh
1,14213
1,14213
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!
– Madrid_datalady
Nov 11 at 17:54
Glad to help. Welcome to programming, don't be afraid to experiment with things and use lots of print statements whenever stuck! :) @Madrid_datalady
– Paritosh Singh
Nov 11 at 17:56
@Madrid_datalady if the question is solved, please accept the answer by clicking the green checkmark to say thank you to Paritosh.
– timgeb
Nov 11 at 19:26
add a comment |
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!
– Madrid_datalady
Nov 11 at 17:54
Glad to help. Welcome to programming, don't be afraid to experiment with things and use lots of print statements whenever stuck! :) @Madrid_datalady
– Paritosh Singh
Nov 11 at 17:56
@Madrid_datalady if the question is solved, please accept the answer by clicking the green checkmark to say thank you to Paritosh.
– timgeb
Nov 11 at 19:26
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!
– Madrid_datalady
Nov 11 at 17:54
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!
– Madrid_datalady
Nov 11 at 17:54
Glad to help. Welcome to programming, don't be afraid to experiment with things and use lots of print statements whenever stuck! :) @Madrid_datalady
– Paritosh Singh
Nov 11 at 17:56
Glad to help. Welcome to programming, don't be afraid to experiment with things and use lots of print statements whenever stuck! :) @Madrid_datalady
– Paritosh Singh
Nov 11 at 17:56
@Madrid_datalady if the question is solved, please accept the answer by clicking the green checkmark to say thank you to Paritosh.
– timgeb
Nov 11 at 19:26
@Madrid_datalady if the question is solved, please accept the answer by clicking the green checkmark to say thank you to Paritosh.
– timgeb
Nov 11 at 19:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251332%2fvalueerror-with-input-and-trying-to-convert-input-value-into-int%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What happens when you input a number and hit enter? Just hitting enter will input
''.– timgeb
Nov 11 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().– Austin
Nov 11 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...
– Madrid_datalady
Nov 11 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('')
– Paritosh Singh
Nov 11 at 17:43