This repository has been archived by the owner on May 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproj3.py
66 lines (52 loc) · 1.91 KB
/
proj3.py
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
61
62
63
64
65
66
#!/usr/bin/env python3
# ukol za 2 body
def first_odd_or_even(numbers):
"""Returns 0 if there is the same number of even numbers and odd numbers
in the input list of ints, or there are only odd or only even numbers.
Returns the first odd number in the input list if the list has more even
numbers.
Returns the first even number in the input list if the list has more odd
numbers.
>>> first_odd_or_even([2,4,2,3,6])
3
>>> first_odd_or_even([3,5,4])
4
>>> first_odd_or_even([2,4,3,5])
0
>>> first_odd_or_even([2,4])
0
>>> first_odd_or_even([3])
0
"""
even_count, odd_count = 0, 0
even_first, odd_first = None, None
for number in numbers:
if number % 2 == 0:
even_count += 1
even_first = number if even_first is None else even_first
else:
odd_count += 1
odd_first = number if odd_first is None else odd_first
return 0 if even_count == odd_count or even_count == 0 or odd_count == 0 \
else odd_first if odd_count < even_count else even_first
# ukol za 3 body
def to_pilot_alpha(word):
"""Returns a list of pilot alpha codes corresponding to the input word
>>> to_pilot_alpha('Smrz')
['Sierra', 'Mike', 'Romeo', 'Zulu']
"""
pilot_alpha = ['Alfa', 'Bravo', 'Charlie', 'Delta', 'Echo', 'Foxtrot',
'Golf', 'Hotel', 'India', 'Juliett', 'Kilo', 'Lima', 'Mike',
'November', 'Oscar', 'Papa', 'Quebec', 'Romeo', 'Sierra', 'Tango',
'Uniform', 'Victor', 'Whiskey', 'Xray', 'Yankee', 'Zulu']
pilot_alpha_list = []
while len(word) > 0:
char = word[0].upper()
alpha_code = [code for code in pilot_alpha if code.startswith(char)]
if alpha_code:
pilot_alpha_list.append(alpha_code[0])
word = word[1:]
return pilot_alpha_list
if __name__ == "__main__":
import doctest
doctest.testmod()