aboutsummaryrefslogtreecommitdiff
path: root/challenge-116/abigail/python/ch-2.py
diff options
context:
space:
mode:
authorE7-87-83 <fungcheokyin@gmail.com>2021-06-16 21:13:20 +0800
committerE7-87-83 <fungcheokyin@gmail.com>2021-06-16 21:13:20 +0800
commit5e631f4b325d6ef41562ec1ef955e49e7da4ab75 (patch)
tree77cd0ba501ebc5d0c0fcb36764e55c98b4869b3c /challenge-116/abigail/python/ch-2.py
parent1dd7eedea237292a3fb563ecff37d004c3bbc772 (diff)
parent0aa46d7e327eb82bd447279a1891f0d1873c46ff (diff)
downloadperlweeklychallenge-club-5e631f4b325d6ef41562ec1ef955e49e7da4ab75.tar.gz
perlweeklychallenge-club-5e631f4b325d6ef41562ec1ef955e49e7da4ab75.tar.bz2
perlweeklychallenge-club-5e631f4b325d6ef41562ec1ef955e49e7da4ab75.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-116/abigail/python/ch-2.py')
-rw-r--r--challenge-116/abigail/python/ch-2.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-116/abigail/python/ch-2.py b/challenge-116/abigail/python/ch-2.py
new file mode 100644
index 0000000000..0876b16b64
--- /dev/null
+++ b/challenge-116/abigail/python/ch-2.py
@@ -0,0 +1,23 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-2.py < input-file
+#
+
+import fileinput
+from math import sqrt
+
+for line in fileinput . input ():
+ sum_of_squares = 0
+ for char in line:
+ if "1" <= char and char <= "9":
+ sum_of_squares = sum_of_squares + int (char) * int (char)
+ root = int (.5 + sqrt (sum_of_squares))
+ if sum_of_squares == root * root:
+ print (1)
+ else:
+ print (0)