Python Forum
input-ValueError: invalid literal for int()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
input-ValueError: invalid literal for int()
#1
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)
Reply
#2
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
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
Or handle the ValueError with try and except.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: Found input variables with inconsistent numbers of samples saoko 0 2,433 Jun-16-2022, 06:59 PM
Last Post: saoko
  ValueError: invalid literal for int() with base 10: omega_elite 5 5,678 Dec-30-2020, 06:11 AM
Last Post: delonbest
  Receiving ValueError("bad input shape {0}".format(shape)) error SuryaCitizen 2 3,473 Jun-01-2020, 06:45 AM
Last Post: pyzyx3qwerty
  invalid literal for int() with base 10: '# NRECS: 1096\n' Baloch 8 4,457 May-24-2020, 02:08 AM
Last Post: Larz60+
  invalid literal for int() with base 10: '' mrsenorchuck 5 5,330 Apr-29-2020, 05:48 AM
Last Post: markfilan
  ValueError: invalid literal for int() with base 10: '\n' srisrinu 9 5,581 Apr-13-2020, 01:30 PM
Last Post: ibreeden
  zlib decompress error: invalid code lengths set / invalid block type DreamingInsanity 0 6,741 Mar-29-2020, 12:44 PM
Last Post: DreamingInsanity
  ValueError: invalid literal for int() with base 10: '0.5' emmapaw24 2 3,673 Feb-16-2020, 07:24 PM
Last Post: emmapaw24
  ValueError: invalid literal for int() with base 10: '' Jay123 7 7,217 Aug-05-2019, 02:43 PM
Last Post: Jay123
  ValueError: invalid rectstyle object fen1c5 1 5,619 Jun-05-2019, 02:51 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020