Using python Problem 5 (10 points). How many times does the body of the while lo
ID: 3857104 • Letter: U
Question
Using pythonProblem 5 (10 points). How many times does the body of the while loop repeat? What is the output of each loop? i=1 while i < 10: if i % 2 == 0: print(i) i += 1 Using python
Problem 5 (10 points). How many times does the body of the while loop repeat? What is the output of each loop? i=1 while i < 10: if i % 2 == 0: print(i) i += 1
Problem 5 (10 points). How many times does the body of the while loop repeat? What is the output of each loop? i=1 while i < 10: if i % 2 == 0: print(i) i += 1
Problem 5 (10 points). How many times does the body of the while loop repeat? What is the output of each loop? i=1 while i < 10: if i % 2 == 0: print(i) i += 1
Explanation / Answer
i=1
i<10 ->true ,it will enter in while
if(i%2==0) ->false
i+=1 ->i=2
i<10 ->true ,it will enter in while
if(i%2==0) ->true
print 2
i+=1 ->i=3
i<10 ->true ,it will enter in while
if(i%2==0) ->false
i+=1 ->i=4
i<10 ->true ,it will enter in while
if(i%2==0) ->true
i+=1 ->i=5
and so on.
simillarly for all even values of i less than 10 program will print the "i"
and for odd values it won't print anything
Final Output will be : 2 4 6 8
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.