For Loops & While Loops in Python - Beginner Python Tutorial #5 (with Exercises)

  Рет қаралды 92,701

Keith Galli

Keith Galli

6 жыл бұрын

Fifth video in my python tutorial series. In this video we cover the two different types of loops, for & while loops. Loops allow you to repeatedly execute blocks of code. For loops work great for a set number of iterations as well as iterating through lists. While loops work well with booleans (true or false).
If you have any questions, leave a comment down below!
Feel free to watch on 1.25x or 1.5x speed.
SUBSCRIBE if you enjoyed this video!! More tutorials to be uploaded real soon.
-------------------------
PYTHON TUTORIAL SERIES:
Setup & Installation: • Why Should you Learn P...
1. Math & Variables: • Math & Variables in Py...
2. Conditional Statements (if, elif, else): • Conditional Statements...
3. Functions: • Functions in Python - ...
4. Lists & Tuples: • Lists & Tuples in Pyth...
5. For Loops & While Loops: • For Loops & While Loop...
Learn to Program a game (mentioned at the start of this video): • How to Program a Game!...
-------------------------
Follow me on social media!
Instagram | / keithgalli
Twitter | / keithgalli
-------------------------
If you are curious to learn how I make my tutorials, check out this video: • How to Make a High Qua...
⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. I've been using Kite for 6 months and I love it! www.kite.com/get-kite/?...
*I use affiliate links on the products that I recommend. I may earn a purchase commission or a referral bonus from the usage of these links.

Пікірлер: 70
@KeithGalli
@KeithGalli 6 жыл бұрын
Video Outline! 1:09 - Intro to For Loops 2:09 - Getting Iteration Number 4:10 - For Loops + Lists 5:31 - Calculating the average value in a list 10:21 - For Loops + Lists (index method) 12:33 - Using the Enumerate function 13:27 - Intro to While Loops 15:02 - Counting to 10 with While loop 18:18 - Break & Continue Statements 21:17 - Coding Bat Example Problems 24:53 - Coding Bat Example #2 30:33 - Video Recap Feel free to watch on 1.25x or 1.5x speed to learn faster!
@ancestraltechnologies3116
@ancestraltechnologies3116 2 жыл бұрын
Keith, can you post your font_face for sublime text?
@cambridgebreaths3581
@cambridgebreaths3581 4 жыл бұрын
man, honestly you are the coolest programmer. I will start enjoy watching your python and NN videos systematically.
@Yordani2031
@Yordani2031 3 жыл бұрын
where were you 4 months ago when I statrted teaching myself python.. you are the man bro.. thanks
@brianwake100
@brianwake100 3 жыл бұрын
Keith your videos a very easy to understand, So helpful Thanks..
@Pythagoras31415
@Pythagoras31415 Жыл бұрын
Thanks. I always learn something new watching your videos.
@fosback13245
@fosback13245 3 жыл бұрын
I used to program in C/C++ using the Windows APi (Petzold book) and it was a complicated process!! Python is so much easier!! Thank you for these tutorials!!
@sarahjustme
@sarahjustme 3 жыл бұрын
Very helpful, thanks a lot!
@NewfieNL
@NewfieNL 4 жыл бұрын
Man! you are simply awesome
@TheFreeballer1
@TheFreeballer1 2 жыл бұрын
you just helped me after being stuck for 2 hrs on this while loop.
@meliyomollameles
@meliyomollameles 4 ай бұрын
It's my first time here but i liked you the first minute the video started and the second you started talking. I don't think I am going anywhere.
@lfggaming4248
@lfggaming4248 5 жыл бұрын
thanks to you i know python
@sylvesterkanev2918
@sylvesterkanev2918 2 жыл бұрын
Hey, Keith. Great video as always! Could you make another one regarding the nested for loops (for loops in for loops) and nested if statements (if statement in if statement)? Stay safe!
@adamrolander3518
@adamrolander3518 5 жыл бұрын
u r da man, bruv
@nehabalani7290
@nehabalani7290 3 жыл бұрын
THank you :)
@CGRunLough
@CGRunLough 4 жыл бұрын
Nice
@christofweber8965
@christofweber8965 5 жыл бұрын
Love your tutorials, easy to follow and good content for beginners. Short question on the Codebat "String_time": did you use the loop intentionally as one could have solved it by simply stating: return str*n Thanks again for your videos!
@KeithGalli
@KeithGalli 5 жыл бұрын
Thanks for the kind comments! Yea so I used the loop intentionally just to demonstrate an example of what this video was about. Your solution to return str*n would be more optimal in general.
@christofweber8965
@christofweber8965 5 жыл бұрын
Thanks for your quick response! Ok, understood .. makes sense. Btw: would you have some recommendations with regard to next steps once finished with your tutorials? Codingbat or any other resources for becoming more advanced? Thanks!
@KeithGalli
@KeithGalli 5 жыл бұрын
Well I guess it really depends on what your programming goals are. What type of stuff do you think is cool? Some potential areas could be game development, robotics, machine learning, app development, etc. Let me know and I'll try to point you to some good resources
@eikun1024
@eikun1024 2 жыл бұрын
For the 24:31 Exercise, I want to ask that why my code doesn't work? What's the difference? def string_times(str, n): for i in range(n): return str*n
@cmg1131
@cmg1131 2 жыл бұрын
takk fyrir !!
2 жыл бұрын
You can also do this: def string_times(str, n): return (str * n)
@veggiebroth5542
@veggiebroth5542 Жыл бұрын
Right, but that wouldn't be a loop
@Youuuuuu
@Youuuuuu 5 жыл бұрын
24:41 For whatever reason this works too... def array123(nums): if 1 and 2 and 3 in nums: return True else: return False
@v_popov152
@v_popov152 5 жыл бұрын
lol its so good but only for this situation
@tanyadyne
@tanyadyne 5 жыл бұрын
But this code will always return True even if the sequence '1, 2, 3' is not in order. For example, print(array123([1, 1, 3, 2, 1])) will still return True as it contains 1, 2 and 3 but not in that order.
@mirsadkuljici2737
@mirsadkuljici2737 2 жыл бұрын
Can someone tell me why do we put a zero number when getting a total value for smth (7:19) .. maybe the question is absurd but I am a beginner. Thank you in advance!
@Kenionatus
@Kenionatus 2 жыл бұрын
Because you can't add to a variable that doesn't exist yet. It also needs to be a number for adding to make any sense. You couldn't add 1 to a function object so Python needs to know it's a number first.
@martinopranjic8242
@martinopranjic8242 5 жыл бұрын
i = 2 n = 1 while n
@panchoprkl4452
@panchoprkl4452 5 жыл бұрын
from time import sleep i = 2 while True: print(i) i *= i sleep(1)
@BN-hy1nd
@BN-hy1nd 4 жыл бұрын
For an absolute, absolute beginner, how do we arrange numbers in ascending or descending order/ Thank you
@ForrestFox0
@ForrestFox0 4 жыл бұрын
Watch his other Python tutorials it's explained in number 4 I think
@edixonbalzan1142
@edixonbalzan1142 Жыл бұрын
Hi man where i can practice more exercises?
@julianjoseph5679
@julianjoseph5679 8 ай бұрын
Hey man thx preparing for exam 😅
@KeithGalli
@KeithGalli 7 ай бұрын
Hope the exam went well!
@mikelim91
@mikelim91 3 жыл бұрын
def string_times(str,n): non = int(n) return str*non
@abhinavkumar8396
@abhinavkumar8396 5 жыл бұрын
keith your videos are awesome ~ can you make on django app on web with python ! step by step .. how to!
@babitakarki5662
@babitakarki5662 3 жыл бұрын
What is "i". Can it be something else instead of "i" when you type "for 'i' in range (10):" ?
@AlbionofRunescape
@AlbionofRunescape 3 жыл бұрын
Yes. You ‘I’can be almost anything.
@muhammaddanishnisar4731
@muhammaddanishnisar4731 3 жыл бұрын
Yes i can be anything it may be a variable name. This i or any variable is usually acts like a counter of for loop
@TheSuccessfulLeader
@TheSuccessfulLeader 4 жыл бұрын
CodingBat.com: good path as a learning aid: thanks Keith;
@reedshay6173
@reedshay6173 3 жыл бұрын
hey just never say standard deeev. Other than that it was a great review thanks big fudge
@v_popov152
@v_popov152 5 жыл бұрын
Hello. First i want to say that i really appriciate your work. Im a 13 yrs old kid and im learing python rn cuz i want to work like software engineer. I can write a simple codes but when i try to solve problems in this site i cannot. I really cannot understand the strings.
@KeithGalli
@KeithGalli 5 жыл бұрын
Hmm I'm not sure I understand your problem. Can you try to be a little bit more specific?
@v_popov152
@v_popov152 5 жыл бұрын
@@KeithGalli when i have an idea to do some sinple code i do it. But if i have it like an exercise like in this site i cannot figure it out. Also im watching your tutorial to do a game and i understand the code but i cannot write it by myself. Btw thank you so much for answering me ur the best❤️
@KeithGalli
@KeithGalli 5 жыл бұрын
Check out this video for additional guidance on solving the coding bat problems. They are not easy at first, but with enough practice you should be able to start getting them! kzbin.info/www/bejne/oqmaoKSQbLOfac0
@matthewwalsh7813
@matthewwalsh7813 3 жыл бұрын
Index of 25 positions with weights varying from about 180 to about 250, and you have what looks like an MIT flag on your wall. I would guess the Bruins.
@KeithGalli
@KeithGalli 3 жыл бұрын
You are correct! I'm a big bruins fan :)
@matthewwalsh7813
@matthewwalsh7813 3 жыл бұрын
@@KeithGalli Well as a Hawks fan, I'm just happy it wasn't Detroit. Cus then I'd have a dilemma on my hands lmao. I spent 4 years living in Boston, so I can get down with Bruins fans. Thanks for all the videos and all the work that you do here man. It's awesome.
@_cursedvlogs
@_cursedvlogs Жыл бұрын
side effects of using visual studio code saving all the time it happens with me too bro lollz
@skepticaltep
@skepticaltep 4 жыл бұрын
5:41
@alexanderpadalka5708
@alexanderpadalka5708 3 жыл бұрын
@rtmbiking67
@rtmbiking67 4 жыл бұрын
so for some reason, it says this is invalid game_over = False score = 0 while not game over: print("playing game")
@rtmbiking67
@rtmbiking67 4 жыл бұрын
can any of you guys tell me whats wrong
@tosstime8950
@tosstime8950 3 жыл бұрын
@@rtmbiking67 Well you used the wrong variable in your while loop. It should be game_over rather than game over!!😊
@rejuszuzevicius9799
@rejuszuzevicius9799 3 жыл бұрын
Ok thanks
@yassinmobarak6226
@yassinmobarak6226 2 жыл бұрын
i have big problem guys that i cant understand the task any body can help me and tell me anything that make me better in that
@georgepoletes4459
@georgepoletes4459 2 жыл бұрын
weights = Red Sox lineup?
@Quaght
@Quaght 2 жыл бұрын
That was my thought! MIT in the background and 25 players.
@jeffkamau3432
@jeffkamau3432 5 жыл бұрын
how can one improve python skills after watching your videos
@cheng-juyeh525
@cheng-juyeh525 Жыл бұрын
god bless u xdd
@ianwilliam9531
@ianwilliam9531 4 жыл бұрын
Red Sox
@KeithGalli
@KeithGalli 4 жыл бұрын
You were very close, but actually took the numbers from the Bruins!
@lisao2920
@lisao2920 Жыл бұрын
bruins!
@joojok72
@joojok72 3 жыл бұрын
which team was it lol
@RyNzOr
@RyNzOr 2 жыл бұрын
i write a code weights = [1, 2, 5, 7, 9, 8] total_weights = 0 for weight in weights: total_weights += weight print(total_weights) and get: 1 3 8 15 24 32 why not sum ?
@johndo3164
@johndo3164 2 жыл бұрын
Move: print (total_weights) out of the loop. Should be vertically aligned to: for weight in weights: .
How to Program a Game! (in Python)
1:10:07
Keith Galli
Рет қаралды 493 М.
CHOCKY MILK.. 🤣 #shorts
00:20
Savage Vlogs
Рет қаралды 15 МЛН
Inside Out 2: Who is the strongest? Joy vs Envy vs Anger #shorts #animation
00:22
Получилось у Миланы?😂
00:13
ХАБИБ
Рет қаралды 5 МЛН
While loops in Python are easy ♾️
6:58
Bro Code
Рет қаралды 335 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 288 М.
Math & Variables in Python - Beginner Python Tutorial #1
18:27
Keith Galli
Рет қаралды 83 М.
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1,1 МЛН
Nested while Loop in Python
12:49
Neso Academy
Рет қаралды 12 М.
Python For Loops - Programming for Beginners
5:19
Python Simplified
Рет қаралды 135 М.
#20 Python Tutorial for Beginners | While Loop in Python
12:43
Telusko
Рет қаралды 1,6 МЛН
Python: While Loops (Reading User Input Indefinitely?!!)
14:40
Python For Loops - Python Tutorial for Absolute Beginners
14:42
Programming with Mosh
Рет қаралды 572 М.
CHOCKY MILK.. 🤣 #shorts
00:20
Savage Vlogs
Рет қаралды 15 МЛН