Input until the user write empty string

hello, I got an exercise to request input from the member, untill he write empty string.
I tried to use this code:

def input_ist():
    data=int(input())
    while data != "":
        data=int(input())
input_ist()

but this I got this error, when I just enter without writin value:
ValueError: invalid literal for int() with base 10: ''

an empty string can’t be converted to integer. So you need to break this down into steps:

  1. get the input
  2. see if the input can be converted to integer
  3. convert the input to integer

or according to python idom: it’s easier to ask for forgiveness than permission, so step 2 could be trying to convert the input and handle the exception.

3 Likes