Şu problemi çözmeye çalışıyordum https://projecteuler.net/problem=1
Burada tek doğru calışan yöntem3 .
Yontem1 ve yontem2 neden yanlış sonuç veriyor ?
Birde yontem4
TypeError: 'int' object is not callable
sebebini anlayamadım, yardımcı olursanız sevinirim.
def yontem1(s1,s2,tavan):
sayillar = [s1,s2]
toplam = 0
for rakamlar in sayillar:
for i in range(1,int((tavan-1)/rakamlar)+1):
toplam += i*rakamlar
return toplam
def yontem2(s1,s2,tavans):
sayilar = [s1,s2]
toplam = 0
for rakamlar in sayilar:
for i in range(1,tavans):
if i % rakamlar == 0:
print(i)
toplam += i
return toplam
def yontem3(s1,s2,tavan):
toplam = 0
for i in range(tavan):
if i%s1 == 0 or i%s2 == 0:
toplam += i
return toplam
def yontem4(s1,s2,tavan):
toplam = 0
toplam([i for i in range(tavan) if i%s1 == 0 or i%s2 == 0 ])
return toplam
print(yontem1(3, 5, 1000))
print(yontem2(3, 5, 50))
print(yontem3(3, 5, 50))
print(yontem4(3, 5, 1000))