Skip to content

Commit 9670475

Browse files
committed
merged
1 parent ddaf69a commit 9670475

58 files changed

Lines changed: 1131 additions & 146 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

en/8-ball/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
<title>The title of this solved example is 8-Ball (Python solution)
2+
<title>8-Ball
33
</title>
44

55
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -35,7 +35,7 @@
3535
<div class="container container-course">
3636
<div class="row">
3737
<div class="col">
38-
<h1>The title of this solved example is 8-Ball (Python solution)
38+
<h1>8-Ball
3939
</h1>
4040
<p class="subtleHeading">The example was solved by Mbaoma Chioma Mary (Section Leader for Section 223)</p>
4141
<hr/>

en/animal_years/demo1.png

45.7 KB
Loading

en/animal_years/demo2.png

43.8 KB
Loading

en/animal_years/index.html

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
2+
<title>Animal Years</title>
3+
4+
<meta name="viewport" content="width=device-width, initial-scale=1">
5+
6+
<meta http-equiv="content-type" content="text/html; charset=UTF8">
7+
8+
9+
<!-- Bootstrap -->
10+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
11+
<link rel="stylesheet" type="text/css" href="../../style.css">
12+
13+
<!-- Java Script -->
14+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
15+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
16+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
17+
18+
19+
20+
<!-- font awesome -->
21+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
22+
23+
<!-- SWAL -->
24+
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
25+
26+
27+
<!-- Stanford -->
28+
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700' rel='stylesheet' type='text/css'>
29+
<link href='https://fonts.googleapis.com/css?family=Source+Serif+Pro:400,600,700' rel='stylesheet' type='text/css'>
30+
31+
32+
<body>
33+
34+
<div class="container container-course">
35+
<div class="row">
36+
<div class="col">
37+
<h1>Animal Years</h1>
38+
<p class="subtleHeading">Problem written by Lucia</p>
39+
<hr/>
40+
<p>
41+
Other animals typically have different lifespans than humans. If you divide the average human lifespan by the average lifespan of another animal, you can calculate the multiplier for converting an age in human years to an age in animal years. For example, the average lifespan of a human is 79 years and the average lifespan of a dog is 11 years. So, 1 human year is equal to 79/11 = 7.18 dog years. Then, to convert say 3 human years to dog years, you'd multiply 3 * 7.18 = 21.54 dog years. That means, if your dog is 3 years old in human years, they're past their teenage years in dog years!
42+
</p>
43+
44+
<p> Write a program that converts human years to animal years (of any animals of your choosing!):</p>
45+
<p></p>
46+
<center>
47+
<img style="width:800px" src="./demo1.png">
48+
</center>
49+
<p></p>
50+
<center>
51+
<img style="width:800px" src="./demo2.png">
52+
</center>
53+
<p></p>
54+
55+
<p>
56+
Since the multipliers for each animal will never change, you should store these as constants.
57+
</p>
58+
<h2>Solution</h2>
59+
<p>
60+
<a class="btn btn-primary" id="soln-btn" onclick="toggleButtonText()"
61+
data-toggle="collapse" href="#soln-collapse" aria-expanded="false"
62+
aria-controls="Collapse">
63+
Show Solution
64+
</a>
65+
</p>
66+
<div class="collapse" id="soln-collapse">
67+
<pre class="console" id="editor" style="height:940.0px"># constants
68+
CAT_YRS_MULTIPLIER = 4.9
69+
DOG_YRS_MULTIPLIER = 7.18
70+
ELEPHANT_YRS_MULTIPLIER = 1.13
71+
LION_YRS_MULTIPLIER = 5.64
72+
MONKEY_YRS_MULTIPLIER = 3.95
73+
RABBIT_YRS_MULTIPLIER = 7.9
74+
HAMSTER_YRS_MULTIPLIER = 39.5
75+
76+
def main():
77+
print(&#039;This program converts human years to animal years.&#039;)
78+
79+
# gets two user inputs, the human years to convert and the animal type
80+
human_yrs_str = input(&#039;Human years: &#039;)
81+
animal_type_str = input(&#039;Animal type (options: cat, dog, elephant, lion, monkey, rabbit, hamster): &#039;)
82+
83+
# converts human years to animal years of the animal type specified
84+
animal_yrs = None
85+
86+
# casts human_yrs_str, a string type variable, to a float type variable
87+
human_yrs = float(human_yrs_str)
88+
89+
# converts human years to animal years based on the animal type input
90+
if animal_type_str == &#039;cat&#039;:
91+
animal_yrs = human_yrs * CAT_YRS_MULTIPLIER
92+
elif animal_type_str == &#039;dog&#039;:
93+
animal_yrs= human_yrs * DOG_YRS_MULTIPLIER
94+
elif animal_type_str == &#039;elephant&#039;:
95+
animal_yrs = human_yrs * ELEPHANT_YRS_MULTIPLIER
96+
elif animal_type_str == &#039;lion&#039;:
97+
animal_yrs = human_yrs * LION_YRS_MULTIPLIER
98+
elif animal_type_str == &#039;monkey&#039;:
99+
animal_yrs = human_yrs * MONKEY_YRS_MULTIPLIER
100+
elif animal_type_str == &#039;rabbit&#039;:
101+
animal_yrs = human_yrs * RABBIT_YRS_MULTIPLIER
102+
elif animal_type_str == &#039;hamster&#039;:
103+
animal_yrs = human_yrs * HAMSTER_YRS_MULTIPLIER
104+
105+
# prints the equivalent animal years for the human year input
106+
# prints error message in animal type was invalid
107+
if animal_yrs:
108+
print(human_yrs_str + &#039; human years is equal to &#039; + str(animal_yrs) + &#039; &#039; + animal_type_str + &#039; years.&#039;)
109+
else:
110+
print(&#039;Animal type is invalid.&#039;)
111+
112+
if __name__ == &#039;__main__&#039;:
113+
main()</pre>
114+
</div>
115+
116+
<script src="../../plugins/ace/ace.js" type="text/javascript" charset="utf-8"></script>
117+
<script>
118+
var editor = ace.edit("editor");
119+
editor.setTheme('ace/theme/eclipse');
120+
editor.getSession().setMode("ace/mode/python");
121+
editor.setReadOnly(true);
122+
editor.renderer.setShowGutter(false);
123+
editor.setFontSize("14px");
124+
/*editor.setTheme("ace/theme/eclipse");
125+
editor.getSession().setMode("ace/mode/java");*/
126+
</script>
127+
<script>
128+
function toggleButtonText() {
129+
var elem = document.getElementById("soln-btn");
130+
if (elem.innerHTML.trim() === "Show Solution") {
131+
elem.innerHTML = "Hide Solution";
132+
} else {
133+
elem.innerHTML = "Show Solution";
134+
}
135+
}
136+
</script>
137+
<hr/>
138+
</div>
139+
</div>
140+
</div>
141+
142+
</body>

en/bmi/demo.png

45.4 KB
Loading

en/bmi/index.html

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
2+
<title>BMI</title>
3+
4+
<meta name="viewport" content="width=device-width, initial-scale=1">
5+
6+
<meta http-equiv="content-type" content="text/html; charset=UTF8">
7+
8+
9+
<!-- Bootstrap -->
10+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
11+
<link rel="stylesheet" type="text/css" href="../../style.css">
12+
13+
<!-- Java Script -->
14+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
15+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
16+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
17+
18+
19+
20+
<!-- font awesome -->
21+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
22+
23+
<!-- SWAL -->
24+
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
25+
26+
27+
<!-- Stanford -->
28+
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700' rel='stylesheet' type='text/css'>
29+
<link href='https://fonts.googleapis.com/css?family=Source+Serif+Pro:400,600,700' rel='stylesheet' type='text/css'>
30+
31+
32+
<body>
33+
34+
<div class="container container-course">
35+
<div class="row">
36+
<div class="col">
37+
<h1>BMI</h1>
38+
<p class="subtleHeading">Problem written by Neha, discovered by Adolphe Quetelet</p>
39+
<hr/>
40+
<p>
41+
The BMI is a convenient rule of thumb used to broadly categorize a person as underweight, normal weight, overweight, or obese
42+
based on tissue mass (muscle, fat, and bone) and height.
43+
<br/>
44+
Commonly accepted BMI ranges are underweight (under 18.5 kg/m2), normal weight (18.5 to 25), overweight (25 to 30), and obese (over 30).
45+
</p>
46+
47+
<p> Write a program that continually reads in mass and height from the user and
48+
then outputs if the user is underweight, normal weight, overweight or obese. Show your work in the following way:</p>
49+
<p></p>
50+
<center>
51+
<img style="width:400px" src="./demo.png">
52+
</center>
53+
<p></p>
54+
<p>
55+
If you ask the user to input weight in kilograms (m) and height in meter (h),
56+
the result of calculating BMI = <i>m</i> / <i>(h * h)</i> will be in kg/m<sup>2</sup>.
57+
The program will then output if the user is underweight etc based on the BMI.
58+
</p>
59+
60+
61+
<h2>Solution</h2>
62+
<p>
63+
<a class="btn btn-primary" id="soln-btn" onclick="toggleButtonText()"
64+
data-toggle="collapse" href="#soln-collapse" aria-expanded="false"
65+
aria-controls="Collapse">
66+
Show Solution
67+
</a>
68+
</p>
69+
<div class="collapse" id="soln-collapse">
70+
<pre class="console" id="editor" style="height:620.0px">
71+
72+
def main():
73+
while True:
74+
# Read the mass in from the user. type is float
75+
mass_in_kg = float(input(&quot;Enter kilos of mass: &quot;))
76+
height_in_meter = float(input(&quot;Enter height in meter: &quot;))
77+
78+
# Calculate BMI
79+
# equivalently bmi = m/h^2
80+
bmi = mass_in_kg / (height_in_meter * height_in_meter)
81+
82+
if bmi &lt; 18.5:
83+
bmi_category = &quot;Underweight&quot;
84+
elif bmi &lt; 25:
85+
bmi_category = &quot;Normal Weight&quot;
86+
elif bmi &lt; 30:
87+
bmi_category = &quot;Overweight&quot;
88+
else:
89+
bmi_category = &quot;Obese&quot;
90+
91+
# Display work to the user
92+
print(&quot;BMI = m / h ^ 2...&quot;)
93+
print(&quot;m = &quot; + str(mass_in_kg) + &quot; kg&quot;)
94+
print(&quot;h = &quot; + str(height_in_meter) + &quot; m&quot;)
95+
print(&quot;BMI is: &quot; + str(bmi) + &quot; kg/m^2&quot;)
96+
print(&quot;BMI category is: &quot;, bmi_category)
97+
98+
99+
if __name__ == &#039;__main__&#039;:
100+
main()
101+
</pre>
102+
</div>
103+
104+
<script src="../../plugins/ace/ace.js" type="text/javascript" charset="utf-8"></script>
105+
<script>
106+
var editor = ace.edit("editor");
107+
editor.setTheme('ace/theme/eclipse');
108+
editor.getSession().setMode("ace/mode/python");
109+
editor.setReadOnly(true);
110+
editor.renderer.setShowGutter(false);
111+
editor.setFontSize("14px");
112+
/*editor.setTheme("ace/theme/eclipse");
113+
editor.getSession().setMode("ace/mode/java");*/
114+
</script>
115+
<script>
116+
function toggleButtonText() {
117+
var elem = document.getElementById("soln-btn");
118+
if (elem.innerHTML.trim() === "Show Solution") {
119+
elem.innerHTML = "Hide Solution";
120+
} else {
121+
elem.innerHTML = "Show Solution";
122+
}
123+
}
124+
</script>
125+
<hr/>
126+
</div>
127+
</div>
128+
</div>
129+
130+
</body>

en/emc2-console/demo.png

-123 KB
Binary file not shown.

en/emc2/demo.png

-123 KB
Binary file not shown.

en/golden-ratio/index.html

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,15 @@ <h1>Golden Ratio</h1>
133133

134134

135135
<h2>Solution</h2>
136-
<pre class="console" id="editor" style="height:660.0px">
136+
<p>
137+
<a class="btn btn-primary" id="soln-btn" onclick="toggleButtonText()"
138+
data-toggle="collapse" href="#soln-collapse" aria-expanded="false"
139+
aria-controls="Collapse">
140+
Show Solution
141+
</a>
142+
</p>
143+
<div class="collapse" id="soln-collapse">
144+
<pre class="console" id="editor" style="height:660.0px">
137145
def main():
138146
&quot;&quot;&quot;
139147
Show the ratio of consecutive Fibonaccy numbers
@@ -166,21 +174,32 @@ <h2>Solution</h2>
166174

167175
if __name__ == &#039;__main__&#039;:
168176
main()</pre>
177+
</div>
169178

170-
<script src="../../plugins/ace/ace.js" type="text/javascript" charset="utf-8"></script>
171-
<script>
172-
var editor = ace.edit("editor");
173-
editor.setTheme('ace/theme/eclipse');
174-
editor.getSession().setMode("ace/mode/python");
175-
editor.setReadOnly(true);
176-
editor.renderer.setShowGutter(false);
177-
editor.setFontSize("14px");
178-
/*editor.setTheme("ace/theme/eclipse");
179-
editor.getSession().setMode("ace/mode/java");*/
180-
</script>
179+
<script src="../../plugins/ace/ace.js" type="text/javascript" charset="utf-8"></script>
180+
<script>
181+
var editor = ace.edit("editor");
182+
editor.setTheme('ace/theme/eclipse');
183+
editor.getSession().setMode("ace/mode/python");
184+
editor.setReadOnly(true);
185+
editor.renderer.setShowGutter(false);
186+
editor.setFontSize("14px");
187+
/*editor.setTheme("ace/theme/eclipse");
188+
editor.getSession().setMode("ace/mode/java");*/
189+
</script>
190+
<script>
191+
function toggleButtonText() {
192+
var elem = document.getElementById("soln-btn");
193+
if (elem.innerHTML.trim() === "Show Solution") {
194+
elem.innerHTML = "Hide Solution";
195+
} else {
196+
elem.innerHTML = "Show Solution";
197+
}
198+
}
199+
</script>
181200
<hr/>
182201
</div>
183202
</div>
184203
</div>
185204

186-
</body>
205+
</body>

0 commit comments

Comments
 (0)