+ 2
Individual digits or any whole integer .
For individual digits, just compare each character to a list of digits.
Counting whole numbers is a bit trickier, you need something to keep track of when a continuous string of numbers end.
I made some quick drafts for you. If you understand how to read and write files on python, you should be able to understand how to count individual digits. Whole integer counting requires a little bit more logic but nothing difficult.
#Individual digit count
digits = "0123456789"
c = 0
with open("integers.txt","r") as fopen:
lines = fopen.readlines()
for line in lines:
for char in line:
if char in digits:
c = c + 1
print(c)
fopen.close()
#Whole integer count
c = 0
wholeInt = False
with open("integers.txt","r") as fopen:
lines = fopen.readlines()
for line in lines:
for char in line:
if char in digits:
if wholeInt != True:
c = c + 1
wholeInt = True
else: wholeInt = False
print(c)
The use of the variable wholeInt is just to track continuous string of digits so they are treated as one number and therefore counting it as a whole integer instead of counting the individual digits. Sorry I couldn't comment as it would have just made it look messy on a mobile.