How to count the number of occurrences of the invalid input when the user enter the wrong input

  for-loop, input, printing, python, while-loop

How to count the number of occurrences of the invalid input when the user enter the wrong input.

I would like to count how many times the words "invalid input " appears.

Here’s my code. Please assist me.

while True:
    number = input("Enter a. number: ")
    if number.isdigit():
        print("The input is  valid.")
    else:
        print("Invalid input.")
        continue

Source: Python Questions

LEAVE A COMMENT