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

Поділитися
Вставка
  • Опубліковано 27 вер 2024
  • For loops Python tutorial.
    This entire series in a playlist: goo.gl/eVauVX
    Keep in touch on Facebook: / entercsdojo
    Download the sample file: www.csdojo.io/...
    Subscribe to my newsletter: www.csdojo.io/...
    Support me on Patreon: / csdojo

КОМЕНТАРІ • 3,9 тис.

  • @shuttershocker
    @shuttershocker 2 роки тому +71

    total4 = 0
    for item in range(1, 100):
    if item % 3 == 0 or item % 5 == 0:
    total4 += item
    print(total4)
    2318
    These videos are a lot better than my lecturer thank you! :)

    • @Bakekun
      @Bakekun 8 місяців тому +1

      Niceeee

    • @LeoDragonheart13
      @LeoDragonheart13 7 місяців тому +2

      Been trying to self teach for years and kept giving up cause I couldn't get anywhere or understand it on my own at the times, with these tutorials it's actually pretty fun and I'm enjoying it. I got most of the answer here for the problem, but completely forgot I could use "or" there, would've been stuck for an hour trying to figure it out if I hadn't looked at the comments xD

    • @Dark_dragon1212
      @Dark_dragon1212 4 місяці тому

      It keeps giving me 0
      What might I be doing wrong?
      Edit: nvm, found it 😅😅😅

    • @abhipatel4595
      @abhipatel4595 2 місяці тому

      @@LeoDragonheart13if you are stuck for that long, you should ask chatgpt, thats what i always do when im really stuck and can’t figure it out 👍❤️

    • @nrrdpanda
      @nrrdpanda 2 місяці тому

      Ooo nice! the "or" threw me off.. i couldn't figure out what i was doing wrong haha

  • @FootnotesToPlato
    @FootnotesToPlato 4 роки тому +1651

    who else is loving this series on quarantine

    • @Boc3phu5
      @Boc3phu5 4 роки тому +19

      Learning a new skill

    • @AbdulKaderAbdeenAgha
      @AbdulKaderAbdeenAgha 4 роки тому +8

      totally

    • @moebulldog6922
      @moebulldog6922 4 роки тому +7

      i need help with python

    • @jjredfox3504
      @jjredfox3504 4 роки тому +12

      I was so bored of doing nothing and this was just some top tier stuff

    • @0_-
      @0_- 4 роки тому +6

      100% me

  • @ginethespinosa9827
    @ginethespinosa9827 3 роки тому +262

    total = 0
    for i in range(1,100):
    if i % 3 == 0 or i % 5 ==0:
    total += i
    print (total)
    Thanks, CSDojo, I love your explanation and homework.

    • @anthonynarine5292
      @anthonynarine5292 2 роки тому +4

      aww why did you post this lol.

    • @cakeuwaifu
      @cakeuwaifu 2 роки тому +19

      @@anthonynarine5292 why not?

    • @anthonynarine5292
      @anthonynarine5292 2 роки тому +23

      I accidentally gazed over the answer 🤣. I unintentionally copied 😅😅😅

    • @oluwadunsinoladipo2956
      @oluwadunsinoladipo2956 2 роки тому +10

      @@anthonynarine5292 😹😹😹you’re the funniest person I’ve met on the net today

    • @anthonynarine5292
      @anthonynarine5292 2 роки тому +1

      @@oluwadunsinoladipo2956 hahahahha

  • @276sedvlintsax7
    @276sedvlintsax7 4 роки тому +256

    Taught me more in ten minutes than 3 of my hour python lessons.

  • @Rasberrychua999
    @Rasberrychua999 4 роки тому +531

    i literally paid around 35 grand a year to get my programming engineering degree, but lecturers and tutors are just reading the codes and not even explaining it lol -.-
    im loving how i have only watched 5 episodes and paid NOTHING, I have learnt way more about programming here compared to uni ;-;

    • @axel_r_
      @axel_r_ 4 роки тому +28

      Same here. I have this one teacher who is more focused on talking about the content than actually teaching the students. When this teacher is done talking its "bye!" and gone... students confused af... --> let's go to youtube and get help from the Dojo gang!

    • @tenesiadontneedja
      @tenesiadontneedja 4 роки тому +16

      that is exactly why I am here lol, teachers do not teach

    • @Turd13s
      @Turd13s 3 роки тому +1

      Wow, 35 grand went down the drain huh.

    • @axel_r_
      @axel_r_ 3 роки тому +11

      @@Turd13s Actually, no. You still need to pay schools to get the official papers that are needed to get into the business with the desired technologies.

    • @ahmedabdelsalamabdelhalims6968
      @ahmedabdelsalamabdelhalims6968 3 роки тому +1

      @@axel_r_ if you put it like that just half of 'em went down the drain...

  • @YeahMadeit_17
    @YeahMadeit_17 2 роки тому +18

    Hi! I'm Russian and i know English little bit, but UA-cam has subtitles and it gives me an opportunity to learn Python) I started watching Your videos because rus UA-cam doesn't have normal lessons. Thank u and don't stop making new videos)

  • @MonteroKirilenko
    @MonteroKirilenko 5 років тому +64

    Hey YK, thanks for the great tut. You deserve 1,000 claps on Medium :-). Here's my answer to the challenge:
    list(range(1, 100))
    total4 = 0
    for number in range(1, 100):
    if number % 3 == 0 or number % 5 == 0:
    total4 += number
    print(total4)
    2318

    • @aryabima256
      @aryabima256 3 роки тому +13

      I was so confused on how to solve it cause I didn't know "or" is a thing 😂

    • @sanjosabu8170
      @sanjosabu8170 3 роки тому +1

      @@aryabima256 same🙄😪😂😜

    • @xuanyuliang101
      @xuanyuliang101 3 роки тому +3

      @@aryabima256 I also didn't realize the "or" part, I tried "elif", but it didn't work😂

    • @lamp9611
      @lamp9611 3 роки тому +1

      AAAAA i feel dumb I included the hundred 💀💀💀

    • @revathirev365
      @revathirev365 3 роки тому +2

      i tried using if and elif and it worked :-) got the same , but your way of approach by using or is very time saving.

  • @amberniesalting9011
    @amberniesalting9011 3 роки тому +38

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

    • @sanjivverasamy5716
      @sanjivverasamy5716 3 роки тому

      the same answer i got

    • @jaubee
      @jaubee 2 роки тому +1

      @@sanjivverasamy5716 ive been trying to find someone with a answer in the comments. this is what i got. he didnt have the answer on his DL file. I also did it differently
      total4 = 0
      for j in range(1, 100):
      if j % 5 == 0:
      total4 += j
      if j % 3 == 0:
      total4 += j
      print(total4)
      2633

    • @t3hdude
      @t3hdude 2 роки тому +3

      @@jaubee Dude I'm pretty sure the answer is 2318. You put 2 if statements I think that's why you got a different answer. It's adding the total from the first if statement to the next one, instead of adding all of them at once. Use an "or" like the comment above and you will get 2318.

    • @spartacus8742
      @spartacus8742 2 роки тому +3

      @@jaubee I agree with the guy above. The crux of why your way doesn’t work (I wanted to try it that way at first as well) is because you are adding numbers that are multiples of 3 AND 5 (like 15, 30) twice.

    • @joeroganpodfantasy42
      @joeroganpodfantasy42 2 роки тому +1

      wait a second we haven't learned or statement yet so your answer is invalid.
      This is as far as I got I have no clue how to substract the numbers that are divisible by 5 and 3 with the current knowledge:
      total3 = 0
      total5 = 0
      for i in range(1, 100):
      if i % 3 == 0:
      total3 += i
      print(total3)
      for i in range(1,100):
      if i % 5 == 0:
      total5 += i
      print(total5)
      c = total3 + total5
      print(c)

  • @luuchoo93
    @luuchoo93 4 роки тому +33

    The level of satisfaction I get when I end up one of your videos achieving the same results on my own, is epic.
    Great tutorial, keep it going!

  • @emmanueloseitutu7376
    @emmanueloseitutu7376 2 роки тому +8

    Perfect explanation for "for loop". I'm yet to watch the while loop but I'm convinced enough.
    Thanks!

    sum, total = 0, 0
    for x in range(1,100):
    if (x%3 ==0):
    sum += x
    elif (x%5 ==0):
    total += x


    print(sum, total)

    • @emreuras2168
      @emreuras2168 2 роки тому +1

      rather than equals the zero both three and five you can do x % 15 == 0 same result

    • @Msliliheart
      @Msliliheart 2 роки тому

      I used this and got the wrong answer for the multiples of 5.

    • @venxity6959
      @venxity6959 2 роки тому

      problem = list(range(1,100))
      sum = 0
      for element in problem:
      if element % 3 == 0 or element % 5 == 0:
      sum += element
      print (sum)
      heres the actual answer, your one doesn't work because it counts nubers that are multiples of both 3 and 5, Good try tho, Similar to what I did at first because I forgot about the "or" statement

  • @horkoser
    @horkoser 4 роки тому +280

    This is my attempt:
    total = 0
    for i in range(1, 100):
    if i%3 == 0 or i%5 == 0:
    total += i
    print ("Total:", total)
    Total: 2318
    Another way:
    total = 0
    for i in range(1, 100):
    if i%3 == 0:
    total += i
    elif i%5 == 0:
    total += i
    print ("Total:", total)
    Total: 2318

    • @hansonng4711
      @hansonng4711 4 роки тому +6

      should I use "and" or "or" ?

    • @gallonrs
      @gallonrs 4 роки тому +25

      @@hansonng4711 if you use and, you will add up only number that are both multiple of 3 and 5, like 15, 30, 60, etc. You should get 315 by doing that.

    • @kenanloughlin5059
      @kenanloughlin5059 4 роки тому +4

      Anyone else just put i % 3 == 0: and get 9

    • @vanwest9614
      @vanwest9614 4 роки тому +2

      bro i got 33

    • @haronbansilan2984
      @haronbansilan2984 4 роки тому +5

      I learned a lot on this conversation. Thank you all

  • @blufy2804
    @blufy2804 3 роки тому +11

    I came with two solutions:
    First
    total = 0
    for i in range(1, 100):
    if i % 3 == 0 or i % 5 == 0:
    total = total + i
    print(total)
    And i got 2318, but because I realized we don't learn 'or' statement yet, I came to second solution
    total = 0
    for i in range(1, 100):
    if i % 3 == 0:
    total += i
    elif i % 5 == 0:
    total += i
    print(total)
    Thanks for the tutorial mate!

    • @TrexTheFirst
      @TrexTheFirst 2 роки тому

      Both the ways have same answer. Which one is more efficient?

    • @farkhodkuchkarov5238
      @farkhodkuchkarov5238 2 роки тому

      But is this the right answer?
      Cause my solutions looks very similar here.

    • @ppmokgoro
      @ppmokgoro 2 роки тому

      my understanding could be wrond: but didnt he say the modulo should be 3 AND 5 as opposed to 3 or 5?

  • @vysakhkodavana8932
    @vysakhkodavana8932 4 роки тому +149

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

    • @gracepayne2936
      @gracepayne2936 4 роки тому +3

      Thanks so much

    • @sushilkumarlohani6709
      @sushilkumarlohani6709 4 роки тому +1

      Thank you

    • @crab1458
      @crab1458 4 роки тому +35

      He said multiples of 3 and 5, that is why he mentioned "15", so the code is actually:
      total = 0
      for i in range(1,100):
      if i % 3 and i % 5 ==0:
      total += i
      print(total)

    • @zen36158
      @zen36158 4 роки тому +4

      list(range(1, 101))

    • @ティツィアーノ
      @ティツィアーノ 4 роки тому +7

      total=0
      for e in list(range(1,101)):
      if e % 3 ==0:
      total += e
      if e % 5 ==0:
      total+=e
      print(total)
      this also works

  • @courtney-nogel
    @courtney-nogel 6 років тому +23

    I experienced a moment of sheer joy when I was (finally) able to get them all to print...WITHOUT sneaking a peek at the comments to find hints lol. Your videos are really helping to motivate me to (also finally) start learning programming. Truly, thank you!!

  • @LAM638
    @LAM638 2 роки тому +2

    I don't usually leave comment in YT but your tutorial is easy to understand for beginner. Thank you

  • @kasperderej7401
    @kasperderej7401 4 роки тому +463

    Please don't stop what you're doing. You're a great teacher!

    • @aidantan9566
      @aidantan9566 3 роки тому +6

      THAT'S WHAT SHE SAID

    • @swallowedinthesea11
      @swallowedinthesea11 2 роки тому +1

      bool( "THAT'S WHAT SHE SAID" )

    • @mdvlogs5418
      @mdvlogs5418 2 роки тому +1

      true he is the best online python (arguably the best offline teacher ) that i personally ever had

    • @pedro.fonseca
      @pedro.fonseca Рік тому

      yes!

    • @uzbek_coding
      @uzbek_coding Рік тому

      ​@@aidantan9566​ he's not girl you must say: THAT'S WHAT HE SAID

  • @hereslookingatyoukid
    @hereslookingatyoukid 4 роки тому +11

    Alternate solution to using or/and/set
    total4 = 0
    for v in range(1, 100):
    if v % 3 == 0:
    total4 += v
    elif v % 5 == 0:
    total4 += v
    print(total4)
    2318

    • @joeroganpodfantasy42
      @joeroganpodfantasy42 2 роки тому +1

      yes this is the correct solution he wants because he hasn't intoduced and or statements.

    • @itssara2053
      @itssara2053 2 роки тому

      I solved it this way too !!
      But used
      Else :
      If:
      Instead of elif:

    • @ernestpaul9954
      @ernestpaul9954 2 роки тому

      @@itssara2053 did you get the same answer though?

    • @itssara2053
      @itssara2053 2 роки тому

      @@ernestpaul9954 sure , elif is a short cut of
      Else :
      If:

    • @luvie692
      @luvie692 2 роки тому

      I got 2327, we have the same code tho
      I used 'or', the answer is 5909 wth haha

  • @MonicaBetancourt-ln9eu
    @MonicaBetancourt-ln9eu 5 місяців тому

    You absolutely make my Phyton learning experience a charm, few have the gift of knowing how to easily convey how to code, you have a gift and for that thank you so very much!

  • @yatink4981
    @yatink4981 6 років тому +12

    You're way good than my programming teacher ,though I'm studying in one of the best institutes in India I always prefer you. Thank u so much.

  • @VgGamerKnight
    @VgGamerKnight 3 роки тому +5

    I love this channel, I'm an absolute beginner and YK explains it so well that I don't even need to take notes.

  • @itay5825
    @itay5825 2 роки тому +2

    i just started python and I've been stuck on for loops for a few days now, when i watched your video i instantly understood the concept and how it works, can't thank you enough!!!!

  • @kangajankuganathan7457
    @kangajankuganathan7457 5 років тому +271

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

    • @theultimateknight7356
      @theultimateknight7356 5 років тому

      Thanks

    • @mrxizhe
      @mrxizhe 5 років тому

      thank you

    • @allstat7342
      @allstat7342 5 років тому +9

      you know you're lazy when you copy this little code

    • @mohitkumar-cm5nk
      @mohitkumar-cm5nk 5 років тому +4

      How come.. print (1 %3) shows 1 ..remainder should be 2 ..can you please help or guide..video time is 8:08

    • @mohitkumar-cm5nk
      @mohitkumar-cm5nk 5 років тому +2

      @@swethaskr2188 I am getting it. I am stuck on this since morning..still I cant understand if you divide 3 by 1 then how come it is 1 mam.

  • @JesusJFuncia
    @JesusJFuncia 4 роки тому +11

    Great video. All the explanations are very clear.
    These are my attempts. With "Compute" I wasn't if you mean to just show all the multilpes of 3 and 5 or also sum them, so I have tried both.
    To show all the multiples of 3 and 5:
    for i in range(1, 100):
    if i % 3 == 0 or i % 5 == 0:
    print(i)
    To sum them:
    total4 = 0
    for i in range(1, 100):
    if i % 3 == 0 or i % 5 == 0:
    total4 += i
    print(total4)
    Total is 2318

    • @mingji753
      @mingji753 2 роки тому

      if we only have to find the sum of multiples of 3
      the formula is:
      for i in range(1, 101):
      if i % 3 == 0:
      print(i)
      #To add them
      total = 0
      for i in range(1, 101):
      if i % 3 == 0:
      total = total + i
      print(total)
      the answer is 1683

  • @davida6146
    @davida6146 2 роки тому +7

    I went through my python class struggling with this but surprisingly still finished well. What you explained in this video, my instructor made it more complicated 😅
    Thank you!

  • @TheProGam3rHD
    @TheProGam3rHD 3 роки тому +5

    I can't believe I figured this on my own! For the multiple of 3, alternatively, you can use a nested for loop:
    for i in range(1, 8):
    for n in range(1, 8):
    if i / 3 == n:
    total3 += i
    print(total3)
    Although inconvenient, this circumvents the need to use the modulo operator. This is what I came up with because I didn't even think to use it.

    • @ramy131
      @ramy131 3 роки тому

      this answer is wrong lmao.

    • @TheProGam3rHD
      @TheProGam3rHD 3 роки тому +2

      @@ramy131 Please explain how this is wrong lmao. It works. 😂

    • @ramy131
      @ramy131 3 роки тому

      @@TheProGam3rHD I copied and pasted it on pycharm and it gave absolutely nothing back

    • @ramy131
      @ramy131 3 роки тому

      @@TheProGam3rHD besides this wasn’t the challenge he fucking asked for

    • @TheProGam3rHD
      @TheProGam3rHD 3 роки тому +2

      @@ramy131 Well clearly 4 other people liked my comment so it worked for them. You must have done something wrong. And why the hell are you getting so butthurt?

  • @tusharedits9
    @tusharedits9 4 роки тому +7

    Hey CS Dojo / YK,
    You are just amazing. I loved the way you teach all the topics so easily. I am learning python and I am going watching your whole series on python because when I started to learn python I was taught that it is very hard and complicated. But now I don't think so now.
    I am from India and I am in high school right now. I wished you were my computer teacher but no problem. Thanks once again for such wonderful videos.

  • @ivanott7196
    @ivanott7196 3 роки тому +2

    When I studied programming at university, I thought I was stupid for being very slow to understand it. As a geo-engineer, we basically understand something through why the result or outcomes become like that instead of just accepting it has to be like that. The programming teacher basically just asked us to watch videos, take tests and do little projects but barely teaching in the depth. I was kinda angry because I think she needs to use different methods how to teach programming to the future engineers, instead of treating us like future IT guys. So this channel does make me understand in detail why the outcomes like that. Thank you!

  • @j9studios384
    @j9studios384 3 роки тому +3

    Thank you so much. I have been struggling learning python on my crappy online college. I learned more in your ten minute video than I have learned staring at a digital text book for weeks. Found my new teacher for learning python

  • @christopherwolters2048
    @christopherwolters2048 8 місяців тому

    I didn't know about the "or" operator in the "if" statement until I read other people's post. Thanks everyone. My first attempt was:
    sum = 0
    for i in range(1,100):
    if i % 3 ==0:
    sum += i
    elif i% 5 == 0:
    sum +=i
    print(sum)
    Answer is 2318.
    I'm going to try using "or" in the "if" statement now.
    Great videos! Thank you!

  • @ericji8632
    @ericji8632 2 роки тому +11

    print(list(range(1, 100)))
    total = 0
    for i in range(1, 100):
    if i % 3 == 0 or i % 5 == 0:
    total = i
    print(total)
    this code is used to find all the numbers inside the list. Print(total) is inside of the "for loop" in this case to list all of the numbers out

    • @manba7344
      @manba7344 Рік тому

      why did you do total=o and total=i in the code? I'm having trouble understanding haha

    • @dhdhdkfjgjdmf5277
      @dhdhdkfjgjdmf5277 Рік тому +2

      @@manba7344 he should have written total += i instead of total = i

    • @prachaurja
      @prachaurja Рік тому

      @Eric Ji you did wrong bro. sorry. but the code will be like -
      sum = 0
      for i in range(1,100):
      if i%3 == 0 or i%5 == 0:
      sum = sum + i
      print(sum)

    • @chimdiikechukwu7142
      @chimdiikechukwu7142 Рік тому

      @@prachaurja what was your final answer when you processed the code?

  • @lanceareadbhar
    @lanceareadbhar 3 роки тому

    Very cool. I came here because I saw multiple people using the code "for node in" and assumed node was a keyword not realizing any text would have worked there.

  • @javierlujan9249
    @javierlujan9249 4 роки тому +6

    The cleanest, easiest video yet in 2020! Thank you I promise to give you a free lambo when I'm rich

  • @blakeparker6588
    @blakeparker6588 5 років тому +25

    Thanks CS dojo, I've learnt and developed my Python skills a lot through your tutorial videos!!

  • @VicLaranja
    @VicLaranja 3 роки тому +2

    Dojogang!
    Ive been learning for a week now, I have started multiple courses so far and yours is honestly the best. So thorough and well explained. Thank you!!

    • @VicLaranja
      @VicLaranja 3 роки тому +1

      what = 0
      for each in range(1, 101):
      if each % 5 == 0:
      print(each)
      if each % 3 == 0:
      print(each)
      Solved this btw

    • @Mr-sn2qw
      @Mr-sn2qw 3 роки тому

      @@VicLaranja I think u know by now, so is it correct?
      for e in range(1, 101):
      e += 1
      if e%3 ==0:
      print (e)
      elif e%5 ==0:
      print(e)

  • @yasserfathelbab1534
    @yasserfathelbab1534 2 роки тому +3

    I really like how you elaborated that we can use element or anything else and where is += is coming from. great educator :))

  • @jaicymelisse5532
    @jaicymelisse5532 2 роки тому +3

    Wow, as everyone else is saying, THANK YOU!! I've been stuck in my current python course and this was a great explanation. Really explaining each part well, to help our minds understand. ✌🏼

    • @dukhtarakhtar
      @dukhtarakhtar 2 роки тому

      Is this video visible? I have problem

  • @kafleykishore87
    @kafleykishore87 9 місяців тому

    sum1 = 0
    for i in range(1,100):
    if i % 3 == 0 or i % 5 == 0:
    sum1 += i
    print(sum1)
    2318
    Your videos are really interesting and teach the concepts in a simplified form. Great Work and Thank You

  • @ryanarpon158
    @ryanarpon158 5 років тому +14

    Hey YK! Having a great time watching your videos.
    Keep it going, buddy. :)
    By the way, tried this and my answer is 2318
    total = 0
    for i in range(1, 100):
    if i % 3 == 0:
    total += i
    elif i % 5 == 0:
    total += i
    print(total)

  • @MazorKuziaki
    @MazorKuziaki 4 роки тому +18

    Thank you so much for this! I'm learning Python and every now and then I'll run into a lesson that I don't understand, so I'll try to find a different UA-cam video to explain it to me in a different way. This helped tremendously.

  • @akinian_
    @akinian_ 3 роки тому +2

    problem = list(range(1,100))
    sum = 0
    for element in problem:
    if element % 3 == 0 or element % 5 == 0:
    sum += element
    print (sum)
    2318
    thank you for the explanation!!

  • @jiyan626
    @jiyan626 4 роки тому +7

    Hi CS dojo, your lesson is super nice!
    And after listening, l gave the code for your final question as below:
    total4=0 #define a new variable for calculating the sum of list
    for i in range(1,100):
    if i%3==0 or i%5==0:
    total4 +=i #total4=total4+i
    print(total4)
    If l have anything wrong, pls tell me. Thank you so much!

    • @f1memelord72
      @f1memelord72 2 роки тому

      Very late reply I know but I have just checked your code and it works, no better way that you could have done it.

  • @harigovind7229
    @harigovind7229 2 роки тому

    range(1,101)
    total4 = 0
    for i in range(1,101):
    if i % 3 == 0:
    if i % 5 == 0:
    total4 += i
    print(total4)
    Ans - 315
    Thank you for being a wonderful teacher :p, #dojogangforever!!

  • @Stabby5656
    @Stabby5656 5 років тому +5

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

    • @AzraelVM
      @AzraelVM 5 років тому

      this is the line i went too :P

    • @the69prophet47
      @the69prophet47 5 років тому

      your code is incomplete. You have to reduce those numbers which are common multiple of 3 & 5, for eg, 15,30...
      these numbers would have come twice with the above code.
      Now you've to add this line to the code.
      if i % 3 and i % 5 == 0
      total = total - i
      you'll eliminate the common multiples once and the result would be 1998

  • @gailk30
    @gailk30 2 роки тому +3

    Love it! Well explained.👏🏼 Just a suggestion for people who wants to see a specific example (e.g. finding the total), it will be nice to have a link to each one of your examples. 👍🏼

  • @justinelustre5905
    @justinelustre5905 2 роки тому

    I'm a python newbie so bear with me. I think have two solutions. Feel free to comment for improvement. :D
    Solution #1:
    total = 0
    for i in range(100):
    if i%3 == 0 or i%5 == 0:
    total += i
    print(total)
    Solution #2:
    total = 0
    a = [n for n in range(100) if n%3 == 0 or n%5 == 0]
    for i in a:
    total += i
    print(total)
    PS: Thank you for your vids. I am currently a student and I have my final exam in Python next week. I already failed the first exam so I have to retake it. :'( But your tutorials are literally saving me! More power to you!

  • @orubele11
    @orubele11 3 роки тому +3

    total3 = 0
    total5 = 0
    for i in range (1,100):
    if i %3 ==0:
    total3 +=i
    elif i %5 ==0:
    total5 +=i
    Total = (total3 + total5)
    print('Total:', Total)
    Total = 2318
    Awesome teaching.

  • @Chefian-ow4jy
    @Chefian-ow4jy 5 років тому +6

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

    • @rikeshpoudel7462
      @rikeshpoudel7462 5 років тому

      well done , but you didn't need to write the first line of code unless you need to see the list....

    • @ts8960
      @ts8960 4 роки тому

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

  • @mg4776
    @mg4776 4 роки тому +1

    For n in range(1, 100):
    If n % 5 == 0:
    Print (n)
    elif n % 3 == 0:
    Print (n)
    AND TO ADD MORE TO IT
    else:
    Print (“can’t be done “)

  • @carloscosta2751
    @carloscosta2751 4 роки тому +8

    list=[ ]
    sum=0
    for i in range(100):
    if i%3==0 or i%5==0:
    list.append(i)
    sum += i
    print(list)
    print(sum)

    • @BenDover-vh9rs
      @BenDover-vh9rs 4 роки тому +1

      Thank you, very smooth

    • @JoulezzzProject
      @JoulezzzProject 4 роки тому +1

      Finally! I didn't understood how the fuck do it. It was a headcracker since he was asking for all the multiples and the script he was using was summing all the results. Thank you.

    • @carloscosta2751
      @carloscosta2751 4 роки тому

      @eman elkholy That's odd. Make sure you have declared an empty list before the loop typing list_name = [ ]. When you don't declare a list making it equal to an empty pair of square brackets, Python considers it as an integer. That's probably where your error comes from.

  • @bengibengi2300
    @bengibengi2300 4 роки тому +25

    Hey, *instead of if i % 3 == 0 or i % 5 ==0: why can't we just use elif alongside if?* I got the same answer (2318) in a different way from the others but here's what I did:
    total = 0
    for i in range(1, 100):
    if i % 3 == 0:
    total += i
    *elif i % 5 == 0:*
    total += i
    print(total)
    *Output: 2318*
    Anyways, I'm sorry for the really really late reply. I started learning how to code just because of quarantine, haha. Good luck to all the others! And hope this helps someone out. :)
    *Edit: I didn't realize YK included the solutions in Python Tutorial 7. Glad I was right at least :3

    • @maromus2496
      @maromus2496 4 роки тому +1

      I did the same

    • @abhishekbagva5110
      @abhishekbagva5110 4 роки тому +2

      print(sum([i for i in range(100) if i%3==0 or i%5==0]))
      You could use list comprehension, to save a few lines, but it does exactly the same as yours:

    • @bengibengi2300
      @bengibengi2300 4 роки тому +1

      Yeah, I learnt about list comprehension later on. They really save a lotta time. Right now I'm making a to-do web app using Django ._.

    • @leonliu2035
      @leonliu2035 4 роки тому

      Works, but less efficient than using or statement.

    • @officialcoffeebag
      @officialcoffeebag 4 роки тому

      t = 0
      for i in range(1,100):
      if i % 3 == 0:
      t += 1
      elif i % 5 == 0:
      t += 1
      print(t)
      why I am not getting same output as yours, please help

  • @dryedapricot1086
    @dryedapricot1086 3 роки тому

    his explanations are really quite clear
    y = 0
    for i in range(1,101):
    if i % 5 == 0:
    y += i
    elif i % 3 == 0:
    y += i

  • @joelkye4493
    @joelkye4493 4 роки тому +4

    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

  • @CleoTheBigBlackDog
    @CleoTheBigBlackDog 3 роки тому

    a = list(range(1, 101))
    total = 0
    for e in a:
    if e % 3 == 0:
    total += e
    print(e)
    if e % 5 == 0:
    total += e
    print(e)
    Thank you for teaching me

  • @MaximQuantum
    @MaximQuantum 4 роки тому +11

    I got 2318.
    My answer:
    total = 0
    for i in range(1,100):
    if i % 3 == 0 or i % 5 == 0:
    total += i
    print(total)

    • @gkdawg5154
      @gkdawg5154 4 роки тому

      Shouldn’t it be and

    • @gkdawg5154
      @gkdawg5154 4 роки тому

      Maxim Quantum instead of or

    • @polrivarola399
      @polrivarola399 4 роки тому +1

      @@gkdawg5154 That just gives you the sum of numbers which are both multiple of 3 and 5
      and throws you 315

    • @sinyiheng3732
      @sinyiheng3732 4 роки тому

      I came up with this solution as well. It seems that Python knows to nullify any duplicates? Correct me if I am wrong.

    • @adityaranjan7916
      @adityaranjan7916 4 роки тому +2

      he said 3 *and* 5 so i used 'and' rather than 'or'. my code was
      total = 0
      for i in a:
      if i % 5 ==0 and i % 3 == 0:
      total = total + i
      print (total)

  • @GIOGONZALES-zj3uh
    @GIOGONZALES-zj3uh Рік тому +3

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

  • @deVon30241
    @deVon30241 3 роки тому +1

    Wow, some of you people are really smart. My answer did not even come close and some of you had nice, simple solutions.

    • @trianglebean3884
      @trianglebean3884 3 роки тому

      don’t sell yourself short b! everyone in the comments are at different levels, and people only post those when they’re pretty confident about it. keep going n you’ll be spitting out nice, simple solutions too !!!

    • @deVon30241
      @deVon30241 3 роки тому +1

      @@trianglebean3884 much appreciated. Coding is so open ended in a way, which kinda throws me off, it requires a different kind of thinking than I'm used to. There's many ways to reach a solution, but there's always a best way, that requires some creativity and a fundamental understanding of the program. Its fun!

  • @tomashirner7627
    @tomashirner7627 4 роки тому +4

    this is what i did
    spolu = 0
    for a in list(range(1,100)):
    if a % 5 == 0:
    spolu += a
    elif a % 3 == 0:
    spolu += a
    print(spolu)
    sum is 2318

    • @crab1458
      @crab1458 4 роки тому

      this is what i got originally until i noticed he said multiples of 3 and 5 like 15 so i changed it up and this is my code:
      total = 0
      for i in range(1,100):
      if i % 3 and i % 5 ==0:
      total += i
      print(total)

    • @crab1458
      @crab1458 4 роки тому

      total would be 635

    • @tomashirner7627
      @tomashirner7627 4 роки тому

      @@crab1458 he said multiples of 3 and 5 but he also explained by telling the numbers.. so, 3,5,6,9,10,12,15 ect are all the numbers you need.. but if you use "AND" you only get numbers that fit in both conditions... so 15, 30, 45.. which is not right.. there is a solution in tutorial No.7

  • @AtangaDouglas-y1k
    @AtangaDouglas-y1k 6 місяців тому

    Thanks to cs dojo, I have learned a lot from your tutorial videos

  • @attackhelicopter3860
    @attackhelicopter3860 5 років тому +156

    I got 2318...
    and I'm sure it's correct because I literally just wrote on my calculator 3+5+6+9+10+12+... and I got 2318 lol

    • @Oiusea
      @Oiusea 5 років тому +2

      Same result here!

    • @XX-qo1my
      @XX-qo1my 5 років тому +24

      wrong, the answer is 315 . "or" and "and" is two different things

    • @attackhelicopter3860
      @attackhelicopter3860 5 років тому +8

      @@XX-qo1my everyone says it's 2318 so you're the one thats wrong

    • @XX-qo1my
      @XX-qo1my 5 років тому +12

      @King_ Rares According 9:07 , all mutilples of 3 and 5 :). It doesn't necessary to say that answer is correct even if everyone said it.

    • @attackhelicopter3860
      @attackhelicopter3860 5 років тому

      @@allofme3182 I did

  • @cubefrikandel3908
    @cubefrikandel3908 4 роки тому +4

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

  • @keshavtripathi8865
    @keshavtripathi8865 4 роки тому +1

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

  • @avikmallick2493
    @avikmallick2493 4 роки тому +5

    total1 = 0
    total2 = 0
    for e in range(1,100):
    if e % 3 == 0:
    total1 += e
    elif e % 5 == 0:
    total2 += e
    print (total1 + total2)

    • @nkwawally4406
      @nkwawally4406 4 роки тому

      right solution, thumbs up!!!

    • @angadpalhundal
      @angadpalhundal 4 роки тому

      Hey but u didn't subtract multiples of 15 because in this they would be added two times

  • @langqin4602
    @langqin4602 4 роки тому +2

    If you are reading this than here is a very nice code if you want to find all even numbers from 1 to 100
    for i in range(1,101,2)
    print(i)
    Odd number checker
    for i in range(1,101)
    if i % 3 == 0:
    print(i)

  • @utsavsapkota2049
    @utsavsapkota2049 5 років тому +13

    Total =0
    for e in range (1,100):
    if e % 3 == 0:
    Total += e
    elif e % 5 == 0:
    Total += e
    Print(total)
    Is this correct? This is what I did and got 2318

    • @maxrandom569
      @maxrandom569 5 років тому

      That's right, well done!

    • @ts8960
      @ts8960 4 роки тому

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

    • @arielrr
      @arielrr 4 роки тому

      TWIN

    • @MinhBinh-dr9rc
      @MinhBinh-dr9rc 4 роки тому +3

      Its not correct. Dojo said "the both multiple of 3 and 5...and 15 is the first number". So I think it have to be: if (e%3==0) and (e%5==0):

    • @Zilgamech
      @Zilgamech 4 роки тому +2

      ​@@MinhBinh-dr9rc He explains @9:35 that you sum 3, 6 then 9 and so on... And noticed that eventually you get to 15 which is a multiple of both. That's why your code is wrong because it only counts the numbers that are multiples of 3 and 5 instead of the multiple of 3 and the multiples of 5 like he explains.

  • @aqilamasri2227
    @aqilamasri2227 3 роки тому

    total4 =0
    for i in range(1,100):
    if i % 3 == 0 or i % 5 ==0:
    total4 += i
    print ('Num:',i,'Total:',total4)
    thanks YK for a great video!

  • @brigidggee7722
    @brigidggee7722 5 років тому +6

    list(range(1,100))
    for n in range(1,100):
    if n%3==0 and n%5==0:
    print(n)

    • @sameergupta8640
      @sameergupta8640 5 років тому

      That's what I did.

    • @tsatsralt9112
      @tsatsralt9112 5 років тому

      actually that is incorrect. He said sum of the numbers that is divided by 3 or 5. So, instead of using (and) you should use (or)

  • @Reneeke9
    @Reneeke9 5 років тому +10

    if the numbers should be divideable by 3 OR 5:
    total3 = 0
    for i in d:
    if i % 3 == 0 or i % 5 == 0:
    total3 = total3 + i
    print(total3)
    2318

    • @KaushalGrover
      @KaushalGrover 5 років тому +1

      For 3 or 5 its right....
      For 3 and 5 its wrong.....you took the sum of (3,6,9,12..etc) and the sum of (5, 10,15, etc).....and added both of them....
      For sum of no. Divisible by 3 AND 5
      total = 0
      for i in range(1, 100):
      If i % 5 == 0:
      Total += i
      If i % 3 == 0:
      Total += i
      Print(total)

    • @epsilontea3519
      @epsilontea3519 5 років тому +1

      @@KaushalGrover i think you misintepreted his message, but if you're just trying to find sum of (15, 30, 45, etc) then you are right.

    • @KaushalGrover
      @KaushalGrover 5 років тому +1

      @@epsilontea3519 yes...i did the sum of 15 30 etc

  • @limotto9452
    @limotto9452 3 місяці тому

    Thank you very much for the video and lesson, it did clear some of my doubts regarding for loops that I have for a very long time.

  • @yeetyot9020
    @yeetyot9020 4 роки тому +5

    i = ["a", "b", "c"]
    for letter in i:
    print(letter)
    So it's just changing the variable for letter to i[number] every iteration?

  • @intansunarmi2669
    @intansunarmi2669 5 років тому +5

    This video is awesome! LOVE it! Thank you for making this vid. You have made my life much easier.
    Oh! and I got 2318 from
    for index in range(1, 100):
    if index % 3 == 0 or index % 5 == 0:
    total += index

  • @Dalai33
    @Dalai33 Рік тому

    Omg thank you!!!! Finally someone who understands python is teaching python.

  • @marsh725
    @marsh725 4 роки тому +3

    I know I'm late but here's mine
    print(list(range(1, 100)))
    total = 0
    for i in range(1,100):
    if i % 3 == 0 or i % 5 == 0:
    total += i
    print(total)

    • @xixyaxgaming4313
      @xixyaxgaming4313 3 роки тому

      you could get rid of your first line of code as it doesnt help to find the sum of all multiples of 3 and 5. Other than that though that works great!

    • @marsh725
      @marsh725 3 роки тому

      @@xixyaxgaming4313 Thanks a lot for this comment it helped

  • @attomix731
    @attomix731 5 років тому +4

    I think the real way to solve this with ONLY the stuff we learned is this:
    total3 = 0
    for i in range(1, 100):
    if i % 3 == 0:
    total3 += i
    elif i % 5 == 0:
    total3 += i
    print(total3)

  • @moundir1486
    @moundir1486 10 місяців тому

    thank you so much i'm watching you in 2023 and still the best teacher we never had

  • @Renzore-iw7tx
    @Renzore-iw7tx 5 років тому +4

    var = 0
    for num in range(1, 100):
    if num % 3 == 0 and num % 5 == 0:
    var += num
    print(var)

    • @Loyaltykamaofficial
      @Loyaltykamaofficial 4 роки тому +1

      the code is actually:
      mul = []
      for i in range(1, 100):
      if i % 3 == 0:
      mul.append(i)
      elif i % 5 == 0:
      mul.append(i)
      print(mul)
      #u dont need to put "and", and u can also use .append

    • @chagantisrichandana8251
      @chagantisrichandana8251 4 роки тому

      The simple thing is
      If(i%15==0):

    • @Loyaltykamaofficial
      @Loyaltykamaofficial 4 роки тому

      @@chagantisrichandana8251 what?😂😂😂

    • @chagantisrichandana8251
      @chagantisrichandana8251 4 роки тому

      @@Loyaltykamaofficial I don't understand why ur laughing
      He asked both multiples of 3 and 5
      That is 15,30,45...etc
      For the above numbers n%15 ==0 we use

    • @chagantisrichandana8251
      @chagantisrichandana8251 4 роки тому

      @@Loyaltykamaofficial do you have any further doubt?

  • @freemusicworld9211
    @freemusicworld9211 4 роки тому +5

    My attempt is
    total = 0
    for e in range(1,100):
    if (e % 3 and e % 5) == 0:
    total += e
    print(total)
    the answer will come 2318

  • @hanneshogstrom6939
    @hanneshogstrom6939 3 роки тому

    Did the challenge in 4 lines and im proud :)
    total = 0
    for i in range(1, 100):
    if i % 3 == 0 or i % 5 == 0: total += i
    print(total)

  • @palestinian5543
    @palestinian5543 6 років тому +5

    lis_99 = range(1, 100)
    total4 = 0
    for num in lis_99:
    if num % 3 == 0 or num % 5 == 0:
    total4 += num
    print total4
    Am I right ?

  • @Anon72005
    @Anon72005 6 років тому +4

    Love you sooooo much! Please do a part 6 thanks!!!! 😘

  • @Ravinder9
    @Ravinder9 3 роки тому

    best part was the way you explain the code that what it really means to write 'i' or any other thing , really helpfull really looking for such explanantion thanks once again

  • @imshivamshakya_
    @imshivamshakya_ 5 років тому +5

    You = [Awesome, Amazing, Cool]
    for me in You:
    print(me)
    Awesome
    Amzaing
    Cool
    #Apni taaref kr di

  • @sohamjagtap1009
    @sohamjagtap1009 3 роки тому +3

    YK sir, can you tell me what would i have learnt by the end of this series? Or what level would i be on? So that when the next time i learn python from a different source, i can continue from that point on

  • @andyc9991
    @andyc9991 3 роки тому +1

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

  • @razmysignas7216
    @razmysignas7216 5 років тому +5

    6:00 that would so helped me in a exam

    • @razmysignas7216
      @razmysignas7216 4 роки тому

      Theare wheare questions in a exam like
      1 2 3 5 6
      Divide that

  • @ecodersofficial
    @ecodersofficial 2 роки тому

    You shown me how to use for loop! I was searching the internet, But only your gave me the right way. Thanks!

  • @loofsan8486
    @loofsan8486 4 роки тому +1

    I got this.
    for a in range(1,100):
    if a % 3 == 0 or a % 5 == 0:
    print(a)
    This will show all multiples of 3 and 5 in order. At first, I got it the long way but, I wanted to make it shorter.

  • @cobarde7514
    @cobarde7514 3 роки тому +3

    If you just want to print the multiples of 3 and 5 out, its the code below.
    for a in range(1, 100):
    if a % 3 == 0 or a % 5 == 0:
    print(a)

  • @vilgotthorsell6194
    @vilgotthorsell6194 3 роки тому +1

    This was my solution:
    total = 0
    for i in range(1, 100):
    if i % 3 or 5 == 0:
    total += i
    print("The sum of the numbers that are multiples of three and five between one and houndred are " + str(total))

  • @gg-bz6rc
    @gg-bz6rc 6 років тому +10

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

    • @narendran.me_
      @narendran.me_ 6 років тому +1

      Its wrong bro, shouldn't use "and", bcoz we need multiples of either 3 or 5 so use "or"

    • @gg-bz6rc
      @gg-bz6rc 6 років тому

      Narendran Kannan well I solved this by manually calculating this and my calculator matches my answer.

    • @gg-bz6rc
      @gg-bz6rc 6 років тому +1

      Narendran Kannan if you use "or" its like using and. For some reason. "and" and "or" are swapped.

    • @narendran.me_
      @narendran.me_ 6 років тому +1

      Dusk Lenny No bro 'and' and 'or' are totally different to each other.... depends upon the usage

    • @gg-bz6rc
      @gg-bz6rc 6 років тому

      Narendran Kannan Narendran Kannan well the computer thinks about it a little different. Like when it says "and" think of it like its saying "if... i % 3 and also if i % 5..."
      You see? Its not checking if the two are both true but its like adding another if. Try running the code and it works fine.

  • @ktmiami08
    @ktmiami08 4 роки тому +4

    using 'or' and using 'elif' both seem to work

  • @nicholasgetty1805
    @nicholasgetty1805 3 роки тому

    Bro you are actually the GOAT, keep it up, you explain it sooooo well

  • @HristoKavalov
    @HristoKavalov 6 років тому +7

    Pretty sure there is solutions with less code but when I am at the beginning at something I like to try to really understand some stuff cause I get confused later:
    _________________________________________________________________________________________________
    #declaring some variables
    total=0
    multipleof3and5 = 0
    multipleof3=0
    multipleof5=0
    #This code calculates multiples of 3
    for each in range(1,100):
    if each % 3 == 0:
    multipleof3 = multipleof3 + each
    #This code calculates multiples of 5
    for each in range(1,100):
    if each % 5 == 0:
    multipleof5 = multipleof5 + each
    #This code calculates multiples of 5 in multiples of 3 so we can escape repetitive addition
    for each in range(1,100):
    if each % 3 == 0:
    if each % 5 == 0:
    multipleof3and5 = multipleof3and5 + each
    #making the simple math of all
    total= multipleof5 + multipleof3 - multipleof3and5
    print(total)
    ______________________________________________________________________________________________________
    This gives the result of : 2318

    • @manita4815
      @manita4815 6 років тому +3

      u can use "or" for much simpler code:
      value = 0
      for i in range(1, 100):
      if i % 3 == 0 or i % 5 == 0:
      value = value + i

      print(value)
      2318

    • @alepharcane99
      @alepharcane99 6 років тому +2

      very inefficient code, but also shows that you thought thoroughly!
      maybe because you were not introduced to 'OR' keyword
      technically, the code is correct, though

    • @abdullahismael8486
      @abdullahismael8486 6 років тому

      Muballig Dalvi please can you tell me the difference between (and) and (or)?
      I did like this:
      Total = 0
      For e in range(1, 100):
      If e % 3 == 0 and e % 5 == 0:
      Total += e
      Please i know I'm wrong but can you explain this for me :/

    • @alepharcane99
      @alepharcane99 6 років тому +4

      Abo D with OR, the program will consider numbers that are divisible by either 3 or 5, like 3, 5, 6, 9,10...
      But with AND, the program will consider numbers that are divisible by both 3 and 5, like 15, 30, 45, 60...

  • @tanmay9878
    @tanmay9878 4 роки тому +2

    Great video buddy . I tried learning python from more than 10 youtube channels but this series is best.

  • @generatedmoon00
    @generatedmoon00 3 роки тому

    I'm coming here from a different tutorial and I couldn't really understand the concept of a for loop, but I think that this tutorial explains it perfectly.

  • @pineapplejuice1156
    @pineapplejuice1156 2 роки тому +1

    This explained all the questions I had from for loops, thanks

  • @woxgamer7044
    @woxgamer7044 6 років тому +7

    i did not understand:
    what do you mean by compute?

    • @woxgamer7044
      @woxgamer7044 6 років тому

      thx but i used this
      www.quora.com/Why-does-the-remainder-of-1-divided-by-3-equal-1-I-tried-it-in-Python-using-%E2%80%98print-1-3-%E2%80%99

    • @GamePropaganda
      @GamePropaganda 6 років тому

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

    • @ushapadhi5527
      @ushapadhi5527 6 років тому

      thanks your code was helpful

    • @ronniechakre
      @ronniechakre 6 років тому

      In your code "or" should be replaced with "and". We are asked to find summation of numbers divisible by 3 and 5.

    • @thecodemonk1851
      @thecodemonk1851 6 років тому +1

      Replacing "or" with "and" will not produce the correct result. The "and" operator states that both conditions has be True for the condition to be True. If say we're checking the value 10 against the condition, i % 3 == 0 would equate to false, then it will not check if i % 5 == 0 equates to True because the entire condition would then automatically equate to False. So, "or" is the best option in order to satisfy both conditions even if one equates to False.

  • @a2editz605
    @a2editz605 2 роки тому +1

    My goodness, so precisely elaborated examples! Thanks a lot man!

  • @RyanEnty
    @RyanEnty 2 роки тому

    This is what i did. Was tough but figured it out after an hour haha.
    CODE:
    list(range(1, 100))
    total = 0
    list_of_multiples = []
    for i in range(1, 100):
    if i % 3 == 0 and i % 5 == 0:
    total += i
    list_of_multiples.append(str(i))
    print("The multiples are: " + str(list_of_multiples))
    print("The sum of the multiples of 3 and 5 up to 99 total is: " + str(total))
    OUTPUT:
    The multiples are: ['15', '30', '45', '60', '75', '90']
    The sum of the multiples of 3 and 5 up to 99 total is: 315

  • @brianlevi4964
    @brianlevi4964 4 роки тому +1

    This was my attempt
    total4 = 0
    for i in range (1,100):
    if i % 3 == 0:
    total4 += i
    elif i % 5 == 0:
    total4 += i
    print (total4)

  • @felipesoaresspiess8048
    @felipesoaresspiess8048 3 роки тому +3

    So, I got this with fewer lines (comparing to what I saw in the comments)
    Here`s what I did, please tell me if I should change something (still getting the right result):
    a = 0
    t = range(1, 100)
    for e in t:
    if e % 3 == 0 or e % 5 == 0:
    a = a + e
    print(a)

    • @shreyashkashyap
      @shreyashkashyap 3 роки тому +1

      It's clean! Could have been a little more descriptive tho.