Ara192 Ara192 - 2 months ago 9
Python Question

Python Count the number of periods (.) there are in the file

Count the number of periods (.) there are in the file.

Use the built-in function

count()
on the file after you have converted it
to a string.

Answer with the result as an integer.

I've no idea to do this..please help!

Answer

try as follow

with open('file.txt') as f:
    file_content = f.read()

result = file_content.count('.')

result will be the number of periods.