From b240ab6a508b9db13139af2290ef02ef66b73f0e Mon Sep 17 00:00:00 2001 From: Saksham Anand Date: Tue, 13 Feb 2024 22:54:26 -0500 Subject: [PATCH 1/4] Added all files --- .gitignore | 0 INSTALL.md | Bin 0 -> 58 bytes README.md | Bin 12 -> 518 bytes gitignore | 0 index.html | 17 +++++++++++++++++ program1.py | 40 ++++++++++++++++++++++++++++++++++++++++ program2.js | 18 ++++++++++++++++++ style.css | 18 ++++++++++++++++++ 8 files changed, 93 insertions(+) create mode 100644 .gitignore create mode 100644 INSTALL.md create mode 100644 gitignore create mode 100644 index.html create mode 100644 program1.py create mode 100644 program2.js create mode 100644 style.css diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000000000000000000000000000000000000..aa6fbf98e65ca7cc93c6eca3ab0eacbb15dccf0e GIT binary patch literal 58 wcmezW&yyjKp_rkBA(0^m2or&%?g505QWb==pBM~f!%#X5Yaj)dH^%i2s1RPUcUO~N}16nF4sFhXU@zVANRg` zS}D{)rBdDuf2t$aQCoG@@pr6B6EfxxI7`i`T4;?m^R`9n{8-MT4V&uBIl(<5>R`+j z;SH5&PbLMq!HbAz|JX|1nBBI!dQHD|vhD}A&bT4^70i_Iwf|$W;zP5D ZsOfM6Q}I^J6u)(8Hnyy(`l-D0-Jb;eT#5hy literal 12 TcmY#ZaL+7J@JUQkFysON6bJ(H diff --git a/gitignore b/gitignore new file mode 100644 index 0000000..e69de29 diff --git a/index.html b/index.html new file mode 100644 index 0000000..47b6286 --- /dev/null +++ b/index.html @@ -0,0 +1,17 @@ + + + + Program 3 + + + + +
+ +
+ +
+ +
+ + \ No newline at end of file diff --git a/program1.py b/program1.py new file mode 100644 index 0000000..41399a9 --- /dev/null +++ b/program1.py @@ -0,0 +1,40 @@ +import sys + +money = sys.argv[1] + +# Replaces the first instance only of "$" and ".". Nothing happens if they don't exist. +money1 = (money.replace("$", "", 1).replace(".", "", 1)) + +if money1.isdigit(): + sum = int(money1) # Makes money1 an integer if money1 is a number. + if sum < 0 or sum > 10000: + print("Error, value must be between 0 and 100 dollars.") + else: + # Dictionary to store the value of each currency. + coins = { + "Dollar": sum // 100, + "Quarter": (sum % 100) // 25, + "Dime": (sum % 25) // 10, + "Nickel": (sum % 10) // 5, + "Penny": (sum % 5) + } + # Another format check, but for the initial variable. + if money[0] != "$" or ("." not in money): + print("Error please provide in the correct format '$x.yz' for x, y, z in positive integers.") + else: + # For key, value in coins + for i, j in coins.items(): + if j > 0: # Only if the value is greater than 0 it gets printed. E.g. 0 dollars won't get printed. + # To correctly grammatically format (dollar vs dollars): + if j == 1: + print(f"{j} {i}") + else: # j > 1 formatting for duplicate currencies. + if i == "Penny": + print(f"{j} Pennies") # Need to print j pennies, not j penny if multiple exist. + else: + print(f"{j} {i}s") # Adding s at the end works for every other currency. + + +else: + # If amount is not in valid format: + print("Error please provide in the correct format '$x.yz' for x, y, z in positive integers.") \ No newline at end of file diff --git a/program2.js b/program2.js new file mode 100644 index 0000000..b973f17 --- /dev/null +++ b/program2.js @@ -0,0 +1,18 @@ +strings = process.argv.slice(2); + +if (!strings || !strings.length) { + console.log("ERROR: You must provide at least one string"); +} + +let wordCounts = {}; // in format (word in string) : (occurrences of word) + +for (let string of strings) { + let words = string.toLowerCase().split(/\s+/); // /\s+/ detects any white space character, so multiple " " or tabs. + for (let word of words) { + if (wordCounts[word] > 0) { + console.log(word); + } + // This line checks if word is already in wordCounts, if it is then +1 to the value. If not, then value stays at 0. + wordCounts[word] = (wordCounts[word] || 0) + 1; + } + } \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..445e668 --- /dev/null +++ b/style.css @@ -0,0 +1,18 @@ +body{ + font-family: Verdana; + font-size: 24pt; + background-color: #346094; + color: #000000; +} + +/* vw and vh are % of viewport width/height. The last 3 lines center. */ +form{ + outline: auto; + outline-color: #000000; + background-color: #8a8a8d; + width: 80vw; + height: 70vh; + position:absolute; + top:50%; + left:50%; +} From 58fb9b948d9f615217d125d1ab888cea5150f2cd Mon Sep 17 00:00:00 2001 From: Saksham Anand Date: Tue, 13 Feb 2024 22:57:43 -0500 Subject: [PATCH 2/4] Made corrections to README.md --- README.md | Bin 518 -> 546 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/README.md b/README.md index b267cdc130882635f4322c77f409d06b1d2a72a9..e9dc7e71c8c20feb3ed87dc531f405da3c24fa84 100644 GIT binary patch delta 96 zcmZo;S;R6y%QurDkD-{sjzNKemw}7Hh9L>e4q|X+2xjnS2xSOja0as#fO7g^S%^A) Y2AEC|AB1%o6gI|dGBN|{$?c5w0NL*jf&c&j delta 68 zcmZ3)(#A4D%e0iijzNKemw}5x3kZW4Tp5BH{24-lEN3tqBnpwYVbEs)sRpXuSgy%9 Ic?n}30BfiU;Q#;t From b587aaab91891d99dee9e50aadb200dd5a03af29 Mon Sep 17 00:00:00 2001 From: Saksham Anand Date: Wed, 14 Feb 2024 00:23:33 -0500 Subject: [PATCH 3/4] Updated README.md and fixed major bug in program2.js thanks to Eric Cai and Elyz --- README.md | Bin 546 -> 572 bytes program2.js | 31 ++++++++++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e9dc7e71c8c20feb3ed87dc531f405da3c24fa84..8b9038332ed244ee83e2cae326cb4e4d1551b25d 100644 GIT binary patch delta 34 ncmZ3)vWI1Z5|flJg93vqLk>eFLluza&5+1Y0%Y+ra4`S?e|iQN delta 7 OcmdnPvWR7a5)%Ll(*ipH diff --git a/program2.js b/program2.js index b973f17..2fbb05c 100644 --- a/program2.js +++ b/program2.js @@ -1,18 +1,27 @@ strings = process.argv.slice(2); +// Check if there are no strings provided or if the array is empty if (!strings || !strings.length) { console.log("ERROR: You must provide at least one string"); } +let wordCounts = new Map(); +let sentence = strings.join(" ").split(" "); -let wordCounts = {}; // in format (word in string) : (occurrences of word) +for (let word of sentence) { + // Convert the word to lowercase for case-insensitive comparison + if (wordCounts.has(word.toLowerCase())) { + // If the word already exists in the wordCounts object, increment its count by 1 + wordCounts.get(word.toLowerCase())[1] += 1; + } else { + // If the word doesn't exist in the wordCounts object, add it with a count of 1 + wordCounts.set(word.toLowerCase(), [word, 1]); + } +} -for (let string of strings) { - let words = string.toLowerCase().split(/\s+/); // /\s+/ detects any white space character, so multiple " " or tabs. - for (let word of words) { - if (wordCounts[word] > 0) { - console.log(word); - } - // This line checks if word is already in wordCounts, if it is then +1 to the value. If not, then value stays at 0. - wordCounts[word] = (wordCounts[word] || 0) + 1; - } - } \ No newline at end of file +for (let word of wordCounts.keys()) { + // Check if the count of the word is greater than or equal to 2 + if (wordCounts.get(word)[1] >= 2) { + // If the count is greater than or equal to 2, print the word + console.log(wordCounts.get(word)[0]); + } +} From 221a84fd3b51d6d1e85e19622073dfd8c32dd005 Mon Sep 17 00:00:00 2001 From: Saksham Anand Date: Wed, 14 Feb 2024 00:39:21 -0500 Subject: [PATCH 4/4] Made more corrections thx to EC and ENK. --- README.md | Bin 572 -> 650 bytes index.html | 4 ++-- style.css | 14 ++++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8b9038332ed244ee83e2cae326cb4e4d1551b25d..0dc8d16d9d9a85467fccfc208e3610b97f341b43 100644 GIT binary patch delta 90 zcmdnP(#5*Lf+0&!HXdnNM
- +
- +
diff --git a/style.css b/style.css index 445e668..eaef37d 100644 --- a/style.css +++ b/style.css @@ -1,8 +1,13 @@ body{ + display: flex; + flex-direction: column; + align-items: center; + height: 95vh; + justify-content: center; font-family: Verdana; font-size: 24pt; background-color: #346094; - color: #000000; + color: #000000; } /* vw and vh are % of viewport width/height. The last 3 lines center. */ @@ -12,7 +17,8 @@ form{ background-color: #8a8a8d; width: 80vw; height: 70vh; - position:absolute; - top:50%; - left:50%; + display:flex; + flex-direction: column; + align-items: center; + justify-content: center; }