Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"python-envs.defaultEnvManager": "ms-python.python:conda",
"python-envs.defaultPackageManager": "ms-python.python:conda"
}
"python-envs.defaultPackageManager": "ms-python.python:conda"
}
Empty file.
70 changes: 70 additions & 0 deletions submissions/Macneyste /Assingment2/Study_log.py
Original file line number Diff line number Diff line change
@@ -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()
112 changes: 112 additions & 0 deletions submissions/Macneyste /Assingment3/work.py
Original file line number Diff line number Diff line change
@@ -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()