# 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
{"ft_lang_label":"__label__en","ft_lang_prob":0.81217223,"math_prob":0.9826124,"size":2911,"snap":"2021-21-2021-25","text_gpt3_token_len":1037,"char_repetition_ratio":0.16821465,"word_repetition_ratio":0.22870663,"special_character_ratio":0.4029543,"punctuation_ratio":0.10656934,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99711066,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46],"im_url_duplicate_count":[null,3,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-06-21T01:24:33Z\",\"WARC-Record-ID\":\"<urn:uuid:25595ad4-1212-45ea-b48e-13d9b2f363f4>\",\"Content-Length\":\"87150\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3b4a5644-2416-45f6-8340-eebf5ebe78d9>\",\"WARC-Concurrent-To\":\"<urn:uuid:88bd7d53-d796-42c1-9cf4-5d488d8f1f88>\",\"WARC-IP-Address\":\"67.205.40.143\",\"WARC-Target-URI\":\"https://www.allfreevideotutorials.com/introduction-to-for-loops-in-python-python-tutorial-5/\",\"WARC-Payload-Digest\":\"sha1:YTINITCHZNZ5VYYWYWLC2U4B3UUS5QUX\",\"WARC-Block-Digest\":\"sha1:E7K7WRWBWPRAW23XAUEWUMTKDGFZRXPP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-25/CC-MAIN-2021-25_segments_1623488259200.84_warc_CC-MAIN-20210620235118-20210621025118-00286.warc.gz\"}"}