Skip to content

Commit 41c1ac0

Browse files
committed
Aggiunte finali
1 parent 006c488 commit 41c1ac0

File tree

4 files changed

+261
-3
lines changed

4 files changed

+261
-3
lines changed

notebooks/Lab 15.ipynb

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Uso di *self* nella definizione di una classe"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 1,
13+
"metadata": {
14+
"collapsed": true
15+
},
16+
"outputs": [],
17+
"source": [
18+
"class Studente(object):\n",
19+
" nome = 'Stefano'\n",
20+
" cognome = 'Gualandi'"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": 24,
26+
"metadata": {
27+
"collapsed": false
28+
},
29+
"outputs": [
30+
{
31+
"name": "stdout",
32+
"output_type": "stream",
33+
"text": [
34+
"Stefano Gualandi\n"
35+
]
36+
}
37+
],
38+
"source": [
39+
"print(Studente.nome, Studente.cognome)"
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": 22,
45+
"metadata": {
46+
"collapsed": false
47+
},
48+
"outputs": [
49+
{
50+
"name": "stdout",
51+
"output_type": "stream",
52+
"text": [
53+
"Stefano\n"
54+
]
55+
}
56+
],
57+
"source": [
58+
"print(Studente().nome)"
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": 3,
64+
"metadata": {
65+
"collapsed": true
66+
},
67+
"outputs": [],
68+
"source": [
69+
"a = Studente()"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": 23,
75+
"metadata": {
76+
"collapsed": false
77+
},
78+
"outputs": [
79+
{
80+
"name": "stdout",
81+
"output_type": "stream",
82+
"text": [
83+
"<__main__.Studente object at 0x000001E50E796588> 2083301975432\n"
84+
]
85+
}
86+
],
87+
"source": [
88+
"print(a, id(a))"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": 5,
94+
"metadata": {
95+
"collapsed": false
96+
},
97+
"outputs": [
98+
{
99+
"name": "stdout",
100+
"output_type": "stream",
101+
"text": [
102+
"Stefano\n"
103+
]
104+
}
105+
],
106+
"source": [
107+
"print(a.nome)"
108+
]
109+
},
110+
{
111+
"cell_type": "code",
112+
"execution_count": 25,
113+
"metadata": {
114+
"collapsed": false
115+
},
116+
"outputs": [
117+
{
118+
"name": "stdout",
119+
"output_type": "stream",
120+
"text": [
121+
"Kobe Bryant 2083302561216\n"
122+
]
123+
}
124+
],
125+
"source": [
126+
"b = Studente()\n",
127+
"b.nome = 'Kobe'\n",
128+
"b.cognome = 'Bryant'\n",
129+
"print(b.nome, b.cognome, id(b))"
130+
]
131+
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": 7,
135+
"metadata": {
136+
"collapsed": false
137+
},
138+
"outputs": [
139+
{
140+
"name": "stdout",
141+
"output_type": "stream",
142+
"text": [
143+
"Stefano Gualandi\n"
144+
]
145+
}
146+
],
147+
"source": [
148+
"print(a.nome, a.cognome)"
149+
]
150+
},
151+
{
152+
"cell_type": "code",
153+
"execution_count": 16,
154+
"metadata": {
155+
"collapsed": true
156+
},
157+
"outputs": [],
158+
"source": [
159+
"def NuovoStudente(var, a, b):\n",
160+
" var.nome = a\n",
161+
" var.cognome = b\n",
162+
" \n",
163+
"def PrintStudente(var):\n",
164+
" print(\"{}, {}\".format(var.nome, var.cognome))"
165+
]
166+
},
167+
{
168+
"cell_type": "code",
169+
"execution_count": 17,
170+
"metadata": {
171+
"collapsed": false
172+
},
173+
"outputs": [
174+
{
175+
"name": "stdout",
176+
"output_type": "stream",
177+
"text": [
178+
"Charlize, Theron\n"
179+
]
180+
}
181+
],
182+
"source": [
183+
"c = Studente()\n",
184+
"NuovoStudente(c, 'Charlize', 'Theron')\n",
185+
"PrintStudente(c)"
186+
]
187+
},
188+
{
189+
"cell_type": "code",
190+
"execution_count": 18,
191+
"metadata": {
192+
"collapsed": true
193+
},
194+
"outputs": [],
195+
"source": [
196+
"class StudenteSelf(object):\n",
197+
" def __init__(var, a, b):\n",
198+
" var.nome = a\n",
199+
" var.cognome = b\n",
200+
" \n",
201+
" def __str__(var):\n",
202+
" return \"{}, {}\".format(var.nome, var.cognome)\n",
203+
" "
204+
]
205+
},
206+
{
207+
"cell_type": "code",
208+
"execution_count": 19,
209+
"metadata": {
210+
"collapsed": false
211+
},
212+
"outputs": [
213+
{
214+
"name": "stdout",
215+
"output_type": "stream",
216+
"text": [
217+
"Charlize, Theron\n"
218+
]
219+
}
220+
],
221+
"source": [
222+
"c = StudenteSelf('Charlize', 'Theron')\n",
223+
"print(c)"
224+
]
225+
},
226+
{
227+
"cell_type": "code",
228+
"execution_count": null,
229+
"metadata": {
230+
"collapsed": true
231+
},
232+
"outputs": [],
233+
"source": []
234+
}
235+
],
236+
"metadata": {
237+
"kernelspec": {
238+
"display_name": "Python [default]",
239+
"language": "python",
240+
"name": "python3"
241+
},
242+
"language_info": {
243+
"codemirror_mode": {
244+
"name": "ipython",
245+
"version": 3
246+
},
247+
"file_extension": ".py",
248+
"mimetype": "text/x-python",
249+
"name": "python",
250+
"nbconvert_exporter": "python",
251+
"pygments_lexer": "ipython3",
252+
"version": "3.5.3"
253+
}
254+
},
255+
"nbformat": 4,
256+
"nbformat_minor": 2
257+
}

scripts/knapsack.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def DP(Left, Br, memo = {}):
114114
Is = [(randint(1,100), randint(5, 25)) for _ in range(30)]
115115
B = 95
116116

117-
118-
117+
import cProfile
118+
cProfile.run('KR(Is,B)')
119+
cProfile.run('DP(Is,B)')
119120
#print(KR(Ls, B))
120121
#print(DP(Ls, B))

scripts/sort_algo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@author: gualandi
66
"""
77

8-
from pairslist import IsEmpty, Min, RemoveFirst, MakeList, MakeRandomInts, Head, Filter, Append
8+
from pairslist import IsEmpty, Min, RemoveFirst, MakeList, MakeRandomInts, Head, Tail, Filter, Append
99

1010
def SelectionSort(As):
1111
""" Semplice implementazione ricorsiva di selection sort """

slides/Varie.pdf

520 KB
Binary file not shown.

0 commit comments

Comments
 (0)