Python Fonksiyondan veri çekme

Kunkka

Hectopat
Katılım
19 Ekim 2019
Mesajlar
1.422
Çözümler
4
Yer
Dire
Aşağıdaki program dosya.txt içerisinde bulunan not listesindeki notları hesaplamakta ve harf notlarını notlar.txt içerisine yazdırmakta. Ben ayriyeten kalanlar.txt ve geçenler.txt dosyası oluşturup kalanları ve geçenleri ayrı dosyalara yazdırmak istiyorum lakin benim başaramadığım şey ise fonksiyon içerisinden koşul için sadece not kısmını çekememek. Cevabınız için şimdiden teşekkürler.

Python:
def not_hesapla(satır):
    satır=satır[:-1]
    liste=satır.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"


with open("dosya.txt","r",encoding="utf-8") as file:
    eklenecekler_listesi=[]
    for i in file:
        eklenecekler_listesi.append(not_hesapla(i))
    print(eklenecekler_listesi)

with open("notlar.txt","w",encoding="utf-8") as file2:
    for i in eklenecekler_listesi:
        file2.write(i)
 
Daha açık nasıl anlatabilirim bilmiyorum arkadaşlar. Kısacası kalanlar ve geçenler diye txt oluşturmak istiyorum ama veriyi çekemiyorum. Nasıl çekebileceğimi soruyorum.
Python:
def hesapla():
    kalanlar = []
    geçenler = []
    eklenecek = []
    ...
    if noot < kalmamak_için_min:
        kalanlar.append(noot)
       
    return kalanlar, geçenler, eklenecek

kalanlar, geçenler, eklenecek = hesapla()
Programın genel yapısını buna benzer bir şey yap.
 
Python:
def not_hesapla(satır):
    global harf
    satır=satır[:-1]
    liste=satır.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, son_not, harf,]


with open("dosya.txt","r",encoding="utf-8") as file:
    for i in file:
        i=not_hesapla(i)
        with open("notlar.txt","a", encoding="utf-8") as file2:
            file2.write(i[0]+"------>"+i[2]+"\n")
        if(i[1]<=60):
            with open("kalanlar.txt","a", encoding="utf-8") as file3:
                file3.write(i[0] + "------>" + i[2] + "\n")
        else:
            with open("gecenler.txt","a", encoding="utf-8") as file4:
                file4.write(i[0] + "------>" + i[2] + "\n")
 

Yeni konular

Geri
Yukarı