Ara192 Ara192 - 4 months ago 15
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.