Answer:
while True:
user_input = input("Please enter a sequence of comma-separated numbers: ")
if user_input.replace(",", "").isdigit():
break
print("Invalid input! Please try again.")
num_list = user_input.split(",")
num_list = [int(num) for num in num_list]
total_sum = sum(num_list)
print("The sum of the numbers is:", total_sum)
Explanation:
This program uses a while loop to repeatedly ask the user for input until they provide a valid sequence of comma-separated numbers (all-digit input). The .isdigit() function is used to check if the input is all-digit. If the input is valid, the program splits the input string at each ',' using the .split() function, converts each item in the resulting list into an integer using list comprehension, then adds all numbers together using the sum() function. Finally, the program outputs the total sum.