# Introduction to For Loops in Python (Python Tutorial #5)

///Introduction to For Loops in Python (Python Tutorial #5)
• ## Introduction to For Loops in Python (Python Tutorial #5)  Add to favorites

For loops Python tutorial.

This entire series in a playlist:
Keep in touch on Facebook:
Download the sample file:
Subscribe to my newsletter:
Support me on Patreon:

source

By |2019-11-15T23:58:12+00:00November 15th, 2019|Python Video Tutorials|20 Comments

### 20 Comments

1. Yan Qing Zhang November 15, 2019 at 11:58 pm - Reply

I got 315

2. SpicyCoral November 15, 2019 at 11:58 pm - Reply

you need to remove duplicate multipul that are in the same time multipul 3 and 5 to dont have dupplicate value
m1=0
for i in range(1,100):
if i % 3== 0 or i % 5 == 0:
m1 += i
m2= 0
if i % 3== 0 and i % 5 == 0:
m2 += i
total= m1 – m2
print(total)
2003

3. Vishnu Priya November 15, 2019 at 11:58 pm - Reply

total = 0

for i in range (1,100):

if i%3 ==0 or i%5 == 0:

total += i

print (total)
ans = 2318

4. Egon Spengler November 15, 2019 at 11:58 pm - Reply

If anyone else is having a hard time keeping up, i set the playback speed to 75% and it made it easier to follow. 😉

5. Egon Spengler November 15, 2019 at 11:58 pm - Reply

I think my brain might be to dumb for this. LOL. I was following pretty okay up to this lesson, then it just left me in the dust. I need coding lessons aimed for 5 year olds. haha. And I'm 38!

6. nilay kanakia November 15, 2019 at 11:58 pm - Reply

total4 = 0
for i in range (1, 100):
if i % 3 == 0 or i % 5 == 0
total4 += i
print(total4)

7. eli eli November 15, 2019 at 11:58 pm - Reply

a=list(range(0,100))

total=0

for i in a:

if i%3==0 or i%5==0:

total+= i

print(total)

8. Al Mamun November 15, 2019 at 11:58 pm - Reply

data=list(range(1,100))

print(data)

total=0

for i in data:

if i%3==0 and i%5==0:

total+=i

print(i)

print(total)

9. I AM HARSH November 15, 2019 at 11:58 pm - Reply

total = 0

range(1, 100)

for m in range(1, 100):

if m % 3 == 0 and m % 5 == 0:

total += m

print(total)

10. Ethan Nguyen November 15, 2019 at 11:58 pm - Reply

why do we have to use the total variable to find the sum? Wouldn't the command "sum" do the same job?

11. Jye Cassidy November 15, 2019 at 11:58 pm - Reply

total4 = 0
for a in range(1,100):
if a % 3 == 0 or a % 5 == 0:
total4 += a
print(total4)

Thumbs up if right

12. MuxTube November 15, 2019 at 11:58 pm - Reply

That is bit complex

total2 = 0

for i in range(1, 5):

total2+=i

print(total2)

result
1

3

6

10

Why it is not giving only 10?

13. Benjamin Hammond November 15, 2019 at 11:58 pm - Reply

total=0
for i in range(1, 100):
if i % 3 == 0:
total += i
elif i % 5 == 0:
total += i
print(total)
2318

14. Shubhangi Zade November 15, 2019 at 11:58 pm - Reply

I got 2633

15. ALHAJICM KALLON November 15, 2019 at 11:58 pm - Reply

I got 1683

16. Joel Kye November 15, 2019 at 11:58 pm - Reply

in addition to totaling multiples of 3 and 5 I wrote the following code lines to deduct multiples of 15,
if E1 % 15 == 0:

#deduct multiples of 15

total4 -= E1

17. Andrew Sinclair-Gunn November 15, 2019 at 11:58 pm - Reply

Great tutorial, though I did find the challenge a bit ambiguous as I wasn't sure if I should count the values divisible by both 3 and 5 twice or just once (e.g. 15 % 3 = 0 and 15 % 5 = 0). So I did both 🙂
total4 = 0

total5 = 0

for i in range(1,100):

if (i% 3 == 0) or (i % 5 == 0):

total4 += 1

print("unique = " + str(total4))

for i in range(1,100):

if (i % 3 == 0):

total5 += 1

if (i% 5 == 0):

total5 += 1

print("total = " + str(total5))

18. Berman Ramadhan Channel November 15, 2019 at 11:58 pm - Reply

someone please tell me what for is

19. Master1001 November 15, 2019 at 11:58 pm - Reply

Fantastic Tutorials in every aspect. Thanks for making them!

20. Ram krishna namdev November 15, 2019 at 11:58 pm - Reply

# to sum up all integers which are multiples of 3 or 5 and less than 16
total4 = 0

for z in range (1, 16):

if (z % 3) == 0 or (z % 5) == 0:

total4 += z

print (total4)

it gives 60

# to sum up all integers which are multiples of 3 or 5 and less than 100

total4 = 0

for z in range (1, 100):

if (z % 3) == 0 or (z % 5) == 0:

total4 += z

print (total4)

it gives 2318