is_found False for in if is_found True break if is_found print Found e

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
a = [1, 3, 5, 2, 3, 8]
y = 3
is_found = False
for x in a:
if x == y:
is_found = True
break
if is_found:
print('Found')
else:
print('Not found :(')
is_found = True
for x in a:
if x == y:
break
else:
is_found = False
if is_found:
print('Found')
else:
print('Not found :(')
# wrong
i = 0
while (a[i] != y) and (i < len(a)):
i += 1
if i == len(a):
print('Not found')
else:
print('Found at index =', i)
i = 0
a.append(y)
while a[i] != y:
i += 1
if i != len(a):
print('Found at index =', i)
else:
print('Not found :(')
# ---
def min_even(n):
best = float('inf')
for x in a:
if x % 2 == 0 and x < best:
best = x
return best
a = [5, 9, 7, 3, 10, 8, 3, 10]
print(min_even(a))