Hi guys, trying to write a function that reads a text file and counts the periods in it and prints the answer. I keep getting an error saying that UnboundLocalError: local variable 'periods' referenced before assignment. I am not sure how to fix this. We must use a function to calculate the periods and we can not use built in things like .count, etc.
Here is my code:
def percount(myFile):
for char in myFile:
if char == '.':
periods +=1
return periods
myFile = open("inn.txt", "r")
p = percount(myFile)
print p