Aula06 adicionada

Signed-off-by: tiagorg <tiagorg@rendlaptop>
This commit is contained in:
tiagorg 2022-10-28 20:13:43 +01:00
parent cdb17cfecd
commit ca82b23778
13 changed files with 705 additions and 0 deletions

7
1ano/fp/aula06/README.md Normal file
View File

@ -0,0 +1,7 @@
# Fundamentos de Programação
## Aula 06
### Tópico principal da aula: Files, Exceptions
#### Em falta: exercício 06
---
*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new)

BIN
1ano/fp/aula06/aula06.pdf Normal file

Binary file not shown.

View File

@ -0,0 +1,406 @@
UP
-218 185
DOWN
-240 189
-246 188
-248 183
-246 178
-244 175
-240 170
-235 166
-229 163
-220 158
-208 156
-203 153
-194 148
-187 141
-179 133
-171 119
-166 106
-163 87
-161 66
-162 52
-164 44
-167 28
-171 6
-172 -15
-171 -30
-165 -46
-156 -60
-152 -67
-152 -68
UP
-134 -61
DOWN
-145 -66
-152 -78
-152 -94
-157 -109
-157 -118
-151 -128
-146 -135
-146 -136
UP
-97 -134
DOWN
-98 -138
-97 -143
-96 -157
-96 -169
-98 -183
-104 -194
-110 -203
-114 -211
-117 -220
-120 -233
-122 -243
-123 -247
-157 -248
-157 -240
-154 -234
-154 -230
-153 -229
-149 -226
-146 -223
-145 -219
-143 -214
-142 -210
-141 -203
-139 -199
-136 -192
-132 -184
-130 -179
-132 -171
-133 -162
-134 -153
-138 -145
-143 -137
-143 -132
-142 -124
-138 -112
-134 -104
-132 -102
UP
-97 -155
DOWN
-92 -151
-91 -147
-89 -142
-89 -135
-90 -129
-90 -128
UP
-94 -170
DOWN
-83 -171
-68 -174
-47 -177
-30 -172
-15 -171
-11 -170
UP
12 -96
DOWN
9 -109
9 -127
7 -140
5 -157
9 -164
22 -176
37 -204
40 -209
49 -220
55 -229
57 -235
57 -238
50 -239
49 -241
51 -248
53 -249
63 -245
70 -243
57 -249
62 -250
71 -250
75 -250
81 -250
86 -248
86 -242
84 -232
85 -226
81 -221
77 -211
73 -205
67 -196
62 -187
58 -180
51 -171
47 -164
46 -153
50 -141
53 -130
54 -124
57 -112
56 -102
55 -98
UP
48 -164
DOWN
54 -158
60 -146
64 -136
64 -131
UP
5 -152
DOWN
1 -150
-4 -145
-8 -138
-14 -128
-19 -119
-17 -124
UP
21 -177
DOWN
14 -176
7 -174
-6 -174
-14 -170
-19 -166
-20 -164
UP
-8 -173
DOWN
-8 -180
-5 -189
-4 -201
-2 -211
-1 -220
-2 -231
-5 -238
-8 -241
-9 -244
-7 -249
6 -247
9 -248
16 -247
21 -246
24 -241
27 -234
27 -226
27 -219
27 -209
27 -202
28 -193
28 -188
28 -184
UP
-60 -177
DOWN
-59 -186
-57 -199
-56 -211
-59 -225
-61 -233
-65 -243
-66 -245
-73 -246
-81 -246
-84 -246
-91 -245
-91 -244
-88 -231
-87 -225
-85 -218
-85 -211
-85 -203
-85 -193
-88 -185
-89 -180
-91 -175
-92 -172
-93 -170
UP
-154 -93
DOWN
-157 -87
-162 -74
-168 -66
-172 -57
-175 -49
-178 -38
-178 -26
-178 -12
-177 4
-175 17
-172 27
-168 36
-161 48
-161 50
UP
-217 178
DOWN
-217 178
-217 177
-215 176
-214 175
-220 177
-223 178
-223 178
-222 178
UP
-248 185
DOWN
-245 184
-240 182
-237 181
-234 179
-231 177
-229 176
-228 175
-226 174
-224 173
-223 173
-220 172
-217 172
-216 171
-214 170
-214 169
UP
-218 186
DOWN
-195 173
-183 165
-175 159
-164 151
-158 145
-152 139
-145 128
-143 122
-139 112
-138 105
-134 95
-131 88
-129 78
-126 67
-125 62
-125 54
-124 44
-125 38
-126 30
-125 27
-125 8
-126 5
-125 -9
-122 -15
-115 -25
-109 -32
-103 -39
-95 -42
-84 -45
-72 -47
-56 -48
-41 -47
-31 -46
-18 -45
-1 -44
9 -43
34 -45
50 -52
67 -61
83 -68
95 -80
112 -97
142 -115
180 -132
200 -146
227 -159
259 -175
289 -185
317 -189
349 -190
375 -191
385 -192
382 -196
366 -199
352 -204
343 -204
330 -205
315 -209
296 -212
276 -214
252 -208
237 -202
218 -197
202 -193
184 -187
164 -179
147 -173
128 -168
116 -164
102 -160
88 -158
78 -159
69 -162
57 -164
56 -165
51 -165
UP
68 -144
DOWN
83 -143
96 -141
109 -139
119 -146
141 -150
161 -155
181 -163
195 -169
208 -179
223 -187
241 -191
247 -193
249 -194
UP
-6 -141
DOWN
-15 -146
-29 -150
-42 -154
-51 -153
-60 -152
-60 -152
UP
-90 -134
DOWN
-85 -131
-79 -128
-78 -123
-80 -115
-82 -106
-80 -101
-76 -101
UP
-81 -132
DOWN
-76 -130
-71 -126
-72 -124
UP
43 -118
DOWN
44 -125
47 -135
41 -156
37 -160
40 -166
47 -171
47 -171
UP
-106 -153
DOWN
-107 -167
-106 -178
-109 -192
-114 -198
-116 -201

View File

@ -0,0 +1,4 @@
13.2
3.5
9.8
2

View File

@ -0,0 +1,20 @@
Numero Nome Curso Regime DataInscricao nota1 nota2 nota3
42003 LUIS CARLOS FIGUEIREDO PAULO 8240 O 2006-10-03 16.6 16.5 16.8
39652 FABIO ANDRE SABINO REAL 8040 O 2006-09-06 17.4 13.4 3.4
34801 ABEL LUIS DIAS CARAPICHOSO 8220 O 2006-09-06 17.4 18.9 10.8
30759 ELISABETE CLAUDIA SANTOS SILVA SOARES 8020 O 2006-09-05 17.6 17.6 14.3
40747 JOEL DOS SANTOS MIRANDA 8220 O 2006-09-05 19.6 19.3 12.2
39450 RUI BARBOSA SOARES FIGUEIREDO 8040 O 2006-09-05 16.8 14.1 7.7
42847 NELSON MIGUEL BREDA COELHO 8204 O 2006-09-21 11.5 15.6 6.1
36700 DAVID JOAO CASTILLO CARVALHO 8040 O 2006-09-06 13.6 11.7 5.4
33955 NUNO JOSE SILVA DOS SANTOS MAGALHAES DA COSTA 8004 O 2006-11-21 12.3 9.8 6.3
42304 JOAO PEDRO PEREIRA 8204 O 2006-09-19 20 16.9 15
43021 NUNO MIGUEL MOGAS DA SILVA 8240 O 2006-10-16 17 16.4 11.4
23973 BARBARA MARTINS BASTIAO PIRES 8240 O 2006-09-18 8.9 11.2 4.5
35007 SANDRA CRISTINA LEAL DA GRACA 8220 O 2006-11-30 18.5 15.7 8.8
38461 JOSE MANUEL VIEIRA DE ALMEIDA RAMOS 8004 O 2006-09-05 16.7 19.4 9.4
10679 JOAO MANUEL MOREIRA CONCEICAO ANDRADE 8204 O 2006-11-21 15.4 15.5 6.5
34385 NARCISO RESENDE SILVA 8028 T 2007-01-31 11.2 8.8 4.2
38063 RUI MIGUEL ALVES FERNANDES PALHA 8004 O 2006-09-05 16.3 13 4.7
37347 ROBERT DE FERNANDES 8028 O 2006-09-05 13.1 16.1 4.4
24983 SANDRA ELISABETE PINHEIRO MORGADO CORREIA 8004 O 2006-09-05 10 7.6 7.5
1 Numero Nome Curso Regime DataInscricao nota1 nota2 nota3
2 42003 LUIS CARLOS FIGUEIREDO PAULO 8240 O 2006-10-03 16.6 16.5 16.8
3 39652 FABIO ANDRE SABINO REAL 8040 O 2006-09-06 17.4 13.4 3.4
4 34801 ABEL LUIS DIAS CARAPICHOSO 8220 O 2006-09-06 17.4 18.9 10.8
5 30759 ELISABETE CLAUDIA SANTOS SILVA SOARES 8020 O 2006-09-05 17.6 17.6 14.3
6 40747 JOEL DOS SANTOS MIRANDA 8220 O 2006-09-05 19.6 19.3 12.2
7 39450 RUI BARBOSA SOARES FIGUEIREDO 8040 O 2006-09-05 16.8 14.1 7.7
8 42847 NELSON MIGUEL BREDA COELHO 8204 O 2006-09-21 11.5 15.6 6.1
9 36700 DAVID JOAO CASTILLO CARVALHO 8040 O 2006-09-06 13.6 11.7 5.4
10 33955 NUNO JOSE SILVA DOS SANTOS MAGALHAES DA COSTA 8004 O 2006-11-21 12.3 9.8 6.3
11 42304 JOAO PEDRO PEREIRA 8204 O 2006-09-19 20 16.9 15
12 43021 NUNO MIGUEL MOGAS DA SILVA 8240 O 2006-10-16 17 16.4 11.4
13 23973 BARBARA MARTINS BASTIAO PIRES 8240 O 2006-09-18 8.9 11.2 4.5
14 35007 SANDRA CRISTINA LEAL DA GRACA 8220 O 2006-11-30 18.5 15.7 8.8
15 38461 JOSE MANUEL VIEIRA DE ALMEIDA RAMOS 8004 O 2006-09-05 16.7 19.4 9.4
16 10679 JOAO MANUEL MOREIRA CONCEICAO ANDRADE 8204 O 2006-11-21 15.4 15.5 6.5
17 34385 NARCISO RESENDE SILVA 8028 T 2007-01-31 11.2 8.8 4.2
18 38063 RUI MIGUEL ALVES FERNANDES PALHA 8004 O 2006-09-05 16.3 13 4.7
19 37347 ROBERT DE FERNANDES 8028 O 2006-09-05 13.1 16.1 4.4
20 24983 SANDRA ELISABETE PINHEIRO MORGADO CORREIA 8004 O 2006-09-05 10 7.6 7.5

View File

@ -0,0 +1,18 @@
Numero Nome Curso Regime DataInscricao nota1 nota2 nota3
41387 RICARDO EMANUEL AMARAL VARAO 8204 O 2006-09-19 16.9 15.5 12.4
10247 JOSE DOMINGOS MARTINS LOURENCO 8004 O 2006-09-05 13.4 13.3 8.9
42738 RICARDO ANDRADE SILVEIRA MONTEIRO AMARAL 8220 O 2006-09-20 16.7 12 11.8
34865 PEDRO MANUEL VELEIRINHO MARTINS 8040 O 2006-09-05 17.9 18.4 9.3
30186 HUGO RICARDO SERRA CONCEICAO CUNHA 8004 O 2006-09-07 10.4 13.2 11.7
42206 MARTA ISABEL DE SOUSA 8204 O 2006-10-03 10.4 12.4 10.7
38569 JOAO GONCALO LAGARINHOS FELGUEIRAS 8004 O 2006-09-05 11.1 13.9 3.5
41084 RICARDO JORGE MOREIRA SILVA MACHADO 8240 O 2006-09-19 12.2 15 6.9
42413 SERGIO FILIPE MARTINS 8240 O 2006-09-20 13.7 8.8 4.6
36406 MARIANA PEREIRA VIEIRA 8004 O 2006-09-05 17.3 18 7.9
39065 MIGUEL ANTUNES RODRIGUES FONSECA RIBEIRO 8004 O 2006-09-05 10.2 10.7 3.9
42576 TIAGO RAFAEL PEREIRA MARQUES PISCO 8204 O 2006-09-22 15 17.1 11.3
39256 SALOME SANTOS PEREIRA 8220 O 2006-09-22 13 17.2 12
43267 ELTON MONTEIRO GOMES 8240 O 2006-10-30 14 14.2 7.8
39442 WING LUEN PINGUELO 8240 O 2006-09-06 12.8 11.4 6.9
41247 DIOGO FRANCO CRUZ 8204 O 2006-09-18 12.7 9 12.8
9634 ANA PAULA ARANTES MORAIS 8020 O 2006-11-27 17.9 16.3 10.8
1 Numero Nome Curso Regime DataInscricao nota1 nota2 nota3
2 41387 RICARDO EMANUEL AMARAL VARAO 8204 O 2006-09-19 16.9 15.5 12.4
3 10247 JOSE DOMINGOS MARTINS LOURENCO 8004 O 2006-09-05 13.4 13.3 8.9
4 42738 RICARDO ANDRADE SILVEIRA MONTEIRO AMARAL 8220 O 2006-09-20 16.7 12 11.8
5 34865 PEDRO MANUEL VELEIRINHO MARTINS 8040 O 2006-09-05 17.9 18.4 9.3
6 30186 HUGO RICARDO SERRA CONCEICAO CUNHA 8004 O 2006-09-07 10.4 13.2 11.7
7 42206 MARTA ISABEL DE SOUSA 8204 O 2006-10-03 10.4 12.4 10.7
8 38569 JOAO GONCALO LAGARINHOS FELGUEIRAS 8004 O 2006-09-05 11.1 13.9 3.5
9 41084 RICARDO JORGE MOREIRA SILVA MACHADO 8240 O 2006-09-19 12.2 15 6.9
10 42413 SERGIO FILIPE MARTINS 8240 O 2006-09-20 13.7 8.8 4.6
11 36406 MARIANA PEREIRA VIEIRA 8004 O 2006-09-05 17.3 18 7.9
12 39065 MIGUEL ANTUNES RODRIGUES FONSECA RIBEIRO 8004 O 2006-09-05 10.2 10.7 3.9
13 42576 TIAGO RAFAEL PEREIRA MARQUES PISCO 8204 O 2006-09-22 15 17.1 11.3
14 39256 SALOME SANTOS PEREIRA 8220 O 2006-09-22 13 17.2 12
15 43267 ELTON MONTEIRO GOMES 8240 O 2006-10-30 14 14.2 7.8
16 39442 WING LUEN PINGUELO 8240 O 2006-09-06 12.8 11.4 6.9
17 41247 DIOGO FRANCO CRUZ 8204 O 2006-09-18 12.7 9 12.8
18 9634 ANA PAULA ARANTES MORAIS 8020 O 2006-11-27 17.9 16.3 10.8

View File

@ -0,0 +1,23 @@
Numero Nome Curso Regime DataInscricao nota1 nota2 nota3
42372 RITA DANIELA VENTURA REAL 8204 O 2006-09-22 17.8 19.6 11.8
11885 VASCO JOAO NOGUEIRA COSTA ALVES 8004 O 2006-10-06 18.2 17.9 6.7
8540 VITOR MANUEL ANICETO PALHINHA 8004 O 2006-11-21 18.2 16 14.6
29826 MARCOS RAFAEL FORTUNA ALMEIDA MARTINS 8004 O 2006-11-21 11.6 11 5
34601 ERIC DE MELO FERREIRA 8220 O 2006-10-04 12 16.4 7.1
42608 HUGO BORGES SILVA SANTOS LOPES 8204 O 2006-10-03 16.8 17 15.2
42709 DIOGO TRIBUNA 8204 O 2006-09-20 12.6 14.1 8
43222 MARCO RODRIGUES 8240 O 2006-10-16 11.8 11.7 7.4
36114 JOSE LINO FERREIRA 8004 O 2006-09-07 12 17.9 3.9
28939 JOANA INES LIMA PEREIRA DOS SANTOS MOTA 8028 O 2006-09-05 15.9 15.5 8.2
38873 SARA CRISTINA HENRIQUES LOPES 8004 O 2006-09-05 10.6 6.7 3.8
29117 CLAUDIA MARIA SILVA CAMACHO 8004 O 2006-09-05 13.1 14.9 6.9
9419 MARIO JORGE MANECAS 8004 O 2006-09-05 10.4 7.7 8.6
42518 BRUNO FILIPE AMARO DOS SANTOS 8204 O 2006-09-20 15.5 17.2 12
19855 HENRIQUE EDUARDO ALMEIDA 8004 O 2006-11-21 13 16.9 6.9
26095 JOAO CARLOS DA COSTA 8220 O 2006-09-05 11.1 8.2 10.1
42717 EDUARDO AIRES GANDRA 8204 O 2006-09-20 11.4 12.3 4.1
42821 RICARDO MIGUEL MONTEIRO 8204 O 2006-10-03 8.8 9.2 1.8
39840 JOAO FILIPE MAGALHAES CARVALHO PINTO 8240 O 2006-11-30 17.5 17.2 18.5
39313 DIOGO MANUEL DA CORTE 8240 O 2006-09-07 13.3 17.7 10.7
40301 FILIPE MIGUEL FIGUEIREDO DA SILVA 8240 O 2006-09-05 11 13 4.5
36129 SARA LEITAO MARQUES 8028 O 2006-09-05 14.3 13.3 5.3
1 Numero Nome Curso Regime DataInscricao nota1 nota2 nota3
2 42372 RITA DANIELA VENTURA REAL 8204 O 2006-09-22 17.8 19.6 11.8
3 11885 VASCO JOAO NOGUEIRA COSTA ALVES 8004 O 2006-10-06 18.2 17.9 6.7
4 8540 VITOR MANUEL ANICETO PALHINHA 8004 O 2006-11-21 18.2 16 14.6
5 29826 MARCOS RAFAEL FORTUNA ALMEIDA MARTINS 8004 O 2006-11-21 11.6 11 5
6 34601 ERIC DE MELO FERREIRA 8220 O 2006-10-04 12 16.4 7.1
7 42608 HUGO BORGES SILVA SANTOS LOPES 8204 O 2006-10-03 16.8 17 15.2
8 42709 DIOGO TRIBUNA 8204 O 2006-09-20 12.6 14.1 8
9 43222 MARCO RODRIGUES 8240 O 2006-10-16 11.8 11.7 7.4
10 36114 JOSE LINO FERREIRA 8004 O 2006-09-07 12 17.9 3.9
11 28939 JOANA INES LIMA PEREIRA DOS SANTOS MOTA 8028 O 2006-09-05 15.9 15.5 8.2
12 38873 SARA CRISTINA HENRIQUES LOPES 8004 O 2006-09-05 10.6 6.7 3.8
13 29117 CLAUDIA MARIA SILVA CAMACHO 8004 O 2006-09-05 13.1 14.9 6.9
14 9419 MARIO JORGE MANECAS 8004 O 2006-09-05 10.4 7.7 8.6
15 42518 BRUNO FILIPE AMARO DOS SANTOS 8204 O 2006-09-20 15.5 17.2 12
16 19855 HENRIQUE EDUARDO ALMEIDA 8004 O 2006-11-21 13 16.9 6.9
17 26095 JOAO CARLOS DA COSTA 8220 O 2006-09-05 11.1 8.2 10.1
18 42717 EDUARDO AIRES GANDRA 8204 O 2006-09-20 11.4 12.3 4.1
19 42821 RICARDO MIGUEL MONTEIRO 8204 O 2006-10-03 8.8 9.2 1.8
20 39840 JOAO FILIPE MAGALHAES CARVALHO PINTO 8240 O 2006-11-30 17.5 17.2 18.5
21 39313 DIOGO MANUEL DA CORTE 8240 O 2006-09-07 13.3 17.7 10.7
22 40301 FILIPE MIGUEL FIGUEIREDO DA SILVA 8240 O 2006-09-05 11 13 4.5
23 36129 SARA LEITAO MARQUES 8028 O 2006-09-05 14.3 13.3 5.3

View File

@ -0,0 +1,60 @@
Numero Nome Nota
8540 VITOR MANUEL ANICETO PALHINHA 16.3
9419 MARIO JORGE MANECAS 8.9
9634 ANA PAULA ARANTES MORAIS 15.0
10247 JOSE DOMINGOS MARTINS LOURENCO 11.9
10679 JOAO MANUEL MOREIRA CONCEICAO ANDRADE 12.5
11885 VASCO JOAO NOGUEIRA COSTA ALVES 14.3
19855 HENRIQUE EDUARDO ALMEIDA 12.3
23973 BARBARA MARTINS BASTIAO PIRES 8.2
24983 SANDRA ELISABETE PINHEIRO MORGADO CORREIA 8.4
26095 JOAO CARLOS DA COSTA 9.8
28939 JOANA INES LIMA PEREIRA DOS SANTOS MOTA 13.2
29117 CLAUDIA MARIA SILVA CAMACHO 11.6
29826 MARCOS RAFAEL FORTUNA ALMEIDA MARTINS 9.2
30186 HUGO RICARDO SERRA CONCEICAO CUNHA 11.8
30759 ELISABETE CLAUDIA SANTOS SILVA SOARES 16.5
33955 NUNO JOSE SILVA DOS SANTOS MAGALHAES DA COSTA 9.5
34385 NARCISO RESENDE SILVA 8.1
34601 ERIC DE MELO FERREIRA 11.8
34801 ABEL LUIS DIAS CARAPICHOSO 15.7
34865 PEDRO MANUEL VELEIRINHO MARTINS 15.2
35007 SANDRA CRISTINA LEAL DA GRACA 14.3
36114 JOSE LINO FERREIRA 11.3
36129 SARA LEITAO MARQUES 11.0
36406 MARIANA PEREIRA VIEIRA 14.4
36700 DAVID JOAO CASTILLO CARVALHO 10.2
37347 ROBERT DE FERNANDES 11.2
38063 RUI MIGUEL ALVES FERNANDES PALHA 11.3
38461 JOSE MANUEL VIEIRA DE ALMEIDA RAMOS 15.2
38569 JOAO GONCALO LAGARINHOS FELGUEIRAS 9.5
38873 SARA CRISTINA HENRIQUES LOPES 7.0
39065 MIGUEL ANTUNES RODRIGUES FONSECA RIBEIRO 8.3
39256 SALOME SANTOS PEREIRA 14.1
39313 DIOGO MANUEL DA CORTE 13.9
39442 WING LUEN PINGUELO 10.4
39450 RUI BARBOSA SOARES FIGUEIREDO 12.9
39652 FABIO ANDRE SABINO REAL 11.4
39840 JOAO FILIPE MAGALHAES CARVALHO PINTO 17.7
40301 FILIPE MIGUEL FIGUEIREDO DA SILVA 9.5
40747 JOEL DOS SANTOS MIRANDA 17.0
41084 RICARDO JORGE MOREIRA SILVA MACHADO 11.4
41247 DIOGO FRANCO CRUZ 11.5
41387 RICARDO EMANUEL AMARAL VARAO 14.9
42003 LUIS CARLOS FIGUEIREDO PAULO 16.6
42206 MARTA ISABEL DE SOUSA 11.2
42304 JOAO PEDRO PEREIRA 17.3
42372 RITA DANIELA VENTURA REAL 16.4
42413 SERGIO FILIPE MARTINS 9.0
42518 BRUNO FILIPE AMARO DOS SANTOS 14.9
42576 TIAGO RAFAEL PEREIRA MARQUES PISCO 14.5
42608 HUGO BORGES SILVA SANTOS LOPES 16.3
42709 DIOGO TRIBUNA 11.6
42717 EDUARDO AIRES GANDRA 9.3
42738 RICARDO ANDRADE SILVEIRA MONTEIRO AMARAL 13.5
42821 RICARDO MIGUEL MONTEIRO 6.6
42847 NELSON MIGUEL BREDA COELHO 11.1
43021 NUNO MIGUEL MOGAS DA SILVA 14.9
43222 MARCO RODRIGUES 10.3
43267 ELTON MONTEIRO GOMES 12.0

View File

@ -0,0 +1,28 @@
import os
from sys import argv
def main():
path = argv[1] if len(argv) > 1 else os.getcwd()
printFilesSize(path)
def printFilesSize(path):
print(f'|{"-"*35}|')
print(f'| {"File":<20} {"Size":>12} |\n|{"-"*35}|')
for file in os.listdir(path):
base_size = os.stat(f'{path}/{file}').st_size
if base_size < 1024:
size = str(base_size) + ' B'
elif base_size < 1024 ** 2:
size = f'{base_size // 1024}.{str(base_size % 1024)[0]} KB'
elif base_size < 1024 ** 3:
size = f'{base_size // (1024**2)}.{str(base_size % (1024**2))[0]} MB'
else:
size = f'{base_size // (1024**3)}.{str(base_size % (1024**3))[0]} GB'
print(f'| {file:<20} {size:>12} |')
print(f'|{"-"*35}|')
if __name__ == "__main__":
main()

26
1ano/fp/aula06/filesum.py Normal file
View File

@ -0,0 +1,26 @@
from tkinter import filedialog
def main():
# 1) Pedir nome do ficheiro (usando alternativa #B):
name = filedialog.askopenfilename(title="Choose File")
# 2) Calcular soma dos números no ficheiro:
total = fileSum(name)
# 3) Mostrar a soma:
print("Sum:", total)
def fileSum(filename):
# Complete a função para ler números do ficheiro e devolver a sua soma.
with open(filename, 'r') as f:
lines = f.readlines()
total = 0
for line in lines:
total += float(line)
return total
if __name__ == "__main__":
main()

View File

@ -0,0 +1,36 @@
import math
def floatInput(prompt, min=-math.inf, max=math.inf):
assert min < max, 'ERROR: O valor mínimo é superior ao máximo!'
try:
res = float(input(prompt))
if (res < min) or (res > max):
print(f"ERROR: Value should be in [{min}, {max}]!")
floatInput(prompt, min, max)
return res
except ValueError:
print("ERROR: Not a float!")
floatInput(prompt)
def main():
print("a) Try entering invalid values such as 1/2 or 3,1416.")
v = floatInput("Value? ")
print("v:", v)
print("b) Try entering invalid values such as 15%, 110 or -1.")
h = floatInput("Humidity (%)? ", 0, 100)
print("h:", h)
print("c) Try entering invalid values such as 23C or -274.")
t = floatInput("Temperature (Celsius)? ", min=-273.15)
print("t:", t)
# d) What happens if you uncomment this?
# impossible = floatInput("Value in [3, 0]? ", min=3, max=0)
return
if __name__ == "__main__":
main()

50
1ano/fp/aula06/school.py Normal file
View File

@ -0,0 +1,50 @@
# Complete o programa!
# a)
def loadFile(fname, lst):
with open(fname, 'r') as f:
for line in f:
line = line.strip('\n')
if not line[0].isnumeric():
continue
data = line.split('\t')
dataTuple = (int(data[0]), data[1], float(data[5]), float(data[6]), float(data[7]))
lst.append(dataTuple)
# b) Crie a função notaFinal aqui...
def notaFinal(reg):
return sum(reg[2:]) / 3
# c) Crie a função printPauta aqui...
# 4. Alterar a função...
def printPauta(lst, filename=""):
text = f'{"Numero":>6} {"Nome":^50} {"Nota":>4}\n'
for aluno in lst:
text += f'{aluno[0]:>6} {aluno[1]:^50} {notaFinal(aluno):>4.1f}\n'
if filename == "":
print(text)
else:
print(text, file=open(filename, 'w'))
# d)
def main():
lst = []
# ler os ficheiros (encontram-se na pasta 'datafiles' (~/1ano/fp/aula06/datafiles)
loadFile("datafiles/school1.csv", lst)
loadFile("datafiles/school2.csv", lst)
loadFile("datafiles/school3.csv", lst)
# ordenar a lista
lst.sort()
# mostrar a pauta
printPauta(lst, filename="datafiles/schooldata.txt")
# Call main function
if __name__ == "__main__":
main()

View File

@ -0,0 +1,27 @@
# Exercise 5 on "How to think like a computer scientist", ch. 11.
import turtle
def main():
t = turtle.Turtle()
# Use t.up(), t.down() and t.goto(x, y)
# Put your code here
with open("datafiles/drawing.txt", 'r') as f:
for line in f.readlines():
if line == "UP\n":
t.up()
elif line == "DOWN\n":
t.down()
else:
x, y = line.split()
t.goto(int(x), int(y))
# wait
turtle.Screen().exitonclick()
if __name__ == "__main__":
main()