Skip to content

Commit 98a47e0

Browse files
committed
First two chapter with modified exercises
1 parent f4fe2f7 commit 98a47e0

File tree

2 files changed

+247
-13
lines changed

2 files changed

+247
-13
lines changed

notebook/Python-1.ipynb

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,27 @@
477477
},
478478
{
479479
"cell_type": "code",
480-
"execution_count": null,
480+
"execution_count": 4,
481481
"metadata": {
482482
"collapsed": false
483483
},
484-
"outputs": [],
485-
"source": []
484+
"outputs": [
485+
{
486+
"name": "stdout",
487+
"output_type": "stream",
488+
"text": [
489+
"1157.625\n"
490+
]
491+
}
492+
],
493+
"source": [
494+
"from __future__ import division\n",
495+
"p=5 #interest rate\n",
496+
"A0= 1000 # initial amount\n",
497+
"T=3 #years\n",
498+
"A= A0*(1+p/100)**T #final amount\n",
499+
"print A"
500+
]
486501
},
487502
{
488503
"cell_type": "markdown",
@@ -738,7 +753,7 @@
738753
"name": "python",
739754
"nbconvert_exporter": "python",
740755
"pygments_lexer": "ipython2",
741-
"version": "2.7.10"
756+
"version": "2.7.12"
742757
}
743758
},
744759
"nbformat": 4,

notebook/Python-2.ipynb

Lines changed: 228 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@
159159
"source": [
160160
"C = 41\n",
161161
"\n",
162-
"print \"Case 1: \", C == 40\n",
163-
"print \"Case 2: \", C != 40 and C < 41\n",
162+
"print \"Case 1: \", C == 40 \n",
163+
"print \"Case 2: \", C != 40 and C < 41 \n",
164164
"print \"Case 3: \", C != 40 or C < 41\n",
165165
"print \"Case 4: \", not C == 40\n",
166166
"print \"Case 5: \", not C > 40\n",
@@ -897,10 +897,55 @@
897897
},
898898
{
899899
"cell_type": "code",
900-
"execution_count": null,
900+
"execution_count": 6,
901+
"metadata": {
902+
"collapsed": false
903+
},
904+
"outputs": [
905+
{
906+
"name": "stdout",
907+
"output_type": "stream",
908+
"text": [
909+
"[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]\n"
910+
]
911+
}
912+
],
913+
"source": [
914+
"n=23\n",
915+
"m=1\n",
916+
"l=[]\n",
917+
"while m <= n:\n",
918+
" l=l+[m]\n",
919+
" m=m+2\n",
920+
"print l \n"
921+
]
922+
},
923+
{
924+
"cell_type": "code",
925+
"execution_count": 7,
901926
"metadata": {
902927
"collapsed": false
903928
},
929+
"outputs": [
930+
{
931+
"name": "stdout",
932+
"output_type": "stream",
933+
"text": [
934+
"[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]\n"
935+
]
936+
}
937+
],
938+
"source": [
939+
"n=23\n",
940+
"print range(1,n+1,2) "
941+
]
942+
},
943+
{
944+
"cell_type": "code",
945+
"execution_count": null,
946+
"metadata": {
947+
"collapsed": true
948+
},
904949
"outputs": [],
905950
"source": []
906951
},
@@ -2142,6 +2187,28 @@
21422187
"somefunc(\"Hello\", [1,2], kwarg1=\"Hi\")"
21432188
]
21442189
},
2190+
{
2191+
"cell_type": "code",
2192+
"execution_count": 9,
2193+
"metadata": {
2194+
"collapsed": false
2195+
},
2196+
"outputs": [
2197+
{
2198+
"name": "stdout",
2199+
"output_type": "stream",
2200+
"text": [
2201+
"(2, 'frog')\n"
2202+
]
2203+
}
2204+
],
2205+
"source": [
2206+
"def golofunc(*args):#as many arguments I want ** gives a dictionary of arguments\n",
2207+
" print args\n",
2208+
" \n",
2209+
"golofunc(2, \"frog\") "
2210+
]
2211+
},
21452212
{
21462213
"cell_type": "code",
21472214
"execution_count": 76,
@@ -2289,12 +2356,134 @@
22892356
},
22902357
{
22912358
"cell_type": "code",
2292-
"execution_count": null,
2359+
"execution_count": 18,
22932360
"metadata": {
22942361
"collapsed": false
22952362
},
2296-
"outputs": [],
2297-
"source": []
2363+
"outputs": [
2364+
{
2365+
"name": "stdout",
2366+
"output_type": "stream",
2367+
"text": [
2368+
"1.48671951473e-06\n",
2369+
"2.43896074589e-06\n",
2370+
"3.96129909103e-06\n",
2371+
"6.36982517887e-06\n",
2372+
"1.01408520655e-05\n",
2373+
"1.59837411069e-05\n",
2374+
"2.49424712901e-05\n",
2375+
"3.85351967421e-05\n",
2376+
"5.89430677565e-05\n",
2377+
"8.92616571771e-05\n",
2378+
"0.000133830225765\n",
2379+
"0.000198655471393\n",
2380+
"0.000291946925791\n",
2381+
"0.000424780270551\n",
2382+
"0.000611901930114\n",
2383+
"0.000872682695046\n",
2384+
"0.00123221916847\n",
2385+
"0.00172256893905\n",
2386+
"0.00238408820146\n",
2387+
"0.0032668190562\n",
2388+
"0.00443184841194\n",
2389+
"0.00595253241978\n",
2390+
"0.00791545158298\n",
2391+
"0.0104209348144\n",
2392+
"0.0135829692337\n",
2393+
"0.0175283004936\n",
2394+
"0.0223945302948\n",
2395+
"0.0283270377416\n",
2396+
"0.0354745928462\n",
2397+
"0.0439835959804\n",
2398+
"0.0539909665132\n",
2399+
"0.0656158147747\n",
2400+
"0.0789501583009\n",
2401+
"0.0940490773769\n",
2402+
"0.110920834679\n",
2403+
"0.129517595666\n",
2404+
"0.149727465636\n",
2405+
"0.171368592048\n",
2406+
"0.194186054983\n",
2407+
"0.217852177033\n",
2408+
"0.241970724519\n",
2409+
"0.266085249899\n",
2410+
"0.289691552761\n",
2411+
"0.312253933367\n",
2412+
"0.333224602892\n",
2413+
"0.352065326764\n",
2414+
"0.368270140303\n",
2415+
"0.381387815461\n",
2416+
"0.391042693975\n",
2417+
"0.396952547477\n",
2418+
"0.398942280401\n",
2419+
"0.396952547477\n",
2420+
"0.391042693975\n",
2421+
"0.381387815461\n",
2422+
"0.368270140303\n",
2423+
"0.352065326764\n",
2424+
"0.333224602892\n",
2425+
"0.312253933367\n",
2426+
"0.289691552761\n",
2427+
"0.266085249899\n",
2428+
"0.241970724519\n",
2429+
"0.217852177033\n",
2430+
"0.194186054983\n",
2431+
"0.171368592048\n",
2432+
"0.149727465636\n",
2433+
"0.129517595666\n",
2434+
"0.110920834679\n",
2435+
"0.0940490773769\n",
2436+
"0.0789501583009\n",
2437+
"0.0656158147747\n",
2438+
"0.0539909665132\n",
2439+
"0.0439835959804\n",
2440+
"0.0354745928462\n",
2441+
"0.0283270377416\n",
2442+
"0.0223945302948\n",
2443+
"0.0175283004936\n",
2444+
"0.0135829692337\n",
2445+
"0.0104209348144\n",
2446+
"0.00791545158298\n",
2447+
"0.00595253241978\n",
2448+
"0.00443184841194\n",
2449+
"0.0032668190562\n",
2450+
"0.00238408820146\n",
2451+
"0.00172256893905\n",
2452+
"0.00123221916847\n",
2453+
"0.000872682695046\n",
2454+
"0.000611901930114\n",
2455+
"0.000424780270551\n",
2456+
"0.000291946925791\n",
2457+
"0.000198655471393\n",
2458+
"0.000133830225765\n",
2459+
"8.92616571771e-05\n",
2460+
"5.89430677565e-05\n",
2461+
"3.85351967421e-05\n",
2462+
"2.49424712901e-05\n",
2463+
"1.59837411069e-05\n",
2464+
"1.01408520655e-05\n",
2465+
"6.36982517887e-06\n",
2466+
"3.96129909103e-06\n",
2467+
"2.43896074589e-06\n",
2468+
"1.48671951473e-06\n"
2469+
]
2470+
}
2471+
],
2472+
"source": [
2473+
"from math import pi, exp, sqrt\n",
2474+
"from __future__ import division\n",
2475+
"from numpy import linspace\n",
2476+
"\n",
2477+
"def gaussian(x,m,s):\n",
2478+
" f=(sqrt(2*pi)*s)**(-1)*exp(-0.5*((x-m)/s)**2)\n",
2479+
" return f\n",
2480+
"values = linspace(-5,5,101)\n",
2481+
"m,s = 0,1\n",
2482+
"for v in values:\n",
2483+
" print gaussian(v,m,s)\n",
2484+
"\n",
2485+
"#print map(gauss,values) #function of a function"
2486+
]
22982487
},
22992488
{
23002489
"cell_type": "markdown",
@@ -2392,7 +2581,8 @@
23922581
"cell_type": "raw",
23932582
"metadata": {},
23942583
"source": [
2395-
"<expression if condition is True> if <condition> else <expression if condition is false>"
2584+
"<expression if condition is True> if <condition> else <expression if condition is false>\n",
2585+
"sqrt(a) if a>=0 else None"
23962586
]
23972587
},
23982588
{
@@ -2409,10 +2599,39 @@
24092599
},
24102600
{
24112601
"cell_type": "code",
2412-
"execution_count": null,
2602+
"execution_count": 19,
24132603
"metadata": {
24142604
"collapsed": false
24152605
},
2606+
"outputs": [
2607+
{
2608+
"data": {
2609+
"text/plain": [
2610+
"True"
2611+
]
2612+
},
2613+
"execution_count": 19,
2614+
"metadata": {},
2615+
"output_type": "execute_result"
2616+
}
2617+
],
2618+
"source": [
2619+
"def H(x):\n",
2620+
" return (1 if x>=0 else 0)\n",
2621+
"\n",
2622+
"def H(x):\n",
2623+
" if x<0:\n",
2624+
" return 0\n",
2625+
" else:\n",
2626+
" return 1"
2627+
]
2628+
},
2629+
{
2630+
"cell_type": "code",
2631+
"execution_count": null,
2632+
"metadata": {
2633+
"collapsed": true
2634+
},
24162635
"outputs": [],
24172636
"source": []
24182637
}
@@ -2433,7 +2652,7 @@
24332652
"name": "python",
24342653
"nbconvert_exporter": "python",
24352654
"pygments_lexer": "ipython2",
2436-
"version": "2.7.10"
2655+
"version": "2.7.12"
24372656
}
24382657
},
24392658
"nbformat": 4,

0 commit comments

Comments
 (0)