aboutsummaryrefslogtreecommitdiff
path: root/challenge-268/sgreen/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-268/sgreen/python/ch-2.py')
-rwxr-xr-xchallenge-268/sgreen/python/ch-2.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-268/sgreen/python/ch-2.py b/challenge-268/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..d0abc6522c
--- /dev/null
+++ b/challenge-268/sgreen/python/ch-2.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def numbers_game(ints: list) -> list:
+ # Check we have an even number of items
+ if len(ints) % 2 != 0:
+ raise ValueError('Please provide an even number of items!')
+
+ # Sort the list
+ ints = sorted(ints)
+
+ for i in range(0, len(ints), 2):
+ # Switch the pairs of numbers around
+ ints[i], ints[i+1], = ints[i+1], ints[i]
+
+ return ints
+
+
+def main():
+ # Convert input into integers
+ array = [int(n) for n in sys.argv[1:]]
+ result = numbers_game(array)
+ print(tuple(result))
+
+
+if __name__ == '__main__':
+ main()