diff --git a/Question1.py b/Question1.py new file mode 100644 index 0000000..12419da --- /dev/null +++ b/Question1.py @@ -0,0 +1,47 @@ +#We already have this in a dictionary called students +students = { + 'Ahmet Yilmaz': [85, 90, 78], #Each student has 3 grades: Midterm, Final, and Oral + 'Mehmet Demir': [92, 88, 76], + 'Ayse Kaya': [78, 89, 95], + 'Zeynep Celik': [65, 70, 80], + 'Ali Kara': [50, 60, 55], + 'Fatma Yildiz': [88, 85, 90], + 'Murat Aydin': [72, 68, 74], + 'Elif Aksoy': [95, 90, 88], + 'Hakan Ozturk': [45, 50, 55], + 'Canan Tas': [80, 75, 82] +} + +# 1. Calculate GPA and add to dictionary +for name, grades, in students.items(): #We loop through the dictionary and add GPA to each student's info .... + midterm, final, oral = grades + print(grades) + print(type(grades)) + gpa = (midterm * 0.3) + (final * 0.5) + (oral * 0.2) + students[name].append(round(gpa, 2)) #students[name]- gets the list of grades +print(students) #.append(...)- adds something to the end of the list.So it's the 4th value in position, but index 3 in code + #round(gpa, 2)- rounds the GPA to 2 decimal places + +# 2. Find student with highest GPA +highest_gpa = 0 #for now 0 , We'll update it later +top_student = "" #empty string, we dont know the best student yet +for name, grades in students.items(): #loop through the dictionary + if grades[3] > highest_gpa: #check if the student's GPA (grades[3]) higher than the current highest + highest_gpa = grades[3] #update highest_gpa to this student’s GPA + top_student = name #save the top_student name +print(f"Top student: {top_student} with GPA {highest_gpa}") + +# 3. Separate names and surnames into a tuple list +name_tuples = [] #create an empty list +for full_name in students: #loop through the dictionary . students is a dictionary + first, last = full_name.split() + name_tuples.append((first, last)) #create a tuple first , last. add it to the list name_tuples +print(name_tuples) + +# 4. Sort names alphabetically and print +sorted_names = sorted([first for first, last in name_tuples]) #sorted() function :sorts the lists in alphabetical order +print("Sorted first names:", sorted_names) #prints the list of names in order + +# 5. Students with GPA < 70 in a set #{name for ... if ...} create a set +low_gpa_students = {name for name, grades in students.items() if grades[3] < 70} #check their GPA, which is the 4th value in the list (index 3) +print("Students with GPA < 70:", low_gpa_students) #if GPA is less than 70 , the student is added to the group diff --git a/Question2.py b/Question2.py new file mode 100644 index 0000000..bb2f2e7 --- /dev/null +++ b/Question2.py @@ -0,0 +1,109 @@ +#1)Create a movie +def create_movie(): + name = input("Enter movie name: ") + director = input("Enter director: ") + year = input("Enter release year: ") + genre = input("Enter genre: ") + + movie = { #create a dictionary + "name": name, #"name" is the key, and the movie name is its value + "director": director, + "year": year, + "genre": genre + } + return movie + +#2)Edit or delete a movie +def edit_movie(movie): + print("Editing movie:", movie["name"]) + fields = {"1":"name", "2":"director", "3": "year", "4": "genre"} #fields is a dictionary that maps user choices (like "1") to the keys in the movie dictionary (like "name") + + print("1. Name\n2. Director\n3. Year\n4. Genre") #print("1. Name") + #print("2. Director") + #print("3. Year") + #print("4. Genre") + choice = input("What do you want to edit? (1-4): ") + + if choice in fields: + new_value = input(f"Enter new {fields[choice]}: ") + movie[fields[choice]] = new_value + else: + print("Invalid choice.") + + return movie + +def delete_movie(collection, name): + for movie in collection: #goes through the list of movies + if movie ["name"].lower() == name.lower(): #if the name matches, it removes the movie from the list + collection.remove(movie) #use .lower() to make sure it matches even if the user uses different capital letters + print("Movie deleted.") + return + print("Movie not found") + +#3)Allow the user to view their collection. List all movies or filter by criteria such as genre or year of release. +def view_movies(collection): + print("1. View all\n2. Filter by genre\n3. Filter by year" ) + choice = input("Choose an option: ") + + if choice == '1': + for movie in collection: + print(movie) + elif choice == '2': + genre = input("Enter genre: ") + for movie in collection: + if movie["genre"].lower() == genre.lower(): + print(movie) + elif choice == '3': + year = input("Enter year: ") + for movie in collection: + if movie["year"] == year: + print(movie) + else: + print("Invalid option.") + +#4-Save the movie data in a file and restore this data when you start the program. +import json + +def save_to_file(collection, filename="movies.json"): + with open(filename, "w") as f: + json.dump(collection, f) + +def load_from_file(filename="movies.json"): + try: + with open(filename, "r") as f: + return json.load(f) + except FileNotFoundError: + return [] + + +def main(): + movies = load_from_file() + + while True: + print("\n1. Add movie\n2. Edit movie\n3. Delete movie\n4. View collection\n5. Save and Exit") + choice = input("Enter your choice: ") + + if choice == '1': + movie = create_movie() + movies.append(movie) + elif choice == '2': + name = input("Enter the movie name to edit: ") + for m in movies: + if m["name"].lower() == name.lower(): + edit_movie(m) + break + else: + print("Movie not found.") + elif choice == '3': + name = input("Enter the movie name to delete: ") + delete_movie(movies, name) + elif choice == '4': + view_movies(movies) + elif choice == '5': + save_to_file(movies) + print("Collection saved. Goodbye!") + break + else: + print("Invalid choice. Try again.") + +main() diff --git a/Question3.py b/Question3.py new file mode 100644 index 0000000..002aabd --- /dev/null +++ b/Question3.py @@ -0,0 +1,103 @@ +#Question 3: Customer Management System +#1)Use a dictionary structure to store customer information. +# Assign a unique customer identification (ID) for each customer and associate customer information with this ID. +# You can use a dictionary containing information such as name, surname, e-mail, phone number for each customer. +customers = {} #empty dictionary to hold all customers record + #the key will be the Customer ID + #the value will be another dictionary with customer details + +#2)Provide a menu where the user can choose the following actions: +#3)Add New Customer +def add_customer(customers): + cid = input("Enter customer ID: ") + + if cid in customers: + print("Customer ID already exists.") + return + + name = input("Enter name: ") + surname = input("Enter surname: ") + email = input("Enter email: ") + phone = input("Enter phone number: ") + + customers[cid] = { + "name": name, + "surname": surname, + "email": email, + "phone": phone + } + + print("Customer added successfully.") + +#4)Update Customer Info +def update_customer(customers): + cid = input("Enter customer ID to update: ") + + if cid not in customers: # check if the ID exists + print("Customer not found.") + return + + print("Current info:", customers[cid]) + #get new info from the user + name = input("Enter new name: ") + surname = input("Enter new surname: ") + email = input("Enter new email: ") + phone = input("Enter new phone number: ") + + customers[cid] = { #update the customer details + "name": name, + "surname": surname, + "email": email, + "phone": phone + } + + print("Customer updated.") + +#5)Delete a Customer +def delete_customer(customers): + cid = input("Enter customer ID to delete: ") + + if cid in customers: #check if the ID exists + del customers[cid] #del removes an item from a dictionary + print("Customer deleted.") + else: + print("Customer not found.") + +#6)List All Customers +def list_customers(customers): + if not customers: + print("No customers in the system.") + return + #Loop through all customers and print their details + for cid, info in customers.items(): #.items() lets us loop through the key and value in the dictionary + print(f"ID: {cid}, Name: {info['name']} {info['surname']}, Email: {info['email']}, Phone: {info['phone']}") + +#7)Menu System (Loop until logout) +def main(): + customers = {} # main dictionary to store customer data.start with an empty dictionary for customers + + while True: #display the menu + print("\nCustomer Management System") + print("1. Add Customer") + print("2. Update Customer") + print("3. Delete Customer") + print("4. List All Customers") + print("5. Exit") + + choice = input("Choose an option (1-5): ") + + if choice == "1": + add_customer(customers) + elif choice == "2": + update_customer(customers) + elif choice == "3": + delete_customer(customers) + elif choice == "4": + list_customers(customers) + elif choice == "5": + print("Goodbye!") + break + else: + print("Invalid choice. Please try again.") + +main() \ No newline at end of file diff --git a/arch.text b/arch.text new file mode 100644 index 0000000..7469fc2 --- /dev/null +++ b/arch.text @@ -0,0 +1,4 @@ +saban|ertem|1973|komedi +hababam|ertem egilmez|1982|komedi +sut|nuri bilge ceylan|2012|dram +seker|nuri bilge ceylan|2014|dram diff --git a/filmler.json b/filmler.json new file mode 100644 index 0000000..c09f54a --- /dev/null +++ b/filmler.json @@ -0,0 +1,12 @@ +{ + "sefiller": { + "yil": "2001", + "yonetmen": "ahmet ss", + "tur": "dram" + }, + "yeni sefiller": { + "yil": "2005", + "yonetmen": "yeni ahmet", + "tur": "yeni dram" + } +} \ No newline at end of file diff --git a/ic_week_2_1.py b/ic_week_2_1.py new file mode 100644 index 0000000..d220459 --- /dev/null +++ b/ic_week_2_1.py @@ -0,0 +1,90 @@ +# Öğrenci isimlerini ve notlarının girişi ve oratlama hesabı + + +# i=1 +# ogrenciler = {} +# while i<=10: + +# adi=str(input("Öğrenci adını giriniz:")) +# final = float(input("Öğrenci final notunu giriniz:")) +# vize = float(input("Öğrenci vize notunu giriniz:")) +# notlar=[final, vize, (final + vize) / 2] +# ogrenciler[adi]= [notlar] + +# i += 1 +# print(ogrenciler) + +students = { + 'Ahmet Yılmaz': [85, 90, 78], # Midterm: 85, Final: 90, Oral: 78 + 'Mehmet Demir': [92, 88, 76], # Midterm: 92, Final: 88, Oral: 76 + 'Ayşe Kaya': [78, 89, 95], # Midterm: 78, Final: 89, Oral: 95 + 'Zeynep Çelik': [65, 70, 80], # Midterm: 65, Final: 70, Oral: 80 + 'Ali Kara': [50, 60, 55], # Midterm: 50, Final: 60, Oral: 55 + 'Fatma Yıldız': [88, 85, 90], # Midterm: 88, Final: 85, Oral: 90 + 'Murat Aydın': [72, 68, 74], # Midterm: 72, Final: 68, Oral: 74 + 'Elif Aksoy': [95, 90, 88], # Midterm: 95, Final: 90, Oral: 88 + 'Hakan Öztürk': [45, 50, 55], # Midterm: 45, Final: 50, Oral: 55 + 'Canan Taş': [80, 75, 82] # Midterm: 80, Final: 75, Oral: 82 +} +en_yuksek_ort = max(students.items(), key=lambda x: x[1][2]) +print(f"En yüksek ortalamaya sahip öğrenci: {en_yuksek_ort[0]} Ortalama: {en_yuksek_ort[1][2]}") + +# Ad ve Soyad bilgilerini ayırma + +students = { + 'Ahmet Yılmaz': [85, 90, 78], # Midterm: 85, Final: 90, Oral: 78 + 'Mehmet Demir': [92, 88, 76], # Midterm: 92, Final: 88, Oral: 76 + 'Ayşe Kaya': [78, 89, 95], # Midterm: 78, Final: 89, Oral: 95 + 'Zeynep Çelik': [65, 70, 80], # Midterm: 65, Final: 70, Oral: 80 + 'Ali Kara': [50, 60, 55], # Midterm: 50, Final: 60, Oral: 55 + 'Fatma Yıldız': [88, 85, 90], # Midterm: 88, Final: 85, Oral: 90 + 'Murat Aydın': [72, 68, 74], # Midterm: 72, Final: 68, Oral: 74 + 'Elif Aksoy': [95, 90, 88], # Midterm: 95, Final: 90, Oral: 88 + 'Hakan Öztürk': [45, 50, 55], # Midterm: 45, Final: 50, Oral: 55 + 'Canan Taş': [80, 75, 82] # Midterm: 80, Final: 75, Oral: 82 +} + +ad_soyad_tuple = [] +ad_soyad_tuple = tuple((ad_soyad.split()[0], ad_soyad.split()[1]) for ad_soyad in students.keys()) +print(ad_soyad_tuple) +print(type(ad_soyad_tuple)) +# İsme göre sıralama + +students = { + 'Ahmet Yılmaz': [85, 90, 78], # Midterm: 85, Final: 90, Oral: 78 + 'Mehmet Demir': [92, 88, 76], # Midterm: 92, Final: 88, Oral: 76 + 'Ayşe Kaya': [78, 89, 95], # Midterm: 78, Final: 89, Oral: 95 + 'Zeynep Çelik': [65, 70, 80], # Midterm: 65, Final: 70, Oral: 80 + 'Ali Kara': [50, 60, 55], # Midterm: 50, Final: 60, Oral: 55 + 'Fatma Yıldız': [88, 85, 90], # Midterm: 88, Final: 85, Oral: 90 + 'Murat Aydın': [72, 68, 74], # Midterm: 72, Final: 68, Oral: 74 + 'Elif Aksoy': [95, 90, 88], # Midterm: 95, Final: 90, Oral: 88 + 'Hakan Öztürk': [45, 50, 55], # Midterm: 45, Final: 50, Oral: 55 + 'Canan Taş': [80, 75, 82] # Midterm: 80, Final: 75, Oral: 82 +} + +ad_soyad_tuple = [] +ad_soyad_tuple = tuple((ad_soyad.split()[0], ad_soyad.split()[1]) for ad_soyad in students.keys()) +ad_soyad_sort = sorted(ad_soyad_tuple) +print(ad_soyad_sort) +# GNO ortalaması 70 altında olan öğrencileri bir listede toplama + +students = { + 'Ahmet Yılmaz': [85, 90, 78], # Midterm: 85, Final: 90, Oral: 78 + 'Mehmet Demir': [92, 88, 76], # Midterm: 92, Final: 88, Oral: 76 + 'Ayşe Kaya': [78, 89, 95], # Midterm: 78, Final: 89, Oral: 95 + 'Zeynep Çelik': [65, 70, 80], # Midterm: 65, Final: 70, Oral: 80 + 'Ali Kara': [50, 60, 55], # Midterm: 50, Final: 60, Oral: 55 + 'Fatma Yıldız': [88, 85, 90], # Midterm: 88, Final: 85, Oral: 90 + 'Murat Aydın': [72, 68, 74], # Midterm: 72, Final: 68, Oral: 74 + 'Elif Aksoy': [95, 90, 88], # Midterm: 95, Final: 90, Oral: 88 + 'Hakan Öztürk': [45, 50, 55], # Midterm: 45, Final: 50, Oral: 55 + 'Canan Taş': [80, 75, 82] # Midterm: 80, Final: 75, Oral: 82 +} + +gno_70 = [] +for adsoyad, notlar in students.items(): + if notlar[2] < 70: + gno_70.append((adsoyad, notlar[2])) +print(gno_70) + diff --git a/ic_week_2_2.py b/ic_week_2_2.py new file mode 100644 index 0000000..fcc95fb --- /dev/null +++ b/ic_week_2_2.py @@ -0,0 +1,82 @@ +# Film kolleksiyonu oluşturma ve yönetme + +import json + +# Film verilerini başta yükle +try: + with open("filmler.json", "r", encoding="utf-8") as f: + filmler = json.load(f) +except FileNotFoundError: + filmler = {} + +# Film Menüsü +msayi = int(input("Film ekleme için 1'e, \nfilm listelemek için 2'ye, \nfilm güncelleme için 3'e, \nfilm silmek için 4'e basın: ")) +if msayi == 1: + + #Film Kolleksiyon Girişi + + while True: + film_adi = input("Film adı (çıkmak için 'q' girin): ") + if film_adi.lower() == 'q': + break + yil = input("Yıl: ") + yonetmen = input("Yönetmen: ") + tur = input("Tür: ") + + # Film bilgilerini sözlükte sakla + filmler[film_adi] = { + 'yil': yil, + 'yonetmen': yonetmen, + 'tur': tur + } + + with open("filmler.json", "w", encoding="utf-8") as f: + json.dump(filmler, f, ensure_ascii=False, indent=4) + print(f"{film_adi} filmi koleksiyona eklendi.") + +elif msayi == 2: + # Film Listeleme (Tüm Liste veya Türe göre Filtreleme) + filtre = input("Filtrelemek ister misiniz? (E/H): ").lower() + if filtre == 'e': + tur_filtre = input("Filtrelemek istediğiniz tür: ") + print(f"{tur_filtre} türündeki filmler:") + for film, bilgiler in filmler.items(): + if bilgiler['tur'].lower() == tur_filtre.lower(): + print(f"Film: {film}, Yıl: {bilgiler['yil']}, Yönetmen: {bilgiler['yonetmen']}, Tür: {bilgiler['tur']}") + else: + print("Tüm filmler:") + for film, bilgiler in filmler.items(): + print(f"Film: {film}, Yıl: {bilgiler['yil']}, Yönetmen: {bilgiler['yonetmen']}, Tür: {bilgiler['tur']}") + + +elif msayi == 3: + # Film Güncelleme + film_adi = input("Güncellemek istediğiniz film adı: ") + if film_adi in filmler: + yil = input("Yeni yıl: ") + yonetmen = input("Yeni yönetmen: ") + tur = input("Yeni tür: ") + + # Film bilgilerini güncelle + filmler[film_adi] = { + 'yil': yil, + 'yonetmen': yonetmen, + 'tur': tur + } + with open("filmler.json", "w", encoding="utf-8") as f: + json.dump(filmler, f, ensure_ascii=False, indent=4) + print(f"{film_adi} filmi güncellendi.") + else: + print(f"{film_adi} filmi bulunamadı.") + +elif msayi == 4: + + # Film Silme + film_adi = input("Silmek istediğiniz film adı: ") + if film_adi in filmler: + del filmler[film_adi] + with open("filmler.json", "w", encoding="utf-8") as f: + json.dump(filmler, f, ensure_ascii=False, indent=4) + print(f"{film_adi} filmi silindi.") + else: + print(f"{film_adi} filmi bulunamadı.") diff --git a/ic_week_2_3.py b/ic_week_2_3.py new file mode 100644 index 0000000..6f4bc7e --- /dev/null +++ b/ic_week_2_3.py @@ -0,0 +1,111 @@ +# Müşteri Yönetim Sistemi + +import json + +# Müşteri verilerini başta yükle +try: + with open("musteriler.json", "r", encoding="utf-8") as f: + musteriler = json.load(f) +except FileNotFoundError: + musteriler = {} + +# Müşteri Yönemit Sistemi Ana Menüsü +# msayi = int(input("Müşteri Ekleme için 1'e, \nMüşteri Bilgilerini Listelemek için 2'ye, \nMüşteri Bilgilerini Güncelleme için 3'e, \nMüşteri Silmek için 4'e,\nProgramdan Çıkmak için 5'e basın: ")) +# if msayi == 1: + + #Müşteri Bilgi Girişi + +while True: + # Müşteri Yönemit Sistemi Ana Menüsü + # Kullanıcıdan işlem seçmesini iste + msayi = int(input("\n1- Müşteri Ekleme \n2- Müşteri Bilgilerini Listeleme \n3- Müşteri Bilgilerini Güncelleme \n4- Müşteri Silmek\n5- Programdan Çıkış \n\nDevam etmek için bir sayı giriniz :")) + if msayi == 1: + + # Müşteri Bilgi Girişi + while True: + mid = input("Müsteri ID giriniz veya \n(**Müşteri Eklemeden Çıkmak Q'ya basınız**): ") + if mid.lower() == "q": + print("Müşteri ekleme işlemi iptal edildi.") + break + elif mid in musteriler: + print("Bu müşteri ID'si zaten mevcut.") + continue + + # Müşteri bilgilerini al + adi = input("Adı : ") + soyadi = input("Soyadı: ") + eposta = input("E-posta: ") + telefon = input("Telefon: ") + + # Müşteri bilgilerini sözlükte sakla + musteriler[mid] = { + 'adi': adi, + 'soyadi': soyadi, + 'eposta': eposta, + 'telefon': telefon + } + + # Müşteri bilgilerini JSON dosyasına yaz + with open("musteriler.json", "w", encoding="utf-8") as f: + json.dump(musteriler, f, ensure_ascii=False, indent=4) + print(f"{mid} {adi} {soyadi} programa kayıt edildi.") + + elif msayi == 2: + # Müşteri Listeleme (Tüm Liste veya Türe göre Filtreleme) + filtre = input("Filtrelemek ister misiniz? (E/H): ").lower() + if filtre == 'e': + adi_filtre = input("Filtrelemek istediğiniz Adlar: ") + print(f"{adi_filtre} Adındaki Müşteriler:") + for musteri, bilgiler in musteriler.items(): + if bilgiler['adi'].lower() == adi_filtre.lower(): + print(f"Müşteri: {musteri} Adı: {bilgiler['adi']}, Soyadı: {bilgiler['soyadi']}, E-Posta: {bilgiler['eposta']}, Telefon: {bilgiler['telefon']}") + else: + print("Tüm Müşteriler:") + for musteri, bilgiler in musteriler.items(): + print(f"Müşteri: {musteri} Adı: {bilgiler['adi']}, Soyadı: {bilgiler['soyadi']}, E-Posta: {bilgiler['eposta']}, Telefon: {bilgiler['telefon']}") + + # Müşteri Bilgilerini Güncelleme + elif msayi == 3: + + print("Tüm Müşteriler:") + for musteri, bilgiler in musteriler.items(): + print(f"Müşteri: {musteri} Adı: {bilgiler['adi']}, Soyadı: {bilgiler['soyadi']}, E-Posta: {bilgiler['eposta']}, Telefon: {bilgiler['telefon']}") + + musteri_id = input("Güncellemek istediğiniz Müşteri ID: ") + if musteri_id in musteriler: + adi = input("Yeni Adı: ") + soyadi = input("Yeni Soyadı: ") + eposta = input("Yeni E-Posta: ") + telefon = input("Yeni telefon: ") + + # Müşteri bilgilerini güncelle + musteriler[musteri_id] = { + 'adi': adi, + 'soyadi': soyadi, + 'eposta': eposta, + 'telefon': telefon + } + with open("musteriler.json", "w", encoding="utf-8") as f: + json.dump(musteriler, f, ensure_ascii=False, indent=4) + print(f"{musteri_id} nolu müşteri güncellendi.") + else: + print(f"{musteri_id} nolu müşteri bulunamadı.") + + # Müşteri Bilgilerini Silme + elif msayi == 4: + print("Tüm Müşteriler:") + for musteri, bilgiler in musteriler.items(): + print(f"Müşteri: {musteri} Adı: {bilgiler['adi']}, Soyadı: {bilgiler['soyadi']}, E-Posta: {bilgiler['eposta']}, Telefon: {bilgiler['telefon']}") + + musteri_id = input("Silmek istediğiniz Müşteri ID: ") + if musteri_id in musteriler: + del musteriler[musteri_id] + with open("musteriler.json", "w", encoding="utf-8") as f: + json.dump(musteriler, f, ensure_ascii=False, indent=4) + print(f"{musteri_id} nolu müşteri silindi.") + else: + print(f"{musteri_id} nolu müşteri bulunamadı.") + elif msayi == 5: + # Programdan Çıkma + print("Programdan çıkılıyor...") + exit() diff --git a/musteriler.json b/musteriler.json new file mode 100644 index 0000000..91f5e54 --- /dev/null +++ b/musteriler.json @@ -0,0 +1,20 @@ +{ + "1": { + "adi": "Halil", + "soyadi": "ismet", + "eposta": "hali@ismet.com", + "telefon": "021255663" + }, + "2": { + "adi": "ibrahim", + "soyadi": "abdullah", + "eposta": "ibrahim@hotmail.com", + "telefon": "06558877" + }, + "3": { + "adi": "Yeni", + "soyadi": "Yenieee", + "eposta": "yeniii@gamam.com", + "telefon": "026663355" + } +} \ No newline at end of file diff --git a/w2-HackerRank1.py b/w2-HackerRank1.py new file mode 100644 index 0000000..8de6061 --- /dev/null +++ b/w2-HackerRank1.py @@ -0,0 +1,14 @@ +x=int(input("x:")) +y=int(input("y:")) +z=int(input("z:")) +n=int(input("n:")) +# l=[] +# for i in range (0,x+1): +# for j in range (0,y+1): +# for k in range (0,z+1): +# if i+j+k<3: +# l.append([i,j,k]) +# print(l) + + +print([[i,j,k] for i in range (0,x+1) for j in range (0,y+1) for k in range (0,z+1) if i+j+k!=n]) \ No newline at end of file diff --git a/w2-HackerRank2 b/w2-HackerRank2 new file mode 100644 index 0000000..cf6339d --- /dev/null +++ b/w2-HackerRank2 @@ -0,0 +1,5 @@ +if __name__ == '__main__': + n = int(input()) + integer_list = map(int, input().split()) + t=tuple(integer_list) + print( hash(t)) \ No newline at end of file diff --git a/w2-HackerRank3 b/w2-HackerRank3 new file mode 100644 index 0000000..591d60c --- /dev/null +++ b/w2-HackerRank3 @@ -0,0 +1,9 @@ +students=[] +for _ in range(int(input())): + name = input() + score = float(input()) + students.append([name,score]) +scores=[i[1] for i in students] +secondScore=sorted(list( set(scores)))[1] +for k in sorted([i for i in students if i[1]==secondScore]): + print(k[0]) \ No newline at end of file diff --git a/w2-q1.py b/w2-q1.py new file mode 100644 index 0000000..88aeede --- /dev/null +++ b/w2-q1.py @@ -0,0 +1,31 @@ +students ={} +for i in range (1,3): + student = {input("Name, Surname? "):[int(input("midterm ")),int(input("final ")), int(input("oral "))]} + students.update(student) + print(students) +for i in students: + students[i].append(round(sum(students[i])/3)) +print(students) +avg=[] +for i in students: + avg.append((students[i])[-1]) +avg=[((students[i])[-1]) for i in students] +for i in students: + if (students[i])[-1]==max(avg): + print("Highest average grade: ",i, ",", max(avg)) +Names=[] +for i in list(students.keys()): + i.split(" ")[0] + Names.append(i.split(" ")[0]) +print(tuple(Names)) +print("sorted names: ",sorted(Names)) +Unseccesfull=[] +for i in students: + if (students[i])[-1]<70: + Unseccesfull.append(i) +print(set(Unseccesfull)) +Unseccesfull=set(Unseccesfull) +for i in students: + if (students[i])[-1]<70: + Unseccesfull.add(i) +print("Unseccesfull students / ",Unseccesfull) diff --git a/w2-q2.py b/w2-q2.py new file mode 100644 index 0000000..1755df6 --- /dev/null +++ b/w2-q2.py @@ -0,0 +1,92 @@ +arch={} +try: + with open("arch.text","r", encoding="utf-8") as file: + for line in file: + m,info=line.strip().split('|',1) + d,y,g=info.strip().split('|') + arch[m]=[d,y,g] +except FileNotFoundError: + print("There is no archive") +print (arch) +s=input("\nMovie Archive Program\nEnter your choice\nto add movies, A\nto edit movies, E \nto delete movies, D\nto list movies, L\nto filter movies, F\nto sort movies, S\nto quit, Q: ").upper() +if s=="A": + while True: + m=input("\nMovie name? ") + d=input("Director? ") + y=input("Year ") + g=input("Genre ") + arch[m]=[d,y,g] + m=input("\nAdd more, enter 'M' or 'Q' ! ").upper() + if m!='M': break +elif s=='L': + for i in arch: + print(f"{i} : {arch[i]}") +elif s== 'E': + mov=input("enter the name of the movie to edit : ") + s=int(input("what information of that movie to edit?\nEnter 0 for the movie name, 1 for Director Name, 2 for year, 3 for genre : ")) + if s==1 : + d=input("Enter Director Name ") + (arch[mov])[0]=d + elif s==2: + r=input("Enter release Date ") + (arch[mov])[1]=r + elif s==3: + g=input("Enter genre ") + (arch[mov])[2]=g + elif s==0: + NewMovi=input('enter movie name to update ') + arch[NewMovi]=arch.pop(mov) + print(arch) +elif s=='S': + sel=input("to sort movies, movie/director/year/genre(0/1/2/3) ").upper() + if sel=='0': + for i in sorted(arch.keys() ): + print(f"{i} : {arch[i]}") + elif sel=='1': + b={} + for i in sorted( [ y[0] for x,y in arch.items() ]): + for j in arch: + if i==arch[j][0]: + b[j]=arch[j] + print("\nSort by Director") + for i in b: + print(f"{i}:{b[i]}") + elif sel=='2': + b={} + for i in sorted( [ y[1] for x,y in arch.items() ]): + for j in arch: + if i==arch[j][1]: + b[j]=arch[j] + print("\nSort by Year") + for i in b: + print(f"{i}:{b[i]}") + elif sel=='3': + b={} + for i in sorted( [ y[2] for x,y in arch.items() ]): + for j in arch: + if i==arch[j][2]: + b[j]=arch[j] + print("\nSort by Genre") + for i in b: + print(f"{i}:{b[i]}") + +# else: print("Please enter a valid input ") +elif s=="F": + sel=input("Enter Y, for YEAR; type G, for GENRE; to filter ").upper() + if sel=="G": + s=input("enter genre?: ") + for x,y in arch.items(): + if y[2]==s: + print(f"{x}, {y}") + elif sel=="Y": + s=input("enter year?: ").upper() + for x,y in arch.items(): + if y[1]==s: + print(f"{x} | {y}") +elif s=='D': + mov=input("enter the name of the movie to delete : ") + del arch[mov] + +with open("arch.text","w", encoding="utf-8") as file: + for movie,info in arch.items(): + file.write(f"{movie}|{info[0]}|{info[1]}|{info[2]}\n") \ No newline at end of file diff --git a/w2-q3.py b/w2-q3.py new file mode 100644 index 0000000..e41eb62 --- /dev/null +++ b/w2-q3.py @@ -0,0 +1,66 @@ +userInfo={} +custInf={} +while True: + userN=input('User Name ') + pas=input('Password ') + if (userN in userInfo and pas==userInfo[userN]): + break + elif userN not in userInfo: + print ('User Name was not found, make a username and passwoord') + userN=input('User Name ') + pas=input('Password') + userInfo[userN]=pas + print("You made a username and password successfully !") + break + +while True: + sel=input("\n---Customer Information Database---\n---Please Select an option---\n---List Customer information, L ---\n---Add Customer,A--- \n---Update Customer, U -----\n---Delete Customer, D ---\n---Quit Program, Q--").upper() + if sel=="A": + id=input("Customer ID ? ") + ns=input ("Name and Surname ? ") + tel=input ("Telephone? ") + email=input ("E-mail? ") + custInf[id]=[ns, tel,email] + + elif sel == "L": + if custInf=={}: + print("\nNo customers found ! ") + else: + for id,info in custInf.items(): + print(f"\n customer ID:{id} Name and Surname:{info[0]} Telephone:{info[1]} E-mail :{info[2]}") + + + elif sel == "U" : + if custInf == {}: + print("\nNo customers found ! ") + else: + for id,info in custInf.items(): + print(f" customer ID:{id} Name and Surname:{info[0]} Telephone:{info[1]} E-mail :{info[2]}") + + ci=input('enter customer Id ? ') + print(f" customer ID:{ci} Name and Surname:{custInf[ci][0]} Telephone:{custInf[ci][1]} E-mail :{custInf[ci][2]}") + sel=input("select customer data to be updated ? (for Name and Surname 0,| for Telephone 1,| for E-mail 2, ") + + if sel =="0": + update=input('Name and Surname? ') + (custInf[ci][0])=update + + elif sel =="1": + update=input('Telephone? ') + (custInf[ci][1])=update + + if sel =="2": + update=input('E-mail? ') + (custInf[ci][2])=update + + elif sel=='D': + ci=input('enter customer Id to delete ? ') + if ci not in custInf.keys(): + ci=input("Id doesn't exist, or wrong Id, enter customer Id again? ") + else: + del custInf[ci] + print ("Customer information was deleted from database") + + + elif sel=='Q': + quit() diff --git a/week2_cs_qs_1.py b/week2_cs_qs_1.py new file mode 100644 index 0000000..9590050 --- /dev/null +++ b/week2_cs_qs_1.py @@ -0,0 +1,54 @@ +#week-2 ws 1 Students +# Week 2 - Ödev 1 +# 1-Calculate each student's GPA and add it to the dictionary. +# 2-Find the student with the highest GPA and print it on the screen. +# 3-Separate each student's name from their surname and store them in a separate tuple and add them to a list. +# 4-Sort the names in alphabetical order and print the sorted list on the screen. +# 5-Keep students with a GPA below 70 in a cluster (set). + +students= [] + +while True: + ad = input("Öğrencinin adını girin: ") + soyad = input("Öğrencinin soyadını girin: ") + not1 = int(input("1. notu girin: ")) + not2 = int(input("2. notu girin: ")) + not3 = int(input("3. notu girin: ")) + ogrenci = { + "ad": ad, + "soyad": soyad, + "notlar": [not1, not2, not3] + } + + ortalama = sum(ogrenci["notlar"])// len(ogrenci["notlar"]) + ogrenci["ortalama"] = ortalama + students.append(ogrenci) + devam = input("Devam mı etmek istiyorsun Cıkmakmı istiyorsun: D_Q : ").upper() + if devam !="D": + break + +# 1-Calculate each student's GPA and add it to the dictionary. +isimler = [ogrenci["ad"] for ogrenci in students] +isimler.sort() +print(f" Sorted names: {isimler}") + +# 2-Find the student with the highest GPA and print it on the screen. +highest = max(students, key=lambda x: x["ortalama"]) +print(f" Highest student: {highest['ad']}") +print(f" Firs student: {isimler[-1]}") + +# 3-Separate each student's name from their surname and store them in a separate tuple and add them to a list. +isimleri = [i["ad"] for i in students] +print(isimleri) + +# 4-Sort the names in alphabetical order and print the sorted list on the screen. +isimleri.sort() +print(isimleri) + +# 5-Keep students with a GPA below 70 in a cluster (set). +under70 = [{"ad": ogrenci["ad"], "ortalama" : ogrenci["ortalama"]} for ogrenci in students if ogrenci["ortalama"]<70] + +print(f" Under 70 student are : {under70}") +print(f" All students are : {students}") + + diff --git a/week_2_cs_List_Comprehensions.py b/week_2_cs_List_Comprehensions.py new file mode 100644 index 0000000..fe4f98b --- /dev/null +++ b/week_2_cs_List_Comprehensions.py @@ -0,0 +1,18 @@ +#List Comprehensions +result=[] +x = int(input("First line: ... ")) +y = int(input("Second line: ... ")) +z = int(input("Third line: ... ")) +n = int(input("N line: ... ")) +for i in range(0, x+1): + for t in range(0, y+1): + for l in range(0, z+1): + if i+t+l == n: + continue + else: + result.append([i, t, l]) +print(result) +result2 =[ (a, b, c) for a in range(0, x+1) for b in range(0, y+1) for c in range(0, z+1) if a+b+c!=n] +print(result2) +#List Comprehensions +result=[] \ No newline at end of file diff --git a/week_2_cs_Tuples.py b/week_2_cs_Tuples.py new file mode 100644 index 0000000..d417a37 --- /dev/null +++ b/week_2_cs_Tuples.py @@ -0,0 +1,9 @@ +nummers = [] +n = int(input("n nummer:... ")) +giris = input("Sayıları boşluk bırakarak girin: ") + +nummer = list(map(int, giris.split())) +nummers.append(nummer) +nummerstuple = tuple(nummers) +hashnummer = hash(nummerstuple) +print(hashnummer) \ No newline at end of file diff --git a/week_2_cs_nested.py b/week_2_cs_nested.py new file mode 100644 index 0000000..aca7ea7 --- /dev/null +++ b/week_2_cs_nested.py @@ -0,0 +1,29 @@ +students =[] +student ={ +"name" : "alpha", "grade" : 20.0, +"name" : "beta", "grade" : 20.0, +"name" : "gama", "grade" : 19.0 + +} +students.append(student) +n = int(input("input number of studens:... ")) +while len(students) < n: + studen = {} + studen["name"] = input("input the name:.... ") + name = input("input the nane:... ") + grade = float(input("input grade")) + students.append(studen) + print(n) + i = 0 + for i in students["name"]: + print(students[i]) + x = 0 + for x in students(grade) + print(students[x]) + +print(students[name]) + + + + + diff --git a/week_2_cs_qs_1.py b/week_2_cs_qs_1.py new file mode 100644 index 0000000..ae28c0d --- /dev/null +++ b/week_2_cs_qs_1.py @@ -0,0 +1,54 @@ +#week-2 ws 1 Students +# Week 2 - Ödev 1 +# 1-Calculate each student's GPA and add it to the dictionary. +# 2-Find the student with the highest GPA and print it on the screen. +# 3-Separate each student's name from their surname and store them in a separate tuple and add them to a list. +# 4-Sort the names in alphabetical order and print the sorted list on the screen. +# 5-Keep students with a GPA below 70 in a cluster (set).... + +students= [] + +while True: + ad = input("Öğrencinin adını girin: ") + soyad = input("Öğrencinin soyadını girin: ") + not1 = int(input("1. notu girin: ")) + not2 = int(input("2. notu girin: ")) + not3 = int(input("3. notu girin: ")) + ogrenci = { + "ad": ad, + "soyad": soyad, + "notlar": [not1, not2, not3] + } + + ortalama = sum(ogrenci["notlar"])// len(ogrenci["notlar"]) + ogrenci["ortalama"] = ortalama + students.append(ogrenci) + devam = input("Devam mı etmek istiyorsun Cıkmakmı istiyorsun: D_Q : ").upper() + if devam !="D": + break + +# 1-Calculate each student's GPA and add it to the dictionary. +isimler = [ogrenci["ad"] for ogrenci in students] +isimler.sort() +print(f" Sorted names: {isimler}") + +# 2-Find the student with the highest GPA and print it on the screen. +highest = max(students, key=lambda x: x["ortalama"]) +print(f" Highest student: {highest['ad']}") +print(f" Firs student: {isimler[-1]}") + +# 3-Separate each student's name from their surname and store them in a separate tuple and add them to a list. +isimleri = [i["ad"] for i in students] +print(isimleri) + +# 4-Sort the names in alphabetical order and print the sorted list on the screen. +isimleri.sort() +print(isimleri) + +# 5-Keep students with a GPA below 70 in a cluster (set). +under70 = [{"ad": ogrenci["ad"], "ortalama" : ogrenci["ortalama"]} for ogrenci in students if ogrenci["ortalama"]<70] + +print(f" Under 70 student are : {under70}") +print(f" All students are : {students}") + + diff --git a/week_2_cs_qs_2.py b/week_2_cs_qs_2.py new file mode 100644 index 0000000..a6b9562 --- /dev/null +++ b/week_2_cs_qs_2.py @@ -0,0 +1,101 @@ +#1-Create a movie data by taking information such as movie name, +# director, release year and genre from the user and store it in a dictionary. +#2-Give the user the option to edit or delete a movie. +# (For this, a suitable function must be written +# for whatever data they want to change about the movie.) +#3-Allow the user to view their collection. List all movies or filter by criteria such as genre or year of release. +#4-Save the movie data in a file and restore this data when you start the program. +import json +import os + +if os.path.exists("movied.json"): + with open("movies.json", "r", encoding="utf-8") as dosya: + movies = json.load(dosya) +else: + movies = [] + +while True: + + choise = str(input("Chooise a menu: ------------------\nDelete a movie:(D)\nChange a movie:(C) \nNew movie:(N) \nList :(L) ").upper()) + if choise == "N": + + while True: + + name = input("Give movie name: ") + year = int(input("Give the year of the movie: ") if input("Give the year of the movie: ").isdigit() else "2023") + if year < 1900 or year > 2023: + print("Please enter a valid year between 1900 and 2023.") + continue + #year = int(input("Give the year of the movie: ") if input("Give the year of the movie: ").isdigit() else "2023") + director = input("Give director name: ") + genre = input("Give genre: ") + xname = { + "name": name, + "year": year, + "director" : director, + "genre" : genre + } + + movies.append(xname) + print(movies) + break + + elif choise == "C": + + xc = input("Give an info over the movie: ") + yc = input("Give new info: ") + for z in movies: + if z["name"] == xc: + z["name"] = yc + print(movies) + elif z["director"] == xc: + z["director"] = yc + print(movies) + elif z["genre"] == xc: + z["genre"] = yc + print(movies) + else: + z["year"] = yc + print(movies) + + elif choise == "L": + choise = str(input("Chooise a sort: \nName:(N)\nYear:(Y) \nGenre:(G) \nDırector :(D) ").upper()) + while True: + if choise == "N": + #for movie in movies if len(movies) > 0, print(movie for movie in movies if movie["name"]), print("list is empty") + #print("".join(str(movie["name"]) for movie in movies) if len(movies) > 0 else "list is empty") + print("".join(str(movie["name"]) for movie in movies) if len(movies) > 0 else "list is empty") + break + elif choise == "Y": + print("".join(str(movie["year"]) for movie in movies) if len(movies) > 0 else "list is empty") + #for movie in movies if len(movies) > 0, print(movie for movie in movies if movie["year"]), print("list is empty") + break + elif choise == "G": + #print("".join(str(movie["genre"]) for movie in movies) if len(movies) > 0 else "list is empty") + #for movie in movies if len(movies) > 0, print(movie for movie in movies if movie["genre"]), print("list is empty") + print("".join(str(movie["genre"]) for movie in movies) if len(movies) > 0 else "list is empty") + break + elif choise == "D": + print("".join(str(movie["director"]) for movie in movies) if len(movies) > 0 else "list is empty") + #for movie in movies if len(movies) > 0, print(movie for movie in movies if movie["director"]), print("list is empty") + break + elif choise == "Q": + break + else: + print(f"{choise} is not defined.") + break + + elif choise == "D": + xm = input("Give an info over the movie: ") + for xm in movies: + movies.remove(xm) + print(movies) + #movies = [movies for movies in movies if movies['name'] != 'Ayşe'] + + else: + print(movies) + +with open("movies.json", "w", encoding="utf-8") as dosya: + json.dump(movies, dosya, ensure_ascii=False, indent=2) + + diff --git a/week_2_cs_qs_3.py b/week_2_cs_qs_3.py new file mode 100644 index 0000000..f29cc96 --- /dev/null +++ b/week_2_cs_qs_3.py @@ -0,0 +1,90 @@ +# # Question 3: Customer Management System +# Project Description: This project involves you creating a customer management system that you can use to manage your customers and perform basic +# transactions. This system will have basic functions such as storing customer information, adding new customers, updating customer information, +# deleting customers and viewing the customer list. Here are the basic steps of the project: +# 1-Use a dictionary structure to store customer information. Assign a UNIQUE customer identification (ID) for each customer and associate customer +# information with this ID. You can use a dictionary containing information such as name, surname, e-mail, phone number for each customer. +# 2-Provide a menu where the user can choose the following actions: +# Add new customers # Updating customer information # Delete customer # List all customers # Check out +# 3-Perform the relevant action according to the user's choice. For example, when adding a new customer, get the required information from the user and +# add a new customer to the dictionary. +# 4-When updating customer information, view the current information using the customer ID and save the updated information. +# 5-In the customer deletion process, get the customer ID from the user and delete this customer from the dictionary. +# 6-In the process of listing all customers, view the list of existing customers. +# 7-Repeat the process until the user logs out. + + +import json +import os + +if os.path.exists("customers.json"): + with open("customers.json", "r", encoding="utf-8") as dosya: + customers = json.load(dosya) +else: + customers = [] + +while True: + + choice = str(input("Chooice a menu: ------------------" \ + "\nNew customer:(N)" \ + "\nUpdate customer:(U) " \ + "\nDelete customer:(D) " \ + "\nList customers:(L) ").upper()) + + if choice == "N": + + while True: + + name = input("Give customer name:...") + surname = input("Give customer surname:...") + id = len(customers) + 1 + phone = int(input("Give phone number:... ")) + email = input("Give email adres:... ") + customer = { + "name": name, + "surname": surname, + "id": id, + "phone" : phone, + "email" : email + } + + customers.append(customer) + print(f"{['name']} {['surname']} added!") + print(customers) + break + + elif choice == "U": + search_name = input("Customer name for update: ") + for person in customers: + if person["name"] == search_name: + print("All information:", person) + person["name"] = input("New name: ") or person["name"] + person["phone"] = int(input("New phone: ") or person["phone"]) + person["surname"] = input("surname: ") or person["surname"] + person["email"] = input("New email: ") or person["email"] + print("Informations updated:", person) + print("------------_\n-------") + + elif choice == "D": + deleted_customer = int(input("Give ID of customer to delete: ")) + for deleted_customer in customers: + confirm = input(f"Are you sure you want to delete {deleted_customer['name']} {deleted_customer['surname']}? (y/n): ") + if confirm.lower() == "y": + customers.remove(deleted_customer) + print(f"Customer {deleted_customer} deleted successfully!") + + else: + print(f"Customer {deleted_customer} not found.") + + + elif choice == "L": + print(customers) + + else: + print(customers) + with open("customers.json", "w", encoding="utf-8") as dosya: + json.dump(customers, dosya, ensure_ascii=False, indent=2) + print("Data saved. Exiting system.") + break + +