ValueError: invalid literal for int() with base 10: '' using input function
-
So I am trying to learn int and float by this script I got from a book.
And it doesn't work
-
Hello @RobinAves
A few things to point out.
- input() takes a string to display and the it is up to the user to enter a value. As long as the input is a valid int you should be safe to convert the input to int
- To print a variable value you just need to use the literal without quotes.
Here is a slightly modified version of your code that should work.
svar = input('Enter a number') x =int(svar) y = x * x print(y)
-
Hello @RobinAves
A few things to point out.
- input() takes a string to display and the it is up to the user to enter a value. As long as the input is a valid int you should be safe to convert the input to int
- To print a variable value you just need to use the literal without quotes.
Here is a slightly modified version of your code that should work.
svar = input('Enter a number') x =int(svar) y = x * x print(y)