summaryrefslogtreecommitdiff
path: root/Engineering_Thermodynamics:_A_Computer_Approach_(SI_Units_Version)/ch14.ipynb
blob: 1618010d0cc2a6d2e4265d4797c17b794f9151e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
{
 "metadata": {
  "name": "ch14"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "'''\nEXAMPLE 14.1 Using a vector of strings\n'''\n\ndef load(v):\n    v.append(\"Japan\")\n    v.append(\"Italy\")\n    v.append(\"Spain\")\n    v.append(\"Egypt\")\n    v.append(\"Chile\")\n    v.append(\"Zaire\")\n    v.append(\"Nepal\")\n    v.append(\"Kenya\")\n\ndef print_(v):\n    for i in v:\n        print i\n\nv = []\nload(v)\nprint_(v)",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Japan\nItaly\nSpain\nEgypt\nChile\nZaire\nNepal\nKenya\n"
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "'''\nEXAMPLE 14.2 \n'''\n\ndef load(v):\n    v.append(\"Japan\")\n    v.append(\"Italy\")\n    v.append(\"Spain\")\n    v.append(\"Egypt\")\n    v.append(\"Chile\")\n    v.append(\"Zaire\")\n    v.append(\"Nepal\")\n    v.append(\"Kenya\")\n\ndef print_(v):\n    for i in v:\n        print i\n\nv = []\nload(v)\nprint_(v)",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Japan\nItaly\nSpain\nEgypt\nChile\nZaire\nNepal\nKenya\n"
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "'''\nEXAMPLE 14.3 \n'''\n\ndef load(v):\n    v.append(\"Japan\")\n    v.append(\"Italy\")\n    v.append(\"Spain\")\n    v.append(\"Egypt\")\n    v.append(\"Chile\")\n    v.append(\"Zaire\")\n    v.append(\"Nepal\")\n    v.append(\"Kenya\")\n\ndef print_(v):\n    for i in range(len(v)):\n        print v[i]\n\nv = []\nload(v)\nprint_(v)",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Japan\nItaly\nSpain\nEgypt\nChile\nZaire\nNepal\nKenya\n"
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "'''\nEXAMPLE 14.4 Using the Generic sort() Algorithm\n'''\n\n\ndef load(v):\n    v.append(\"Japan\")\n    v.append(\"Italy\")\n    v.append(\"Spain\")\n    v.append(\"Egypt\")\n    v.append(\"Chile\")\n    v.append(\"Zaire\")\n    v.append(\"Nepal\")\n    v.append(\"Kenya\")\n\ndef print_(v):\n    for i in v:\n        print i\n\nv = []\nload(v)\nv.sort()\nprint_(v)\n",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Chile\nEgypt\nItaly\nJapan\nKenya\nNepal\nSpain\nZaire\n"
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "'''\nEXAMPLE 14.5 Using the Assignment Operator to Duplicate a vector\n'''\n#This program demonstrates that one vector can be assigned to another.\n\n\n\ndef load(v):\n    v.append(\"Japan\")\n    v.append(\"Italy\")\n    v.append(\"Spain\")\n    v.append(\"Egypt\")\n    v.append(\"Chile\")\n    v.append(\"Zaire\")\n    v.append(\"Nepal\")\n    v.append(\"Kenya\")\n\ndef print_(v):\n    for i in v:\n        print i\n\nv = []\nload(v)\nw = v\nprint_(v)\nprint_(w)",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Japan\nItaly\nSpain\nEgypt\nChile\nZaire\nNepal\nKenya\nJapan\nItaly\nSpain\nEgypt\nChile\nZaire\nNepal\nKenya\n"
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "'''\nEXAMPLE 14.6 \n'''\n\ndef load(v):\n    v.append(\"Japan\")\n    v.append(\"Italy\")\n    v.append(\"Spain\")\n    v.append(\"Egypt\")\n    v.append(\"Chile\")\n    v.append(\"Zaire\")\n    v.append(\"Nepal\")\n    v.append(\"Kenya\")\n\ndef print_(v):\n    for i in v:\n        print i\n\nv = []\nload(v)\nv.sort()\nprint_(v)\nprint \"v.front() = \" + v[0]\nprint \"v.back() = \" + v.pop(-1) \nprint \"v.back() = \" + v.pop(-1) \nprint \"v.back() = \" + v[-1] \nprint_(v)",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Chile\nEgypt\nItaly\nJapan\nKenya\nNepal\nSpain\nZaire\nv.front() = Chile\nv.back() = Zaire\nv.back() = Spain\nv.back() = Nepal\nChile\nEgypt\nItaly\nJapan\nKenya\nNepal\n"
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "'''\nEXAMPLE 14.7 Using the erase() Function\n'''\n\ndef load(v):\n    v.append(\"Japan\")\n    v.append(\"Italy\")\n    v.append(\"Spain\")\n    v.append(\"Egypt\")\n    v.append(\"Chile\")\n    v.append(\"Zaire\")\n    v.append(\"Nepal\")\n    v.append(\"Kenya\")\n\ndef print_(v):\n    for i in v:\n        print i\n\nv = []\nload(v)\nv.sort()\nprint_(v)\nv.pop(2) # removes Italy\nv.pop(-2) # removes Spain\nprint_(v)",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Chile\nEgypt\nItaly\nJapan\nKenya\nNepal\nSpain\nZaire\nChile\nEgypt\nJapan\nKenya\nNepal\nZaire\n"
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "'''\nEXAMPLE 14.8 Using the insert() Function\n'''\ndef load(v):\n    v.append(\"Japan\")\n    v.append(\"Italy\")\n    v.append(\"Spain\")\n    v.append(\"Egypt\")\n    v.append(\"Chile\")\n    v.append(\"Zaire\")\n    v.append(\"Nepal\")\n    v.append(\"Kenya\")\n\ndef print_(v):\n    for i in v:\n        print i\nv = []\nload(v)\nv.sort()\nprint_(v)\nr = []\nfor i in range(2,len(v)-2):\n    r.append(v[i]) #removes the segment Italy..Nepal\n    \nfor i in r:\n    v.remove(i)\nprint_(v)\nv.insert(2,\"India\")\nprint_(v)",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Chile\nEgypt\nItaly\nJapan\nKenya\nNepal\nSpain\nZaire\nChile\nEgypt\nSpain\nZaire\nChile\nEgypt\nIndia\nSpain\nZaire\n"
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "'''\nEXAMPLE 14.9 Using the find() Function\n'''\n\ndef load(v):\n    v.append(\"Japan\")\n    v.append(\"Italy\")\n    v.append(\"Spain\")\n    v.append(\"Egypt\")\n    v.append(\"Chile\")\n    v.append(\"Zaire\")\n    v.append(\"Nepal\")\n    v.append(\"Kenya\")\n    v.append(\"India\")\n    v.append(\"China\")\n    v.append(\"Malta\")\n    v.append(\"Syria\")\n\ndef print_(v):\n    for i in v:\n        print i\n\nv = []\nload(v)\nprint_(v)\negypt = v.index('Egypt')\nmalta = v.index('Malta')\nw = v[egypt:malta+1]\nw.sort()\nprint_(w)",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "Japan\nItaly\nSpain\nEgypt\nChile\nZaire\nNepal\nKenya\nIndia\nChina\nMalta\nSyria\nChile\nChina\nEgypt\nIndia\nKenya\nMalta\nNepal\nZaire\n"
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "'''\nEXAMPLE 14.10\n'''\ndef copy(v,x,n):\n    for i in x:\n        v.append(i)\n\ndef projection(v,b):\n    v_size = len(v)\n    w = []\n    for i in range(0,v_size):\n        if b[i]:\n            w.append(v[i])\n    return w\n\ndef print_(v):\n    for i in v:\n        print i,\n    print ''\n\nx = [ 22.2, 33.3, 44.4, 55.5, 66.6, 77.7, 88.8, 99.9 ]\nv = []\ncopy(v, x, 8)\ny = [ False, True, False, True, True, True, False, True ]\nb = []\ncopy(b, y, 8)\nw = projection(v, b)\nprint_(v)\nprint_(w)",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "22.2 33.3 44.4 55.5 66.6 77.7 88.8 99.9 \n33.3 55.5 66.6 77.7 99.9 \n"
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": "",
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}