+ 1
Explain this question please
What is the largest number this code prints? for i in range(10): if i > 5: print(i) break else: print("7") #python
20 Answers
+ 5
Let's simplify code :---
-- in this loop i is being incremented by 1
when
i = 0 ( i > 5 is False )
i = 1 ( i > 5 is False )
i = 2 ( i > 5 is False )
i = 3 ( i > 5 is False )
i = 4 ( i > 5 is False )
i = 5 ( i > 5 is False )
i = 6 ( i > 5 is True )
when condition is True
-- code executes
-- prints 6
-- loop breaks
this is why largest number this code prints is 6
Hope this helps !
+ 3
Hi,
what is the output?
after: which of the printed numbers is the highest?
+ 3
Priyanshu Gupta First of all else condition is executed when for loop is not terminated by break or any condition in for loop is not true & second thing is, in this loop when condition becomes true we prints i and break statement terminate the loop so when condition is true and loop is terminated by break statement. Then else condition will not be executed.
+ 2
💞𝐒𝐨𝐦𝐲𝐚💞 what is output if i is 1🧐
+ 2
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥
ohhhh evil 😈😈😈
+ 2
Code Crasher Yupp ! My Best wishes with you for your exam
+ 1
💞𝐒𝐨𝐦𝐲𝐚💞
the indent of else might be missing accidently or ment as little trap.
+ 1
Code Crasher Some learning stuff should only be experienced by own.
Thank you for your concern !
+ 1
The largest number is six since "7" is not a number but a string.
To understand why it is six:
The for loop will terminate immediately it printed out the first int > 5 which is six
Although it printed 7 five times d answer is not seven since the seven printed out is a string not a number
+ 1
The output will be 6
+ 1
Output will be
7
7
7
7
7
7
6 , beacause when if block comes true , loop breaks and , iteration stops. Before this, else block comes true , and prints 7
+ 1
Output ->
7
7
7
7
7
7
6
Largest number -> 7