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.............
9 Answers
+ 1
I have got the point .. Thanking you teacher
0
Yup
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.
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:
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..)
0
Thanks



