From 60103d69713f2ed97cf80d377890774fc2fea50b Mon Sep 17 00:00:00 2001 From: mjfernez Date: Sun, 9 Feb 2020 15:20:00 -0500 Subject: Organized everything, update README --- 09-Special-Pythagorean-Triplet/pyth.py | 49 ++++++++++++------------ 17-Number-Letter-Counts/wordnums.py | 68 +++++++++++++++++----------------- 2 files changed, 60 insertions(+), 57 deletions(-) diff --git a/09-Special-Pythagorean-Triplet/pyth.py b/09-Special-Pythagorean-Triplet/pyth.py index 5b1e6f9..a37f026 100644 --- a/09-Special-Pythagorean-Triplet/pyth.py +++ b/09-Special-Pythagorean-Triplet/pyth.py @@ -1,29 +1,30 @@ -#A Pythagorean triplet is a set of three natural numbers, -#a < b < c, for which, -#a2 + b2 = c2 -#For example, 32 + 42 = 9 + 16 = 25 = 52. -#There exists exactly one Pythagorean triplet for which a + b + c = 1000. -#Find the product abc. +# A Pythagorean triplet is a set of three natural numbers, +# a < b < c, for which, +# a2 + b2 = c2 +# For example, 32 + 42 = 9 + 16 = 25 = 52. +# There exists exactly one Pythagorean triplet for which a + b + c = 1000. +# Find the product abc. + +import PIL +import math -import PIL, math def isTriple(abc): - if len(abc) > 3: - return False - legs = abc[0]**2 +abc[1]**2 - hyp = abc[2]**2 + if len(abc) > 3: + return False + legs = abc[0]**2 + abc[1]**2 + hyp = abc[2]**2 + + if (hyp == legs): + return True + else: + return False - if (hyp == legs): - return True - else: - return False - -for i in range(1,1000): - for j in range(1,1000): - for k in range(1,1000): - if (i+j+k)==1000 and isTriple([i,j,k]): - print([i, j, k]) - print(i*j*k) - exit() - +for i in range(1, 1000): + for j in range(1, 1000): + for k in range(1, 1000): + if (i+j+k) == 1000 and isTriple([i, j, k]): + print([i, j, k]) + print(i*j*k) + exit() diff --git a/17-Number-Letter-Counts/wordnums.py b/17-Number-Letter-Counts/wordnums.py index f1276b9..34b5705 100644 --- a/17-Number-Letter-Counts/wordnums.py +++ b/17-Number-Letter-Counts/wordnums.py @@ -1,46 +1,48 @@ -import PIL, math +import PIL +import math -ones = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"] +ones = ["", "one", "two", "three", "four", + "five", "six", "seven", "eight", "nine"] weirdos = ["thirteen", "twelve", "eleven", "ten"] -tens = ["", "teen", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"] +tens = ["", "teen", "twenty", "thirty", "forty", + "fifty", "sixty", "seventy", "eighty", "ninety"] nd = "AND" #num must be less than 999# + def numToWord(num): - digits = str(num) - if (len(digits) == 1):#one digit - return ones[num] - if (len(digits) == 2):#two digits - if(num < 14):#special case for ten eleven twelve - return weirdos[13 - num] - if (num == 15): - return "fifteen" - if (num == 18): - return "eighteen" - t = digits[0] - o = digits[1] - if (int(t)==1): - return numToWord(int(o)) + tens[int(t)] - else: - return tens[int(t)] + numToWord(int(o)) - #number is three digits# - h = digits[0] - t = digits[1] - o = digits[2] - if(num % 100 == 0): - return numToWord(int(h)) + "hundred" - else: - return numToWord(int(h)) + "hundred"+nd+numToWord(int(t+o)) - - + digits = str(num) + if (len(digits) == 1): # one digit + return ones[num] + if (len(digits) == 2): # two digits + if(num < 14): # special case for ten eleven twelve + return weirdos[13 - num] + if (num == 15): + return "fifteen" + if (num == 18): + return "eighteen" + t = digits[0] + o = digits[1] + if (int(t) == 1): + return numToWord(int(o)) + tens[int(t)] + else: + return tens[int(t)] + numToWord(int(o)) + #number is three digits# + h = digits[0] + t = digits[1] + o = digits[2] + if(num % 100 == 0): + return numToWord(int(h)) + "hundred" + else: + return numToWord(int(h)) + "hundred"+nd+numToWord(int(t+o)) + n = int(input("Number: ")) -out ="" +out = "" for i in range(1, n): - out += numToWord(int(i)) + out += numToWord(int(i)) -out+="onethousand" +out += "onethousand" print(out) print(str(len(out)) + " letters") - -- cgit v1.2.3