Looking to create a function that will return a count of the number of occurences of a specified number in a file.
def countingNumber(num):
infile = open('text.txt', 'r')
contents = infile.read()
count = 0
for line in contents.split('\n'):
if str(number) in line:
count +=1
return count
Everything works, but I am getting more than the desired number, so say for example that I want to search for the number 30 and type:
countingNumber(30)
I will also get a count of any lines that have the number 300 or 3000 in it. Is there a way to get unique numbers counts?