• Web sitemizin içeriğine ve tüm hizmetlerimize erişim sağlamak için Web sitemize kayıt olmalı ya da giriş yapmalısınız. Web sitemize üye olmak tamamen ücretsizdir.
  • Sohbetokey.com ile canlı okey oynamaya ne dersin? Hem sohbet et, hem mobil okey oyna!
  • Soru mu? Sorun mu? ''Bir Sorum Var?'' sistemimiz aktiftir. Paylaşın beraber çözüm üretelim.
Bu, hızlı yüklenen mobil optimize edilmiş bir AMP sayfadır, gerçek sayfayı yüklemek istiyorsanız bu metni tıklayın.

Dosya İşlemleri - Egzersiz 2

burakcode

MFC Üyesi
Üyelik Tarihi
20 Nis 2021
Konular
90
Mesajlar
944
MFC Puanı
2,120
Elinizde konu ekinden indirebileceğiniz dosya.txt dosyanız olsun. Burada öğrenciler ve aldıkları 2 vize ve final notları yazılı. Bu dosyadaki bilgiler ile öğrencilerin harf notunu hesaplayıp FF alanların kalanlar FF ten yüksek alanların geçenler olarak ayıran 2 adet ayrı fonksiyon yazın. Daha sonra bu fonksiyonları kullanarak yeni oluşturmanız gereken kalanlar.txt ve geçenler.txt dosyalarına bu bilgileri yazdırın. Örnek sonuç yine konu ekinde kalanlar.txt ve geçenler.txt olarak eklenmiştir.

Python:
def not_hesapla(satir):
    satir = satir[:-1]

    liste = satir.split(",")

    isim = liste[0]
    not1 = int(liste[1])
    not2 = int(liste[2])
    not3 = int(liste[3])

    son_not = (not1 * 3/10) + (not2 * 3/10) + (not3 * 4/10)

    if son_not >= 90:
        harf = "AA"
    elif son_not >= 85:
        harf = "BA"
    elif son_not >= 80:
        harf = "BB"
    elif son_not >= 75:
        harf = "CB"
    elif son_not >= 70:
        harf = "CC"
    elif son_not >= 65:
        harf = "DC"
    elif son_not >= 60:
        harf = "DD"
    elif son_not >= 55:
        harf = "FD"
    else:
        harf = "FF"

    return isim + "-------------------------->" + harf + "\n"


def kalanlar(satir):
    satir = satir[:-1]

    liste = satir.split(",")

    isim = liste[0]
    not1 = int(liste[1])
    not2 = int(liste[2])
    not3 = int(liste[3])

    son_not = (not1 * 3/10) + (not2 * 3/10) + (not3 * 4/10)

    if son_not < 55:
        return isim + " --- FF\n"
    else:
        return ""

def gecenler(satir):
    satir = satir[:-1]

    liste = satir.split(",")

    isim = liste[0]
    not1 = int(liste[1])
    not2 = int(liste[2])
    not3 = int(liste[3])

    son_not = (not1 * 3/10) + (not2 * 3/10) + (not3 * 4/10)

    if son_not >= 90:
        harf = "AA"
    elif son_not >= 85:
        harf = "BA"
    elif son_not >= 80:
        harf = "BB"
    elif son_not >= 75:
        harf = "CB"
    elif son_not >= 70:
        harf = "CC"
    elif son_not >= 65:
        harf = "DC"
    elif son_not >= 60:
        harf = "DD"
    elif son_not >= 55:
        harf = "FD"
    else:
        harf = "FF"

    if harf != "FF":
        return isim + " --- " + harf + "\n"
    else:
        return ""

with open("dosya.txt","r",encoding="utf-8") as file:
    eklenecekler_listesi = []
    for x in file:
        eklenecekler_listesi.append(kalanlar(x))
    for x in eklenecekler_listesi:
        if x == "":
            eklenecekler_listesi.remove("")

    with open("kalanlar.txt","w",encoding="utf-8") as file2:
        for x in eklenecekler_listesi:
            file2.write(x)

with open("dosya.txt","r",encoding="utf-8") as file:
    eklenecekler_listesi = []
    for x in file:
        eklenecekler_listesi.append(gecenler(x))
    for x in eklenecekler_listesi:
        if x == "":
            eklenecekler_listesi.remove("")

    with open("gecenler.txt","w",encoding="utf-8") as file2:
        for x in eklenecekler_listesi:
            file2.write(x)

© 2021. Burakcode - Tüm Hakları Saklıdır.
 

Ekli dosyalar

  • dosya.txt
    2 KB · Görüntüleme: 3
  • kalanlar.txt
    903 bayt · Görüntüleme: 3
  • gecenler.txt
    999 bayt · Görüntüleme: 3