diff --git a/README.md b/README.md index 4fed924..7951758 100644 --- a/README.md +++ b/README.md @@ -1 +1,13 @@ -# Git Lab 1 +# Kunal Singh + +**RESOURCES** + +* https://www.freecodecamp.org/news/what-is-git-and-how-to-use-it-c341b049ae61/ + +* https://moez-62905.medium.com/the-ultimate-guide-to-command-line-arguments-in-python-scripts-61c49c90e0b3#:~:text=In%20Python%2C%20command%2Dline%20arguments,arguments%20passed%20to%20the%20script. + +* https://www.scaler.com/topics/isalpha-in-python/ + +* https://github.com/tchapi/markdown-cheatsheet/blob/master/README.md + +* https://webtuu.com/blog/04/a-laymans-introduction-to-git \ No newline at end of file diff --git a/gitignore b/gitignore new file mode 100644 index 0000000..e69de29 diff --git a/program1.js b/program1.js new file mode 100644 index 0000000..6fdc627 --- /dev/null +++ b/program1.js @@ -0,0 +1,86 @@ +const args = process.argv.slice(2); + +function parseAmount(amountStr) { + let errorMessage = []; + + if (!amountStr.startsWith("$")) { + errorMessage.push("ERROR: The string must begin with a $"); + return [null, errorMessage.join("\n")]; + } + + if (amountStr.length < 4 || amountStr[1] === '.') { + errorMessage.push("ERROR: The string must include a dollar amount"); + return [null, errorMessage.join("\n")]; + } + + let amountWithoutDollarSign = amountStr.substring(1); + let [dollars, cents] = amountWithoutDollarSign.split("."); + let dollarsInt = parseInt(dollars, 10); + let centsInt = parseInt(cents, 10); + + if (isNaN(dollarsInt) || dollars === "") { + errorMessage.push("ERROR: The string must include a dollar amount"); + return [null, errorMessage.join("\n")]; + } + if (dollarsInt < 0 || dollarsInt > 100 || centsInt < 0 || centsInt > 99) { + errorMessage.push("ERROR: Dollar amount must be between 0 and 100, and cents between 0 and 99"); + return [null, errorMessage.join("\n")]; + } + + return [{ dollars: dollarsInt, cents: centsInt }, null]; +} + +function calculateDenominations(dollars, cents) { + let denominations = []; + + if (dollars > 0) { + denominations.push(`${dollars} dollar${dollars > 1 ? 's' : ''}`); + } + + let coins = [ + { name: "quarter", value: 25 }, + { name: "dime", value: 10 }, + { name: "nickel", value: 5 }, + { name: "penny", value: 1 } + ]; + + for (let i = 0; i < coins.length; i++) { + let coin = coins[i]; + let count = Math.floor(cents / coin.value); + cents %= coin.value; + + if (count > 0) { + let name = coin.name === "penny" && count > 1 ? "pennies" : coin.name + (count > 1 && coin.name !== "penny" ? 's' : ''); + denominations.push(`${count} ${name}`); + } + } + + return denominations; +} + +function main() { + if (args.length !== 1) { + console.log("ERROR: Incorrect number of arguments provided."); + console.log("Usage: node program1.js '$X.YZ'"); + return; + } + + let [amount, error] = parseAmount(args[0]); + + if (error) { + console.log(error); + return; + } + + let denominations = calculateDenominations(amount.dollars, amount.cents); + + if (denominations.length > 0) { + for (let i = 0; i < denominations.length; i++) { + console.log(denominations[i]); + } + } else { + console.log("No money specified."); + } +} + +main(); diff --git a/program2.py b/program2.py new file mode 100644 index 0000000..7e01e8d --- /dev/null +++ b/program2.py @@ -0,0 +1,51 @@ +import sys + +def find_duplicates(strings): + word_count = {} + for word in strings: + #converts word to lowercase for case-insensitive comparison + word_lower = word.lower() + if word_lower in word_count: + #updates the count if the word is already seen + word_count[word_lower][1] += 1 + else: + #stores the word with its original case and a count of 1 + word_count[word_lower] = [word, 1] + + #filters the dictionary to only include words with count > 1 + duplicates = [original[0] for original in word_count.values() if original[1] > 1] + return duplicates + +#function to split a string into words +def split_words(arg): + words = [] + word = "" + for char in arg: + if char.isalpha(): + word += char + elif word: + words.append(word) + word = "" + if word: + words.append(word) + return words + +def main(): + if len(sys.argv) < 2: + print("ERROR: You must provide at least one string") + return + + words = [] + for arg in sys.argv[1:]: + #split each argument into words using the split_words function + words.extend(split_words(arg)) + + duplicates = find_duplicates(words) + + if duplicates: + for word in duplicates: + print(word) + else: + print("No duplicates found.") + +main() diff --git a/program3.html b/program3.html new file mode 100644 index 0000000..e425cd2 --- /dev/null +++ b/program3.html @@ -0,0 +1,22 @@ + + + + + Program 3 + + + +
+
+

User Login

+ + + + + + + +
+
+ + diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..cc1261a --- /dev/null +++ b/styles.css @@ -0,0 +1,48 @@ +body { + margin: 0; + padding: 0; + background-color: #346094; /* ncssm blue screen background*/ + color: black; /* text color white */ + font-family: Arial, sans-serif; +} + +.container { + display: flex; + justify-content: center; + align-items: center; + height: 100vh; +} + +.form { + width: 80%; + height: 70%; + background-color: #8a8a8d; /* ncssm grey form background*/ + padding: 20px; + border-radius: 10px; +} + +label { + display: block; + margin-bottom: 10px; +} + +input[type="text"], +input[type="password"], +input[type="color"], +button { + width: 100%; + padding: 10px; + margin-bottom: 20px; + border: none; + border-radius: 5px; +} + +button { + background-color: blue; /* button background color blue */ + color: white; + cursor: pointer; +} + +button:hover { + background-color: navy; /* button hover color navy */ +}