I want to build a while loop if user gives an input in a incorrect way, it says invalid input and try again. The input from user should be numbers separated by comma then it will be stored in a list. The input is given like:
number = input("input your number? (separated by comma): ")
number_list = number.split(',')
numbers = [int(x.strip()) for x in number_list]
print(numbers)
But the problem I dont know how to check if the input is numbers separated by comma. So for example if user input 0,1 it will be stored in a list like [0,1]. and when user input anything other than number like 'b' it should ask user to give a correct input.
so ideal code would be something like:
# Start a loop that will run until the user a give valid input.
while numbers != 'List of Numbers separated by comma':
# Ask user for input.
number = input("input your number? (separated by comma): ")
number_list = number.split(',')
numbers = [int(x.strip()) for x in number_list]
# Add the new name to our list.
if numbers == 'List of Numbers separated by comma':
print(numbers)
else:
print('Gave an incorrect input, please try again')
Thank you for your help.