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
<em> if entry.count(",") == 0:</em>
<em> print("Error: No comma in string")</em>
<em> entry = input("Sentence: ")</em>
This is executed if the number of commas is more than 1
<em> elif entry.count(",") > 1:</em>
<em> print("Error: Too many comma in input")</em>
<em> entry = input("Sentence: ")</em>
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
<em> print("Comma not followed by an integer")</em>
<em> entry = input("Sentence: ")</em>
If otherwise, the loop is exited
<em> else:</em>
<em> break</em>
This prints valid input, when the user enters a valid string
print("Valid Input")
Note that: entry = input("Sentence: ") <em>is used to get input</em>