0

help me

I have not clarified about the while loop .. Please i request any python experts to clarify my doubt as a beginner with an example.............

21st Jul 2017, 12:03 PM
Darwin
Darwin - avatar
9 Answers
+ 1
I have got the point .. Thanking you teacher
21st Jul 2017, 12:26 PM
Darwin
Darwin - avatar
0
Yup
21st Jul 2017, 12:11 PM
Darwin
Darwin - avatar
0
#The while loop starts and continues as long as a condition is true. cats = 2 print("I have {} cats".format(cats)) while cats > 0: print("My cat ran away") cats -= 1 print("I have {} cats".format(cats)) print() #It can also be escaped out of if you need to leave early dogs = 4 print("I have {} dogs".format(dogs)) while dogs > 0: print("My dog ran away") if dogs == 2: break dogs -= 1 print("I have {} dogs".format(dogs)) #You must always have a way to exit your loop, otherwise it will go indefinitely, and usually this will cause an issue.
21st Jul 2017, 12:13 PM
Jim Tully
Jim Tully - avatar
0
i=2 while i<=10: print(i) i=i+3 print("program done") First i=2 and has the output as 5 Next the number is 3 but the output is another:
21st Jul 2017, 12:14 PM
Darwin
Darwin - avatar
0
Sorry first printed 2 ::next the number is 3 after two and it should give the output as 6 : but in my console it is 5 .. You may think of me as a foolish guy.. The true is I'm a good in studies but i am new to programming..)
21st Jul 2017, 12:22 PM
Darwin
Darwin - avatar
0
Thanks
21st Jul 2017, 12:23 PM
Darwin
Darwin - avatar