Skip to content

Commit aedb348

Browse files
committed
Changes during Python class
1 parent 043a04b commit aedb348

File tree

1 file changed

+98
-27
lines changed

1 file changed

+98
-27
lines changed

notebook/Python-1.ipynb

Lines changed: 98 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,15 @@
7979
},
8080
"outputs": [
8181
{
82-
"ename": "TypeError",
83-
"evalue": "unsupported operand type(s) for ^: 'float' and 'int'",
84-
"output_type": "error",
85-
"traceback": [
86-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
87-
"\u001b[0;32m<ipython-input-2-2cffe887fbc6>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mprint\u001b[0m \u001b[0;36m5\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;36m0.6\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0;36m0.5\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;36m9.81\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;36m0.6\u001b[0m\u001b[0;34m^\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
88-
"\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for ^: 'float' and 'int'"
82+
"name": "stdout",
83+
"output_type": "stream",
84+
"text": [
85+
"1.2342\n"
8986
]
9087
}
9188
],
9289
"source": [
93-
"print 5*0.6 - 0.5*9.81*0.6^2"
90+
"print 5*0.6 - 0.5*9.81*0.6**2"
9491
]
9592
},
9693
{
@@ -218,7 +215,7 @@
218215
},
219216
{
220217
"cell_type": "code",
221-
"execution_count": 6,
218+
"execution_count": 20,
222219
"metadata": {
223220
"collapsed": false
224221
},
@@ -250,12 +247,33 @@
250247
},
251248
{
252249
"cell_type": "code",
253-
"execution_count": null,
250+
"execution_count": 17,
254251
"metadata": {
255252
"collapsed": false
256253
},
257-
"outputs": [],
258-
"source": []
254+
"outputs": [
255+
{
256+
"name": "stdout",
257+
"output_type": "stream",
258+
"text": [
259+
"(262.20472440944883, 21.850393700787404, 7.283464566929134, 3.0)\n",
260+
"21.8503937008\n",
261+
"7.28346456693\n",
262+
"3.0\n"
263+
]
264+
}
265+
],
266+
"source": [
267+
"length=666 #meters\n",
268+
"Inches=length/2.54\n",
269+
"Feet=Inches/12\n",
270+
"Yards=Feet/3\n",
271+
"Miles=Feet/Yards\n",
272+
"print (Inches, Feet, Yards, Miles)\n",
273+
"print Feet\n",
274+
"print Yards\n",
275+
"print Miles"
276+
]
259277
},
260278
{
261279
"cell_type": "markdown",
@@ -267,7 +285,7 @@
267285
},
268286
{
269287
"cell_type": "code",
270-
"execution_count": 7,
288+
"execution_count": 24,
271289
"metadata": {
272290
"collapsed": false
273291
},
@@ -276,12 +294,12 @@
276294
"name": "stdout",
277295
"output_type": "stream",
278296
"text": [
279-
"At t=0.6 s, y is 1.23 m.\n"
297+
"At t=0.6s, y is 1.234 m.\n"
280298
]
281299
}
282300
],
283301
"source": [
284-
"print \"At t=%g s, y is %.2f m.\" % (t, y)"
302+
"print \"At t=%gs, y is %.3f m.\" % (t, y)"
285303
]
286304
},
287305
{
@@ -334,12 +352,35 @@
334352
},
335353
{
336354
"cell_type": "code",
337-
"execution_count": null,
355+
"execution_count": 46,
338356
"metadata": {
339357
"collapsed": false
340358
},
341-
"outputs": [],
342-
"source": []
359+
"outputs": [
360+
{
361+
"name": "stdout",
362+
"output_type": "stream",
363+
"text": [
364+
"0.333333333333\n",
365+
"Drag force is 5.1 kgm/s2 and the force of gravity is 4.2 kgm/s2\n"
366+
]
367+
}
368+
],
369+
"source": [
370+
"import math\n",
371+
"Cd=0.2\n",
372+
"Density=1.2 #kg/m3\n",
373+
"Area= math.pi*11**2 #m^2\n",
374+
"V=120 #km/h\n",
375+
"V=V/(60.0*60.0) #km/h\n",
376+
"V=V*10\n",
377+
"m=0.43 #kg\n",
378+
"g = 9.81\n",
379+
"Fd=0.5*Cd*Density*Area*V**2\n",
380+
"Fm=m*g\n",
381+
"print V\n",
382+
"print \"Drag force is %.1f kgm/s2 and the force of gravity is %.1f kgm/s2\" % (Fd, Fm)\n"
383+
]
343384
},
344385
{
345386
"cell_type": "markdown",
@@ -434,12 +475,25 @@
434475
},
435476
{
436477
"cell_type": "code",
437-
"execution_count": null,
478+
"execution_count": 56,
438479
"metadata": {
439480
"collapsed": false
440481
},
441-
"outputs": [],
442-
"source": []
482+
"outputs": [
483+
{
484+
"name": "stdout",
485+
"output_type": "stream",
486+
"text": [
487+
"Amount after 3 years is 1158 EUR\n"
488+
]
489+
}
490+
],
491+
"source": [
492+
"Initial=1000 #EUR\n",
493+
"n=3\n",
494+
"Amountn=Initial*(1+5/100.0)**n\n",
495+
"print \"Amount after %g years is %.f EUR\" %(n, Amountn)"
496+
]
443497
},
444498
{
445499
"cell_type": "markdown",
@@ -589,19 +643,36 @@
589643
},
590644
{
591645
"cell_type": "code",
592-
"execution_count": null,
646+
"execution_count": 62,
593647
"metadata": {
594648
"collapsed": false
595649
},
596-
"outputs": [],
650+
"outputs": [
651+
{
652+
"name": "stdout",
653+
"output_type": "stream",
654+
"text": [
655+
"(-0.25+0.968245836552j) (-0.25-0.968245836552j)\n"
656+
]
657+
}
658+
],
597659
"source": [
598660
"a = 2; b = 1; c = 2\n",
599-
"from math import sqrt\n",
661+
"from cmath import sqrt\n",
600662
"q = sqrt(b*b - 4*a*c)\n",
601-
"x1 = (-b + q)/2*a\n",
602-
"x2 = (-b - q)/2*a\n",
663+
"x1 = (-b + q)/(2*a)\n",
664+
"x2 = (-b - q)/(2*a)\n",
603665
"print x1, x2"
604666
]
667+
},
668+
{
669+
"cell_type": "code",
670+
"execution_count": null,
671+
"metadata": {
672+
"collapsed": true
673+
},
674+
"outputs": [],
675+
"source": []
605676
}
606677
],
607678
"metadata": {
@@ -620,7 +691,7 @@
620691
"name": "python",
621692
"nbconvert_exporter": "python",
622693
"pygments_lexer": "ipython2",
623-
"version": "2.7.10"
694+
"version": "2.7.6"
624695
}
625696
},
626697
"nbformat": 4,

0 commit comments

Comments
 (0)