+ 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
10 ответов
+ 4
I'm wrong.
:c
+ 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
0
In [9]: 10/4==2.0
Out[9]: True
it should break out when i==4,so just output
1
2
2
2
0
10/4 is 2.5
Why would it break at i=4
0
because the answer of divsion of two integer is integer,and ceil
0
answer is 9
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
0
1 is the ans
0
the answer is 1
0
its 1