We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0f4a299 commit 3ab2cf9Copy full SHA for 3ab2cf9
lab-12/file-stats.py
@@ -1,9 +1,14 @@
1
import os
2
+
3
def stats(file_path):
4
file = open(file_path, "r")
5
file_data = file.read()
6
file_characters = len(file_data)
7
file_lines = int(sum(1 for line in file_data) / 10)
8
file_words = len(file_data.split())
9
+ print(f"File statistics for {os.path.basename(file_path)}: \n\
10
+{file_characters} characters\n\
11
+{file_words} words\n\
12
+{file_lines} lines")
13
14
stats(os.path.expanduser('~') + "\\src\\python-programming\\lab-12\\test.txt")
0 commit comments