From 170013f99b3370ffc14dc2d263126d7d4baa9f3d Mon Sep 17 00:00:00 2001 From: asemasda Date: Fri, 18 Apr 2025 10:55:06 +0200 Subject: [PATCH 1/7] =?UTF-8?q?homework=20solutions=20(Q1=E2=80=93Q3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Customer Management System.py | 79 ++++++++++++++++++ Film Library Management System Project.py | 98 +++++++++++++++++++++++ Student Grades Processing.py | 70 ++++++++++++++++ movies.json | 8 ++ 4 files changed, 255 insertions(+) create mode 100644 Customer Management System.py create mode 100644 Film Library Management System Project.py create mode 100644 Student Grades Processing.py create mode 100644 movies.json diff --git a/Customer Management System.py b/Customer Management System.py new file mode 100644 index 0000000..4077989 --- /dev/null +++ b/Customer Management System.py @@ -0,0 +1,79 @@ +# Question 1: Use a dictionary structure to store customer info with unique ID +customers = {} + +# Question 2: Provide a menu for user actions +while True: + + print("\n1. Add new customer") + print("2. Update customer") + print("3. Delete customer") + print("4. List all customers") + print("5. Check out (exit)") + + choice = input("Choose an option: ") + + # Question 3: Perform action based on user choice — Add customer + if choice == "1": + customer_id = input("Enter customer ID: ") + first_name = input("Enter first name: ") + last_name = input("Enter last name: ") + email = input("Enter email: ") + phone = input("Enter phone number: ") + + customers[customer_id] = { + "first_name": first_name, + "last_name": last_name, + "email": email, + "phone": phone + } + + print("Customer added!") + + # Question 4: Update customer info using ID + elif choice == "2": + customer_id = input("Enter customer ID to update: ") + if customer_id in customers: + print("Current info:", customers[customer_id]) + first_name = input("New first name: ") + last_name = input("New last name: ") + email = input("New email: ") + phone = input("New phone number: ") + + customers[customer_id] = { + "first_name": first_name, + "last_name": last_name, + "email": email, + "phone": phone + } + print("Customer updated.") + else: + print("Customer not found.") + + # Question 5: Delete customer by ID + elif choice == "3": + customer_id = input("Enter customer ID to Delete: ") + if customer_id in customers: + del customers[customer_id] + print("Customer deleted.") + else: + print("Customer not found!") + + # Question 6: List all customers + elif choice =="4": + if customers: + for customer_id, info in customers.items(): + print("ID:", customer_id) + print("Name:", info["first_name"], info["last_name"]) + print("Email:", info["email"]) + print("Phone:", info["phone"]) + print("-" * 10) + else: + print("No customers yet.") + + # Question 7: Repeat until user logs out + elif choice == "5": + print("Exiting Customer Management System. Goodbye!") + break + + else: + print("Invalid option. Please choose 1–5.") \ No newline at end of file diff --git a/Film Library Management System Project.py b/Film Library Management System Project.py new file mode 100644 index 0000000..542c32d --- /dev/null +++ b/Film Library Management System Project.py @@ -0,0 +1,98 @@ +import json + + +# Question 4: Restore the movie data when the program starts +try: + with open("movies.json", "r") as file: + movie_library = json.load(file) +except FileNotFoundError: + movie_library = [] + + + + + +# Question 2: Delete a field from a movie +def delete_movie(movie): + key_to_delete = input("Which field do you want to delete? (e.g., genre): ") + if key_to_delete in movie: + del movie[key_to_delete] + print(f"{key_to_delete} was deleted.") + else: + print("That field does not exist.") + +# Question 3: View the movie collection (all, by genre, or year) +def view_movies(): + choice = input("View all movies (all), by genre (genre), or by year (year)?: ") + if choice == "all": + for m in movie_library: + print(m) + elif choice == "genre": + g = input("Enter genre: ") + for m in movie_library: + if "genre" in m and m["genre"].lower() == g.lower(): + print(m) + elif choice == "year": + y = input("Enter release year: ") + for m in movie_library: + if "Release year" in m and m["Release year"] == y: + print(m) + else: + print("Invalid option.") + +# Question 4: Save the movie data in a file +def save_to_file(): + with open("movies.json", "w") as file: + json.dump(movie_library, file, indent=4) + +# Question 1: Create a movie dictionary with user input +movie = { + "Movie name": input("Enter Movie: "), + "Release year": input("Enter release year: "), + "genre": input("Enter genre: "), + "director": input("Enter director: ") +} +movie_library.append(movie) +save_to_file() +print("First movie saved!") + + +while True: + print("\n Movie Library Menu:") + print("1. Add another movie") + print("2. View movies") + print("3. Delete a field from last added movie") + print("4. Exit") + + action = input("Choose an option: ") + + if action == "1": + new_movie = { + "Movie name": input("Enter Movie: "), + "Release year": input("Enter release year: "), + "genre": input("Enter genre: "), + "director": input("Enter director: ") + } + + + movie_library.append(new_movie) + print("Movie added!") + save_to_file() + + elif action == "2": + view_movies() + + elif action == "3": + if movie_library: + delete_movie(movie_library[-1]) + save_to_file() + else: + print("No movie to delete from.") + + elif action == "4": + print("Goodbye!") + save_to_file() + break + + else: + print("Invalid selection. Try again.") \ No newline at end of file diff --git a/Student Grades Processing.py b/Student Grades Processing.py new file mode 100644 index 0000000..7c965e5 --- /dev/null +++ b/Student Grades Processing.py @@ -0,0 +1,70 @@ +students = { + 'Ahmet Yılmaz': [85, 90, 78], + 'Mehmet Demir': [92, 88, 76], + 'Ayşe Kaya': [78, 89, 95], + 'Zeynep Çelik': [65, 70, 80], + 'Ali Kara': [50, 60, 55], + 'Fatma Yıldız': [88, 85, 90], + 'Murat Aydın': [72, 68, 74], + 'Elif Aksoy': [95, 90, 88], + 'Hakan Öztürk': [45, 50, 55], + 'Canan Taş': [80, 75, 82] +} + +# ---------------------------- +# Question 1: Calculate the GPA of each student +# ---------------------------- +top_student = None +top_gpa = 0 +low_gpa_students = set() # For Q5 + +print("GPAs:\n") +low_gpa_students = set() +for name, grades in students.items(): + gpa=sum(grades)/3 + + + # For Question 2 + if gpa > top_gpa: + top_gpa=gpa + top_student=name + + # For Question 5: Add to set if GPA is below 70 + if gpa < 70: + low_gpa_students.add(name) + print(f"{name}: {gpa:.2f}") + +# ---------------------------- +# Question 2: Print the student with the highest GPA +# ---------------------------- +print("\nTop student is:", top_student) +print("With GPA:", f"{top_gpa:.2f}") + + +# ---------------------------- +# Question 3: Separate names into (first_name, last_name) tuples +# ---------------------------- +name_tuples = [] + +for student in students: + first_name, last_name = student.split() + name_tuples.append((first_name, last_name)) + + +print("\nList of name tuples:") +print(name_tuples) + + +# ---------------------------- +# Question 4: Sort the name tuples alphabetically +# ---------------------------- + +name_tuples.sort() +print("Sorted names:") +print(name_tuples) + +# ---------------------------- +# Question 5: Print students with GPA below 70 (stored in a set) +# ---------------------------- +print("low gpa studnets") +print(low_gpa_students) diff --git a/movies.json b/movies.json new file mode 100644 index 0000000..d1e20d3 --- /dev/null +++ b/movies.json @@ -0,0 +1,8 @@ +[ + { + "Movie name": "Inception", + "Release year": "2010", + "genre": "Action", + "director": "Christopher" + } +] \ No newline at end of file From b61c21a60f72d4a98384c3e584a9a67def3b768c Mon Sep 17 00:00:00 2001 From: Israakhalayli Date: Fri, 18 Apr 2025 10:57:54 +0200 Subject: [PATCH 2/7] Homework --- Question_1.py | 41 +++++++++++++++++++++ Question_2.py | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ Question_3.py | 76 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 217 insertions(+) create mode 100644 Question_1.py create mode 100644 Question_2.py create mode 100644 Question_3.py diff --git a/Question_1.py b/Question_1.py new file mode 100644 index 0000000..1d090aa --- /dev/null +++ b/Question_1.py @@ -0,0 +1,41 @@ +#Question 1 +students={ + 'Ahmet Yilmaz':[85,90,78], + 'Mehmet Demir':[92,88,78], + 'Ayse Kaya':[78,89,95], + 'Zenep Celik':[65,70,80], + 'Ali Kara':[50,60,55], + 'Fatma Yildiz':[88,85,90], + 'Murat ydin':[72,68,74], + 'Elif Aksoy':[95,90,88], + 'Hakan Ozturk':[45,50,55], + 'Çanan Tas':[80,75,82] +} + +# create new dictionary for averages and names: +averages={name:round(sum(grade)/len(grade),2) for name, grade in students.items()} +print('Averages : ', averages ) +print('') + +#find the student with the highest GPA: +heighest_GPA_student=max(averages) +heighest_GPA=averages[heighest_GPA_student] +print('Heighest GPA : ',heighest_GPA_student , ' ' , heighest_GPA) + +print('') +#Separate each student's name from their surname and store them in a separate tuple and add them to a list +full_names=[( name.split()[0] ,name.split()[1] )for name in students.keys()] +print("Separate each student's name from their surname:") +print(full_names) + +print('') +#Sort the names in alphabetical order and print the sorted list on the screen +names=[name[0] for name in full_names] +names.sort() +print('Sort the names in alphabetical order: ') +print(names) + +print('') +#Keep students with a GPA below 70 in a cluster (set) +GPA_below_70={average for average in averages.values() if average<70} +print('students with a GPA below 70: ',GPA_below_70) \ No newline at end of file diff --git a/Question_2.py b/Question_2.py new file mode 100644 index 0000000..88be065 --- /dev/null +++ b/Question_2.py @@ -0,0 +1,100 @@ +#Question 2 +import json + +# Function to create a movie entry +def create_movie(): + movie_name = input("Enter movie name: ") + director = input("Enter director: ") + release_year = input("Enter release year: ") + genre = input("Enter genre: ") + movie = { + "name": movie_name, + "director": director, + "release_year": release_year, + "genre": genre + } + return movie + +# Function to edit a movie +def edit_movie(collection): + name_to_edit = input("Enter the name of the movie to edit: ") + for movie in collection: + if movie["name"] == name_to_edit: + print("Current details:", movie) + movie["name"] = input("Enter new movie name (or press Enter to keep current): ") + movie["director"] = input("Enter new director (or press Enter to keep current): ") + movie["release_year"] = input("Enter new release year (or press Enter to keep current): ") + movie["genre"] = input("Enter new genre (or press Enter to keep current): ") + print("Movie updated!") + print("Movie not found.") + +# Function to delete a movie +def delete_movie(collection): + name_to_delete = input("Enter the name of the movie to delete: ") + for movie in collection: + if movie["name"] == name_to_delete: + collection.remove(movie) + print(f"Movie '{name_to_delete}' deleted!") + + print("Movie not found.") + +# Function to view movies +def view_collection(collection): + choice = input("View all movies or filter by genre/year? (all/genre/year): ").lower() + if choice == "all": + for movie in collection: + print(movie) + elif choice == "genre": + genre = input("Enter genre to filter: ") + filtered_movies = [movie for movie in collection if movie["genre"].lower() == genre.lower()] + for movie in filtered_movies: + print(movie) + elif choice == "year": + year = input("Enter year to filter: ") + filtered_movies = [movie for movie in collection if movie["release_year"] == year] + for movie in filtered_movies: + print(movie) + else: + print("Invalid choice.") + +# Function to save data to a file +def save_data(collection): + with open("movies.json", "w") as file: + json.dump(collection, file) + print("Data saved successfully!") + +# Function to load data from a file +def load_data(): + try: + with open("movies.json", "r") as file: + return json.load(file) + except FileNotFoundError: + return [] + +# Main program loop +def main(): + movie_collection = load_data() + while True: + print("\nFilm Library Management System") + print("1. Add a movie") + print("2. Edit a movie") + print("3. Delete a movie") + print("4. View collection") + print("5. Save and Exit") + choice = input("Enter your choice (1-5): ") + if choice == "1": + movie_collection.append(create_movie()) + elif choice == "2": + edit_movie(movie_collection) + elif choice == "3": + delete_movie(movie_collection) + elif choice == "4": + view_collection(movie_collection) + elif choice == "5": + save_data(movie_collection) + print("Goodbye!") + break + else: + print("Invalid choice. Please try again.") + +main() diff --git a/Question_3.py b/Question_3.py new file mode 100644 index 0000000..ac0f347 --- /dev/null +++ b/Question_3.py @@ -0,0 +1,76 @@ +#Question 3 +customers_information={} + +def display_menu(): + print('1. Add new customers') + print('2.Updating customer information') + print('3.Delete customer') + print('4.List all customers') + print('5.Check out') + +def add_customer(): + id=input('Enter unique customer ID: ') + name=input('enter customer name: ') + surname=input('Enter customer surname: ') + email=input('Enter customer e-mail: ') + phone_number=input('Enter customer phone number: ') + customers_information[id]={ + 'Name':name, + 'Surname':surname, + 'Email':email, + 'Phone_number':phone_number + } + +def updating_customer_information(): + id=input('enter customer ID to update: ') + if id in customers_information: + name=input('Enter new name / leave blank to keep current: ') + surname=input('Enter customer surname / leave blank to keep current: ') + email=input('Enter customer e-mail / leave blank to keep current: ') + phone_number=input('Enter customer phone number / leave blank to keep current: ') + if name: + customers_information[id]['Name']=name + print('Update name is succesful! ') + if surname: + customers_information[id]['Surname']=surname + print('Update surname is succesful!') + if email: + customers_information[id]['Email']=email + print('Update email is succesful!') + if email: + customers_information[id]['Phone_number']=phone_number + print('Update phone number is succesful!') + else: + print(' Customer is not found ') + +def delete_customer(): + id = input ('Enter ID customer to delete: ') + if id in customers_information: + del customers_information[id] + print('delete customer is succesful! ') + else: + print('customer is not found') + +def list_all_customers(): + if customers_information: + for id,info in customers_information.items(): + print('ID: ',id ,'-','Info: ', info) + else: + print('no customers available') + +while True: + display_menu() + choise=input('Enter your choise: ') + if choise=='1': + add_customer() + elif choise=='2': + updating_customer_information() + elif choise=='3': + delete_customer() + elif choise=='4': + list_all_customers() + elif choise=='5': + print('Exiting the system ') + break + else: + print('Invalid choise, Try again!') From d9271e5e836fd75445de8bf9e3c83329e70d3e6b Mon Sep 17 00:00:00 2001 From: Israakhalayli Date: Fri, 18 Apr 2025 11:00:05 +0200 Subject: [PATCH 3/7] Homework --- movies.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 movies.json diff --git a/movies.json b/movies.json new file mode 100644 index 0000000..e6d1a32 --- /dev/null +++ b/movies.json @@ -0,0 +1 @@ +[{"name": "4", "director": "h", "release_year": "y]\\ty", "genre": "rt"}] \ No newline at end of file From 5a6cbbb40f118f2e13dee2a53526f9327d5fcc6c Mon Sep 17 00:00:00 2001 From: Israakhalayli Date: Fri, 18 Apr 2025 11:26:17 +0200 Subject: [PATCH 4/7] Homework --- Question_1.py => Israa_Question_1.py | 0 Question_2.py => Israa_Question_2.py | 0 Question_3.py => Israa_Question_3.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename Question_1.py => Israa_Question_1.py (100%) rename Question_2.py => Israa_Question_2.py (100%) rename Question_3.py => Israa_Question_3.py (100%) diff --git a/Question_1.py b/Israa_Question_1.py similarity index 100% rename from Question_1.py rename to Israa_Question_1.py diff --git a/Question_2.py b/Israa_Question_2.py similarity index 100% rename from Question_2.py rename to Israa_Question_2.py diff --git a/Question_3.py b/Israa_Question_3.py similarity index 100% rename from Question_3.py rename to Israa_Question_3.py From b9a65a6b431ffee2c01dfcffc9ccb6dcfc109960 Mon Sep 17 00:00:00 2001 From: asemasda Date: Fri, 18 Apr 2025 18:33:48 +0200 Subject: [PATCH 5/7] change file name --- Film Library Management System Project.py | 4 ++-- movies.json => mov.json | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename movies.json => mov.json (100%) diff --git a/Film Library Management System Project.py b/Film Library Management System Project.py index 542c32d..a796bd9 100644 --- a/Film Library Management System Project.py +++ b/Film Library Management System Project.py @@ -3,7 +3,7 @@ # Question 4: Restore the movie data when the program starts try: - with open("movies.json", "r") as file: + with open("mov.json", "r") as file: movie_library = json.load(file) except FileNotFoundError: movie_library = [] @@ -42,7 +42,7 @@ def view_movies(): # Question 4: Save the movie data in a file def save_to_file(): - with open("movies.json", "w") as file: + with open("mov.json", "w") as file: json.dump(movie_library, file, indent=4) # Question 1: Create a movie dictionary with user input diff --git a/movies.json b/mov.json similarity index 100% rename from movies.json rename to mov.json From a23b63f2ef2328e9742ddb159dda616b690b42d3 Mon Sep 17 00:00:00 2001 From: mabaz1985 Date: Fri, 18 Apr 2025 19:26:32 +0200 Subject: [PATCH 6/7] Mohammad homework Q1 --- Mohammad Q1.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Mohammad Q1.py diff --git a/Mohammad Q1.py b/Mohammad Q1.py new file mode 100644 index 0000000..e69de29 From f7d4c037ad9ccc95ff25f1887a6e77ab26c079a8 Mon Sep 17 00:00:00 2001 From: mabaz1985 Date: Fri, 18 Apr 2025 19:29:38 +0200 Subject: [PATCH 7/7] Mohammad honework --- Mohammad Q1.py | 42 ++++++++++++++ Mohammad Q2.py | 151 +++++++++++++++++++++++++++++++++++++++++++++++++ Mohammad Q3.py | 99 ++++++++++++++++++++++++++++++++ 3 files changed, 292 insertions(+) create mode 100644 Mohammad Q2.py create mode 100644 Mohammad Q3.py diff --git a/Mohammad Q1.py b/Mohammad Q1.py index e69de29..593a793 100644 --- a/Mohammad Q1.py +++ b/Mohammad Q1.py @@ -0,0 +1,42 @@ +# Question1: Student Grades Processing +students = { + 1: {'name': 'Ahmet Yilmaz', 'midterm': 85, 'final': 90, 'oral': 78}, + 2: {'name': 'Mehmet Demir', 'midterm': 92, 'final': 88, 'oral': 76}, + 3: {'name': 'Ayse Kaya', 'midterm': 78, 'final': 89, 'oral': 95}, + 4: {'name': 'Zeynep Celik', 'midterm': 50, 'final':60, 'oral': 55}, + 5: {'name': 'Ali Kara', 'midterm': 50, 'final': 60, 'oral': 55}, + 6: {'name': 'Fatma Yildiz', 'midterm': 88, 'final': 85, 'oral': 90}, + 7: {'name': 'Murat Aydin', 'midterm': 72, 'final': 68, 'oral': 74}, + 8: {'name': 'Elif Aksoy', 'midterm': 95, 'final': 90, 'oral': 88}, + 9: {'name': 'Hakan Öztürk', 'midterm': 45, 'final': 50, 'oral': 55}, + 10: {'name': 'Canan Tas', 'midterm': 80, 'final': 75, 'oral': 82} +} + +# 1. GPA +for student in students.values(): + gpa = (student['midterm'] * 0.3 + student['final'] * 0.5 + student['oral'] * 0.2) + student['GPA'] = gpa + +# 2. highest GPA +highest_gpa = max(students.items(), key=lambda item: item[1]['GPA']) +print("Student with highest GPA:") +print(f"{highest_gpa[1]['name']} with GPA: {highest_gpa[1]['GPA']}") + +# 3. Separate names and surnames +full_name = [] +for student in students.values(): + firstname, lastname = student['name'].split() + full_name.append((firstname, lastname)) + +# 4. Sort names alphabetically +sorted_names = sorted(full_name) +print("\nSorted names:") +for name in sorted_names: + print(name) + +# 5. Store students with GPA < 70 +low_gpa = {student['name'] for student in students.values() if student['GPA'] < 70} +print("\nStudents with GPA below 70:") +print(low_gpa) + + diff --git a/Mohammad Q2.py b/Mohammad Q2.py new file mode 100644 index 0000000..87c2db8 --- /dev/null +++ b/Mohammad Q2.py @@ -0,0 +1,151 @@ + +# Question 2: Film Library Management System Project +print("Question 2") +import json + +# File to store the movie data +MOVIE_FILE = 'movies.json' + +# Load movie data from file +def load_movies(): + name = input("Enter movie name: ") + director = input("Enter director: ") + year = input("Enter release year: ") + genre = input("Enter genre: ") + movie = { + "name": name, + "director": director, + "release_year": year, + "genre": genre + } + return movie + +# Save movie data to file +def save_movies(movies): + with open(MOVIE_FILE, 'w') as f: + json.dump(movies, f, indent=4) + +# Add a new movie +def add_movie(movies): + name = input("Enter movie name: ").strip() + if not name: + print("Movie name cannot be empty.") + return + if name in movies: + print("Movie already exists.") + return + director = input("Enter director: ").strip() + year = input("Enter release year: ").strip() + while not year.isdigit(): + year = input("Invalid year. Enter a valid release year: ").strip() + genre = input("Enter genre: ").strip() + + movies[name] = { + 'director': director, + 'year': year, + 'genre': genre + } + print("Movie added.") + +# Edit movie details +def edit_movie(movies): + name = input("Enter movie name to edit: ").strip() + if name not in movies: + print("Movie not found.") + return + print("What do you want to edit?") + print("1. Director") + print("2. Release Year") + print("3. Genre") + choice = input("Choose (1-3): ").strip() + if choice == '1': + movies[name]['director'] = input("Enter new director: ").strip() + elif choice == '2': + year = input("Enter new release year: ").strip() + while not year.isdigit(): + year = input("Invalid year. Enter a valid release year: ").strip() + movies[name]['year'] = year + elif choice == '3': + movies[name]['genre'] = input("Enter new genre: ").strip() + else: + print("Invalid choice.") + return + print("Movie updated.") + +# Delete a movie +def delete_movie(movies): + name = input("Enter movie name to delete: ").strip() + if name in movies: + del movies[name] + print("Movie deleted.") + else: + print("Movie not found.") + +# View the movie collection +def view_movies(movies): + print("1. View all movies") + print("2. Filter by genre") + print("3. Filter by release year") + choice = input("Choose an option: ").strip() + if choice == '1': + if not movies: + print("No movies in the library.") + else: + for name, details in movies.items(): + print(f"\nTitle: {name}") + print(f" Director: {details['director']}") + print(f" Year: {details['year']}") + print(f" Genre: {details['genre']}") + elif choice == '2': + genre = input("Enter genre to filter: ").strip().lower() + found = False + for name, details in movies.items(): + if details['genre'].lower() == genre: + print(f"\nTitle: {name}") + print(f" Director: {details['director']}") + print(f" Year: {details['year']}") + print(f" Genre: {details['genre']}") + found = True + if not found: + print("No movies found for that genre.") + elif choice == '3': + year = input("Enter release year to filter: ").strip() + found = False + for name, details in movies.items(): + if details['year'] == year: + print(f"\nTitle: {name}") + print(f" Director: {details['director']}") + print(f" Year: {details['year']}") + print(f" Genre: {details['genre']}") + found = True + if not found: + print("No movies found for that year.") + else: + print("Invalid choice.") + +# Main menu +def main(): + movies = load_movies() + while True: + print("\n--- Movie Library Menu ---") + print("1. Add Movie") + print("2. Edit Movie") + print("3. Delete Movie") + print("4. View Movies") + print("5. Exit") + choice = input("Choose an option: ").strip() + if choice == '1': + add_movie(load_movies) + elif choice == '2': + edit_movie(movies) + elif choice == '3': + delete_movie(movies) + elif choice == '4': + view_movies(movies) + elif choice == '5': + save_movies(movies) + print("Goodbye!") + break + else: + print("Invalid option.") +main() \ No newline at end of file diff --git a/Mohammad Q3.py b/Mohammad Q3.py new file mode 100644 index 0000000..eb31801 --- /dev/null +++ b/Mohammad Q3.py @@ -0,0 +1,99 @@ + + +# Question 3: Customer Management System +print("Question 3") +customers = {} +def add_customer(): + customer_id = input("Enter a unique Customer ID: ") + if customer_id in customers: + print("Customer ID already exists!") + return + name = input("Enter Customer's First Name: ") + surname = input("Enter Customer's Last Name: ") + email = input("Enter Customer's Email: ") + phone = input("Enter Customer's Phone Number: ") + + customers[customer_id] = { + 'Name': name, + 'Surname': surname, + 'Email': email, + 'Phone': phone + } + print(f"Customer {name} {surname} added successfully.") + +#Function to update customer information +def update_customer(): + customer_id = input("Enter the Customer ID to update: ") + if customer_id not in customers: + print("Customer not found!") + return + print("Current Information:") + print(customers[customer_id]) + + name = input("Enter new Customer's First Name: ") + surname = input("Enter new Customer's Last Name: ") + email = input("Enter new Customer's Email: ") + phone = input("Enter new Customer's Phone Number: ") + + customers[customer_id] = { + 'Name': name, + 'Surname': surname, + 'Email': email, + 'Phone': phone + } + print(f"Customer ID {customer_id} updated successfully.") + +# Function to delete a customer +def delete_customer(): + customer_id = input("Enter the Customer ID to delete: ") + if customer_id in customers: + del customers[customer_id] + print(f"Customer ID {customer_id} deleted successfully.") + else: + print("Customer not found!") + +# Function to list all customers +def list_customers(): + if customers: + for customer_id, info in customers.items(): + print(f"Customer ID: {customer_id}") + for key, value in info.items(): + print(f"{key}: {value}") + print("-" * 20) + else: + print("No customers available.") + +# Function to exit the system +def check_out(): + print("Logging out. Goodbye!") + exit() + +# Main +def customer_management_system(): + while True: + print("\nCustomer Management System") + print("1. Add new customer") + print("2. Update customer information") + print("3. Delete customer") + print("4. List all customers") + print("5. Check out (Exit)") + + choice = input("Please choose an action (1-5): ") + + if choice == '1': + add_customer() + elif choice == '2': + update_customer() + elif choice == '3': + delete_customer() + elif choice == '4': + list_customers() + elif choice == '5': + check_out() + else: + print("Invalid choice, please try again.") + +# Run the customer management system +customer_management_system() + +