This Python program reads a sentence from the user and counts how many numeric digits (0 to 9) appear in it.
For example, in the sentence “Today is 1404/07/13”, there are 8 digits: 1, 4, 0, 4, 0, 7, 1, 3.
# Read sentence from user
sentence = input("Enter a sentence: ")
# Digit counter
digit_count = 0
# Check each character
for ch in sentence:
if ch.isdigit():
digit_count += 1
print("Number of digits (0–9):", digit_count)
Enter a sentence: Today is 1404/07/13
Number of digits (0–9): 8
- The input() function reads the full sentence
- A loop checks each character individually
- ch.isdigit() returns True if the character is a digit
- The digit_count variable keeps track of how many digits are found