0

enter image description here

here is my code

a = int(input())
b = int(input())

print(a, b)

and run result is here.

C:\PycharmProjects\venv\Scripts\python.exe C:/PycharmProjects/main.py
1
10
Traceback (most recent call last):
  File "C:\PycharmProjects\main.py", line 2, in <module>
    b = int(input())
ValueError: invalid literal for int() with base 10: ''

Process finished with exit code 1

i just input 5(enter)10 but error has occurred

in debug mode, it is OK Why occur ValueError in code?? please refer to attached picture also. thanks..!!

khelwood
  • 55,782
  • 14
  • 81
  • 108
JH. Lee
  • 29
  • 2
  • Looks like a problem with input in PyCharm. If you ran this code in a terminal it would work fine. – khelwood May 29 '22 at 09:19
  • Looking again, it appears that somehow / somewhere the input function is getting an *empty string*, which is throwing the error when being converted to an int. Test this with `int('')`, which throws the same error. – S3DEV May 29 '22 at 09:21
  • @S3DEV like this? a = int('') b = int('') print(a, b) C:\PycharmProjects\venv\Scripts\python.exe C:/PycharmProjects/main.py Traceback (most recent call last): File "C:\PycharmProjects\main.py", line 1, in a = int('') ValueError: invalid literal for int() with base 10: '' Process finished with exit code 1 – JH. Lee May 29 '22 at 09:36
  • @khelwood Yes, it is success in terminal. Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> a = int(input()) 5 >>> b = int(input()) 10 >>> print(a,b) 5 10 >>> – JH. Lee May 29 '22 at 09:36

0 Answers0