From e93e66f0951684ca2ff4e40fe8902a5e8217504b Mon Sep 17 00:00:00 2001 From: abdinasir Date: Tue, 2 Jun 2026 14:52:02 +0200 Subject: [PATCH] final project added --- .../python final project/data/airport.txt | 0 .../abdinasir97/python final project/main.py | 119 ++++++++++++++++++ .../python final project/models/__init__.py | 0 .../__pycache__/__init__.cpython-314.pyc | Bin 0 -> 188 bytes .../__pycache__/airport.cpython-314.pyc | Bin 0 -> 6045 bytes .../python final project/models/airport.py | 86 +++++++++++++ .../python final project/utils/__init__.py | 0 .../__pycache__/__init__.cpython-314.pyc | Bin 0 -> 187 bytes .../utils/__pycache__/storage.cpython-314.pyc | Bin 0 -> 4363 bytes .../python final project/utils/storage.py | 45 +++++++ 10 files changed, 250 insertions(+) create mode 100644 submissions/abdinasir97/python final project/data/airport.txt create mode 100644 submissions/abdinasir97/python final project/main.py create mode 100644 submissions/abdinasir97/python final project/models/__init__.py create mode 100644 submissions/abdinasir97/python final project/models/__pycache__/__init__.cpython-314.pyc create mode 100644 submissions/abdinasir97/python final project/models/__pycache__/airport.cpython-314.pyc create mode 100644 submissions/abdinasir97/python final project/models/airport.py create mode 100644 submissions/abdinasir97/python final project/utils/__init__.py create mode 100644 submissions/abdinasir97/python final project/utils/__pycache__/__init__.cpython-314.pyc create mode 100644 submissions/abdinasir97/python final project/utils/__pycache__/storage.cpython-314.pyc create mode 100644 submissions/abdinasir97/python final project/utils/storage.py diff --git a/submissions/abdinasir97/python final project/data/airport.txt b/submissions/abdinasir97/python final project/data/airport.txt new file mode 100644 index 0000000..e69de29 diff --git a/submissions/abdinasir97/python final project/main.py b/submissions/abdinasir97/python final project/main.py new file mode 100644 index 0000000..b052927 --- /dev/null +++ b/submissions/abdinasir97/python final project/main.py @@ -0,0 +1,119 @@ +from models.airport import planes, airport +from utils.storage import DATA_PATH,load_airport,purse_seat,save_airport + +def menu_add(airport:airport)->None: + flen = input("FLEET_NUMBER:").strip() + name= input("NAME:").strip + if not flen or name: + print("fleet_number and name are required") + return + try: + seats = purse_seat(list) + except ValueError: + print("seats must be numbers sepparated by coma(e.g 33,56).") + return + fn= airport(fleet_number=flen, name=name, seats=seats) + if airport.add(fn): + print("added") + else: + print("fleet_number already exist") + +def print_airport(rows:list[airport])->None: + if not rows: + print("no airport yet") + for a in rows: + print(f"(a)") + +def menu_list(airport: airport)->None: + print_airport(airport.all()) + +def remove_menu(airport:airport)->None: + flen = input("fleet_number to remove").strip() + if airport.remove(flen): + print("removed") + else: + print("no fleet_number to remove"); + +def menu_search(airport:airport)->None: + q = input("serch(flen or name): ").strip() + found = airport.search(q) + if not found: + print("not match") + return + print_airport(found) + +def menu_update(airport:airport)->None: + flen = input("enter fleet_number to apdate" ).strip + if airport.find_by_fleet(flen) is None: + print("no plane this fleet_number") + return + new_name = input("new_name(enter to keep:)").strip + raw = input("new seats coma separated (enter to keep:type name to clear): ").strip() + name_arg = new_name if new_name else None + if raw.lower() == "None": + seat_arag: list[float] | None = [] + elif raw: + try: + seat_arag =purse_seat(raw) + except ValueError: + print("invailed seat : no thing changed ") + return + else: + seat_arag = None + if not airport.update(flen, name=name_arg,seats=seat_arag): + print("update filed") + return +print("updated") + +def print_menu()->None: + print() + print("--- airport management---") + print( "1) Add airport") + print( "2) List all") + print( "3)remove plane") + print( "3)Search") + print( "4) update airport") + print( "5) Save to file") + print( "0)quite (alse saves)") + + +def main()-> None: + airport= airport() + load_airport(DATA_PATH,airport,) + + + + +try: + while True: + print_menu() + choice = input("choice: ").strip() + if choice == "1": + menu_add(airport) + elif choice == "2": + list(airport) + elif choice == "3": + remove_menu(airport) + elif choice == "4": + menu_search(airport) + elif choice == "5": + menu_update(airport) + elif choice == "6": + save_airport(DATA_PATH, airport) + elif choice == '0': + print("have anice time ") + break +finally: + try: + save_airport(DATA_PATH.airport) + print(f"(data saved by {DATA_PATH}") + except OSError as e: + print("couldn't save:",e) + + +if __name__ =="__main__": + main() + + + + diff --git a/submissions/abdinasir97/python final project/models/__init__.py b/submissions/abdinasir97/python final project/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/submissions/abdinasir97/python final project/models/__pycache__/__init__.cpython-314.pyc b/submissions/abdinasir97/python final project/models/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1ae8a09a9fbfb7a20157b0033de6c5fc615dfd55 GIT binary patch literal 188 zcmdPqh$$$_PcKT$&CE-WDX1*T$j^gP3Tc^ni8%^D z>8#Y`l9=55l+>K!nE3e2yv&mLc)fzkTO2k(!P1;myCPPgO(3@vgBYKf85tRin1L(+ DU$!y= literal 0 HcmV?d00001 diff --git a/submissions/abdinasir97/python final project/models/__pycache__/airport.cpython-314.pyc b/submissions/abdinasir97/python final project/models/__pycache__/airport.cpython-314.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a6a2feb5d26411051b68f6453738182159a3a0c1 GIT binary patch literal 6045 zcmbtYZ){uD6~Fhr=l^z`#Lk~4Y2qYps7sX4Hk49I*NRdog)F=l1I6X()qW19FSfbw zxzMa)*&k`?fHh@B&7^M2v`P?Z(?FX9`!J1<``FMz+^0&@w0+^5vn&fAcg}r&j+45n z(5~e3&i#MxJ?H$+xqh%A?vN$5xV@E1eOi`Ag-PK0)MpKgAz{fcJakAn+m1 zd*ue;!<_fYjlef?-Y+);AK`pJj>;`^tK2dy$ZgQtj;*?22IVbK>)>NTa!WsncYcks z#RbckR!udftA=5@GFeSerz%48k5s8F9|T5)W1l7_m5C|5Dw$#{$&=GkFFEa!=_Ax0 zX}S|+55;THy{1PNO>csjK3Re-U6#9`t2xbxQ!AX-GHOvbm5iD)^Xz;Ir&pFBxTy%g zDubxk-W;UO*T!yBaMqIQ+!(^7E zXAKi>PtU6++^9Q~XA`Pvg%pL~YdV`U6~(~y`=+dyQu~uH!1_i~J(JGnlHbi~M_Bfp zmOP>vXU%*eSz!5brcPvY29Oitv}nhuL(Ss~BNp~879 zs3>YKmp4^YQxq#=-}O*!BVMfWB#>`@LVig8;Sc@b*piD-y5uGeO+R>c$%DL?G`B2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*|X^eF5x-iz1)bG?-qUF-_Z)$AKBzXqO5JnsfdKP$#zF~>^ zqG{VF*!emTg0z&SUSrQgGuL4X7_iY`)1~7VkH7QWVz6f+*mE=3J5B!{ZY)JwrjM1j z_CRu3W42dEFOM!pcPvDA+>GwL72f%g`svbRn(M(BUaC^!WlfP})mZDl7#u}bK!jnE&d^G0(?e0!b@l=@a&aIi!NPaKk(nb1 z@HfM;8{QZfgsXRyKN!{}ZfJu1=A2|`<6k}--~fi(Wj(~p(%P-o2Z{~jT}ixOUWV~s zDtAqIz_*Mos*NR54VK^u@0&>MgF%KJ5m!kAh72J8>eyO#!S_G-Ps@z?K}Xq#H9v{A zUvqu%*j)6>$o6son}Wm}TnYiV9&s=_R8?p~1tVg;n6j4X6{LiefjO02QP3bNqUYz< zR4;1qPed1~`5QoV6rYfCxF0W=F=9pmS>sX27kON;U6w;E{*~kSZ4h|73tMYFciT26 zeJB>-|3{5MB18CP9Rg;Glp9E>X))Nn5bU14a5FeKO-q5`PanM<-2xfq7lF=FYsb5Z zQlRmRK-Zntj@gHQes=osyHDMYw87t5!8)_-{f0|V^G*e3ZQCOg&t zZ78Z0$P7NZ9931X6-HJ!kMhm$esuBB%pXg4d6g@r1GKSMU?$(R^2lmwt3I;g4OXD~ z7p`V7RFwVK8rrq}Iv+-E7m`Cra3x!B2$uF7t(@-k$r{oEPKezIe56@6ee=G^K304jOV4*&oF literal 0 HcmV?d00001 diff --git a/submissions/abdinasir97/python final project/models/airport.py b/submissions/abdinasir97/python final project/models/airport.py new file mode 100644 index 0000000..295c6ec --- /dev/null +++ b/submissions/abdinasir97/python final project/models/airport.py @@ -0,0 +1,86 @@ + + +from dataclasses import dataclass, field +@dataclass +class planes: + name: str + service: str + fleet_number:str + location:str + seats:list[float] = field(default_factory=list) +def average_seats(self)->float: + if not self.seats: + return 0.0 + return sum(self.seats) / len(self.seats) +def __str__(self)->str: + avg = self.average_seats + avg_txt = f"{avg:.2f}" if self.seats else("full seats") + return f"{self.fleet_number} | {self.name} | seats={self.seats}| avg = {avg.txt}" + +class airport: + def __init__(self)-> None: + self.planes : list[planes] = [] + +def add(self, planes: planes) -> bool: + if self.find_by_fleet(planes.fleet_number) is not None: + return "false" + self.planes.append(planes) + return True +def remove(self, fleet_number:str)->bool: + flen = fleet_number.strip + for i,s in enumerate (self.planes): + if s.fleet_number == flen: + del self.planes[i] + return True + return False + +def find_by_fleet(self, fleet_number:str)->planes | None: + flen = fleet_number.strip() + for s in self.planes: + if s.fleet_number == flen: + return s + return None + +def search(self, query:str)->list[planes]: + q = query.strip().lower() + if not q: + return [] + out :list [planes] = [] + for s in self.planes: + if q in s.fleet_number.lower() or q in s.name.lower(): + out.append(s) + return out +def all(self)->list[planes]: + return list(self.planes) + +def update( + self, + fleet_number: str, + *, + name:str | None = None, + seats: list[float] | None= None + )->bool: + s = self.find_by_fleet(fleet_number) + if s is None: + return False + if name is not None: + s.name = name + if seats is not None: + s.seats = list(seats) + return True + +def clear(self)->None: + self.planes =[] + + + + + + + + + + + + + diff --git a/submissions/abdinasir97/python final project/utils/__init__.py b/submissions/abdinasir97/python final project/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/submissions/abdinasir97/python final project/utils/__pycache__/__init__.cpython-314.pyc b/submissions/abdinasir97/python final project/utils/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000000000000000000000000000000000000..18e8e187e2fed9b9a618792d98ef406865bd75f4 GIT binary patch literal 187 zcmdPq_I|p@<2{{|u766_IQe6Iz^F zR2-9-l#-bjp6w)&D5_1%Q z(pjm=B{8KXnK{KV@$s2?nI-Y@dIgoYIBatBQ%ZAE?TT1|7J-~n3}Sp@W@Kb6Vg|AR D6`nDX literal 0 HcmV?d00001 diff --git a/submissions/abdinasir97/python final project/utils/__pycache__/storage.cpython-314.pyc b/submissions/abdinasir97/python final project/utils/__pycache__/storage.cpython-314.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2c4079162b3143db983af41946d7db0f6646d274 GIT binary patch literal 4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-*(J_x8Sb z_Rm?0tnLTy!qLs6>iF&%ckO+5?Zk<{mwHCI+0qSHPhUEH`K?j@Vd=&(?fSWo&P}K@ zz8!acJH9IRJ}9c5;Ae{J?iSTSZ`R|z?)=C(zGM8vv?nlXeNeP+G<~^goL*@`ZcW{U z^h^6E`IGt6HI1Kr?+^61HNOx3COF;n<1gB#!~mL)S5RaijJcb7G7@GgaV@wjz8|M!~c)?(@T2{4Ml*M=~(w#YM2OqQm z_R?-N?dQr8ngcRRh|D6lD$??$1TY&<^js-e#CH=>0KF}%qUs`g`p7a&1%wduM7xPg ztHcd!*t*)+4cyCtza_-#?8_mU1Ci@RsML9i&=Gr4V;?!yFiWCgh zzXSgBjZjqpG>(uS(hl&d&#+Y;CsAZsN5tO=L?K2$0? zZx&H=XuABWY#(w_>>N~xruOrlKk1y|OEP@PSZtzaiZ8jxZ=ZE_jf7_1#TVav@68Vn zze{I}ORsiZ>d1H-CSL!f_v7AaZ^LwP1AI5wT^EH5!qmDS-m|wFSUkp!56rlO_uau; zg|jaA#l7$CMaBVzznv75A&2ygzz`R|7&kI+zcIF_LAY z8wL{N{*%POldO8|&9Fr}A-Av|;G?ans3X8!O8-GT56Mekxe7)-?|03(Dl)E$Y1if% y*OrWH%ZzJ##list[float]: + s = s.strip + if not s: + return [] + return[float(p.strip) for p in s.split(".")if p.split()] + +def is_colum_hearer_line(line:str)->bool: + return line.strip().lower().replace(" "," ") == FILE_HEADER.lower().replace(" "," ") + +def load_airport(path:Path, airport:airport)->None: + airport.clear() + try: + with open(path,"r",encoding="utf-8")as f: + for row in f: + line = row.strip() + if not line or line.startswith("#"): + continue + if is_colum_hearer_line(line): + continue + parts = line.split("|",2) + if len(parts) !=3: + continue + flen, name, seats_txt = parts[0].strip(), parts[1].strip(), parts(2) + try: + seats = purse_seat(seats_txt) + except ValueError: + continue + airport.add(planes(fleet_number = flen, name=name, seats=seats)) + + except FileNotFoundError: + pass + +def save_airport(path:Path, airport:airport)->None: + path.parent.mkdir(parents=True, exist_ok=True) + line=(f"colums:pipe-separated rows after the headerline\n f(FILE HEADER)\n") + for s in airport.all(): + seats_txt = ",".join(str(g) for g in s.seats) + line.append(f"(s.fleet_number) | (s.name)|(seats.txt)\n") + with open(path, "w", encoding="utf-8")as f: + f.writelines \ No newline at end of file