Learn Python Programming - 21 - While Loops

  Рет қаралды 118,419

Clever Programmer

Clever Programmer

Күн бұрын

Code Notes -- repl.it/EBns/2
Enroll in Course -- cleverprogramm...?
Let's cover while loops in Python. They are useful when you don't know how long something is going to take to end. Whereas you should use for loops when you know when something should end. Ex: While you are not tired... Keep going. While the user wants to keep playing... Keep playing. For 10 times, do pushups. For 55 times, do jumping jacks. Hopefully, you get a little bit of an idea. ...
...
★☆★ FREE Lesson 1: The Most Important Thing For a Successful Programmer★☆★
www.cleverprog...
Enroll for coding exercises, projects, tutorials, and courses...
cleverprogramm...? ------------------------------------
Clever Programmer
Website ► cleverprogramm...?
Facebook ► cleverprogramme...
Twitter ► cleverprogramme...
Instagram ► cleverprogramme...
Snapchat ► Rafeh1
iTunes Podcast ► cleverprogramme...
Google Podcast ► cleverprogramme...
Support (Patreon) ► cleverprogramme...
KZbin ► / cleverprogrammer
Github (Code) ► cleverprogramme... Biz / Sponsorships 👉 www.cleverprog...

Пікірлер: 194
@raghavanand1648
@raghavanand1648 6 жыл бұрын
Love this man!!!! I just did something myself, and It felt so good count = 100 while count > 0: print (count) count = count - 1 if count == 0: print ("Boooyah!")
@sithummethmika1676
@sithummethmika1676 3 жыл бұрын
Boyaah
@soldiergaming2722
@soldiergaming2722 6 жыл бұрын
I've watched all your python tutorials and haven't seen anyone who explains it better than you
@nevon_j2am61
@nevon_j2am61 3 жыл бұрын
I liked the way u related while loops with push-ups
@ezra2370
@ezra2370 3 жыл бұрын
count = 100 # this also works while count>=0: if count>0: print(count) else: print("blast off") count = count - 1
@talesofeer
@talesofeer 4 жыл бұрын
count = 0 while count > 0: print(count) count = count - 1 if count == 0: print("BLAST OFF!!!!!") I think this is easier. I really love your lectures.
@francescowang
@francescowang 3 жыл бұрын
Thanks for the explanation. What's the difference between the following two answers? The output is 0 to 9. The other one is 1 to 10. Why is that? count = 0 while count < 10: print(count) count = count + 1 vs. count = 0 while count < 10: count = count + 1 print(count)
@suryanshporwal932
@suryanshporwal932 4 жыл бұрын
you can also write like this m = int(input("Enter a number ")) while 0 < m: print(m) m -= 1 print("yes i know while loop")
@ellies_silly_zoo
@ellies_silly_zoo 7 жыл бұрын
can't you just do that? count = 100 while count > 0: print(count) count -= 1 print("Blast off!")
@ajithv8582
@ajithv8582 7 жыл бұрын
Wand_Platte then you will get 100 blast 99 blast 98 blast........ so you r wrong
@syedazeemjaved
@syedazeemjaved 7 жыл бұрын
No, I think that the print("Blast off!") is outside the body of the while loop. So it will run when once after the while loop is executed.
@tannerbarcelos6880
@tannerbarcelos6880 6 жыл бұрын
Azeem Javed yes sir
@harambe2185
@harambe2185 5 жыл бұрын
In this situation yes you can
@valeraezekielvancleoi.97
@valeraezekielvancleoi.97 4 жыл бұрын
ahh, that's exactly what I did except there were some more lines (lol)
@sgtkeebler
@sgtkeebler 6 жыл бұрын
I am new to coding but a really good hint for new users like me. spacing after : counts. I ran a while loop that had a infinite loop because I didn't space things properly.
@jtak69
@jtak69 7 жыл бұрын
I just don't understand how someone could possibly enjoy doing this...... I'm only doing this for a class that I have to take, and I hate my life hahahaha. But hey, to each their own. Anyways, thanks for the help man!! You post awesome content!
@cgd1602
@cgd1602 4 жыл бұрын
count = 100 while count > 0: print(count) count = count - 1 print(count) if (count == 0): print("Blast off!") WOW I learned a lot from this simplke code! I forgot turn this sign around: from ""
@MrM0NKEYZER0
@MrM0NKEYZER0 6 жыл бұрын
count = 100 while count > 0: print(count) count = count - 1 if count == 0: print('blast off') could this work fine?
@harambe2185
@harambe2185 5 жыл бұрын
Yh
@aamirshaikh4392
@aamirshaikh4392 5 жыл бұрын
Thanks man! Was stuck on this topic for quite some time. Really helped!!
@nitinchaudhary7686
@nitinchaudhary7686 5 жыл бұрын
Me too , im stuck now..
@reset8209
@reset8209 4 жыл бұрын
Yea I was stuck too
@satheeshkumar2543
@satheeshkumar2543 7 жыл бұрын
count = 100 while count > 0: print(count) count = count - 1 if count
@Dezzy7model
@Dezzy7model 4 жыл бұрын
I ran the code : count = 100 while count >= 0: if count == 0: print('Blast off!') else: print(count) count = count - 1 But i get... SyntaxError: multiple statements found while compiling a single statement
@Hampetorp
@Hampetorp 7 жыл бұрын
count = 100 while count>0: print(count) count = count -1 print('BLASTOFF!!')
@ezra2370
@ezra2370 3 жыл бұрын
wow it worked so python finish code under the while loop before doing anything else out side the while loop and after the condition is false. it will print out ("blast off ") tnx bro
@horatione
@horatione 4 жыл бұрын
0:43 best example, dude
@Shams_Defi
@Shams_Defi 7 жыл бұрын
simple count=100 while count>0: print(count) count=count-1 else: print('blast of')
@tauhidurrahman312
@tauhidurrahman312 4 жыл бұрын
count = 100 while 0 < count
@valeraezekielvancleoi.97
@valeraezekielvancleoi.97 4 жыл бұрын
#at 9:13 #the code block I came up with is: count = 101 while count > 1: count += -1 print(count) print("BLAST OFF") #edit #while my code was shorter, I was able to get more insight on the code that you have written #it seems like a more plausible option to check if my code would run
@sueholder703
@sueholder703 4 жыл бұрын
A brilliantly broken down explanation which helped me solve a coding challenge I was stuck on.
@hhinfosystemspvt.ltd.2705
@hhinfosystemspvt.ltd.2705 6 жыл бұрын
while count>1: print(count) count=count-1 while count==1: print('BLAST OFF') break
@palestinian5543
@palestinian5543 6 жыл бұрын
my_energy = 100 while my_energy > 90: print "Do Pushups" my_energy -= 1
@firozwaseem938
@firozwaseem938 6 жыл бұрын
Palestinian when count =count-1 Count=100 100-1=99 When it runs From 99-1 Why 100 also running
@lishengyang9779
@lishengyang9779 4 жыл бұрын
count = 0 count = 100 while count > 0: print(count) count = count - 1 if count == 0: print('blast off')
@luka2987
@luka2987 6 жыл бұрын
i dont know if u read the comments anymore but if someone reads this can you tell me is this wrong count = 100 >>> while count > 0: print(count) count = count - 1 if count
@omerturan6784
@omerturan6784 7 жыл бұрын
There is actually another way to make it say "blast off" here is my code: count = 100 while count > 0: count = count - 1 if count == 0: print("Blast OFF!!!") else: print(count) I just put the if_loop after the subtraction so count turns to 0 and boom. The if-loop sees that the variable count equals to 0 and prints the String Hopefully it is correct. I would be happy if you comment on this.
@nikhilsingh1296
@nikhilsingh1296 5 жыл бұрын
This is really awesome way to explain, but what if I want to have a series like 1,2,3,6,4,5,6,15,7,8...till 100
@ahmed1ghanim
@ahmed1ghanim 7 жыл бұрын
this works tho :D count = 100 while count > 0: print(count) count = count - 1 print('blastoff')
@scott9695
@scott9695 6 жыл бұрын
count = 100 while count > 0: print(count) count -= 1 if count == False: print("Blast off!")
@muradelmissalati8150
@muradelmissalati8150 7 жыл бұрын
this is how I did mine and it worked number = 100 while number != 0: print(number) number -= 1 if number == 0: print("blast off")
@ENcyb
@ENcyb 3 жыл бұрын
Got it right on first time ,but only after this video! Well done boy!Keep up good work please!
@sumitrana1652
@sumitrana1652 7 жыл бұрын
i did the same code as you did for showing blast off in the last but when i run it blast off keeps on printing , so i figured it myself : >>>count=100 >>> while count>=0: if count ==0: print('yeah!') break else: print(count) count= count-1
@Gigahertzzz
@Gigahertzzz 6 жыл бұрын
You did a great job on explaining the reasoning behind the process. Thanks a ton!
@Moises-Devzz
@Moises-Devzz 5 жыл бұрын
count = 99 while 0 < count < 100: print(count) count -= 1 print('Blast off')
@RockDavid
@RockDavid 5 жыл бұрын
for i in range(3,0,-1): print(i) if i == 1: print('lift off') SImplicity at its finest ^
@pravinkannaa
@pravinkannaa 6 жыл бұрын
HERE IS MINE: count = 100 while (count > -1): if count == 0: print("Blastoff") break print(count) count = count-1
@factsandmyths3301
@factsandmyths3301 6 жыл бұрын
count = 100 while count > 0: print(count) count = count - 1 if (count == 0): print("blast!") else: print(count)
@sdr262
@sdr262 3 жыл бұрын
count = 100 while count > 0: count = count - 1 if count == 0: print("Blast off!") else: print(count)
@stephenmandelbaum2027
@stephenmandelbaum2027 7 жыл бұрын
I received the same results but in a slightly different way: count = 100 while count > 0: print(count) if count
@Allan62111q
@Allan62111q 7 жыл бұрын
count = 100 while count >= 0: if count ==0: print('Blast Off') else: print(count) count = count - 1
@dianeconrardy3924
@dianeconrardy3924 7 жыл бұрын
Thank you for this video. I now understand more about While Loops then ever before!
@souley3292
@souley3292 2 жыл бұрын
Another way to write the same code: count = 100 while (count>0) : print(count) count -= 1 if count==0: print("Blast off")
@najninbegum3934
@najninbegum3934 4 жыл бұрын
You’re the best!!! I was going crazy looking for my hw solution. Your video help me out!!!!!!!!
@nitinchaudhary7686
@nitinchaudhary7686 5 жыл бұрын
What is while true? And whats the difference between while loop and while true ?
@henrijz8336
@henrijz8336 6 жыл бұрын
i did this :count=100 while count>0: print (count) count=count-1 if count
@ezra2370
@ezra2370 3 жыл бұрын
count = 100 while count>0: print(count) count = count-1 if count == 0: print("blast off!!")
@kingzed2855
@kingzed2855 6 жыл бұрын
why is using "break" a bad thing can you explain? thanks!
@bibo0909
@bibo0909 7 жыл бұрын
this is mine(changed to 10 because it will take forever if it was 100): import time count = 10 while count > 0: print(count) count = count - 1 time.sleep(1) if count == 0: print("BLASTOFF!")
@jenickjohnson4361
@jenickjohnson4361 6 жыл бұрын
print("list of no. of rooms") count=1 while count
@rdsilvalopes
@rdsilvalopes 6 жыл бұрын
A little late, but always on time. print("list of no. of rooms") count=0 while count
@johnsknows3135
@johnsknows3135 6 жыл бұрын
Thanks for the vid. how come = doesn't work (I get why == works)?
@akyberdiew8797
@akyberdiew8797 3 жыл бұрын
Thanks so much. I'm very very grateful. Perfect explanation.
@hirokiyamamoto4799
@hirokiyamamoto4799 7 жыл бұрын
count = 0 while count < 100 : print (100 - count) count = count + 1 print ('Blast off') I started for Zero. Is this okay too? I love your videos!!
@nitinchaudhary7686
@nitinchaudhary7686 5 жыл бұрын
From where i get the examples , i understand while loop is used for when we dont know, how can we know , we have to use while loop here , im stuck here past 4 days.
@arjunmehta2853
@arjunmehta2853 6 жыл бұрын
Smaller and easier code : # Do 100 pushups count_pushups = 100 while (count_pushups > 0 ): print(count_pushups) count_pushups -= 1 if(count_pushups == 0): print ('0 : Blast off!')
@JackJack-wg8tb
@JackJack-wg8tb 4 жыл бұрын
count = 0 while count < 100: print(count) count = count+1 print("Blast off")
@holytraininggrounds4685
@holytraininggrounds4685 7 жыл бұрын
Ive come up with another shorter solution to the problem: >>> count = 100 >>> while count >= 0: print(count) count = count - 1 if count == -1: print('Blast Off!') Logic: the 'while' function runs until the value is equal or greater than 0. the function stops running at -1 because -1
@alymok2
@alymok2 6 жыл бұрын
this will print 0 and then "blast off" while he wanted to print the words instead of the number 0
@secretaryofstate1
@secretaryofstate1 5 жыл бұрын
Dude is brilliant
@hiteshvishal5436
@hiteshvishal5436 4 жыл бұрын
You could have used this count = 100 while count > 0: print (count) count = count - 1 print("blast off")
@iswarkumar5430
@iswarkumar5430 4 жыл бұрын
You started with a good example... :)
@roeyleon22
@roeyleon22 3 жыл бұрын
perfect explanation!
@Dezzy7model
@Dezzy7model 4 жыл бұрын
Why am i getting syntax error when i run in shell not repl.it while count > 0: if count == 0: print(count) count = count - 1 ???
@gassxy7841
@gassxy7841 4 жыл бұрын
hi man tks for the video just i have a qst count = 100 while count >= 0 : if count == 0 : print("Blast off") else: print("count ", count) count -= 1 i did this to try what happen the program runs without stopping blast off can u explain why tks
@carlschmidt6262
@carlschmidt6262 7 жыл бұрын
its really funny to see the motivation of many people by the views of the videos the first python tutorials had about 20000 views this for example just 850
@CleverProgrammer
@CleverProgrammer 7 жыл бұрын
+Carl Schmidt certainly! It gets harder haha
@carlschmidt6262
@carlschmidt6262 7 жыл бұрын
Yeah but its way easier to understand then other tutorials Great job btw!
@intyinty1478
@intyinty1478 7 жыл бұрын
you can check out other tutorials,same thing. Few people can keep learning,otherwise the world will be full of programmers.haha
@fahimaljahangir3059
@fahimaljahangir3059 5 жыл бұрын
its because they give up and go study gender studies course.
@dakk3
@dakk3 6 жыл бұрын
count = 100 while count > -1: print(count) count = count - 1 else: print("Blast off!")
@dakk3
@dakk3 6 жыл бұрын
What about this?
@andrejpetrushevski
@andrejpetrushevski 7 жыл бұрын
count = 100 while count > 0: print(count) count = count - 1 if count == 0 : print("Blast off!")
@sergmarine1992
@sergmarine1992 6 жыл бұрын
This video helped a lot. Thanks for sharing!
@christopherimpey6208
@christopherimpey6208 7 жыл бұрын
imanaged to get the same result using the following code, count = 100 while count > 0: print(count) count = count - 1 if count == 0: print('BLAST OFF!')
@TrupinelisTv-LT
@TrupinelisTv-LT 7 жыл бұрын
Here's mine! count = 100 while count > 0: print(count) count = count - 1 print ("BLAST OFF!!!")
@eminescinescu
@eminescinescu 7 жыл бұрын
count = 100 while count > 0: print(count) count = count - 1 print('blastoff') :))))
@jimaguelo7113
@jimaguelo7113 7 жыл бұрын
this is mine count = 100 while count > 0: count = count - 1 print(count) if count == 0: print("blast off")
@ajithv8582
@ajithv8582 7 жыл бұрын
same as mine....
@clementinerosette1038
@clementinerosette1038 7 жыл бұрын
i ran the code.. why did it start at 99
@avp300
@avp300 7 жыл бұрын
why it runs 0 as well, 0 is not greater than 0?
@avp300
@avp300 7 жыл бұрын
Thanks man! I think I got it. So is this mean we don't need else: statement as he explains in video?
@avp300
@avp300 7 жыл бұрын
Sorry, just one more thing, according to your first reply I understood how it got the zero, but we gave it a command line that whenever count == 0, it should not print zero and instead 'Blast Off' ..Why it still printing zero then?
@TeslaTrading
@TeslaTrading 6 жыл бұрын
count = 100 while count > 1: count = count - 1 print(count) print("Blast Off!")
@tadhgryan2012
@tadhgryan2012 7 жыл бұрын
Got it in 5 minuts count = 10 while count> 0: print(count) count = count - 1 if count == 0: print('Blast Off!!!')
@user-kp5du4cs9q
@user-kp5du4cs9q 6 жыл бұрын
count = 3 while count > 0: print(count) count = count - 1 if count == 0: print('BLAST OFF!')
@eissaibrahim31
@eissaibrahim31 7 жыл бұрын
we always use for loop with range?
@blzfrost
@blzfrost 6 жыл бұрын
Keep it simple count = 100 while count > 0: print (count) count = count - 1 if count == 0: print ("BLAST OFF")
@hhinfosystemspvt.ltd.2705
@hhinfosystemspvt.ltd.2705 6 жыл бұрын
count=100 >>> while count>0: print(count) count=count-1 if count==0: print('BLAST OFF!')
@GrbesicM
@GrbesicM 5 жыл бұрын
count = 100 while count > 0: print(count) count = count - 1
@combatxhoop7069
@combatxhoop7069 7 жыл бұрын
this is how i did it while count > 0: print(count) count -= 1 if count == 0: print('BLAST OFF')
@frankzannimendez1851
@frankzannimendez1851 6 жыл бұрын
Easier code, be sure to put print('Blast off') outside the body count = 100 while count > 0: print(count) count = count - 1 print('Blast off')
@anshikagoyal9834
@anshikagoyal9834 5 жыл бұрын
My output is getting to infinity i mean that after 1its printing blast off again and again its not getting stopped.
@georgegreen9145
@georgegreen9145 7 жыл бұрын
I have another way of getting the same result count = 100 while count
@anshikagoyal9834
@anshikagoyal9834 5 жыл бұрын
I have wrote the same code as yours!!
@thierrynavarre4161
@thierrynavarre4161 7 жыл бұрын
x = 100 while x > 1: x = x - 1 print(x) if x
@irfanhashim18
@irfanhashim18 7 жыл бұрын
Dear, you have course for Pyqt , communication with sqlite?
@azminislam6149
@azminislam6149 7 жыл бұрын
mine isn't working!what should i do?
@MrWardo2009
@MrWardo2009 5 жыл бұрын
Thank you for doing this video! It really helped!
@philipirving5860
@philipirving5860 6 жыл бұрын
Study Material WOOH!!!
@sheisks
@sheisks 2 жыл бұрын
i=100 while i>0: print(i) i-=1 print("blastoff!")
@jassstar8761
@jassstar8761 6 жыл бұрын
im in 11th clas and i dont know much about python but seeing u i felt that python is very easy thank u very much
@devabd404
@devabd404 6 жыл бұрын
Can you please try to run the python files using command prompt?
@nitinchaudhary7686
@nitinchaudhary7686 5 жыл бұрын
How can we notice while examples in real world ?
@anusmitasamanta2608
@anusmitasamanta2608 4 жыл бұрын
Hey, cool!!
@fatmaalharthi7699
@fatmaalharthi7699 4 жыл бұрын
HELP GUYSS :( WHO CAN SOLVE THIS ---> Write a program to play the following game. There is a list of several country names and the program randomly picks one. The player then must guess letters in the word one at a time. Before each guess the country name is displayed with correctly guessed letters filled in and the rest of the letters represented with dashes. For instance, if the country is Canada and the player has correctly guessed a, d, and n, the program would display _ana_da. The program should continue until the player either guesses all of the letters of the word or gets five letters wrong.
@Abhishek-ts4yu
@Abhishek-ts4yu 3 жыл бұрын
thanks a lot man
@eduese
@eduese 6 жыл бұрын
Please how do I get the link to the tutorials as you say in the video
@Adrian-le9ij
@Adrian-le9ij 4 жыл бұрын
thank you
@simonehaynes-noel6462
@simonehaynes-noel6462 6 жыл бұрын
i did it like this an it worked count = 100 while count > 0: print(count) count = count - 1 print('blass off')
@tedicuko1538
@tedicuko1538 6 жыл бұрын
I dont know why bu everytime i use else it gives me a syntax error !!! please help
@fairoosok5810
@fairoosok5810 6 жыл бұрын
count=100 while(count>0): print(count) count=count-1 print('Blast off!')
@zerocopy8407
@zerocopy8407 6 жыл бұрын
Well im starting to see the part where just one mistake can mess the whole thing. The first time I tried doing it I was doing less than 0 instead of greater than. Then I had restarted python and forgot to set count to 100. Then every time I put the code in and got it wrong(from a missed quote or colon) it set the count to 99 and didnt realize it. This should be interesting.
@austingrant3264
@austingrant3264 7 жыл бұрын
I made mine only with the '>' and it worked? count = 100 while count > 0: print(count) count = count - 1 if count == 0: print("Blast Off!!")
@avp300
@avp300 7 жыл бұрын
I also did exactly same way and it does get the result we want, but I think (I am also new learner!) it wrong way to do it. Its like saying python first print from 100 to 1 and then print 'blast off' regardless. If you will reorder the lines (like write this 'count = count -1' last but same indent as if > it will not print blast off) ..so what I understood is that we have to give if statement before we tell it to count from 100 to 1....I think!
@otkacademy5401
@otkacademy5401 4 жыл бұрын
that was very helpfull
Learn Python Programming - 22 - Sum Two (Exercise)
5:04
Clever Programmer
Рет қаралды 48 М.
Learn Python Programming - 20 - For Loops
20:40
Clever Programmer
Рет қаралды 131 М.
Un coup venu de l’espace 😂😂😂
00:19
Nicocapone
Рет қаралды 4,4 МЛН
How Strong is Tin Foil? 💪
00:26
Preston
Рет қаралды 152 МЛН
While Loop in Python (Perform a Task 1000000 times With Ease) #8
10:12
While Loops in Python | Python for Beginners
5:40
Alex The Analyst
Рет қаралды 59 М.
Learn Python Programming - 11 - String Slicing NOT Cake Slicing
17:39
Clever Programmer
Рет қаралды 94 М.
While loops in Python are easy ♾️
6:58
Bro Code
Рет қаралды 373 М.
10 Crazy Python Operators That I Rarely Use
11:37
Indently
Рет қаралды 27 М.
Please Master These 10 Python Functions…
22:17
Tech With Tim
Рет қаралды 170 М.
Python Decorators in 15 Minutes
15:14
Kite
Рет қаралды 444 М.
Un coup venu de l’espace 😂😂😂
00:19
Nicocapone
Рет қаралды 4,4 МЛН