From fe606211f50512da2db3145dc23d27baa497de4a Mon Sep 17 00:00:00 2001 From: ChouthaSai Date: Mon, 19 Feb 2024 22:02:20 +0530 Subject: [PATCH 1/3] Added all the files from lab1-git repository --- INSTALL.md | 1 + gitignore | 0 index.html | 30 ++++++++++++++++++++++++++ program1.js | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ program2.py | 47 +++++++++++++++++++++++++++++++++++++++++ styles.css | 50 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 189 insertions(+) create mode 100644 INSTALL.md create mode 100644 gitignore create mode 100644 index.html create mode 100644 program1.js create mode 100644 program2.py create mode 100644 styles.css diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..60697a6 --- /dev/null +++ b/INSTALL.md @@ -0,0 +1 @@ +Installation Instructions: 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..1570881 --- /dev/null +++ b/index.html @@ -0,0 +1,30 @@ + + + Problem 3: User Form + + + +
+
+ +

+ + +

+ + +

+ + +
+
+ + + + diff --git a/program1.js b/program1.js new file mode 100644 index 0000000..4b01549 --- /dev/null +++ b/program1.js @@ -0,0 +1,61 @@ +function processInput(input) { + // make sure the input is in the right format + let regex = /^\$([1-9]\d*|0)(\.\d{2})?$/; + if (!regex.test(input)) { + console.log("Eror: The string must be in the format $X.YZ"); + return; + } + + //seperate the dollars and cents from the input + let splitinput = input.slice(1).split('.'); + let amtdollars = splitinput[0]; + let cents; + if (splitinput.length > 1) { + cents = splitinput[1]; + } else { + cents = '00'; + } + + //cast both amounts to int and get the total amount of cents + let total = parseInt(amtdollars) * 100 + parseInt(cents); + + function sort(totalcents) { + let dollars = Math.floor(totalcents / 100); + totalcents = totalcents % 100; + let quarters = Math.floor(totalcents / 25); + totalcents = totalcents % 25; + let dimes = Math.floor(totalcents / 10); + totalcents = totalcents % 10; + let nickels = Math.floor(totalcents / 5); + let pennies = totalcents % 5; + + return { + dollars: dollars, + quarters: quarters, + dimes: dimes, + nickels: nickels, + pennies: pennies + }; + } + + //log all the denominations + let denominations = sort(total); + if (denominations.dollars > 0) console.log(`${denominations.dollars} dollars`); + if (denominations.quarters > 0) console.log(`${denominations.quarters} quarters`); + if (denominations.dimes > 0) console.log(`${denominations.dimes} dimes`); + if (denominations.nickels > 0) console.log(`${denominations.nickels} nickels`); + if (denominations.pennies > 0) console.log(`${denominations.pennies} pennies`); + +} + +// Main +if (process.argv.length !== 3) { + console.log("ERROR: Incorrect number of arguments. Usage: node program.js \"$X.YZ\""); +} else { + var input = process.argv[2]; + if (!input.startsWith('$')) { + console.log("ERROR: The string must begin with a $"); + } else { + processInput(input); + } +} diff --git a/program2.py b/program2.py new file mode 100644 index 0000000..7e11113 --- /dev/null +++ b/program2.py @@ -0,0 +1,47 @@ +import sys + +def duplicates(strings): + + #check if strings is empty + if not strings: + print("ERROR: You must provide at least one string") + return + + #word counts is where the program stores the count of words + word_counts = {} + for string in strings: + #split into substrings + words = string.split() + + for word in words: + #convert word to lowercase + word_lower = word.lower() + if word_lower not in word_counts: + #if word is not yet in word count, it will add it + word_counts[word_lower] = [] + #if word is already found, the program appends the extra word to that list + word_counts[word_lower].append(word) + + + #set makes sure that we dont accidentally add duplicates twice to the list + duplicates = set() + + #if the length of a world list is more than 1 that means there was a duplicate word, so when it is greater than 1, it is added to the duplicates set + for word_list in word_counts.values(): + if len(word_list) > 1: + duplicates.update(word_list) + + # #If word is in duplicates it will print + # for string in strings: + # for word in string.split(): + # if word.lower() in duplicates: + # print(word) + # duplicates.remove(word.lower()) + + for word in duplicates: + print(word) + + +#get input from terminal +args = sys.argv[1:] +duplicates(args) diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..e8c809b --- /dev/null +++ b/styles.css @@ -0,0 +1,50 @@ +body { + margin: 0; + padding: 0; + font-family: Arial, sans-serif; + background-color: rgb(57, 146, 235); + color: #ffffff; +} + +.container { + display: flex; + justify-content: center; + align-items: center; + height: 100vh; +} + +.user-form { + width: 80%; + height: 70%; + background-color: rgb(161, 161, 161); + padding: 20px; + border-radius: 10px; + box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); +} + +label { + font-size: 18px; + font-weight: bold; +} + +#username, +#password, +#fav-color, +#submit { + width: calc(100% - 20px); + padding: 10px; + margin-bottom: 10px; + border: 1px solid #ccc; + border-radius: 5px; + font-size: 16px; +} + +#submit { + background-color: rgb(40, 78, 154); + color: #ffffff; + cursor: pointer; +} + +#submit:hover { + background-color: rgb(139, 199, 212); +} From c917d2ac817319aa9e5f05982cc38a9d17ed7eb7 Mon Sep 17 00:00:00 2001 From: ChouthaSai Date: Mon, 19 Feb 2024 22:07:39 +0530 Subject: [PATCH 2/3] I did not see the read me file with resources so I added that --- README 2.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README 2.md diff --git a/README 2.md b/README 2.md new file mode 100644 index 0000000..4fed924 --- /dev/null +++ b/README 2.md @@ -0,0 +1 @@ +# Git Lab 1 From bfb3c7e695cf36bde8183ac28b568d11f106b851 Mon Sep 17 00:00:00 2001 From: ChouthaSai Date: Mon, 19 Feb 2024 22:16:05 +0530 Subject: [PATCH 3/3] added come comments. Also the program1.js works with single quotes around the amount --- program1.js | 13 +++++++++++++ program2.py | 16 ++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/program1.js b/program1.js index 4b01549..cbbd7a7 100644 --- a/program1.js +++ b/program1.js @@ -1,3 +1,10 @@ + +/** + * Checks the input string that represents some amount of money + * must be in the format '$X.YZ' where X is the dollar amount and YZ represents cents. + * @param {string} input - The input string representing the monetary amount. + */ + function processInput(input) { // make sure the input is in the right format let regex = /^\$([1-9]\d*|0)(\.\d{2})?$/; @@ -19,6 +26,12 @@ function processInput(input) { //cast both amounts to int and get the total amount of cents let total = parseInt(amtdollars) * 100 + parseInt(cents); + /** + * sorts the total cents into seperate denominations. + * @param {number} totalCents - total amount in cents. + * @returns {Object} an object containing the counts of dollars, quarters, dimes, nickels, and pennies. + */ + function sort(totalcents) { let dollars = Math.floor(totalcents / 100); totalcents = totalcents % 100; diff --git a/program2.py b/program2.py index 7e11113..b8e5044 100644 --- a/program2.py +++ b/program2.py @@ -2,6 +2,16 @@ def duplicates(strings): + """ + finds and prints duplicate words in a list of strings. + + Arguments: + strings (list): a list of strings provided by the user to check for duplicates + + Returns: + none + """ + #check if strings is empty if not strings: print("ERROR: You must provide at least one string") @@ -31,12 +41,6 @@ def duplicates(strings): if len(word_list) > 1: duplicates.update(word_list) - # #If word is in duplicates it will print - # for string in strings: - # for word in string.split(): - # if word.lower() in duplicates: - # print(word) - # duplicates.remove(word.lower()) for word in duplicates: print(word)