Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week 2 Assingments Ritapragya Biswas #75

Open
wants to merge 8 commits into
base: week2_assignment
Choose a base branch
from
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
168 changes: 168 additions & 0 deletions week_1/week_1-ritapragya-biswas.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.top-align {
height: 125px;
vertical-align: top;
}


body {
background-color: rgb(198, 255, 255);
}

h2 {
color: rgb(255, 145, 71);
}

h4 {
color: brown;
}

textarea {
background-color: rgb(255, 255, 205);
}

textarea:hover {
background-color: rgb(161, 255, 210);
}

input[type=text] {
font-family: Georgia, 'Times New Roman', Times, serif;
background-color: rgb(255, 255, 205);
}

input[type=text]:hover {
font-family: Georgia, 'Times New Roman', Times, serif;
background-color: rgb(161, 255, 210);
}

input[type=checkbox]:hover {
box-shadow: 0px 0px 10px #1300ff;
}
</style>
</head>

<body>
<h2>My Guest Book </h2>
Please sign my guest book. Thanks!
<table>
<tr>
<td>
<form>
<label for="name">
<h4>What is your name?</h4>
</label>
</td>
<td>
<input type="text" id="name" name="name"><br>
</form>
</td>
</tr>
<tr>
<td>
<form>
<label for="email">
<h4>What is your email?</h4>
</label>
</td>
<td>
<input type="text" id="email" name="email"><br>
</form>
</td>
</tr>
<tr>
<td class="top-align">
<form>
<label for="feedback">
<h4>Please check all that apply:</h4>
</label>
</td>
<td>
<input type="checkbox" id="feedback1" name="feedback1">
<label for="feedback1"> I really like your website</label><br>
<input type="checkbox" id="feedback2" name="feedback2">
<label for="feedback2"> One of the best sites I've seen</label><br>
<input type="checkbox" id="feedback3" name="feedback3">
<label for="feedback3"> I sure wish my site looked as good as yours</label><br>
<input type="checkbox" id="feedback4" name="feedback4">
<label for="feedback4"> I have no taste and I'm pretty dense so I don't like your site</label><br>
</form>
</td>
</tr>
<tr>
<td class="top-align">
<form>
<label for="like">
<h4>Choose the one thing you like about my website:</h4>
</label>
</td>
<td>
<input type="radio" id="like1" name="like1">
<label for="like1">That gorgeous picture of you</label><br>
<input type="radio" id="like1" name="like1">
<label for="like2">All the beautiful pictures of your cat</label><br>
<input type="radio" id="like1" name="like1">
<label for="like3">The inspiring recap of your suburb childhood</label><br>
<input type="radio" id="like1" name="like4">
<label for="like4">The detailed list of Elvis memorabilia's</label><br>
</form>
</td>
</tr>
<tr>
<td class="top-align">
<form>
<label for="longtext">
<h4>If my website were a book, how many copies would it sell?</h4>
</label>
</td>
<td>
<textarea id="longtext" name="longtext" rows="5" cols="30"></textarea><br>
</form>
</td>
</tr>
<tr>
<td>
<form>
<label for="dropdown">
<h4>How can I improve about my website:</h4>
</label>
</td>
<td>
<select name="dropwdown" id="dropwdown">
<option value="nothing">Nothing. Simply perfect.</option>
<option value="everything">Literally evrything. I hate this.</option>
<option value="style">Better styling. The site looks like it belongs to the 90s</option>
<option value="colour">Better colour scheme. I actually value my eyes unlike you.</option>
</select>
</form>
</td>
</tr>
<tr>
<td class="top-align">
<form>
<label for="longtext">
<h4>Feel free to type more praise, gift offers etc:</h4>
</label>
</td>
<td>
<textarea id="longtext" name="longtext" rows="7" cols="50"></textarea><br>
</form>
</td>
</tr>

</table>
<br>
<form>
<input type="submit" value="Click here to submit">
<input type="submit" value="Erase and start over">
</form>
</body>

</html>
164 changes: 61 additions & 103 deletions week_2/pet.rb
Original file line number Diff line number Diff line change
@@ -1,115 +1,73 @@
class Pet
ANIMAL_TYPE = {
1 => 'Arthropod',
2 => 'Fish',
3 => 'Amphibia',
4 => 'Reptiles',
5 => 'Birds',
6 => 'Mammals'
}
ANIMAL_TYPE = {
1 => 'Arthropod',
2 => 'Fish',
3 => 'Amphibia',
4 => 'Reptiles',
5 => 'Birds',
6 => 'Mammals'
}

# Each animal type requires a diffrent type of food
# The food cost per 1 kg is is stored in the `FOOD_COST_PER_KG` Hash
# where the `key` is the animal id and `value` is the cost
#
# Eg- The food of reptiles(animal_type id = 4) costs 300/kg.
# (FOOD_COST_PER_KG[4] = 300)
FOOD_COST_PER_KG = {
1 => 100,
2 => 600,
3 => 1000,
4 => 300,
5 => 450,
6 => 800
}
FOOD_COST_PER_KG = {
1 => 100,
2 => 600,
3 => 1000,
4 => 300,
5 => 450,
6 => 800
}

# Each animal requires its own habitat.
#
# The `HABITATS` hash stores the habitat required by each animal
# The `key` is the habitat and the `value` is the array of
# animal_type ids that live in that habitat.
#
# "habitat" => [animal_type_id]
HABITATS = {
"Aquatic" => [2, 1, 3],
"Terrariums" => [4],
"Cages" => [5, 6]
}
HABITATS = {
"Aquatic" => [2, 1, 3],
"Terrariums" => [4],
"Cages" => [5, 6]
}

attr_accessor :name, :animal_type_id, :food_consumed_per_day
attr_accessor :name, :animal_type_id, :food_consumed_per_day

def initialize(name: , animal_type_id: , food_consumed_per_day:)
@name = name
@animal_type_id = animal_type_id
@food_consumed_per_day = food_consumed_per_day
end
def initialize(name: , animal_type_id: , food_consumed_per_day:)
@name = name
@animal_type_id = animal_type_id
@food_consumed_per_day = food_consumed_per_day
end

# Return the habitat of the pet
def habitat
raise NotImplementedError # TODO
end
def habitat
if HABITATS["Aquatic"].include? animal_type_id
return "Aquatic"
end
if HABITATS["Terrariums"].include? animal_type_id
return "Terrariums"
end
if HABITATS["Cages"].include? animal_type_id
return "Cages"
end
end

# Returns the cost of food required to feed the animal
# per day
def food_cost_per_day
return FOOD_COST_PER_KG[animal_type_id] * food_consumed_per_day
end
def food_cost_per_day
return FOOD_COST_PER_KG[animal_type_id] * food_consumed_per_day
end

# This function takes the number of `days` as the input
# and returns the food required(in kgs) to feed the
# pet for that many number of days
#
# Eg - if the pet requires 0.5 kg of food per day
# (i.e, food_consumed_per_day = 0.5), then
# pet.food_required(5) will return 2.5 as the answer
#
# cat = Pet.new(name: 'cat', animal_type_id: 6, food_consumed_per_day: 0.4)
# cat.food_required(28) = 11.2 (0.4 * 28)
def food_required(days)
raise NotImplementedError # TODO
end
def food_required(days)
return food_consumed_per_day * days
end

# This function takes the number of `days` as the input
# and returns the cost incurred to feed the pet for
# that many number of days
#
# cat = Pet.new(name: 'cat', animal_type_id: 6, food_consumed_per_day: 0.4)
# cat.food_cost(28) = 8960
def food_cost(days)
raise NotImplementedError # TODO
end
def food_cost(days)
return food_cost_per_day * days
end

# This function takes an array of pets and the `days`
# as input and returns the cost to feed them all
# for the specified number of `days`
#
# Eg -
# cat = Pet.new(name: 'cat', animal_type_id: 6, food_consumed_per_day: 0.4)
# dog = Pet.new(name: 'dog', animal_type_id: 6, food_consumed_per_day: 0.7)
# fish = Pet.new(name: 'clownfish', animal_type_id: 2, food_consumed_per_day: 0.1)
# snake = Pet.new(name: 'python', animal_type_id: 4, food_consumed_per_day: 0.3)
# Pet.cost_to_feed([cat, dog, fish, snake], 6) will return 6180.0
def self.cost_to_feed(pets, days)
raise NotImplementedError # TODO
end
def self.cost_to_feed(pets, days)
for animal in pets
total += animal.food_consumed_per_day * FOOD_COST_PER_KG[animal]
end
return total * days.to_i
end

# This function takes an array of pets as input
# and returns a hash with pets name grouped by their animal type
#
# Eg -
# cat = Pet.new(name: 'cat', animal_type_id: 6, food_consumed_per_day: 0.4)
# dog = Pet.new(name: 'dog', animal_type_id: 6, food_consumed_per_day: 0.7)
# fish = Pet.new(name: 'clownfish', animal_type_id: 2, food_consumed_per_day: 0.1)
# snake = Pet.new(name: 'python', animal_type_id: 4, food_consumed_per_day: 0.3)
# Pet.group_by_animal_type([cat, dog, fish, snake]) will return the follwing hash
# {
# 6 => ['cat', 'dog'],
# 2 => ['clownfish'],
# 4 => ['python']
# }
#
# Note - Order is not important
def self.group_by_animal_type(pets)
raise NotImplementedError # TODO
end
def self.group_by_animal_type(pets)
ans = {}
for animal in pets
ans[animal.animal_type_id].push(name) #couldn't figure out how to make the values of the hash to be arrays
end
print pets
return ans
end
end
28 changes: 15 additions & 13 deletions week_2/prime_numbers.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# A prime number is a whole number greater than 1
# that cannot be exactly divided by any whole number
# other than itself and 1
# (e.g. 2, 3, 5, 7, 11).
def prime(n)

# The function below takes a keyword arguments `n` and
# returns an array of prime numbers less than or equal to
# `n`.
for i in (2..n/2)
if n % i == 0
return false
end
end
return true

# For example, prime_numbers(n: 20) should return the following:
# [2, 3, 5, 7, 11, 13, 17, 19]
end

# If the user gives a invalid input like -4
# We will raise an `ArgumentError` exception to let the caller know that
# their function arguments were incorrect.
def prime_numbers(n:)
raise NotImplementedError # TODO
arr = Array.new
for i in (2..n)
if prime(i)
arr.push(i)
end
end
return arr
end