diff --git a/Python_function_exercises.py b/Python_function_exercises.py new file mode 100644 index 0000000..ee30e77 --- /dev/null +++ b/Python_function_exercises.py @@ -0,0 +1,60 @@ +#1- Verilen bir kelimeyi belirtilen kez ekrana yazdiran python fonksiyonu yazınız. +#1. Print a Word Multiple Times +def print_word(word, count): + for i in range(count): + print(word) + +print_word("Hello", 3) + + +#2- Verilen 2 sayı arasındaki tüm asal sayıları bulan python fonksiyonunu yazınız. +#2. Prime Numbers Between Two Numbers +# A prime number is only divisible by 1 and itself.Examples: 2, 3, 5, 7, 11... +def is_prime(num): + if num < 2: + return False + for i in range(2, int(num**0.5)+1): #loop through all numbers from 2 up to square root of num. +1 because range is exclusive at the end,it stops before the last number. + if num %i == 0: #check if num is divisible by i + return False + return True + +def find_primes(start, end): + for num in range(start, end + 1): + if is_prime(num): + print(num) +find_primes(10, 20) + +#3- Saati saniyeye çeviren bir fonksiyon yazınız. +#3. Convert Time to Seconds + +def convert_to_seconds(hours, minutes, seconds): + total_seconds = hours * 3600 + minutes *60 + seconds + return total_seconds +print(convert_to_seconds(1, 30, 15)) + + +#4- Matematik, Fizik ve Kimya derslerinin Vize ve Final ortalamalarina gore +# (Vize nin %40 i , Finalin %60 i) ogrencinin derslerden hangi not ile gectigini veya kaldigini gosteren bir program yaziniz. +#4. Calculate Student Grades (Vize 40%, Final 60%) + +def calculate_grade(vize, final): + average = vize * 0.4 + final * 0.6 + + if average >= 85: + grade = "AA" + elif average >= 70: + grade = "BB" + elif average >= 55: + grade = "CC" + elif average >= 45: + grade = "DD" + else: + grade = "FF" + if average >= 45: + status = "Passed" + else: + status = "Failed" + + print(f"Average: {average:.2f} - Grade: {grade} - Status: {status}") #:.2f floating point (decimal) numbers + +calculate_grade(60, 70) \ No newline at end of file diff --git a/Question1.py b/Question1.py new file mode 100644 index 0000000..60a691f --- /dev/null +++ b/Question1.py @@ -0,0 +1,85 @@ +#Project Description: In this assignment, you will create a task manager application using the Python programming language. +#This application will allow users to add, complete, delete, and list their tasks. +#Requirements: +#1-Tasks will be stored in a Python list and each task will be represented as a dictionary. Each task must have the following properties: +#Sequence Number (Automatically assigned). Task Name. Status (Completed, Pending, or Deleted) +#2- Operations that the user can perform: +#Add a new task. Complete a task. Delete a task. List completed tasks. List all tasks with their status. Exit +#3- 4- 5- 6 + +def greet_user(): + print("Welcome to Task Manager") +greet_user() # Call the function + +tasks = [] #task list will store all tasks +next_sequence = 1 #this will increase with each new task + +# Function to add a new task +def add_task(name): # name is a parameter + global next_sequence + task = { + "Sequence": next_sequence, #automatically assigned number + "Name": name, #task name entered by user + "Status": "Pending" #default status + } + tasks.append(task) + print(f"Task '{name}' added with number {next_sequence}.") + next_sequence += 1 #increase the task number for next task + + +# Function to complete a task +def complete_task(task_number): + for task in tasks: + if task["Sequence"] == task_number and task["Status"] == "Pending": #find the task by its number and make sure it's not already done + task["Status"] = "Completed" #change status + print(f"Task {task_number} marked as Completed.") + return + print("Task not found or cannot be completed.") #if not found + +# Function to delete a task +def delete_task(task_number): + for task in tasks: + if task["Sequence"] == task_number and task["Status"] != "Deleted": + task["Status"] = "Deleted" + print(f"Task {task_number} marked as Deleted.") + return + print("Task not found or already deleted.") + +# Function to list all tasks +def list_tasks(): + print("\n Task List") + for task in tasks: + print(f"{task['Sequence']}: {task['Name']} - [{task['Status']}]") + print() # Empty line for spacing. extra space after list + +# Main function to show the menu and take user input +def main(): + while True: + print("Task Manager Menu") + print("1. Add Task") + print("2. Complete Task") + print("3. Delete Task") + print("4. List All Tasks") + print("5. Exit") + + choice = input("Choose an option (1-5): ") + + if choice == "1": + name = input("Enter the task name: ") + add_task(name) + elif choice == "2": + number = int(input("Enter the task number to complete: ")) + complete_task(number) + elif choice == "3": + number = int(input("Enter the task number to delete: ")) + delete_task(number) + elif choice == "4": + list_tasks() + elif choice == "5": + print("Exiting Task Manager. Goodbye!") + break + else: + print("Invalid choice. Please try again.") + +# Run the program +main() \ No newline at end of file diff --git a/ic_week_3_1.py b/ic_week_3_1.py new file mode 100644 index 0000000..229069c --- /dev/null +++ b/ic_week_3_1.py @@ -0,0 +1,125 @@ +# Görev Yönetim Sistemi +#1- Yeni bir görev ekle +#2- Bir görevi tamamla +#3- Bir görevi sil +#4- Tamamlanan görevleri listele +#5- Tüm görevleri durumlarıyla birlikte listele +#6- Çıkış + +gorev_listesi = [] +def add_gorev(ID, gorev_tanimi, gorev_durumu): + """ + Yeni bir görev ekler. + """ + gorev_bilgileri = { + "ID": ID, + "Görev Tanınım": gorev_tanimi, + "Görev Durumu": gorev_durumu + } + gorev_listesi.append(gorev_bilgileri) + return gorev_listesi + +def menu(): + """ + Kullanıcıdan seçim alır. + """ + print("***Görev Yönetim Sistemi***\n") + print("1- Yeni bir görev ekle") + print("2- Bir görevi durumunu değiştir") + print("3- Bir görevi sil") + print("4- Tamamlanan görevleri listele") + print("5- Tüm görevleri durumlarıyla birlikte listele") + print("6- Çıkış\n") + + secim = input("Seçiminizi yapın (1-6): ") + if secim not in ["1", "2", "3", "4", "5", "6"]: + print("Geçersiz seçim. Lütfen tekrar deneyin.") + return menu() + return secim + +def uygun_id_al(): + mevctut_idler = sorted([int(gorev["ID"]) for gorev in gorev_listesi]) + for ID in range(1, len(mevctut_idler) + 2): + if ID not in mevctut_idler: + return str(ID) + + """ + Kullanıcıdan uygun bir ID alır. + """ + +#1- Yeni bir görev ekle +while True: + menu_secim = menu() + if menu_secim == "1": + #ID = input("Görev ID'sini girin: ") + ID = uygun_id_al() + if any(gorev["ID"] == ID for gorev in gorev_listesi): + print("Bu ID'ye sahip bir görev zaten var. Lütfen başka bir ID girin.") + continue + # Görev tanımını ve durumunu al + gorev_tanimi = input("Görev tanımını girin: ") + gorev_durumu = input("Görev durumunu girin (Tamamlandı/Bekliyor/Silindi): ") + if gorev_durumu not in ["Tamamlandı", "Bekliyor", "Silindi"]: + print("Geçersiz görev durumu. Lütfen tekrar deneyin.") + continue + # Görev ekleme fonksiyonunu çağır + add_gorev(ID, gorev_tanimi, gorev_durumu) + print("Görev başarıyla eklendi.") + elif menu_secim == "2": + ID = input("Durumu değiştirmek istediğiniz görev ID'sini girin: ") + if any(gorev["ID"] == ID for gorev in gorev_listesi): + #print("Bu ID bulundu.") + # Görev durumunu güncelle + gorev_durumu = input("Görev durumunu girin (Tamamlandı/Bekliyor/Silindi): ") + if gorev_durumu not in ["Tamamlandı", "Bekliyor", "Silindi"]: + print("Geçersiz görev durumu. Lütfen tekrar deneyin.") + continue + else: + for gorev in gorev_listesi: + if gorev["ID"] == ID: + gorev["Görev Durumu"] = gorev_durumu + print("Görev durumu başarıyla güncellendi.") + else: + print("Bu ID'ye sahip bir görev bulunamadı.") + continue + + elif menu_secim == "3": + ID = input("Silmek istediğiniz görev ID'sini girin: ") + if any(gorev["ID"] == ID for gorev in gorev_listesi): + #print("Bu ID bulundu.") + # Görev silme işlemi + for gorev in gorev_listesi: + if gorev["ID"] == ID: + gorev_listesi.remove(gorev) + print("Görev başarıyla silindi.") + else: + print("Bu ID'ye sahip bir görev bulunamadı.") + continue + + elif menu_secim == "4": + # Tamamlanan görevleri listele + tamamlanan_gorevler = [gorev for gorev in gorev_listesi if gorev["Görev Durumu"] == "Tamamlandı"] + if tamamlanan_gorevler: + print("Tamamlanan Görevler:") + for gorev in tamamlanan_gorevler: + print(f"ID: {gorev['ID']}, Görev Tanımı: {gorev['Görev Tanınım']}, Görev Durumu: {gorev['Görev Durumu']}") + else: + print("Tamamlanan görev bulunamadı.") + + elif menu_secim == "5": + # Tüm görevleri listele + if gorev_listesi: + print("Tüm Görevler:\n") + for gorev in gorev_listesi: + print(f"ID: {gorev['ID']}, Görev Tanımı: {gorev['Görev Tanınım']}, Görev Durumu: {gorev['Görev Durumu']}\n") + else: + print("Görev listesi boş.") + + elif menu_secim == "6": + + print("Çıkış yapılıyor... İyi günler!") + break + else: + print("Bu özellik henüz uygulanmadı.") + + diff --git a/ic_week_3_Fnk-4.py b/ic_week_3_Fnk-4.py new file mode 100644 index 0000000..c745bf4 --- /dev/null +++ b/ic_week_3_Fnk-4.py @@ -0,0 +1,60 @@ +#1- Verilen bir kelimeyi belirtilen kez ekrana yazdiran python fonksiyonu yazınız. + +def kelimeyaz(kelime, sayi): + for i in range(sayi): + print(kelime) + + +kelime = input("Bir kelime giriniz") +sayi = int(input("Kaç kere yazdırmak istersiniz?")) +kelimeyaz(kelime, sayi) + + +#2- Verilen 2 sayı arasındaki tüm asal sayıları bulan python fonksiyonunu yazınız. + +def asalsayilar(sayi1, sayi2): + asal_sayilar = [] + for sayi in range(sayi1, sayi2 + 1): + if sayi > 1: + for i in range(2, int(sayi ** 0.5) + 1): + if sayi % i == 0: + break + else: + asal_sayilar.append(sayi) + return asal_sayilar + +print(f"1 ile 10 arası asalsayılar: {asalsayilar(1, 10)}") + + +#3- Saati saniyeye çeviren bir fonksiyon yazınız. + +def saniye(): + saat=int(input("Saat: ")) + dakika=int(input("Dakika: ")) + saniye=int(input("Saniye: ")) + toplam_saniye=(saat*3600)+(dakika*60)+saniye + print(f"Toplam saniye: {saat} Saat {dakika} dakika {saniye} saniye toplamı {toplam_saniye} saniyedir") + +saniye() + + +#4- Matematik, Fizik ve Kimya derslerinin Vize ve Final ortalamalarina gore (Vize nin %40 i , Finalin %60 i) ogrencinin derslerden hangi not ile gectigini veya kaldigini gosteren bir program yaziniz. + +def vize_final(ders, vnotu, fnotu): + ders = input("Ders adı: ") + vnotu = int(input("Vize notu: ")) + fnotu = int(input("Final notu: ")) + ortalama = (vnotu * 0.4) + (fnotu * 0.6) + if ortalama >= 0 and ortalama <= 44: + print("FF - Kaldınız") + elif ortalama >= 45 and ortalama <= 54: + print("DD - Geçtiniz") + elif ortalama >= 55 and ortalama <= 69: + print("CC - Geçtiniz") + elif ortalama >= 70 and ortalama <= 84: + print("BB - Geçtiniz") + elif ortalama >= 85 and ortalama <= 100: + print("AA - Geçtiniz") + + +vize_final("", 0, 0) diff --git a/ic_week_3_hr_1-2.py b/ic_week_3_hr_1-2.py new file mode 100644 index 0000000..4c92239 --- /dev/null +++ b/ic_week_3_hr_1-2.py @@ -0,0 +1,29 @@ +def sayi_rakam_bolen(n): + """ + Bu fonksiyon, verilen bir sayının rakamlarının verilen sayıyının tam bölemleri sayısını verir. + + """ + adet = 0 + for i in str(n): + if i != '0' and n % int(i) == 0: + adet += 1 + return adet + + # count = 0 + # for digit in str(n): + # if digit != '0': + # if n % int(digit) == 0: + # count += 1 + #return count + +print(sayi_rakam_bolen(1012)) + + +def naam(s): + words = s.split(" ") + capitalized_words = [w[0].upper() + w[1:] if w else "" for w in words] + return " ".join(capitalized_words) + +print(naam("ahmet 12mehmet ali")) + + diff --git a/w3-q1.py b/w3-q1.py new file mode 100644 index 0000000..942adaa --- /dev/null +++ b/w3-q1.py @@ -0,0 +1,83 @@ +tasks = [] +deleted = [] +taskNumber = 0 # Tracks task numbers + +def add_task(): + global taskNumber + + if deleted: + deletedTaskNo = deleted.pop(0) + for task in tasks: + if task["taskNumber"] == deletedTaskNo and task["taskStatus"] == "deleted": + task_name = input("Enter the task: ") + task["taskName"] = task_name + task["taskStatus"] = "pending" + print(f"Reused Task no: {deletedTaskNo} updated with Name: '{task_name}'.") + return + + taskNumber += 1 + new_task_number = taskNumber + task_name = input("Enter the task: ") + task = {"taskNumber": new_task_number, "taskName": task_name, "taskStatus": "pending"} + tasks.append(task) + print(f"Task no: {new_task_number} Task Name: '{task_name}' added.") + +def list_tasks(): + if not tasks: + print("No tasks available.") + else: + for task in tasks: + print(f"Task no: {task['taskNumber']} Task Name: '{task['taskName']}' Status: '{task['taskStatus']}'") + +def delete_task(): + if not tasks: + print("No tasks available.") + return + + num = int(input("Enter the task number to delete: ")) + for task in tasks: + if task["taskNumber"] == num and task["taskStatus"] != "deleted": + task["taskStatus"] = "deleted" + deleted.append(num) + print(f"Task no: {num} deleted.") + return + print("Task not found or already deleted.") + +def complete_task(): + if not tasks: + print("No tasks available.") + return + + num = int(input("Enter the task number to complete: ")) + for task in tasks: + if task["taskNumber"] == num and task["taskStatus"] == "pending": + task["taskStatus"] = "completed" + print(f"Task no: {num} completed.") + return + print("Task not found or already completed/deleted.") + +def main(): + while True: + print("\nTask Manager") + print("Choose an option:") + print("1. Add Task") + print("2. List Tasks") + print("3. Delete Task") + print("4. Complete Task") + print("5. Exit") + choice = input("Enter your choice: ") + if choice == '1': + add_task() + elif choice == '2': + list_tasks() + elif choice == '3': + delete_task() + elif choice == '4': + complete_task() + elif choice == '5': + print("Exiting Task Manager.") + break + else: + print("Invalid choice. Please try again.") + +main() diff --git a/week_3_cs_qs_1.py b/week_3_cs_qs_1.py new file mode 100644 index 0000000..70a87e1 --- /dev/null +++ b/week_3_cs_qs_1.py @@ -0,0 +1,82 @@ +#task manager +# +tasks = [] +íd = 0 +while True: + print("1/ Add task") + print("2/ Remove task") + print("3/ Show tasks") + print("4/ List tasks") + print("5/ Exit") + choice = input("Choose an option: ") + if choice == "1": + name = input("Enter task name: ") + status = input("Enter task status: ") + due_date = input("Enter task due date: ") + task = { + "id": id, + "name": name, + "status": status, + "due_date": due_date + } + tasks.append(task) + íd += 1 + print("Task added.") + elif choice == "2": + task_id = int(input("Enter task ID to remove: ")) + for task in tasks: + if task["id"] == task_id: + tasks.remove(task) + print("Task removed.") + break + else: + print("Task not found.") + elif choice == "3": + for task in tasks: + print(f"ID: {task['id']}, Name: {task['name']}, Status: {task['status']}, Due Date: {task['due_date']}") + print("Do you want to edit this task? (yes/no)") + edit_choice = input() + if edit_choice.lower() == "yes": + new_name = input("Enter new task name: ") + new_status = input("Enter new task status: ") + new_due_date = input("Enter new task due date: ") + task["name"] = new_name + task["status"] = new_status + task["due_date"] = new_due_date + print("Task updated.") + elif edit_choice.lower() == "no": + print("No changes made.") + else: + print("Invalid choice. No changes made.") + + elif choice == "4": + print("List of tasks:") + print("1/ ID\t 2/ Name\t 3/ Status\t 4/ Due Date\t 5/ Comleted Tasks") + + choiselist = input("Choose a task to list: ") + if choiselist == "1": + for task in tasks: + print(f"ID: {task['id']}, Name: {task['name']}") + elif choiselist == "2": + for task in tasks: + print(f"ID: {task['id']}, Name: {task['name']}") + elif choiselist == "3": + for task in tasks: + print(f"ID: {task['id']}, Status: {task['status']}") + elif choiselist == "4": + for task in tasks: + print(f"ID: {task['id']}, Due Date: {task['due_date']}") + elif choiselist == "5": + for task in tasks: + if task["status"].lower() == "completed": + print(f"ID: {task['id']}, Name: {task['name']}") + + else: + print("Invalid choice.") + break + elif choice == "5": + print("Exiting the task manager.") + break + + + diff --git a/week_3_cs_qs_2.py b/week_3_cs_qs_2.py new file mode 100644 index 0000000..3823057 --- /dev/null +++ b/week_3_cs_qs_2.py @@ -0,0 +1,28 @@ +def get_user_input(): + user_input_number = int(input("Give e number: ")) + return user_input_number + +def split_number(number): + digits = [int(digit) for digit in str(number)] + return digits + +# Call the function to get user input and print the result +number = get_user_input() +digits = split_number(number) +print(f"The digits of the number {number} are: {digits}") + +def divisor(digits): + divisors = [] + for i in digits : + if i == 0: + continue + elif number % i == 0: + divisors.append(i) + return divisors + +result = divisor(digits) +count_divisors = len(result) +if count_divisors > 0: + print(f"The number {number} has {count_divisors} divisors.") +else: + print("The number is zero, so it has no divisors.") diff --git a/week_3_cs_qss.py b/week_3_cs_qss.py new file mode 100644 index 0000000..70a87e1 --- /dev/null +++ b/week_3_cs_qss.py @@ -0,0 +1,82 @@ +#task manager +# +tasks = [] +íd = 0 +while True: + print("1/ Add task") + print("2/ Remove task") + print("3/ Show tasks") + print("4/ List tasks") + print("5/ Exit") + choice = input("Choose an option: ") + if choice == "1": + name = input("Enter task name: ") + status = input("Enter task status: ") + due_date = input("Enter task due date: ") + task = { + "id": id, + "name": name, + "status": status, + "due_date": due_date + } + tasks.append(task) + íd += 1 + print("Task added.") + elif choice == "2": + task_id = int(input("Enter task ID to remove: ")) + for task in tasks: + if task["id"] == task_id: + tasks.remove(task) + print("Task removed.") + break + else: + print("Task not found.") + elif choice == "3": + for task in tasks: + print(f"ID: {task['id']}, Name: {task['name']}, Status: {task['status']}, Due Date: {task['due_date']}") + print("Do you want to edit this task? (yes/no)") + edit_choice = input() + if edit_choice.lower() == "yes": + new_name = input("Enter new task name: ") + new_status = input("Enter new task status: ") + new_due_date = input("Enter new task due date: ") + task["name"] = new_name + task["status"] = new_status + task["due_date"] = new_due_date + print("Task updated.") + elif edit_choice.lower() == "no": + print("No changes made.") + else: + print("Invalid choice. No changes made.") + + elif choice == "4": + print("List of tasks:") + print("1/ ID\t 2/ Name\t 3/ Status\t 4/ Due Date\t 5/ Comleted Tasks") + + choiselist = input("Choose a task to list: ") + if choiselist == "1": + for task in tasks: + print(f"ID: {task['id']}, Name: {task['name']}") + elif choiselist == "2": + for task in tasks: + print(f"ID: {task['id']}, Name: {task['name']}") + elif choiselist == "3": + for task in tasks: + print(f"ID: {task['id']}, Status: {task['status']}") + elif choiselist == "4": + for task in tasks: + print(f"ID: {task['id']}, Due Date: {task['due_date']}") + elif choiselist == "5": + for task in tasks: + if task["status"].lower() == "completed": + print(f"ID: {task['id']}, Name: {task['name']}") + + else: + print("Invalid choice.") + break + elif choice == "5": + print("Exiting the task manager.") + break + + +