Skip to content

Commit

Permalink
added problems to 01 and 02
Browse files Browse the repository at this point in the history
  • Loading branch information
rcc02007 committed Jan 2, 2020
1 parent 54905e9 commit cfde585
Show file tree
Hide file tree
Showing 11 changed files with 2,540 additions and 26,555 deletions.
291 changes: 116 additions & 175 deletions notebooks/.ipynb_checkpoints/01_Interacting_with_Python-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@
"metadata": {},
"source": [
"## Reflection point\n",
"When we created `sum_xy` and `diff_xy` two new variables were created that depended upon previously created variables. "
"When we created `sum_xy` and `diff_xy` two new variables were created that depended upon previously created variables `x` and `y`. How else can we accomplish this? Could we make a function? Could we combine the commands in one block as a script?"
]
},
{
Expand Down Expand Up @@ -911,9 +911,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"metadata": {},
"source": [
"**None is not Zero**: `None` is a special variable indicating that no value was assigned or that a behavior is undefined. It is different than the value zero, an empty string, or some other nil value. \n",
"\n",
Expand All @@ -924,7 +922,10 @@
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": true
"collapsed": true,
"jupyter": {
"outputs_hidden": true
}
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -967,7 +968,10 @@
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": true
"collapsed": true,
"jupyter": {
"outputs_hidden": true
}
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -1006,7 +1010,10 @@
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": true
"collapsed": true,
"jupyter": {
"outputs_hidden": true
}
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -1066,7 +1073,10 @@
"cell_type": "code",
"execution_count": 40,
"metadata": {
"collapsed": true
"collapsed": true,
"jupyter": {
"outputs_hidden": true
}
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -1228,182 +1238,113 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Recommended Readings\n",
"# Problems\n",
"\n",
"1. Calculate some properties of a rectangular box that is 12.5\"$\\times$11\"$\\times$14\" and weighs 31 lbs\n",
"\n",
" a. What is the volume of the box?\n",
" \n",
" b. What is the average density of the box?\n",
" \n",
" c. What is the result of the following logical operation, `volume>1000` (in inches^3)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2. Use the variables given below, `str1` and `str2`, and check the following \n",
"\n",
" a. `str1<str2`\n",
" \n",
" b. `str1==str2`\n",
" \n",
" c. `str1>str2`\n",
" \n",
" d. How could you force (b) to be true? [Hint](https://docs.python.org/3/library/stdtypes.html?highlight=str.lower#str.lower) or [Hint](https://docs.python.org/3/library/stdtypes.html?highlight=str.lower#str.upper)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"str1='Computational Mechanics'\n",
"str2='computational mechanics'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"3. The following code has an error, fix the error so that the correct result is returned:\n",
"\n",
"- [\"Yes, Python is Slow, and I Don’t Care\"](https://hackernoon.com/yes-python-is-slow-and-i-dont-care-13763980b5a1) by Nick Humrich, on Hackernoon. (Skip the part on microservices, which is a bit specialized, and continue after the photo of moving car lights.)\n",
"- [\"Why I Push for Python\"](http://lorenabarba.com/blog/why-i-push-for-python/), by Prof. Lorena A. Barba (2014). This blog post got a bit of interest over at [Hacker News](https://news.ycombinator.com/item?id=7760870)."
"```y is 20 and x is less than y```"
]
},
{
"cell_type": "code",
"execution_count": 45,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<link href=\"https://fonts.googleapis.com/css?family=Merriweather:300,300i,400,400i,700,700i,900,900i\" rel=\"stylesheet\">\n",
"<link href=\"https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300i,400,400i,700,700i\" rel=\"stylesheet\">\n",
"<link href='http://fonts.googleapis.com/css?family=Source+Code+Pro:300,400' rel='stylesheet' type='text/css'>\n",
"<style>\n",
"\n",
"@font-face {\n",
" font-family: \"Computer Modern\";\n",
" src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf');\n",
"}\n",
"\n",
"\n",
"#notebook_panel { /* main background */\n",
" background: rgb(245,245,245);\n",
"}\n",
"\n",
"div.cell { /* set cell width */\n",
" width: 800px;\n",
"}\n",
"\n",
"div #notebook { /* centre the content */\n",
" background: #fff; /* white background for content */\n",
" width: 1000px;\n",
" margin: auto;\n",
" padding-left: 0em;\n",
"}\n",
"\n",
"#notebook li { /* More space between bullet points */\n",
"margin-top:0.8em;\n",
"}\n",
"\n",
"/* draw border around running cells */\n",
"div.cell.border-box-sizing.code_cell.running { \n",
" border: 1px solid #111;\n",
"}\n",
"\n",
"/* Put a solid color box around each cell and its output, visually linking them*/\n",
"div.cell.code_cell {\n",
" background-color: rgb(256,256,256); \n",
" border-radius: 0px; \n",
" padding: 0.5em;\n",
" margin-left:1em;\n",
" margin-top: 1em;\n",
"}\n",
"\n",
"\n",
"div.text_cell_render{\n",
" font-family: 'Source Sans Pro', sans-serif;\n",
" line-height: 140%;\n",
" font-size: 110%;\n",
" width:680px;\n",
" margin-left:auto;\n",
" margin-right:auto;\n",
"}\n",
"\n",
"/* Formatting for header cells */\n",
".text_cell_render h1 {\n",
" font-family: 'Merriweather', serif;\n",
" font-style:regular;\n",
" font-weight: bold; \n",
" font-size: 250%;\n",
" line-height: 100%;\n",
" color: #004065;\n",
" margin-bottom: 1em;\n",
" margin-top: 0.5em;\n",
" display: block;\n",
"}\t\n",
".text_cell_render h2 {\n",
" font-family: 'Merriweather', serif;\n",
" font-weight: bold; \n",
" font-size: 180%;\n",
" line-height: 100%;\n",
" color: #0096d6;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 0.5em;\n",
" display: block;\n",
"}\t\n",
"\n",
".text_cell_render h3 {\n",
" font-family: 'Merriweather', serif;\n",
"\tfont-size: 150%;\n",
" margin-top:12px;\n",
" margin-bottom: 3px;\n",
" font-style: regular;\n",
" color: #008367;\n",
"}\n",
"\n",
".text_cell_render h4 { /*Use this for captions*/\n",
" font-family: 'Merriweather', serif;\n",
" font-weight: 300; \n",
" font-size: 100%;\n",
" line-height: 120%;\n",
" text-align: center;\n",
" margin-top: 1em;\n",
" margin-bottom: 2em;\n",
" font-style: regular;\n",
"}\n",
"\n",
".text_cell_render h5 { /*Use this for small titles*/\n",
" font-family: 'Source Sans Pro', sans-serif;\n",
" font-weight: regular;\n",
" font-size: 130%;\n",
" color: #e31937;\n",
" font-style: italic;\n",
" margin-bottom: .5em;\n",
" margin-top: 1em;\n",
" display: block;\n",
"}\n",
"\n",
".text_cell_render h6 { /*use this for copyright note*/\n",
" font-family: 'Source Code Pro', sans-serif;\n",
" font-weight: 300;\n",
" font-size: 9pt;\n",
" line-height: 100%;\n",
" color: grey;\n",
" margin-bottom: 1px;\n",
" margin-top: 1px;\n",
"}\n",
"\n",
" .CodeMirror{\n",
" font-family: \"Source Code Pro\";\n",
"\t\t\tfont-size: 90%;\n",
" }\n",
"/* .prompt{\n",
" display: None;\n",
" }*/\n",
"\t\n",
" \n",
" .warning{\n",
" color: rgb( 240, 20, 20 )\n",
" } \n",
"</style>\n",
"<script>\n",
" MathJax.Hub.Config({\n",
" TeX: {\n",
" extensions: [\"AMSmath.js\"], \n",
" equationNumbers: { autoNumber: \"AMS\", useLabelIds: true}\n",
" },\n",
" tex2jax: {\n",
" inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
" displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
" },\n",
" displayAlign: 'center', // Change this to 'center' to center equations.\n",
" \"HTML-CSS\": {\n",
" styles: {'.MathJax_Display': {\"margin\": 4}}\n",
" }\n",
" });\n",
"</script>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
"ename": "TypeError",
"evalue": "'<' not supported between instances of 'str' and 'int'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-8-54c31d5056b5>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m20\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0;32mif\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m<\u001b[0m\u001b[0my\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m==\u001b[0m\u001b[0;36m20\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'y is 20 and x is less than y'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mTypeError\u001b[0m: '<' not supported between instances of 'str' and 'int'"
]
}
],
"source": [
"# Execute this cell to load the notebook's style sheet, then ignore it\n",
"from IPython.core.display import HTML\n",
"css_file = '../style/custom.css'\n",
"HTML(open(css_file, \"r\").read())"
"x='1'\n",
"y=20\n",
"\n",
"if x<y and y==20:\n",
" print('y is 20 and x is less than y')\n",
"else:\n",
" print('x is not less than y')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"4. Create a script that takes the clock hour in 24 hours and prints the clock hour with am or pm. \n",
"\n",
" Hint: Use an if-else statement with `print` commands"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"test_time=10\n",
"\n",
"#your code here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test_time=16"
]
}
],
Expand All @@ -1423,13 +1364,13 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.7.5"
},
"widgets": {
"state": {},
"version": "1.1.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Loading

0 comments on commit cfde585

Please sign in to comment.