AI'yı Denetle
Pozitif Toplam
Her çözümü etiketle: doğru, doğru ama gereksiz yavaş, ya da hatalı. Hatalı olan tek bir karakterle yanılıyor.Problem
positive_sum(values): listedeki pozitif sayıların toplamını döndür.Çözüm A
1def positive_sum(values):
2 return sum(v for v in values if v > 0)
Çözüm B
1def positive_sum(values):
2 total = 0
3 for v in values:
4 if v > 0:
5 total =+ v
6 return total
Çözüm C
1def positive_sum(values):
2 total = 0
3 for v in sorted(values):
4 if v > 0:
5 total += v
6 return total