added classes 4 and 5
This commit is contained in:
1 parent
55803f6037
commit
e17bd52294
2 files changed
+614
-47
No files matched your search
+142
-47
@@ -4,7 +4,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Class numero quatro"
|
||||
"## Classo numero quatro"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -23,18 +23,15 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"#'user/lst-2"
|
||||
]
|
||||
},
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[1 2 3 4 5 6 7 8]"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
@@ -43,7 +40,8 @@
|
||||
"(defn times-2 [n]\n",
|
||||
" (* 2 n))\n",
|
||||
"\n",
|
||||
"(def lst-2 (map times-2 lst))"
|
||||
"(def lst-2 (map times-2 lst))\n",
|
||||
"(print lst)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -55,7 +53,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -64,7 +62,7 @@
|
||||
"(0 2 4 6 8 10 12 14 16 18)"
|
||||
]
|
||||
},
|
||||
"execution_count": 6,
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -84,10 +82,11 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 36,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"(def persen {:name \"steph\"}) ;:age 34\n",
|
||||
"(def foo 2) ;; this is a comment. We call it a \"line comment\"\n",
|
||||
"\n",
|
||||
"(comment (println \"This is what we call a block comment, rarely used\"))\n",
|
||||
@@ -116,25 +115,37 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"#'user/print-odd-or-even"
|
||||
]
|
||||
},
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"99 is odd\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(defn print-odd-or-even [n]\n",
|
||||
" (if (odd? n)\n",
|
||||
" (println n \" is odd\")\n",
|
||||
" (println n \" is even\")))"
|
||||
" (println n \" is even\")))\n",
|
||||
"\n",
|
||||
"(defn custom-hello [gender]\n",
|
||||
" (if (= gender :male)\n",
|
||||
" \"his\"\n",
|
||||
" (if (= gender :female)\n",
|
||||
" \"her\"\n",
|
||||
" \"hex\")))\n",
|
||||
"\n",
|
||||
"(defn custom-hello-2 [gender]\n",
|
||||
" (when (= gender :male)\n",
|
||||
" (println \"his\")))\n",
|
||||
" \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"(print-odd-or-even 99)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -151,51 +162,64 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 32,
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
";; the bellow line \"imports\" the functions required to display html\n",
|
||||
";; in the jupyter notebook\n",
|
||||
"(require '[clojupyter.misc.display :as display]) ;; https://github.com/clojupyter/clojupyter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 38,
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<h3>We can very easely print stuff from code</h3>"
|
||||
"<h3 style='color:yellow'>We can very easely print stuff from code</h3>"
|
||||
]
|
||||
},
|
||||
"execution_count": 38,
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(display/html \"<h3>We can very easely print stuff from code</h3>\") "
|
||||
"(display/html \"<h3 style='color:yellow'>We can very easely print stuff from code</h3>\") "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 43,
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"#'user/html-h1"
|
||||
"text/html": [
|
||||
"<b>borris</b"
|
||||
]
|
||||
},
|
||||
"execution_count": 43,
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(defn html-h1 [title])"
|
||||
"\n",
|
||||
"(defn wrap-html [title tag]\n",
|
||||
" \"Wraps a 'title' in a html 'tag'. this function\n",
|
||||
" main goal is to show how hard and boring it is to\n",
|
||||
" surround a simple text by html tags programatically.\"\n",
|
||||
" (str \"<\" tag \">\" title \"</\" tag))\n",
|
||||
"\n",
|
||||
"(defn html-h1 [title]\n",
|
||||
" \"wraps title in html h1 tags\"\n",
|
||||
" (wrap-html title \"b\"))\n",
|
||||
"\n",
|
||||
"(display/html (html-h1 \"borris\"))"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -207,7 +231,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 42,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -216,33 +240,36 @@
|
||||
"<h3>hiccup is much better</h3>"
|
||||
]
|
||||
},
|
||||
"execution_count": 42,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
";; Hiccup is THE way to create html content from clojure\n",
|
||||
"(display/hiccup-html [:h3 \"hiccup is much better\"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 45,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"#'user/hiccup-h1"
|
||||
"text/html": [
|
||||
"<h1>ok</h1>"
|
||||
]
|
||||
},
|
||||
"execution_count": 45,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(defn hiccup-h1 [title])"
|
||||
"(defn hiccup-h1 [title]\n",
|
||||
" [:h1 title])\n",
|
||||
"(display/hiccup-html (hiccup-h1 \"ok\"))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -254,19 +281,87 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"#'user/dodgeball-data"
|
||||
]
|
||||
},
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(def dodgeball-data\n",
|
||||
" [{:team-1 :drummonville :team-2 :montreal :points-1 4 :points-1 5}\n",
|
||||
" {:team-1 :drummonville :team-2 :montreal :points-1 4 :points-1 5}\n",
|
||||
" {:team-1 :drummonville :team-2 :montreal :points-1 4 :points-1 5}\n",
|
||||
" {:team-1 :drummonville :team-2 :montreal :points-1 4 :points-1 5}])\n",
|
||||
" [{:team-1 :drummonville :team-2 :montreal :points-1 4 :points-2 5}\n",
|
||||
" {:team-1 :quebec :team-2 :montreal :points-1 12 :points-2 2}\n",
|
||||
" {:team-1 :gatineau :team-2 :montreal :points-1 7 :points-2 5}\n",
|
||||
" {:team-1 :amos :team-2 :montreal :points-1 1 :points-2 12}])\n",
|
||||
" \n",
|
||||
" \n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<table><thead><tr><td>Ville</td><td>Resultat</td><td>Ville</td><td>Resultat</td></tr></thead><tr><td>drummonville</td><td>4</td><td style=\"font-weight: bold;\">montreal</td><td>5</td></tr><tr><td style=\"font-weight: bold;\">quebec</td><td>12</td><td>montreal</td><td>2</td></tr><tr><td style=\"font-weight: bold;\">gatineau</td><td>7</td><td>montreal</td><td>5</td></tr><tr><td>amos</td><td>1</td><td style=\"font-weight: bold;\">montreal</td><td>12</td></tr></table>"
|
||||
]
|
||||
},
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(def bold {:style \"font-weight: bold;\"})\n",
|
||||
"(def not-bold nil)\n",
|
||||
"\n",
|
||||
"(defn team-1-style [game]\n",
|
||||
" (if (> (game :points-1) (game :points-2))\n",
|
||||
" bold\n",
|
||||
" not-bold))\n",
|
||||
"\n",
|
||||
"(defn team-2-style [game]\n",
|
||||
" (if (< (game :points-1) (game :points-2))\n",
|
||||
" bold\n",
|
||||
" not-bold))\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"(defn create-row [game]\n",
|
||||
" [:tr [:td (team-1-style game ) (:team-1 game)]\n",
|
||||
" [:td (:points-1 game)]\n",
|
||||
" [:td (team-2-style game ) (:team-2 game)]\n",
|
||||
" [:td (:points-2 game)]])\n",
|
||||
"\n",
|
||||
"(defn summary-table [games]\n",
|
||||
" [:table\n",
|
||||
" [:thead\n",
|
||||
" [:tr [:td \"Ville\"]\n",
|
||||
" [:td \"Resultat\"]\n",
|
||||
" [:td \"Ville\"]\n",
|
||||
" [:td \"Resultat\"]]]\n",
|
||||
" (map create-row games)])\n",
|
||||
"\n",
|
||||
"(display/hiccup-html (summary-table dodgeball-data))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
||||
Reference in new issue
Block a user