2nd int-casting input-taking variables causes problem

Viewed 39

I'm working in PyCharm. I haven't been programming for a few months and when I came back I saw a problem.

There are 2 user-input-taking variables, input is converted to int.

height = int(input())
width = int(input())

(it's literally entire code, there's nothing more)

When I run the program and give the 1st integer value, it's still fine, but the 2nd integer causes the following error:

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

For some reason, it is "ValueError", though I just give it integer value (see screen at the end) and it seems to indicate that I gave it an empty string which is untrue (again, see the screen - I even marked the values I had given; in this case it was 4 and 5).

If I put some code between the 2 variables, like below, the problem doesn't appear:

height = int(input())
print(height)
width = int(input())

Also note that if it's just one variable, the problem doesn't appear.

And the problem appears only in PyCharm, I did the same in VSCode and everything worked properly. I also reinstalled PyCharm to check if it helps, but it didn't.

I suppose the problem is related to PyCharm, but since hard reinstall (deleting all that Revo Uninstaller found being related to PyCharm) didn't help I have no more ideas...

Visualization: error

3 Answers

Please, check your python --version in virtual environment (it should be python 3.x)

I just ran the code myself (with a few amendments just to see the prompts) and it runs completely fine in my vs code even before my prompt amendments.

height = int(input("Input Height: "))
width = int(input("Input Width: "))# Write your code here :-)
area = height * width
print(area)

I would suggest checking you have the most update version of python and that everything is configured correctly on your machine.

Also it might help to re-save the file and re run.

Related