Python Programming Series (Loops 4): Nested loops

Поделиться
HTML-код
  • Опубликовано: 8 янв 2025

Комментарии • 109

  • @joshuaf.5398
    @joshuaf.5398 3 года назад +32

    I've been working on this class assignment for my coding class for 2 days, should've taken no more than 15 minutes. Couldn't get the code to output the way expected. Your video basically helped me finally connect the dots on how to complete the assignment! Thank you!

  • @AMA_RILDO
    @AMA_RILDO 2 года назад +2

    I had doubts for months about the shit for loop, I wish I watched this tutorial on my first programming day. Thank you bro

  • @Honda-nn3ee
    @Honda-nn3ee 5 лет назад +11

    Awesome video. This really helped me learn nested loops. For anyone wondering how to print this triangle without using nested loops, here’s one approach:
    i=8
    for j in range(1,17,2):
    print(i*" "+j*"*")
    i=i-1
    # i is the number of spaces, and j is the number of stars being printed, which goes down by 2 each row.

  • @papie5151
    @papie5151 4 года назад +5

    I was struggling with nested for loops, the range function and pattern printing until this video. I've watched several videos and this was the ah ha moment. Thanks.

  • @basalduat
    @basalduat 7 лет назад +9

    Excellent visual presentation! Great voice. Thank you for using a large font. You are a good teacher.

  • @myenjoyablehobbies
    @myenjoyablehobbies 6 лет назад +17

    excellent explanation, I learned a lot as you went thru this step by step. Thank you.

  • @mehdighafari7672
    @mehdighafari7672 Год назад

    You taught us this in the best possible way

  • @satyajitdas2780
    @satyajitdas2780 6 лет назад +4

    Excellent, Sir. I really liked your approach. It is unique and most logical. I can connect the dots after every steps .

  • @sunnyveerpratapsingh1102
    @sunnyveerpratapsingh1102 5 лет назад

    I have been to so many videos for understanding loops by far u are the best one . thanks pls keep up the good work I subscribed

  • @danielbriller3714
    @danielbriller3714 2 года назад

    it was a nice, simple, and quick explanation, i understood it very quickly

  • @abyazkarim6755
    @abyazkarim6755 2 года назад

    great video, appreciate the step-by-step thinking approach

  • @KenyiReyes23
    @KenyiReyes23 2 года назад

    Thank you very much, I was able to learn this subject better thanks to your help.

  • @ananthbyju
    @ananthbyju 4 года назад +1

    Keep up the Good Work Mate! Understood the concept...Thanks!

  • @MSMEJanardhanMuralidhar
    @MSMEJanardhanMuralidhar 3 года назад

    Thank you for explaining these concepts so well.

  • @alexhicks930
    @alexhicks930 7 лет назад +18

    You are my savior!!

  • @bongajewelmsimang5337
    @bongajewelmsimang5337 Год назад

    Thank you for the great explanation , this really helped me intepret another project that was using different symbols. defintely gonna practise the pyramid for fun though.

  • @dp0813
    @dp0813 5 лет назад +12

    Great vid! I got this in 4 tries, but my code was a little cleaner just because I used a variable ('x') for the number of 0s printed:
    x = 1 # number of 0s
    for i in range(0,7): # number of rows
    for j in range(0,7-i): # number of spaces over, starting with 7 but decreasing by 1 each time
    print(' ', end = '')
    print('0' * x) # number of zeros to print on each line
    x += 2 # increment the number of zeros by 2 to get increasing, consecutive odd numbers for each row (1,3,5,...)

  • @julianash3379
    @julianash3379 3 года назад

    iv been trying to solve this for a day. Thank you so much

  • @muzik6808
    @muzik6808 5 лет назад +2

    for i in range(1,8):
    for j in range(1,8-i):
    print(" ",end="")
    print("0"*(2*i-1))

    •  5 лет назад

      Why 8-i

    • @muzik6808
      @muzik6808 5 лет назад

      @ in the pattern we left spaces then print 0.. it means after 7 spaces we have to print 0..then on the next line we have left 5 spaces then print 0.. likewise it goes on .. and because we have to print 2 more 0's on each next line thats why we multiply by 2 and decrease it by 1..

    • @stevenewbank
      @stevenewbank 4 года назад

      Now that is a nice bit of code...thanks for sharing

  • @ninjapirate123
    @ninjapirate123 5 месяцев назад

    Wow your teaching is amazing

  • @rajeshbabu1972
    @rajeshbabu1972 5 лет назад

    Very clean and neat presentation.. Its really very helpful..

  • @pythonocean7879
    @pythonocean7879 6 лет назад +8

    try this way:
    for x in range(1,10):
    print(' '*(9-x)+'*'*(x*2))

    • @RecursiveTriforce
      @RecursiveTriforce 5 лет назад +2

      for x in range(6):
      print( " "*(7-x) + "0"*(2*x+1) )
      In this exact problem.

    • @RecursiveTriforce
      @RecursiveTriforce 5 лет назад +2

      @@DeViLTh0rn why?

    • @taylorbell6879
      @taylorbell6879 5 лет назад

      @@RecursiveTriforce How would you resolve this code to execute range values higher than 8? I am learning, and when I use your code I see that numbers 9 and above do not make perfect pyramids, so I asked myself well what should you do to fix that and make it perfect. But my problem is I barely understand your code. On top of answering this question, if you would, can you point me to some good learning websites? How did you learn this so well?

    • @RecursiveTriforce
      @RecursiveTriforce 5 лет назад +1

      @@taylorbell6879
      for x in range(size-1):
      print(" "*(size-x) + "0"*(2*x+1) )
      For syntax I would recommend:
      ruclips.net/p/PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M
      But this is just string formatting. Draw a pyramid with dimensions and you see...
      Uneven number of 0's:
      [ "0"*(2*x+1) ]
      In front of the zeros is always one less space:
      [ " "*(start-x) ]
      After the zeros:
      Newline [implied in print]

    • @interezting3940
      @interezting3940 5 лет назад

      @@RecursiveTriforce this code makes error

  • @53Strat
    @53Strat 4 года назад +1

    How did you comment the piramide all at once? Seems like a usefull hotkey.

    • @FT4YOU
      @FT4YOU 4 года назад

      i can't figure it out too. there is a command key for commenting blocks of code at ones. i just don't understand it.

    • @DeeBeeGames101
      @DeeBeeGames101 2 года назад

      @@FT4YOU me neither.

  • @MohammedAli-lr9rd
    @MohammedAli-lr9rd 3 года назад +1

    4:16 how do you comment it?

  • @manoharsagunthalla9215
    @manoharsagunthalla9215 9 месяцев назад

    Will you please tell me what mathematics involved in printing pyramid. Will explain how it works?

  • @davidusharauli2227
    @davidusharauli2227 7 лет назад +2

    why does nested for loop iterates 7 times? outside for loops iterates 7 times * nested range but why nested loop should do it 7 times too? should not it loop only 1 time as an independent loop would do?

  • @roselinevimala9151
    @roselinevimala9151 4 года назад

    Super sir your video are helpful for my online classes

  • @jeremiahv6498
    @jeremiahv6498 Год назад

    Okay, I like to try before I watch the solution. I didn't really get the isosceles triangle you got, but I did make right triangle. I just need to work on the spaces, But I don't have time right now, so heres my code so far.
    z,x,w,v = "*" , 1 , " ", 6
    for i in range(0,4):
    for j in range(0,5):
    print(v*w+z*x)
    x+=1

  • @BrendanMetcalfe
    @BrendanMetcalfe 4 года назад

    those 2 for loops at the same indentation - think its possible to do that in a list comp?

  • @adrianeduardo6222
    @adrianeduardo6222 4 года назад

    what a nice/clear way to teach. ty

  • @rocky-lk2hc
    @rocky-lk2hc 6 месяцев назад

    but how do you get rid of that single space?

  • @abisokhalifa
    @abisokhalifa Месяц назад

    pyramid_width = 10
    for i in range(0, pyramid_width):
    print(" " * (pyramid_width - i), end="")
    n = 2 * i + 1
    print("$" * n)
    I try this it gives same result wow coding is sweet

  • @loganhawkins6486
    @loganhawkins6486 4 года назад

    if you had a list of numbers how could you group every set of 4 numbers together? so if you had 12 numbers you would have 3 lists of 4.

  • @Ryan_online
    @Ryan_online 5 лет назад

    Please cover the topic for regular expression in python

  • @trevthegamedev
    @trevthegamedev 5 лет назад

    where are these exercises you speak of?

  • @freemanfreed1581
    @freemanfreed1581 3 года назад

    but how it internally implement the iteration protocol is the real magic. how does it implement it??

  • @pectenmaximus231
    @pectenmaximus231 4 года назад

    for i in range(0, 7):
    for j in range(0, 7-i):
    print(" ", end="")
    for k in range(i*2):
    print("0",end="")
    print("0")
    This worked for me. One thing I don't understand here, when I look at this on PythonTutor, is why in the k-index, on the first line (where i=0, and thus k=0 as 0*2=0), the program doesn't start the k loop, but instead jumps down to the print statement and then starts again at i=1. While this program accomplishes what I want, I don't understand what is going on. Since indexes start at 0, as for example in our for-loops, where the range starts at 0, allowing n to be what we want (since range goes up to n-1, if we start at 0, range will go to n), I wonder why, when i=0, k should also be 0, and then the print statement under k's loop should be printed? When following along in PythonTutor, k doesn't start until we get to the next line, with i=1 (so k's range is 1*2 = 2, so index of 0 and 1). So why does Python(?) require that i be a non-zero value, for a loop whose range is i*some-number? I just don't understand this, and any clarification from some knowing person would be amazing.

  • @lazartutulic7577
    @lazartutulic7577 3 года назад

    ##'QUESTION HERE##
    for i in range(0,7):
    for j in range(7 - i) /// but yours starts at (0,7):
    print(' ', end = '')
    print('0')
    ''
    why is this code giving me the same output as yours? For me its logical that second loop starts at 7 so it prints 7 spaces at start of the first iteration.

    • @lazartutulic7577
      @lazartutulic7577 3 года назад

      okay i got it. I forgot that the outer loop iterates only once, and the inner one iterates to the end of the range it haves. xD

  • @jinkazama3647
    @jinkazama3647 Год назад

    t=int(input("put the number here:"))
    for i in range(t):
    print(" " * (t-i-1) + "*"" " * (i+1))
    Can u tell me how to double the rectangle bro?

  • @shivanshd12
    @shivanshd12 6 лет назад

    pls give a link of nested loops questions with solutions

  • @zukofire6424
    @zukofire6424 2 года назад

    thanks for this! loved it

  • @bdaman_2595
    @bdaman_2595 4 года назад

    Thanks! This vid helped a lot!

  • @anita_cr7
    @anita_cr7 6 лет назад

    In my program print(" ",end="") is not running.it say end="" syntax error .please give me a suggestion to solve this problem

  • @marcusmorrow3900
    @marcusmorrow3900 6 лет назад

    This was beautiful. thanks.

  • @dineshroyal4108
    @dineshroyal4108 6 лет назад

    Sir can u write a python program calendar without built in function

    • @RecursiveTriforce
      @RecursiveTriforce 5 лет назад +1

      You probably don't even know what a leap year is.
      You can but working with time is tedious.

  • @MANISHKUMAR-be3wb
    @MANISHKUMAR-be3wb 6 лет назад

    How to apply nested for loop for float numbers?

  • @murodalisharipov5929
    @murodalisharipov5929 6 лет назад

    How to get rid of that last one space?

  • @davidconiglio7577
    @davidconiglio7577 Год назад

    I did for loop with 4, and later, I will do with 5 .The program takes all combinations for mega million and powerball 😅 .I did run this program in liberty basic and truebasic it will take more than 4 hours, and in phyton, it will take less. THIS WHY I AM LEARNING PHYTON .It was free to download others I paid.

  • @Michaelzonneveld
    @Michaelzonneveld 6 лет назад +1

    very clean

  • @Pankaj-Verma-
    @Pankaj-Verma- 11 месяцев назад

    That was awesome 😎

  • @dolfinho87
    @dolfinho87 2 года назад

    Amazing! Thank you!

  • @حيدراسعد-ف5ع
    @حيدراسعد-ف5ع 4 года назад

    this my way
    n = input('inter number')
    n = int(n)
    for i in range (n):
    i = i + 1
    print((n-i) * " " ,(i * 2 - 1) * " *")

  • @jakeeaves218
    @jakeeaves218 5 лет назад

    why does i = 1

    • @imtiazshahed944
      @imtiazshahed944 5 лет назад

      here i is the number of rows in the pyramid.

  • @mehdighafari7672
    @mehdighafari7672 Год назад

    Perfect 👏👍🙏🏽

  • @4ikemir
    @4ikemir 4 года назад

    Thanks for the video

  • @omervnl
    @omervnl 2 года назад

    i=8
    for j in range(-1,17,2):
    print(i*" "+j*"0")
    i=i-1
    way more easier tbh

    • @gomitos8866
      @gomitos8866 2 года назад

      when u put "for j in range(-1,17,2)" its going to add 2 to -1 until it reaches 17, right???

  • @مرادموسى-ك5خ
    @مرادموسى-ك5خ 4 года назад +3

    pyramid depends on ' i '. illuminati confirmed

    • @mojo6112
      @mojo6112 4 года назад

      ركز الله يهديك😂

  • @sapnamanohara2234
    @sapnamanohara2234 2 года назад

    thank you so much..

  • @GoogleAccount-ho6ng
    @GoogleAccount-ho6ng Год назад

    i just dont get it

  • @adamumustapha7868
    @adamumustapha7868 6 лет назад

    Hello please i need help, So I have this gridded data of dimention (144,72,636). this is montthy precipitation data and I want to calculate sliding window percentiles for 10 years window for 5th 50th and 95 percentiles. who can please help me.

  • @gomitos8866
    @gomitos8866 2 года назад

    even if i watch this 200 times, i wont get it. The only thing i could do was for i in range(7):
    for j in range(7):
    its so confusing and idk what to do. i watched this tutorial " Python Tutorial - Python Full Course for Beginners " and repeated the nested loops part like 10 times , i still cant understand a SHIT

    • @vaby7789
      @vaby7789 2 года назад

      same here this shit is annoying as hell

    • @turtlecodes8319
      @turtlecodes8319 Год назад

      @@vaby7789 fr

    • @ninjapirate123
      @ninjapirate123 5 месяцев назад

      I understand it but I just don't understand end="" and print("") at the end

  • @kikejoo2240
    @kikejoo2240 2 года назад

    hard to understand

  • @priscillaton7669
    @priscillaton7669 5 лет назад

    thank you!

  • @justinharris6898
    @justinharris6898 4 года назад +1

    *1 second into the video of speaking*
    me: OH THANK GOD SOME CLEAR ENGLISH SPEAKING PERSON
    seriously. all love no offense to the other videos I seen but it was literally like listening to gibberish

  • @antoniobanderas5316
    @antoniobanderas5316 Год назад

    This is so confusing to wrap your head around... I mean this when not following the video steps.

  • @031219400
    @031219400 7 лет назад

    thank for you this

  • @DeViLTh0rn
    @DeViLTh0rn 5 лет назад +1

    4:27

  • @ShermanSitter
    @ShermanSitter 5 лет назад

    I've never used a wa-loop :)

  • @WannaBe-21
    @WannaBe-21 6 лет назад

    Sir can you make your code more visible it pains my eyes watching for long time simply by adjustment of themes like that

  • @jessp5966
    @jessp5966 2 года назад

    genius

  • @tangaucheplease9621
    @tangaucheplease9621 3 года назад

    Noice

  • @jerrynguyen9895
    @jerrynguyen9895 2 года назад

    illoopminati

  • @notmymainyes
    @notmymainyes Год назад

    how to do print something then loop it forever

  • @ntwaliobadiah425
    @ntwaliobadiah425 Год назад +1

    for i in range(6):
    for j in range(0,6-i):
    print(' ',end="")
    for k in range(0,2*i):
    print('0',end="")
    print("0")

  • @jonnierobinson8579
    @jonnierobinson8579 4 года назад

    How do I get the triangle upside down