Preparing git repo for final project

This commit is contained in:
2023-07-09 11:19:26 +02:00
parent 6a38966eef
commit 63d06d6b35
67 changed files with 1587 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import os
import sys
def main():
try:
file_name = sys.argv[1]
except IndexError:
print("Provide a file name from command line!")
sys.exit(1)
if len(sys.argv) > 2:
print("Too many command-line arguments")
sys.exit(1)
if not os.path.isfile(file_name): # Or try opening and catch FileNotFoundError
print(f"The file `{file_name}` does not exist!")
sys.exit(1)
if not file_name.endswith('.py'):
print(f"The file `{file_name}` is not a python script (does not end with the proper suffix)!")
sys.exit(1)
line_count = count_lines(file_name)
print(line_count)
def count_lines(file_name: str) -> int:
line_count = 0
with open(file_name, 'r') as file_object:
for line in file_object:
if len(line.strip()) > 0 and not line.strip().startswith('#'):
line_count += 1
return line_count
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,13 @@
from lines import count_lines
def main():
test_count_lines()
def test_count_lines():
assert count_lines('lines.py') == 28
if __name__ == "__main__":
main()