From 15ff62419201a3142b71d16cb5e919334a92d097 Mon Sep 17 00:00:00 2001 From: David Ferrone Date: Thu, 15 Feb 2024 15:56:34 -0500 Subject: Recent Python scripts --- challenge-252/zapwai/python/ch-1.py | 14 ++++++++++++++ challenge-252/zapwai/python/ch-2.py | 13 +++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 challenge-252/zapwai/python/ch-1.py create mode 100644 challenge-252/zapwai/python/ch-2.py (limited to 'challenge-252') diff --git a/challenge-252/zapwai/python/ch-1.py b/challenge-252/zapwai/python/ch-1.py new file mode 100644 index 0000000000..541d927568 --- /dev/null +++ b/challenge-252/zapwai/python/ch-1.py @@ -0,0 +1,14 @@ +def proc(ints): + spec = [] + for i in range(len(ints)): + if len(ints) % (i+1) == 0: + spec.append(ints[i]) + sum = 0 + for v in spec: + sum += v*v + print("Input: ints =", ints) + print(f"Output: {sum}") +ints = [1,2,3,4] +proc(ints) +ints = [2, 7, 1, 19, 18, 3] +proc(ints) diff --git a/challenge-252/zapwai/python/ch-2.py b/challenge-252/zapwai/python/ch-2.py new file mode 100644 index 0000000000..998cba13e9 --- /dev/null +++ b/challenge-252/zapwai/python/ch-2.py @@ -0,0 +1,13 @@ +def proc(n): + print(f"Input : n = {n}") + l = [] + if n % 2 == 1: + l.append(0) + k = int( (n - 1) / 2 ) + val = 1 + for i in range(k): + l.append(val); l.append(-1*val) + val += 1 + print("Output:", l) +for n in [5, 3, 1]: + proc(n) -- cgit