Python Forum

Full Version: input-ValueError: invalid literal for int()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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)
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
Or handle the ValueError with try and except.