Python Programming Series (Loops 4): Nested loops

A look at how to nest loops and an example of what can be done with when you do.
www.leftpeel.com

Пікірлер: 108

  • @joshuaf.5398
    @joshuaf.53983 жыл бұрын

    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!

  • @papie5151
    @papie51514 жыл бұрын

    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
    @basalduat6 жыл бұрын

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

  • @myenjoyablehobbies
    @myenjoyablehobbies5 жыл бұрын

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

  • @satyajitdas2780
    @satyajitdas27806 жыл бұрын

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

  • @Honda-nn3ee
    @Honda-nn3ee5 жыл бұрын

    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.

  • @AMA_RILDO
    @AMA_RILDO2 жыл бұрын

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

  • @sunnyveerpratapsingh1102
    @sunnyveerpratapsingh11024 жыл бұрын

    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

  • @MSMEJanardhanMuralidhar
    @MSMEJanardhanMuralidhar2 жыл бұрын

    Thank you for explaining these concepts so well.

  • @mehdighafari7672
    @mehdighafari7672 Жыл бұрын

    You taught us this in the best possible way

  • @abyazkarim6755
    @abyazkarim6755 Жыл бұрын

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

  • @deadbutt
    @deadbutt2 жыл бұрын

    Clear and objective. Really good video, thank you man, it helped a lot! Liked and subscribed!!

  • @danielbriller3714
    @danielbriller37142 жыл бұрын

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

  • @ananthbyju
    @ananthbyju3 жыл бұрын

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

  • @rajeshbabu1972
    @rajeshbabu19725 жыл бұрын

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

  • @julianash3379
    @julianash33793 жыл бұрын

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

  • @alexhicks930
    @alexhicks9306 жыл бұрын

    You are my savior!!

  • @KenyiReyes23
    @KenyiReyes23 Жыл бұрын

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

  • @BrendanMetcalfe
    @BrendanMetcalfe4 жыл бұрын

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

  • @davidusharauli2227
    @davidusharauli22276 жыл бұрын

    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?

  • @bongajewelmsimang5337
    @bongajewelmsimang533710 ай бұрын

    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.

  • @ninjapirate123
    @ninjapirate12319 күн бұрын

    Wow your teaching is amazing

  • @adrianeduardo6222
    @adrianeduardo62224 жыл бұрын

    what a nice/clear way to teach. ty

  • @marcusmorrow3900
    @marcusmorrow39005 жыл бұрын

    This was beautiful. thanks.

  • @roselinevimala9151
    @roselinevimala91514 жыл бұрын

    Super sir your video are helpful for my online classes

  • @shivanshdadhwal6989
    @shivanshdadhwal69896 жыл бұрын

    pls give a link of nested loops questions with solutions

  • @bdaman_2595
    @bdaman_25954 жыл бұрын

    Thanks! This vid helped a lot!

  • @Ryan_online
    @Ryan_online5 жыл бұрын

    Please cover the topic for regular expression in python

  • @trevthegamedev
    @trevthegamedev4 жыл бұрын

    where are these exercises you speak of?

  • @zukofire6424
    @zukofire64242 жыл бұрын

    thanks for this! loved it

  • @jonnierobinson8579
    @jonnierobinson85794 жыл бұрын

    How do I get the triangle upside down

  • @dp0813
    @dp08135 жыл бұрын

    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,...)

  • @manoharsagunthalla9215
    @manoharsagunthalla92154 ай бұрын

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

  • @loganhawkins6486
    @loganhawkins64863 жыл бұрын

    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.

  • @Michaelzonneveld
    @Michaelzonneveld5 жыл бұрын

    very clean

  • @rocky-lk2hc
    @rocky-lk2hcАй бұрын

    but how do you get rid of that single space?

  • @freemanfreed1581
    @freemanfreed15813 жыл бұрын

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

  • @MohammedAli-lr9rd
    @MohammedAli-lr9rd2 жыл бұрын

    4:16 how do you comment it?

  • @dolfinho87
    @dolfinho872 жыл бұрын

    Amazing! Thank you!

  • @Pankaj-Verma-
    @Pankaj-Verma-6 ай бұрын

    That was awesome 😎

  • @sapnamanohara2234
    @sapnamanohara2234 Жыл бұрын

    thank you so much..

  • @anita_cr7
    @anita_cr76 жыл бұрын

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

  • @user-es1hu5xj5p

    @user-es1hu5xj5p

    6 жыл бұрын

    becaus you have 2 pythone vershion!

  • @ntwaliobadiah425
    @ntwaliobadiah425 Жыл бұрын

    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")

  • @ntwaliobadiah425

    @ntwaliobadiah425

    Жыл бұрын

    Thank u

  • @4ikemir
    @4ikemir3 жыл бұрын

    Thanks for the video

  • @53strat55
    @53strat553 жыл бұрын

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

  • @FT4YOU

    @FT4YOU

    3 жыл бұрын

    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.

  • @muzik6808
    @muzik68085 жыл бұрын

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

  • 4 жыл бұрын

    Why 8-i

  • @muzik6808

    @muzik6808

    4 жыл бұрын

    @ 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

  • @priscillaton7669
    @priscillaton76694 жыл бұрын

    thank you!

  • @MANISHKUMAR-be3wb
    @MANISHKUMAR-be3wb6 жыл бұрын

    How to apply nested for loop for float numbers?

  • @RecursiveTriforce

    @RecursiveTriforce

    5 жыл бұрын

    ?

  • @dineshroyal4108
    @dineshroyal41085 жыл бұрын

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

  • @RecursiveTriforce

    @RecursiveTriforce

    5 жыл бұрын

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

  • @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?

  • @murodalisharipov5929
    @murodalisharipov59295 жыл бұрын

    How to get rid of that last one space?

  • @RecursiveTriforce

    @RecursiveTriforce

    5 жыл бұрын

    Which?

  • @031219400
    @0312194006 жыл бұрын

    thank for you this

  • @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

  • @pythonocean7879
    @pythonocean78796 жыл бұрын

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

  • @RecursiveTriforce

    @RecursiveTriforce

    5 жыл бұрын

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

  • @RecursiveTriforce

    @RecursiveTriforce

    4 жыл бұрын

    @@DeViLTh0rn why?

  • @taylorbell6879

    @taylorbell6879

    4 жыл бұрын

    @@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

    4 жыл бұрын

    @@taylorbell6879 for x in range(size-1): print(" "*(size-x) + "0"*(2*x+1) ) For syntax I would recommend: kzread.info/head/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

    4 жыл бұрын

    @@RecursiveTriforce this code makes error

  • @mehdighafari7672
    @mehdighafari7672 Жыл бұрын

    Perfect 👏👍🙏🏽

  • @lazartutulic7577
    @lazartutulic75773 жыл бұрын

    ##'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

  • @pectenmaximus231
    @pectenmaximus2313 жыл бұрын

    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.

  • @ghassanjenainaty4212

    @ghassanjenainaty4212

    2 жыл бұрын

    what was your output please? It showed me some errors

  • @jakeeaves218
    @jakeeaves2185 жыл бұрын

    why does i = 1

  • @imtiazshahed944

    @imtiazshahed944

    5 жыл бұрын

    here i is the number of rows in the pyramid.

  • @davidconiglio7577
    @davidconiglio757710 ай бұрын

    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.

  • @user-vl6ld2is1j
    @user-vl6ld2is1j3 жыл бұрын

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

  • @GoogleAccount-ho6ng
    @GoogleAccount-ho6ng Жыл бұрын

    i just dont get it

  • @jessp5966
    @jessp5966 Жыл бұрын

    genius

  • @adamumustapha7868
    @adamumustapha78685 жыл бұрын

    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.

  • @kikejoo2240
    @kikejoo2240 Жыл бұрын

    hard to understand

  • @tangaucheplease9621
    @tangaucheplease96212 жыл бұрын

    Noice

  • @user-ep6pd2ss8g
    @user-ep6pd2ss8g4 жыл бұрын

    pyramid depends on ' i '. illuminati confirmed

  • @mojo6112

    @mojo6112

    3 жыл бұрын

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

  • @ShermanSitter
    @ShermanSitter4 жыл бұрын

    I've never used a wa-loop :)

  • @gomitos8866
    @gomitos88662 жыл бұрын

    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

    Жыл бұрын

    same here this shit is annoying as hell

  • @turtlecodes8319

    @turtlecodes8319

    Жыл бұрын

    @@vaby7789 fr

  • @ninjapirate123

    @ninjapirate123

    19 күн бұрын

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

  • @omervnl
    @omervnl2 жыл бұрын

    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???

  • @antoniobanderas5316
    @antoniobanderas5316 Жыл бұрын

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

  • @DeViLTh0rn
    @DeViLTh0rn4 жыл бұрын

    4:27

  • @justinharris6898
    @justinharris68984 жыл бұрын

    *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

  • @WannaBe-21
    @WannaBe-215 жыл бұрын

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

  • @jerrynguyen9895
    @jerrynguyen98952 жыл бұрын

    illoopminati

  • @user-cg4xz3bn4l
    @user-cg4xz3bn4l Жыл бұрын

    how to do print something then loop it forever