Python Forum
input-ValueError: invalid literal for int() - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: input-ValueError: invalid literal for int() (/thread-24596.html)



input-ValueError: invalid literal for int() - jacklee26 - Feb-21-2020

i have a question about this script
if i press empty it will occur ValueError: invalid literal for int() with base 10: ''
Do anyone know why or how to change it.

code description:
if i press empty it should print 5, and if i enter10, it should print 10, something like that.



import subprocess
import os
input11= 5

input_no= int(input("Enter a number: "))

if input_no =='':
    input_no=input11
print(input_no)



RE: input-ValueError: invalid literal for int() - menator01 - Feb-21-2020

Take the int out

input11=5
input_no=input("Enter as number: ")

if input_no == '':
  input_no=input11
print(input_no)
Output:
Enter as number: 5
Output:
Enter as number: 10 10



RE: input-ValueError: invalid literal for int() - ndc85430 - Feb-21-2020

Or handle the ValueError with try and except.