From 869b1bf5035fdd727c8587a662327dfa6bdb11fc Mon Sep 17 00:00:00 2001 From: Macneyste Date: Sat, 2 May 2026 11:39:36 +0300 Subject: [PATCH 1/2] assingment 2 commited --- submissions/Macneyste /Assingment2/Answer.md | 0 .../Macneyste /Assingment2/Study_log.py | 70 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 submissions/Macneyste /Assingment2/Answer.md create mode 100644 submissions/Macneyste /Assingment2/Study_log.py diff --git a/submissions/Macneyste /Assingment2/Answer.md b/submissions/Macneyste /Assingment2/Answer.md new file mode 100644 index 0000000..e69de29 diff --git a/submissions/Macneyste /Assingment2/Study_log.py b/submissions/Macneyste /Assingment2/Study_log.py new file mode 100644 index 0000000..9558b56 --- /dev/null +++ b/submissions/Macneyste /Assingment2/Study_log.py @@ -0,0 +1,70 @@ +# Author: Macneyste +# Description: A simple study log program that lets the user add and view +# one-line notes. Notes are saved to a text file and loaded on startup. + +# ── Section 4: Functions ────────────────────────────────────────────────────── + +def load_notes(path): + """Read notes from file and return them as a list of strings. + Returns an empty list if the file does not exist yet.""" + # Section 5: try/except FileNotFoundError + with open + encoding + try: + with open(path, "r", encoding="utf-8") as f: + return [line.rstrip("\n") for line in f] + except FileNotFoundError: + return [] + + +def save_notes(path, notes): + """Write every note in the list to the file, one note per line.""" + # Section 5: with open for writing + encoding + with open(path, "w", encoding="utf-8") as f: + for note in notes: + f.write(note + "\n") + + +def main(): + # Section 1: variables, print, input + FILE = "notes.txt" + + # Optional: ask for the user's name once + name = input("What is your name? ").strip() + if name == "": + name = "Student" + print(f"Welcome, {name}!\n") + + # Section 3: a list to hold all notes + notes = load_notes(FILE) + + # Section 4 / Section 3: while loop + menu + while True: + # Section 1: print the menu + print("1) Add note 2) List 3) Quit") + choice = input("Pick: ").strip() + + # Section 2: if / elif / else on the input string + if choice == "1": + note = input("Note: ").strip() + notes.append(note) # Section 3: list append + + elif choice == "2": + if notes: + for note in notes: # Section 3: for loop + print(note) + else: + print("No notes yet.") + + elif choice == "3": + save_notes(FILE, notes) # Section 5: save before quitting + print("Bye!") + break # exit the while loop + + else: + print("Please enter 1, 2, or 3.") + + print() # blank line for readability + + +# Section 4: entry point guard +if __name__ == "__main__": + main() From d168b546383b6183376981584b9fdda1ab770aa4 Mon Sep 17 00:00:00 2001 From: Macneyste Date: Wed, 13 May 2026 11:13:09 +0300 Subject: [PATCH 2/2] last assingment bnl --- .vscode/settings.json | 5 +- submissions/Macneyste /Assingment3/work.py | 112 +++++++++++++++++++++ 2 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 submissions/Macneyste /Assingment3/work.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 4b5a294..56f6c9b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,3 @@ { - "python-envs.defaultEnvManager": "ms-python.python:conda", - "python-envs.defaultPackageManager": "ms-python.python:conda" -} \ No newline at end of file + "python-envs.defaultPackageManager": "ms-python.python:conda" +} diff --git a/submissions/Macneyste /Assingment3/work.py b/submissions/Macneyste /Assingment3/work.py new file mode 100644 index 0000000..18b9161 --- /dev/null +++ b/submissions/Macneyste /Assingment3/work.py @@ -0,0 +1,112 @@ +# Yonis Abdulkadir Osman +# Simple personal catalog program using OOP, files, functions, and lists. + +from dataclasses import dataclass + + +@dataclass +class CatalogItem: + title: str + year: int + + def __str__(self): + return f"{self.title} ({self.year})" + + +class Catalog: + def __init__(self): + self.items = [] + + def add_item(self, item): + self.items.append(item) + + def list_all(self): + if not self.items: + print("Catalog is empty.") + else: + print("\nCatalog Items:") + for item in self.items: + print(item) + + +def load_catalog(path, catalog): + try: + with open(path, "r", encoding="utf-8") as file: + for line in file: + line = line.strip() + + if not line: + continue + + parts = line.split("|") + + if len(parts) == 2: + title = parts[0] + year = int(parts[1]) + + item = CatalogItem(title, year) + catalog.add_item(item) + + except FileNotFoundError: + print("No catalog file found. Starting with an empty catalog.") + + +def save_catalog(path, catalog): + with open(path, "w", encoding="utf-8") as file: + for item in catalog.items: + file.write(f"{item.title}|{item.year}\n") + + print("Catalog saved successfully.") + + +def main(): + file_path = "catalog.txt" + + catalog = Catalog() + + load_catalog(file_path, catalog) + + while True: + print("\nMy Catalog — Movies") + print("1) Add") + print("2) List") + print("3) Save") + print("4) Quit") + + choice = input("Pick: ") + + if choice == "1": + title = input("Title: ") + + year_input = input("Year: ") + + if year_input.isdigit(): + year = int(year_input) + + item = CatalogItem(title, year) + + catalog.add_item(item) + + print("Item added.") + else: + print("Invalid year. Please enter a number.") + + elif choice == "2": + catalog.list_all() + + elif choice == "3": + save_catalog(file_path, catalog) + + elif choice == "4": + save_catalog(file_path, catalog) + + print("Saved. Bye!") + + break + + else: + print("Invalid choice. Please select 1-4.") + + +if __name__ == "__main__": + main() \ No newline at end of file