Answer:
In Python:
entry = input("Sentence: ")
while True:
if entry.count(",") == 0:
print("Error: No comma in string")
entry = input("Sentence: ")
elif entry.count(",") > 1:
print("Error: Too many comma in input")
entry = input("Sentence: ")
else:
ind = entry.index(',')+1
if entry[ind].isnumeric() == False:
print("Comma not followed by an integer")
entry = input("Sentence: ")
else:
break
print("Valid Input")
Explanation:
This prompts the user for a sentence
entry = input("Sentence: ")
The following loop is repeated until the user enters a valid entry
while True:
This is executed if the number of commas is 0
if entry.count(",") == 0:
print("Error: No comma in string")
entry = input("Sentence: ")
This is executed if the number of commas is more than 1
elif entry.count(",") > 1:
print("Error: Too many comma in input")
entry = input("Sentence: ")
This is executed if the number of commas is 1
else:
This calculates the next index after the comma
ind = entry.index(',')+1
This checks if the character after the comma is a number
if entry[ind].isnumeric() == False:
If it is not a number, the print statement is executed
print("Comma not followed by an integer")
entry = input("Sentence: ")
If otherwise, the loop is exited
else:
break
This prints valid input, when the user enters a valid string
print("Valid Input")
Note that: entry = input("Sentence: ") is used to get input