What is the output produced when this code executes?i = 1while(i<=7):i *= 2print(i)816414
Question
What is the output produced when this code executes?i = 1while(i<=7):i *= 2print(i)816414
Solution
The output of the code will be 16. Here's the step by step execution:
- Initialize
ito 1. - Enter the while loop because
i(1) is less than or equal to 7. - In the loop,
iis multiplied by 2, soibecomes 2. - The loop continues because
i(2) is still less than or equal to 7. iis multiplied by 2 again, soibecomes 4.- The loop continues because
i(4) is still less than or equal to 7. iis multiplied by 2 again, soibecomes 8.- The loop continues because
i(8) is still less than or equal to 7. iis multiplied by 2 again, soibecomes 16.- The loop ends because
i(16) is not less than or equal to 7. - The value of
i(16) is printed.
Similar Questions
1 pointWhat is the output of the following code?i = 1while True: if i%2 == 0: break print(i) i += 211 21 2 3 4 5 6 ...1 3 5 7 9 11 ...
What will be the output for the following code?i=0while(i<3): j=0 while(j<3): print(i,j,end=" ") j+=1 print()
What will be the output of the following Python code?i = 7while True: if i%0O11 == 0: break print(i) i += 2
Study the following program:i = 0while i < 3: print(i) i += 1 else: print(0)
What will be the output of the following program?while i < 20: print(i) i += 1
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.