Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# mrfiiqane == so dhowow magacaygu waa mohamed mohamud Kani waa assignment 2 ==

# general question
name = input("what is your name?")
print("welcome!", name, "let start question.\n")
Expand Down
2 changes: 2 additions & 0 deletions submissions/mrfiiqane/assigment02/note.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mohamed
xamdi
58 changes: 58 additions & 0 deletions submissions/mrfiiqane/assigment02/study_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# mrfiiqane == so dhowow magacaygu waa mohamed mohamud Kani waa assignment 2 ==

from pathlib import Path
BASE_DIR = Path(__file__).parent

note_path = BASE_DIR / "note.txt"

# soo jiido notes ka
def load(path):
try:
with open(path, "r", encoding="utf-8") as f:
notes = []
for line in f:
notes.append(line.strip())
return notes
except FileNotFoundError:
print("File not found")
return []

# save garee note ka
def save(path, notes):
with open(path, "w", encoding="utf-8") as f:
# if not "./note.txt":
# mkdir("./note.txt")
for note in notes:
f.write(note + "\n")

# qeybta menu oo leh add,list,quit
def menu():
notes = load(note_path)
print("Welcome to Study Log")

while True:
print("\n1. Add \n2. List \n3. Quit")
choice = input("Enter your choice: ")

if choice == "1":
note = input("enter note: ")
notes.append(note)

elif choice == "2":
if not notes:
print("No notes found")
else:
print("\nYour Notes: ")
for note in notes:
print("-", note)

elif choice == "3":
save(note_path, notes)
print("Notes saved. Bye!")
break

else:
print("Invalid choice")

if __name__ == "__main__":
menu()
103 changes: 103 additions & 0 deletions submissions/mrfiiqane/assigment03/catalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@

# mrfiiqane == so dhowow magacaygu waa mohamed mohamud Kani waa assignment 3 ==
from dataclasses import dataclass
from pathlib import Path
BASE_DIR = Path(__file__).parent

catalog_file = BASE_DIR / "catalog.txt"

@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("No books found.")
return

print("\n Book Catalog:")

for item in self.items:
print("-", item)

# soo jiido notes ka
def load(path, catalog):
try:
with open(path, "r", encoding="utf-8") as f:
items = []
for line in catalog.items:
line = line.strip()
if not line:
continue

title, year = line.split("|")
items.append(CatalogItem(title, int(year)))

return items

except FileNotFoundError:
print("file not found")
return []

# save garee
def save(path, catalog):
with open(path, "w", encoding="utf-8") as f:
for item in catalog.items:
f.write(f"{item.title}|{item.year}\n")


def main():

catalog = Catalog()

load(catalog_file, catalog)

print("Welcome to Book Catalog")

while True:

print("\n1. Add Book, \n2. List Books, \n3. Save \n4. Quit")

choice = input("choice: ")

if choice == "1":

title = input("Title: ")
year = int(input("Year: "))

item = CatalogItem(title, year)
catalog.add_item(item)

print("Book added!")

elif choice == "2":
catalog.list_all()

elif choice == "3":

save(catalog_file, catalog)
print("Catalog saved!")

elif choice == "4":
save(catalog_file, catalog)
print("Saved. Bye!")
break

else:
print("Invalid choice.")


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions submissions/mrfiiqane/assigment03/catalog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tailwingcss|2020
rich dad poor dad|2019
Loading