aboutsummaryrefslogtreecommitdiff
path: root/challenge-116/abigail/python/ch-2.py
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2021-06-14 16:05:16 +0800
committer冯昶 <fengchang@novel-supertv.com>2021-06-14 16:05:16 +0800
commit313cc70a885ed652579869eea7209d31ffb7774a (patch)
tree8fa3c3184bbc39cc7713c37454ac50c9ad113bc2 /challenge-116/abigail/python/ch-2.py
parent0e851de358a804fa5df6cbf8d5e94ee08a455fb7 (diff)
parentc962097d9d0850163cd3f945958c16152f14e14c (diff)
downloadperlweeklychallenge-club-313cc70a885ed652579869eea7209d31ffb7774a.tar.gz
perlweeklychallenge-club-313cc70a885ed652579869eea7209d31ffb7774a.tar.bz2
perlweeklychallenge-club-313cc70a885ed652579869eea7209d31ffb7774a.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)