Am I wrong | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Am I wrong

>>> for i in range(10): ... try: ... if 10 / i == 2.0: ... break ... except ZeroDivisionError: ... print(1) ... else: ... print(2) ... 1 2 2 2 >>> but the answer given is 9

10th Dec 2016, 7:48 AM
root1024
10 Answers
+ 4
I'm wrong. :c
10th Dec 2016, 8:17 AM
Ahri Fox
Ahri Fox - avatar
+ 3
range(10) start at index 0 and the for loop break at index 5. 0 = 1 1 = 2 2 = 2 3 = 2 4 = 2 5 = break out of for loop
10th Dec 2016, 7:53 AM
Klah Thom
Klah Thom - avatar
0
In [9]: 10/4==2.0 Out[9]: True it should break out when i==4,so just output 1 2 2 2
10th Dec 2016, 8:13 AM
root1024
0
10/4 is 2.5 Why would it break at i=4
10th Dec 2016, 8:40 AM
Rishi Anand
Rishi Anand - avatar
0
because the answer of divsion of two integer is integer,and ceil
10th Dec 2016, 3:07 PM
root1024
0
answer is 9
24th Jul 2018, 7:31 PM
Nishet Vyas
Nishet Vyas - avatar
0
for i in range(10): try: if 10 / i == 2.0: break except ZeroDivisionError: print(1) else: print(2) # o/p:- 1 2 2 2 2
8th Jan 2021, 12:03 PM
Diptiranjan Malik
0
1 is the ans
20th Feb 2021, 6:47 AM
Ishika sinha
0
the answer is 1
24th Mar 2021, 6:34 PM
Sophia Porras
Sophia Porras - avatar
0
its 1
27th Apr 2021, 6:51 PM
angelina starn