-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path020_Even or Odd in Array.py
69 lines (45 loc) · 1.15 KB
/
020_Even or Odd in Array.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
67
68
69
"""
Codewars Coding Challenge
Odd or Even?
Given a list of integers, determine whether the sum of its elements is odd or even.
Give your answer as a string matching "odd" or "even".
If the input array is empty consider it as: [0] (array with a zero).
Examples:
Input: [0]
Output: "even"
Input: [0, 1, 4]
Output: "odd"
Input: [0, -1, -5]
Output: "even"
Have fun!
https://www.codewars.com/kata/5949481f86420f59480000e7/train/python
"""
# My Solution
def odd_or_even(arr):
if sum(arr) % 2 == 0:
return "even"
else:
return "odd"
# Sample test
"""
import codewars_test as test
from solution import odd_or_even
@test.describe("Fixed Tests")
def fixed_tests():
@test.it('Basic Test Cases')
def basic_test_cases():
test.assert_equals(odd_or_even([0, 1, 2]), "odd")
test.assert_equals(odd_or_even([0, 1, 3]), "even")
test.assert_equals(odd_or_even([1023, 1, 2]), "even")
"""
"""
PERFECT SOLUTION FROM CODEWARS
=1=
def oddOrEven(arr):
return 'even' if sum(arr) % 2 == 0 else 'odd'
=2=
def oddOrEven(arr):
return ('even', 'odd')[sum(arr) % 2]
=3=
oddOrEven = lambda l: "odd" if sum(l) % 2 else "even"
"""