Counting a string within a file in python
===

hi I have generated 10 files with 100 random numbers named randomnumbers(1-10).py. I want to create a program which says congratulations when a string of 123 is found and count the number of times 123 shows up as well. I have the congratulations part and I have written a code for the counting part but i always get zero as a result. What's wrong?

    for j in range(0,10):
	n = './randomnumbers' + str(j) + '.py'			
	s='congradulations'	
	z='123'	
	def replacemachine(n, z, s):
		file = open(n, 'r')				
		text=file.read()	
		file.close()	
		file = open(n, 'w')	
		file.write(text.replace(z, s))
		file.close()
		print "complete"
	replacemachine(n, z, s)	
	count = 0
	if 'z' in n:
		count = count + 1
	else:
		pass
	print count