burakcode
MFC Üyesi
-
- Üyelik Tarihi
- 20 Nis 2021
-
- Mesajlar
- 877
-
- MFC Puanı
- 2,470
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 hesaplayan ve dosyaya nasıl yazılmasını istiyorsanız o şekilde return dönen bir fonksiyon yazın. Daha sonra bu fonksiyonu kullanarak yeni oluşturmanız gereken notlar.txt dosyasına bu bilgileri yazdırın. Örnek sonuç yine konu ekinde notlar.txt olarak eklenmiştir.
© 2021. Burakcode - Tüm Hakları Saklıdır.
Python:
def not_hesapla(satir):
satir = satir[:-1] #bu işlem her satırın sonundaki \n karakterini siler.
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"
with open("dosya.txt","r",encoding="utf-8") as file:
eklenecekler_listesi = []
for x in file:
eklenecekler_listesi.append(not_hesapla(x))
with open("notlar.txt","w",encoding="utf-8") as file2:
for x in eklenecekler_listesi:
file2.write(x)