Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# Git Lab 1
# Kunal Singh

<ins>**RESOURCES**</ins>

* 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
Empty file added gitignore
Empty file.
86 changes: 86 additions & 0 deletions program1.js
Original file line number Diff line number Diff line change
@@ -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();
51 changes: 51 additions & 0 deletions program2.py
Original file line number Diff line number Diff line change
@@ -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()
22 changes: 22 additions & 0 deletions program3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Program 3</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<form class="form">
<h2>User Login</h2>
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<label for="fav-color">Favorite Color:</label>
<input type="color" id="fav-color" name="fav-color" required>
<button type="submit">Submit</button>
</form>
</div>
</body>
</html>
48 changes: 48 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -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 */
}