0

I want a program to convert user input to an integer and store it in a list only if it can be. If the input is not able to be converted to an integer, the program should just continue and ignore the input.

1 Answers1

3

The best approach here is to just try and convert it and ignore the error if the conversion fails. For example:

try:
    your_list.append(int(user_input))
except ValueError:
    pass
Andrew Clark
  • 202,379
  • 35
  • 273
  • 306