Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
def main():
# write your code here
pass
def main() -> None:
file_name = get_file_name()

content = get_file_content()

create_file(file_name, content)


def get_file_name() -> str:
"""Get and validate file name."""
while True:
file_name = input("Enter name of the file: ").strip()
if file_name: # Check not empty
return file_name


def get_file_content() -> list:
"""Get content line by line until 'stop'."""
content = []
while True:
line = input("Enter new line of content: ")
if line.strip().lower() == "stop":
break
content.append(line)
return content


def create_file(file_name: str, content: list) -> bool:
"""Create .txt file with content."""
full_name = f"{file_name}.txt"
with open(full_name, "w") as f:
for line in content:
f.write(line + "\n")
return True


if __name__ == "__main__":
Expand Down
Loading