diff --git a/Adnan_team4_member_week_3.py b/Adnan_team4_member_week_3.py new file mode 100644 index 0000000..dff8bc6 --- /dev/null +++ b/Adnan_team4_member_week_3.py @@ -0,0 +1,96 @@ +print("Gorevlerinizi gorebilecegeniz, degisterebilecegiz ve silebilecegeniz programda hosgeldiniz!") +gorevler=[] +def gorev_ekle(gorev_listesi): + gorev_ad=input("Gorev adini giriniz:") + gorev_durum="Bekliyor" + gorev_sirasi=len(gorev_listesi)+1 + gorev={"ad":gorev_ad,"durum":gorev_durum,"sira":gorev_sirasi} + gorev_listesi.append(gorev) + print(f"Gorev eklendi: {gorev['ad']}.{gorev['sira']}-{gorev['durum']}") + return gorev_listesi + +def gorev_tamamla(gorev_listesi): + if not gorev_listesi: + print("Gorev listesi bos.") + return + gorev_sirasi=int(input("Tamamlamak istediginiz gorevin sirasi:")) + for gorev in gorev_listesi: + if gorev["sira"]==gorev_sirasi: + gorev["durum"]="Tamamlandi" + print(f"Gorev tamamlandi: {gorev['ad']}") + return + print("Gorev bulunamadi.") + +def gorev_sil(gorev_listesi): + if not gorev_listesi: + print("Gorev listesi bos.") + return + gorev_sil=int(input("Silmek istediginiz gorevin sirasi:")) + for gorev in gorev_listesi: + if gorev["sira"]==gorev_sil: + gorev_listesi.remove(gorev) + for g in gorev_listesi: + if g["sira"]>gorev_sil: + g["sira"]-=1 + print(f"Gorev silindi: {gorev['ad']}") + return + print("Gorev bulunamadi.") + + +def tamamlanan_gorevleri_sil(gorev_listesi): + if not gorev_listesi: + print("Gorev listesi bos.") + return + for gorev in gorev_listesi[:]: + if gorev["durum"]=="Tamamlandi": + gorev_listesi.remove(gorev) + print(f"Gorev silindi: {gorev['ad']}") + print("Tamamlanan gorevler silindi.") + +def gorevleri_listele(gorev_listesi): + if not gorev_listesi: + print("Gorev listesi bos.") + else: + print("Gorevler:") + gorev_listesi.sort(key=lambda x:x["sira"]) + for gorev in gorev_listesi: + print(f"{gorev['sira']}. {gorev['ad']} - {gorev['durum']}") + + +def tamamlanan_gorevleri_listele(gorev_listesi): + print("Tamamlanan Gorevler:") + gorev_listesi.sort(key=lambda x:x["sira"]) + for gorev in gorev_listesi: + if gorev["durum"]=="Tamamlandi": + print(f"{gorev['sira']}. {gorev['ad']} - {gorev['durum']}") + +while True: + secenek=int(input(""" + Ne yapmak istiyorsunuz?: + 1-Yeni bir gorev ekle + 2-Gorevi Tamamla + 3-Gorevi sil + 4-Tamamlanan gorevleri sil + 5-Gorevleri Listele + 6-Tamamlanan gorevleri listele + 7-Cikis + Seceneginizi giriniz:""")) + + if secenek==1: + gorev_ekle(gorevler) + + elif secenek==2: + gorev_tamamla(gorevler) + elif secenek==3: + gorev_sil(gorevler) + elif secenek==4: + tamamlanan_gorevleri_sil(gorevler) + elif secenek==5: + gorevleri_listele(gorevler) + elif secenek==6: + tamamlanan_gorevleri_listele(gorevler) + elif secenek==7: + print("Cikis yapiliyor...") + break + else: + print("Gecersiz secenek. Lutfen tekrar deneyin.") \ No newline at end of file diff --git a/Feyz_week3.ipynb b/Feyz_week3.ipynb new file mode 100644 index 0000000..ff0446f --- /dev/null +++ b/Feyz_week3.ipynb @@ -0,0 +1,705 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "e38c6de8", + "metadata": {}, + "source": [ + "Python_Modul_Week_3\n", + "Question 1: Task Manager Application\n", + "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.\n", + "\n", + "Requirements:\n", + "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:\n", + "\n", + "Sequence Number (Automatically assigned)\n", + "\n", + "Task Name\n", + "\n", + "Status (Completed, Pending, or Deleted)\n", + "\n", + "2- Operations that the user can perform:\n", + "\n", + "Add a new task\n", + "\n", + "Complete a task\n", + "\n", + "Delete a task\n", + "\n", + "List completed tasks\n", + "\n", + "List all tasks with their status\n", + "\n", + "Exit\n", + "\n", + "3- Tasks should automatically receive a sequence number in the order they are added.\n", + "\n", + "4- New tasks should be saved in place of the numbers of deleted tasks.\n", + "\n", + "5- When listing tasks, they should be sorted by their sequence number.\n", + "\n", + "6- Appropriate feedback should be given to the user after each operation. For example, when a new task is added, they should see a message indicating that the task has been added.\n", + "\n", + "Bonus Question 1\n", + "HACKERRANK: FIND DIGITS\n", + "\n", + "Bonus Question 2\n", + "HACKERRANK: CAPITALIZE\n", + "\n", + "\n", + "\n", + "\n", + "Python_Modul_Hafta_3\n", + "Soru 1: Görev Yöneticisi Uygulamasi\n", + "Proje Açiklamasi:\n", + "Bu ödevde, Python programlama dilini kullanarak bir görev yöneticisi uygulamasi oluşturacaksiniz. Bu uygulama, kullanicilarin görev eklemesine, tamamlamasina, silmesine ve görev listesini görüntülemesine olanak taniyacaktir.\n", + "\n", + "Gereksinimler:\n", + "1- Görevler bir Python listesinde saklanacak ve her görev bir sözlük (dictionary) olarak temsil edilecektir. Her görev aşağidaki özelliklere sahip olmalidir:\n", + "\n", + "Sira Numarasi (Otomatik olarak atanacak)\n", + "\n", + "Görev Adi\n", + "\n", + "Durum (Tamamlandi, Beklemede ya da Silindi)\n", + "\n", + "2- Kullanicinin gerçekleştirebileceği işlemler:\n", + "\n", + "Yeni görev ekle\n", + "\n", + "Görevi tamamla\n", + "\n", + "Görevi sil\n", + "\n", + "Tamamlanmiş görevleri listele\n", + "\n", + "Tüm görevleri durumlariyla birlikte listele\n", + "\n", + "Çikiş\n", + "\n", + "3- Görevler eklendikçe otomatik olarak sira numarasi almalidir.\n", + "\n", + "4- Yeni görevler, silinmiş görevlerin sira numaralari yerine kaydedilmelidir.\n", + "\n", + "5- Görevler listelenirken sira numarasina göre siralanmalidir.\n", + "\n", + "6- Her işlemden sonra kullaniciya uygun bir geri bildirim verilmelidir. Örneğin, yeni bir görev eklendiğinde, görev eklendiğine dair bir mesaj gösterilmelidir." + ] + }, + { + "cell_type": "markdown", + "id": "c64c6429", + "metadata": {}, + "source": [ + "## Python_Modul_Hafta_3\n", + "\n", + "\n", + "Soru 1: Görev Yöneticisi Uygulamasi\n", + "Proje Açiklamasi:\n", + "Bu ödevde, Python programlama dili kullanarak bir görev yöneticisi uygulamasi oluşturacaksiniz. Bu uygulama, kullanicilarin görev eklemesine, tamamlamasina, silmesine ve görevlerini listelemesine olanak taniyacak.\n", + "\n", + "Gereksinimler:\n", + "\n", + "1- Görevler bir Python listesinde saklanacak ve her görev bir sözlük (dictionary) olarak temsil edilecek. Her görev şu özelliklere sahip olmalidir:\n", + "\n", + "Sira Numarasi (Otomatik olarak atanacak)\n", + "\n", + "Görev Adi\n", + "\n", + "Durum (Tamamlandi, Bekliyor veya Silindi)\n", + "\n", + "2- Kullanicinin gerçekleştirebileceği işlemler:\n", + "\n", + "Yeni bir görev eklemek\n", + "\n", + "Bir görevi tamamlamak\n", + "\n", + "Bir görevi silmek\n", + "\n", + "Tamamlanan görevleri listelemek\n", + "\n", + "Tüm görevleri durumlariyla birlikte listelemek\n", + "\n", + "Çikiş yapmak\n", + "\n", + "3- Görevlere, eklendikleri siraya göre otomatik olarak bir sira numarasi verilmelidir.\n", + "\n", + "4- Yeni eklenen görevler, silinmiş görevlerin numaralarinin yerine kaydedilmelidir.\n", + "\n", + "5- Görevler listelenirken sira numarasina göre sirali olarak gösterilmelidir.\n", + "\n", + "6- Her işlemden sonra kullaniciya uygun bir geri bildirim verilmelidir. Örneğin, yeni bir görev eklendiğinde, görev eklendiğini belirten bir mesaj gösterilmelidir." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "269ce4a1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Görev eklendi: knm\n", + "Görev eklendi: schrijven\n", + "Tüm Görevler:\n", + "1. knm - bekliyor\n", + "2. schrijven - bekliyor\n", + "Tamamlanmiş görev yok.\n", + "1 numarali görev silindi.\n", + "Tüm Görevler:\n", + "2. schrijven - bekliyor\n", + "Görev eklendi: lezen\n", + "Tüm Görevler:\n", + "1. lezen - bekliyor\n", + "2. schrijven - bekliyor\n", + "Çikiliyor...\n" + ] + } + ], + "source": [ + "gorevler = []\n", + "bos_siralar = [] \n", + "sira_numarasi = 0 \n", + "\n", + "def gorev_ekleme():\n", + " global sira_numarasi\n", + "\n", + " gorev_adi = input(\"Görev adi giriniz: \")\n", + " gorev_durumu = \"bekliyor\" \n", + "\n", + " if bos_siralar:\n", + " yeni_sira = bos_siralar.pop(0)\n", + " gorevler[yeni_sira] = {\n", + " \"numara\": yeni_sira + 1,\n", + " \"ad\": gorev_adi,\n", + " \"durum\": gorev_durumu\n", + " }\n", + " else:\n", + " gorevler.append({\n", + " \"numara\": sira_numarasi + 1,\n", + " \"ad\": gorev_adi,\n", + " \"durum\": gorev_durumu\n", + " })\n", + " sira_numarasi += 1\n", + "\n", + " print(f\"Görev eklendi: {gorev_adi}\")\n", + "\n", + "def gorev_tamamlama():\n", + " try:\n", + " sira = int(input(\"Tamamlanacak görevin numarasini giriniz: \"))\n", + " for g in gorevler:\n", + " if g and g[\"numara\"] == sira:\n", + " g[\"durum\"] = \"tamamlandi\"\n", + " print(f\"{sira} numarali görev tamamlandi.\")\n", + " return\n", + " print(\"Görev bulunamadi.\")\n", + " except ValueError:\n", + " print(\"Geçerli bir sayi girin.\")\n", + "\n", + "def gorev_silme():\n", + " try:\n", + " numara = int(input(\"Silinecek görev numarasini girin: \"))\n", + " for i, g in enumerate(gorevler):\n", + " if g and g[\"numara\"] == numara:\n", + " g[\"durum\"] = \"Silindi\"\n", + " bos_siralar.append(i)\n", + " print(f\"{numara} numarali görev silindi.\")\n", + " return\n", + " print(\"Görev bulunamadi.\")\n", + " except ValueError:\n", + " print(\"Geçerli bir sayi girin.\")\n", + "\n", + "def tamamlanan_gorevleri_listeleme():\n", + " tamamlanmislar = [g for g in gorevler if g and g[\"durum\"] == \"tamamlandi\"]\n", + " if not tamamlanmislar:\n", + " print(\"Tamamlanmiş görev yok.\")\n", + " else:\n", + " print(\"Tamamlanmiş Görevler:\")\n", + " for g in tamamlanmislar:\n", + " print(f'{g[\"numara\"]}. {g[\"ad\"]} - {g[\"durum\"]}')\n", + "\n", + "def tum_gorevleri_listeleme():\n", + " aktif_gorevler = [g for g in gorevler if g and g[\"durum\"] != \"Silindi\"]\n", + " if not aktif_gorevler:\n", + " print(\"Görev bulunamadi.\")\n", + " else:\n", + " print(\"Tüm Görevler:\")\n", + " for g in aktif_gorevler:\n", + " print(f'{g[\"numara\"]}. {g[\"ad\"]} - {g[\"durum\"]}')\n", + "\n", + "\n", + "# Ana döngü\n", + "while True:\n", + " try:\n", + " kullanici_girisi = int(input(\"\"\"\n", + " Yapmak istediğiniz işlemin numarasini giriniz: \n", + " 1 - Görev ekleme \n", + " 2 - Görev tamamlama\n", + " 3 - Görev silme \n", + " 4 - Tamamlanan görevleri listeleme \n", + " 5 - Tüm görevleri listeleme \n", + " 6 - Çikiş yapma\n", + " >>> \"\"\"))\n", + "\n", + " if kullanici_girisi == 1:\n", + " gorev_ekleme()\n", + " elif kullanici_girisi == 2:\n", + " gorev_tamamlama()\n", + " elif kullanici_girisi == 3:\n", + " gorev_silme()\n", + " elif kullanici_girisi == 4:\n", + " tamamlanan_gorevleri_listeleme()\n", + " elif kullanici_girisi == 5:\n", + " tum_gorevleri_listeleme()\n", + " elif kullanici_girisi == 6:\n", + " print(\"Çikiliyor...\")\n", + " break\n", + " else:\n", + " print(\"Geçersiz seçim. Lütfen 1-6 arasinda bir sayi girin.\")\n", + " except ValueError:\n", + " print(\"Lütfen bir sayi girin.\")" + ] + }, + { + "cell_type": "markdown", + "id": "fee4c3e5", + "metadata": {}, + "source": [ + "# 1. Calculating the Square of a Number\n", + " Create code that calculates the square of a number both without and with using a function.\n", + " Question:\n", + " Write a function that calculates the square of a given number.\n", + " If no argument is provided, it should return the square of 10 by default.\n", + " Write a function that multiplies three different numbers and call it without specifying at least one argument.\n", + " 2. Adding Two Numbers\n", + " Create a function to add two numbers.\n", + " Question:\n", + " Write a function named add(a, b).\n", + " This function should add two numbers and return the result.\n", + " 3. Calculating Factorial\n", + " Write a function that calculates the factorial of a number.\n", + " Question:\n", + " Write a function named factorial(number).\n", + " This function should calculate the factorial of the given number. It should return 1 for 0.\n", + " 4. Finding the Largest Number in a List\n", + " Write a function that finds the largest number in a list.\n", + " Question:\n", + " Create a function named largest_number(list).\n", + " This function should return the largest number in the given list.\n", + " Example Input: [2, 3, 1, 7, 4, 2]\n", + " Expected Output: 7\n", + " 5. Calculating Retirement Age\n", + " Write a function that calculates the years left until retirement based on the user's age and gender.\n", + " Question:\n", + " Write a function named calculate_retirement_age(is_female, age).\n", + " If the person is female, the retirement age is 55.\n", + " If the person is male, the retirement age is 63.\n", + " If the person is already retired, return 'Already retired'.\n", + " 6. Recursive Factorial Calculation\n", + " Calculate the factorial using recursion instead of a loop.\n", + "# Question:\n", + " Write a function named recursive_factorial(number).\n", + " This function should calculate the factorial using recursion.\n", + " 7. Reversing Words\n", + " Create a system that reverses each word in a text.\n", + "# Question:\n", + " Write a function named split_words(text) that splits the given text into words.\n", + " Write a function named reverse_words(words) that reverses the words.\n", + " Write a function named create_new_text(reversed_words) that creates a new text with the reversed words.\n", + " Example Input: \"Ali ata bak\"\n", + " Expected Output: \"ilA ata kab\"\n", + " 8. Calculating Word Frequency\n", + " Write a function that calculates how many times each word appears in a text.\n", + "# Question:\n", + "# Write a function named word_frequency(text).\n", + "# Example Input: \"this is a test this is only a test\"\n", + "# Expected Output: {'this': 2, 'is': 2, 'a': 2, 'test': 2, 'only': 1}\n", + "# 9. Adding with Lambda\n", + "# Perform operations using anonymous (lambda) functions.\n", + "# Question:\n", + "# Create a lambda function that adds two numbers.\n", + "# 10. Calculating the Average of a List\n", + "# Calculate the average of a given list.\n", + "# Question:\n", + "# Example Input: [1, 5, 10, 2, 20]\n", + "# Expected Output: 7.6\n", + "# def average(list):\n", + "# return sum(list) / len(list)\n", + "# print(average([1, 5, 10, 2, 20]))\n", + "# 11. Filtering with Lambda\n", + "# Perform filtering on a list using lambda.\n", + "# Question:\n", + "# Write a lambda expression that filters only odd numbers in a list.\n", + "# Write a lambda expression that filters negative numbers in a list.\n", + "# Example Input: [-1, 4, 8, 14, -5]\n", + "# Expected Output: [-1, -5]\n", + "# 12. List Operations with Reduce\n", + "# Apply addition and multiplication operations to the elements of a list.\n", + "# Question:\n", + "# Calculate the sum and product of the elements of a list using reduce.\n", + "# Find the largest number in the list using reduce.\n", + "# Example Input: [1, 5, 3, 9, 2]\n", + "# Expected Output:\n", + "# Sum: 20\n", + "# Product: 270\n", + "# Largest: 9\n", + "# 13. Creating a Fibonacci Sequence\n", + "# Question:\n", + "# Write a function that returns a list of Fibonacci sequence elements up to a given number.\n", + "# For example, when fibonacci(10) is called, it should produce a Fibonacci sequence with 10 elements.\n", + "# 14. Checking if a Number is Prime\n", + "# Question:\n", + "# Write a function that checks if a number is prime and returns True (prime) or False (not prime).\n", + "# For example, when is_prime(29) is called, it should return True, and when is_prime(10) is called, it should return False.\n", + "# Question: Write a Python function that calculates the total price of items in a user's cart on an e-commerce site and applies any discounts if available.\n", + "# Function name: calculate_cart(cart, discount_code)\n", + "# Parameters:\n", + "# cart: A dictionary where each key is the product name and the value is the product's price.\n", + "# discount_code: A string containing specific discount codes (\"DISCOUNT10\" for 10% off, \"DISCOUNT20\" for 20% off).\n", + "# Expected Output: The function should calculate the total price and apply the discount if available. For example, if the cart is:\n", + "# cart = {\n", + "# 'laptop': 1500,\n", + "# 'headphones': 200,\n", + "# 'mouse': 50\n", + "# }\n", + "# and the discount code is \"DISCOUNT10\", the function calculate_cart(cart, \"DISCOUNT10\") should return 1575 (10% off 1750).\n", + "# 15. Separating List Elements as Even or Odd\n", + "# Question:\n", + "# Write a function that labels elements in a list as \"Even\" or \"Odd\".\n", + "# The function should create a list of strings indicating \"Even\" or \"Odd\" for each element in the order they appear. For example, when separate_even_odd([1, 2, 3, 4, 5]) is called, it should return ['Odd', 'Even', 'Odd', 'Even', 'Odd'].\n", + "# list = [1, 2, 3, 4, 5]\n", + "# 16. Grouping List Elements as Even and Odd Numbers\n", + "# Question:\n", + "# Write a function that separates a list into two lists. The first list should contain only even numbers, and the second list should contain only odd numbers. The function should return these two lists as a tuple. For example, when group([1, 2, 3, 4, 5]) is called, it should return ([2, 4], [1, 3, 5]).\n", + "# 17. Reversing a List\n", + "# Question:\n", + "# Write a function that reverses a list.\n", + "# For example, when reverse([1, 2, 3, 4, 5]) is called, it should return [5, 4, 3, 2, 1].\n", + "# def reverse(my_list):\n", + "# return my_list[::-1]\n", + "# print(reverse(my_list = [1, 2, 3, 4, 5]))\n", + "# 18. Calculating the Average of a List\n", + "# Question:\n", + "# Write a function that calculates the arithmetic mean of the elements of a list and returns the result. For example, when list_average([10, 20, 30]) is called, it should return 20.0.\n", + "# 19. Finding the Smallest Element in a List\n", + "# Question:\n", + "# Write a function that returns the smallest element in a list. For example, when smallest([10, 20, 5, 15]) is called, it should return 5.\n", + "# 20. Finding the Frequency of Letters in a List\n", + "# Question:\n", + "# Write a function that calculates the frequency of letters in a string. The function should return a dictionary with the letters and their respective counts. For example, when letter_frequency(\"hello world\") is called, it should return {'h': 1, 'e': 1, 'l': 3, 'o': 2, ' ': 1, 'w': 1, 'r': 1, 'd': 1}." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "af24e880", + "metadata": {}, + "outputs": [], + "source": [ + "#question 1 \n", + "import string\n", + "\n", + "\n", + "a = lambda a,b=1,c=1: a*b*c \n", + "print(a(2))\n", + "\n", + "b = lambda x: x**2 \n", + "\n", + "def calc(a=10):\n", + " return a*a\n", + "\n", + "\n", + "def kare(x=10): \n", + " return x*x\n", + "print(\"sonuc : \",kare())\n", + "print(\"sonuc : \",kare(6))\n", + "print(\"sonuc : \",kare(8))\n", + "def kare_hesapla(sayi: int | float) -> int | float:\n", + " \"\"\"Verilen sayinin karesini döndürür.\"\"\"\n", + " return sayi ** 2\n", + "\n", + "# Test\n", + "print(kare_hesapla(2)) # 4\n", + "print(kare_hesapla(3.5)) # 12.25" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d72a67ba", + "metadata": {}, + "outputs": [], + "source": [ + "#question 2 \n", + "a = lambda x,y: x+y\n", + "print(a(3,4))\n", + "\n", + "def add(a:float, b:float):\n", + " return a+b\n", + "\n", + "print(add(3,3.5))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fbb78e39", + "metadata": {}, + "outputs": [], + "source": [ + "#question 4 \n", + "\n", + "a = [3,4,7,10,1,23]\n", + "\n", + "def enbuyukbul(args):\n", + " return max(args)\n", + "\n", + "print(enbuyukbul(a))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "79f4a61f", + "metadata": {}, + "outputs": [], + "source": [ + "#question 5\n", + "\n", + "def retired(age , gender):\n", + " \n", + " if gender == \"female\" and age>63:\n", + " return \"zaten emeklisin\"\n", + " if gender ==\"female\" and age>55:\n", + " return \"zaten emeklisin\"\n", + " \n", + " if gender == \"female\":\n", + " return 55-age\n", + " else:\n", + " return 63-age\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ff76fa74", + "metadata": {}, + "outputs": [], + "source": [ + "#question 6\n", + "\n", + "def faktoriyel(a):\n", + " if a<0:\n", + " return \"eksi sayi girdiniz\"\n", + " elif a == 1:\n", + " return 1 \n", + " else: \n", + " return a * faktoriyel(a-1)\n", + "print(faktoriyel(5))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "45912dd4", + "metadata": {}, + "outputs": [], + "source": [ + "#question 7\n", + "\n", + "\n", + "def ters(arg):\n", + " for i in arg.split():\n", + " print(*reversed(i),sep=\"\",end=\"\")\n", + " print(\"-\",end=\" \")\n", + "\n", + "print(ters(\"burasi cok sicak\"))\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c39f997e", + "metadata": {}, + "outputs": [], + "source": [ + "#question 8\n", + "def word_frequency(text):\n", + " words = text.split()\n", + " frequency = {}\n", + " for word in words:\n", + " if word in frequency:\n", + " frequency[word] += 1 \n", + " else:\n", + " frequency[word] = 1 \n", + " \n", + " return frequency\n", + "text = \"this is a test this is only a test\"\n", + "print(word_frequency(text))\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "38d9c5af", + "metadata": {}, + "outputs": [], + "source": [ + "#question 9\n", + "fonk = lambda a,b: a+b\n", + "print(fonk(3,5))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2221afe6", + "metadata": {}, + "outputs": [], + "source": [ + "#question 10\n", + "\n", + "def avare(a:list) -> list:\n", + " toplam = sum(a)\n", + " return toplam/len(a)\n", + "\n", + "print(avare([1,10,34,21,2,4]))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "839dbca9", + "metadata": {}, + "outputs": [], + "source": [ + "#question 11\n", + "\n", + "test = list(filter(lambda x: x%2 !=0 and x<0, [-1, 4, 8, 14, -5,-7])) \n", + "\n", + "print(test)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "efda2876", + "metadata": {}, + "outputs": [], + "source": [ + "#question 12\n", + "from functools import reduce\n", + "\n", + "veri = [1, 5, 3, 9, 2]\n", + "print(\"sum: {}\".format(sum(veri)))\n", + "\n", + "test = reduce(lambda x,y:x*y, [1, 5, 3, 9, 2])\n", + "print(\"product: {}\".format(test))\n", + "\n", + "print(\"max: {}\".format(max(veri)))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2c3d57ab", + "metadata": {}, + "outputs": [], + "source": [ + "#question 13\n", + "from functools import reduce\n", + "\n", + "test = reduce(lambda x,y:x*y,range(1,6))\n", + "print(test)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8e3c74a1", + "metadata": {}, + "outputs": [], + "source": [ + "#question 14\n", + "\n", + "def prime(sayi):\n", + " if sayi<=1: \n", + " return False\n", + " for i in range(2, int(sayi**0.5)+1):\n", + " if sayi % i == 0:\n", + " return False\n", + " return True\n", + "\n", + "print(prime(5))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "41c3c202", + "metadata": {}, + "outputs": [], + "source": [ + "# question 15\n", + "\n", + "cart = {\n", + "'laptop': 1500,\n", + "'headphones': 200,\n", + "'mouse': 50\n", + "}\n", + "def calculate_card(card:dict, discount_code):\n", + " sum_price = 0\n", + " for i in card.values():\n", + " sum_price += int(i)\n", + "\n", + " discount_price = sum_price*int(discount_code[-2:])/100\n", + "\n", + " return int(sum_price-discount_price)\n", + "\n", + "print(calculate_card(cart,\"DISCOUNT10\"))\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2bdc6960", + "metadata": {}, + "outputs": [], + "source": [ + "# question 16\n", + "\n", + "\n", + "\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}