aboutsummaryrefslogtreecommitdiff
path: root/challenge-113/roger-bell-west/python/ch-2.py
diff options
context:
space:
mode:
authorRoger Bell_West <roger@firedrake.org>2021-05-17 12:59:43 +0100
committerRoger Bell_West <roger@firedrake.org>2021-05-17 12:59:43 +0100
commit0bdf5928c01ed343627fb572ba43ec2e77bd43f7 (patch)
treeec3629406fae82b6c03ff771b7af7e5adc90129b /challenge-113/roger-bell-west/python/ch-2.py
parentc3cd45087006d3f63b05219b8280a25dc1ea7ba9 (diff)
downloadperlweeklychallenge-club-0bdf5928c01ed343627fb572ba43ec2e77bd43f7.tar.gz
perlweeklychallenge-club-0bdf5928c01ed343627fb572ba43ec2e77bd43f7.tar.bz2
perlweeklychallenge-club-0bdf5928c01ed343627fb572ba43ec2e77bd43f7.zip
Solutions for challenge #113
Diffstat (limited to 'challenge-113/roger-bell-west/python/ch-2.py')
-rwxr-xr-xchallenge-113/roger-bell-west/python/ch-2.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-113/roger-bell-west/python/ch-2.py b/challenge-113/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..48a01cb2b0
--- /dev/null
+++ b/challenge-113/roger-bell-west/python/ch-2.py
@@ -0,0 +1,23 @@
+#! /usr/bin/python3
+
+import unittest
+
+def rbt(ti):
+ s=0
+ for n in ti:
+ if n>0:
+ s += n
+ to=list()
+ for n in ti:
+ if n>0:
+ to.append(s-n)
+ else:
+ to.append(n)
+ return to
+
+class TestRbt(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(rbt([1,2,3,4,-1,5,6,-1,7]),[27,26,25,24,-1,23,22,-1,21],'example 1')
+
+unittest.main()