Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 5 - Loops - Section 5.2 - The while Loop - Check Point - MyProgrammingLab - Page 142: 5.3

Answer

a) Loop is repeated infinite times. Printout is none existent. b) Loop is repeated infinite times. Printout is none existent. c) Loop is repeated 9 times. Printout is: 24568

Work Step by Step

a) Variable i is initialized to 1 so the loop condition $i \lt 10$ is always true because there is no code inside the loop that changes the value of i. Therefore the loop is repeated infinite times. Furthermore, if statement inside the loop states that when i is an even number it is printed out. Because i is never changed from 1 the if statement is never true and the printout is non existent. b) Variable i is initialized to 1 and it is only increased by one when i is an even number. Because i is initially odd that if statement is never true and loop is repeated infinite times. Furthermore, if statement inside the loop states that when i is an even number it is printed out. Because i is never changed from 1 the if statement is never true and the printout is non existent. c) Variable i is initialized to 1 and every step in the loop it is increased by 1. The loop condition $i \lt 10$ becomes false when i equals 10 and the loop is repeated $10 - 1 = 9$ times. Furthermore the if statement inside the loop is true when i is an even number and then i is printed out. The printout is equal to even number in row from 1 to 9. Printout is: 24568
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.