From 819d71f121b5130029423adc95efab60a6d8d038 Mon Sep 17 00:00:00 2001 From: mirzabahcecinl Date: Thu, 23 Oct 2025 21:51:06 +0200 Subject: [PATCH 1/4] week_3_project_1 --- Project3_1.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Project3_1.py diff --git a/Project3_1.py b/Project3_1.py new file mode 100644 index 0000000..982cbde --- /dev/null +++ b/Project3_1.py @@ -0,0 +1,12 @@ +class Rectangle: + def __init__(self, width, height): + self.width = width + self.height = height + def area(self): + return self.width * self.height + def perimeter(self): + return 2 * (self.width + self.height) + +rectangle = Rectangle(5,7) +print("Area: ", rectangle.area()) +print("Perimeter: ", rectangle.perimeter()) \ No newline at end of file From 6e284908f7cff773716fc4b2576e70ea04067b52 Mon Sep 17 00:00:00 2001 From: mirzabahcecinl Date: Thu, 23 Oct 2025 22:58:02 +0200 Subject: [PATCH 2/4] Implement School class with student and teacher management --- Project3_2 | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Project3_2 diff --git a/Project3_2 b/Project3_2 new file mode 100644 index 0000000..9c88f4a --- /dev/null +++ b/Project3_2 @@ -0,0 +1,35 @@ +class School: + def __init__(self, name, fondation_year): + self.name = name + self.fondation_year = fondation_year + self.students = [] # ogrenciler listei + self.teachers = {} # ogretmenler sozlugu + + def add_new_student(self, student_name, student_class): + self.students.append({"name" : student_name, "class" : student_class}) + print(f"New Student added :{student_name} (class {student_class})") + + def add_new_teacher(self, teacher_name, branch): + self.teachers[teacher_name] = branch + print(f"New Teacher added : {teacher_name} (branch : {branch})") + + def view_student_list(self): + print("\nStudent_List") + for student in self.students: + print(f" - {student["name"]} (Class : {student["class"]})") + + def view_teacher_list(self): + print("\nTeacher List:") + for teacher, branch in self.teachers.items(): + print(f"- {teacher} (Branch: {branch})") + +school = School("Green Valley High School", 1998) + +school.add_new_student("Alice", "10A") +school.add_new_student("Bob", "9B") + +school.add_new_teacher("Mr. Smith", "Mathematics") +school.add_new_teacher("Ms. Johnson", "English") + +school.view_student_list() +school.view_teacher_list() From baf5af74a454ce9dce1e5e0d6554a18a212134c1 Mon Sep 17 00:00:00 2001 From: Ali Albayrak <140837941+aademey@users.noreply.github.com> Date: Fri, 24 Oct 2025 20:56:36 +0200 Subject: [PATCH 3/4] Add files via upload --- Project3_3.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Project3_3.py diff --git a/Project3_3.py b/Project3_3.py new file mode 100644 index 0000000..eefe6c0 --- /dev/null +++ b/Project3_3.py @@ -0,0 +1,21 @@ +class Shape: + def __init__(self,height,width): + self.height = height + self.width = width +class Rectangle(Shape): + def __init__(self,height,width): + super().__init__(height,width) + def area(self): + return self.height * self.width +class Square(Shape): + def __init__(self,side): + super().__init__(side,side) + def area(self): + return self.height * self.width +rect=Rectangle(10,15) +print(rect.area()) +sqr=Square(10) +print(sqr.area()) + + + From 9c0eb0e76326a020aa8d555e6a448090a187d914 Mon Sep 17 00:00:00 2001 From: BeyzaNurSarikaya <161241878+BeyzaNurSarikaya@users.noreply.github.com> Date: Sat, 25 Oct 2025 20:01:29 +0200 Subject: [PATCH 4/4] Add files via upload --- Question4.py | 40 ++++++++ Question5.py | 64 +++++++++++++ library.py | 264 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 368 insertions(+) create mode 100644 Question4.py create mode 100644 Question5.py create mode 100644 library.py diff --git a/Question4.py b/Question4.py new file mode 100644 index 0000000..84ea78a --- /dev/null +++ b/Question4.py @@ -0,0 +1,40 @@ +class Vehicle: + def __init__(self, make, model, year): + self.make = make + self.model = model + self.year = year + + def display_info(self): + print(f"Make: {self.make}") + print(f"Model: {self.model}") + print(f"Year: {self.year}") + + +class Off_Road_Vehicle(Vehicle): + def __init__(self, make, model, year, four_wheel_drive): + super().__init__(make, model, year) + self.four_wheel_drive = four_wheel_drive + + def display_info(self): + super().display_info() + print(f"Four Wheel Drive: {'Yes' if self.four_wheel_drive else 'No'}") + + +class Sports_Car(Vehicle): + def __init__(self, make, model, year, max_speed): + super().__init__(make, model, year) + self.max_speed = max_speed + + def display_info(self): + super().display_info() + print(f"Max Speed: {self.max_speed} km/h") + + +offroad = Off_Road_Vehicle("Jeep", "Wrangler", 2023, True) +sports_Car = Sports_Car("Ferrari", "F8 Tributo", 2022, 340) + + + +offroad.display_info() + +sports_Car.display_info() \ No newline at end of file diff --git a/Question5.py b/Question5.py new file mode 100644 index 0000000..6432b65 --- /dev/null +++ b/Question5.py @@ -0,0 +1,64 @@ +class Customer: + def __init__(self, name, surname, tc_identification, phone): + self.name = name + self.surname = surname + self.tc_identification = tc_identification + self.phone = phone + + # def display_information(self): + # print(f"Name: {self.name}") + # print(f"Surname: {self.surname}") + # print(f"TC: {self.tc_identification}") + # print(f"Phone: {self.phone}") + + def __str__(self): + return ( + f"Customer Information\n" + f"---------------------------\n" + f"Name & Surname : {self.name} {self.surname}\n" + f"TC ID Number : {self.tc_identification}\n" + f"Phone Number : {self.phone}" + ) + + + +class Account(Customer): + def __init__(self, name, surname, tc_identification, phone, account_number, balance): + super().__init__(name, surname, tc_identification, phone) + self.account_number = account_number + self.balance = balance + + def deposit(self, amount): + if amount > 0: + self.balance += amount + print(f"{amount} TL deposited successfully.") + + def money_check(self, amount): + if amount <= 0: + print("Withdrawal amount must be positive.") + elif amount > self.balance: + print(f"Insufficient balance! Your current balance is {self.balance} TL.") + else: + self.balance -= amount + print(f"{amount} TL withdrawn successfully.") + + def display_balance(self): + print(f"Account Number: {self.account_number}") + print(f"Current Balance: {self.balance:,.2f} TL") + + +customer_account = Account("Beyza Nur", "Sarıkaya", "12345678910", "0555-123-4567", "TR123456789", 5000) + +print(customer_account.__str__()) + + +customer_account.deposit(2000) + +customer_account.money_check(1000) + +customer_account.money_check(7000) +customer_account.display_balance() + + +print(customer_account.__str__()) + diff --git a/library.py b/library.py new file mode 100644 index 0000000..3ef68e0 --- /dev/null +++ b/library.py @@ -0,0 +1,264 @@ +import json +import os + +# Book Classes +class Book: + def __init__(self, title, author, publication_year,): + self.title = title + self.author = author + self.publication_year = publication_year + self.is_borrowed = False + self.borrowed_by = None + + + def show_info(self): + status = f"Borrowed by: {self.borrowed_by}" if self.is_borrowed else "Available" + print(f"{self.title} by {self.author} ({self.publication_year}) - {status}") + + + def borrow(self, user): + if not self.is_borrowed: + self.is_borrowed = True + self.borrowed_by = user.name + user.borrowed_books.append(self.title) + print(f"{user.name} borrowed {self.title}.") + else: + print("Book is already borrowed.") + + + def return_book(self, user): + if self.is_borrowed and self.borrowed_by == user.name: + self.is_borrowed = False + self.borrowed_by = None + user.borrowed_books.remove(self.title) + print(f"{user.name} returned {self.title}.") + else: + print("You cannot return this book.") + + + def to_dict(self): + return { + "type": self.__class__.__name__, + "title": self.title, + "author": self.author, + "publication_year": self.publication_year, + "is_borrowed": self.is_borrowed, + "borrowed_by": self.borrowed_by + } + + + + +class Novel(Book): + def __init__(self, title, author, publication_year, genre): + super().__init__(title, author, publication_year) + self.genre = genre + + def to_dict(self): + data = super().to_dict() + data["genre"] = self.genre + return data + + +class Magazine(Book): + def __init__(self, title, author, publication_year, issue): + super().__init__(title, author, publication_year) + self.issue = issue + + def to_dict(self): + data = super().to_dict() + data["issue"] = self.issue + return data + + +# ------------------------------------- +# User Class +class User: + def __init__(self, name, password): + self.name = name + self.password = password + self.borrowed_books = [] + + def borrow_book(self, book): + book.borrow(self) + + def return_book(self, book): + book.return_book(self) + + def list_borrowed_books(self): + if not self.borrowed_books: + print("No borrowed books.") + else: + print("Borrowed Books:") + for title in self.borrowed_books: + print(f"- {title}") + + def to_dict(self): + return { + "name": self.name, + "password": self.password, + "borrowed_books": self.borrowed_books + } + + + +# --------------------------------------------------- +# Library Class + +class Library: + def __init__(self, name): + self.name = name + self.books = [] + self.users = [] + + def add_book(self, book): + self.books.append(book) + + def add_user(self, user): + self.users.append(user) + + def find_user(self, name): + for user in self.users: + if user.name == name: + return user + return None + + def find_book(self, title): + for book in self.books: + if book.title.lower() == title.lower(): + return book + return None + + def show_all_books(self): + print("\n All Books in Library:") + for book in self.books: + book.show_info() + + def login(self, name, password): + user = self.find_user(name) + if user and user.password == password: + print(f"Welcome, {name}") + return user + print("Invalid username or password.") + return None + + def save(self, filename): + data = { + "name": self.name, + "books": [b.to_dict() for b in self.books], + "users": [u.to_dict() for u in self.users] + } + with open(filename, "w") as f: + json.dump(data, f, indent=4) + print("Data saved successfully.") + + def load(self, filename): + if not os.path.exists(filename): + print("No saved data found, opening new file.") + return + with open(filename, "r") as f: + data = json.load(f) + self.name = data["name"] + self.books = [] + self.users = [] + + for b in data["books"]: + if b["type"] == "Novel": + book = Novel(b["title"], b["author"], b["publication_year"], b.get("genre", "Unknown")) + elif b["type"] == "Magazine": + book = Magazine(b["title"], b["author"], b["publication_year"], b.get("issue", "N/A")) + else: + book = Book(b["title"], b["author"], b["publication_year"]) + book.is_borrowed = b["is_borrowed"] + book.borrowed_by = b["borrowed_by"] + self.books.append(book) + + + for u in data["users"]: + user = User(u["name"], u["password"]) + user.borrowed_books = u["borrowed_books"] + self.users.append(user) + + print("Data loaded successfully.") + + + +# ----------------------------------- +# Main Program + +def main(): + library = Library("Yellowstone Library") + filename = "library_data.json" + library.load(filename) + + print("\n Welcome to the Library Management System") + current_user = None + + while not current_user: + print("\n1 - Login") + print("2 - Create Account") + print("3 - Exit") + choice = input("Select option: ") + + if choice == "1": + name = input("Name: ") + password = input("Password: ") + current_user = library.login(name, password) + + elif choice == "2": + name = input("Create username: ") + password = input("Create password: ") + if library.find_user(name): + print("User already exists.") + else: + user = User(name, password) + library.add_user(user) + print("Account created successfully.") + + elif choice == "3": + print("👋 Exiting program... Goodbye!") + exit() + else: + print("Invalid option.") + + + while True: + print(f"\n Logged in as: {current_user.name}") + print("1 - List all books") + print("2 - Borrow a book") + print("3 - Return a book") + print("4 - Show my borrowed books") + print("5 - Save and exit") + + option = input("Choose: ") + + if option == "1": + library.show_all_books() + elif option == "2": + title = input("Enter book title to borrow: ") + book = library.find_book(title) + if book: + current_user.borrow_book(book) + else: + print("Book not found.") + elif option == "3": + title = input("Enter book title to return: ") + book = library.find_book(title) + if book: + current_user.return_book(book) + else: + print("Book not found.") + elif option == "4": + current_user.list_borrowed_books() + elif option == "5": + library.save(filename) + print("Goodbye!") + break + else: + print("Invalid choice.") + + +if __name__ == "__main__": + main() + +