Solució de l’examen parcial d’Ampliació d’Informàtica - Torn 1¶
- Organització:
Secció ETSEIB, Departament de Ciències de la Computació, UPC
- Data:
31 d’octubre de 2024
- Durada:
1 hora i 10 minuts
- Copyright:
Reconeixement-CompartirIgual 3.0 No adaptada de Creative Commons
Jocs de proves
Els exemples que compten per la nota són només els que van seguits de
# doctesttag: +TAG=
Tests per a dia_mes_proper¶
>>> from dies import dia_mes_proper
>>> from datetime import date
>>> l1 = [date(2022, 2, 25), date(2024, 6, 15), date(2022, 6, 3), date(2020, 10, 28),
... date(2010, 7, 18), date(2030, 6, 27), date(2030, 1, 24), date(2000, 9, 11)]
>>> l2 = [date(2020, x, x) for x in range(1, 13)]
>>> dia_mes_proper(l1, date(2024, 7, 15)) # doctesttag: +TAG=1_dia_mes_proper
(datetime.date(2024, 6, 15), 30)
>>> dia_mes_proper(l2, date(2024, 1, 1)) # doctesttag: +TAG=1_dia_mes_proper
(datetime.date(2020, 12, 12), 1115)
>>> for x in range(1, 6): # doctesttag: +TAG=1_dia_mes_proper
... print(dia_mes_proper(l1, date(2012, 7, 3*x)))
(datetime.date(2010, 7, 18), 716)
(datetime.date(2010, 7, 18), 719)
(datetime.date(2010, 7, 18), 722)
(datetime.date(2010, 7, 18), 725)
(datetime.date(2010, 7, 18), 728)
>>> for x in range(1, 7): # doctesttag: +TAG=1_dia_mes_proper
... print(dia_mes_proper(l2, date(2012, x, 28)))
(datetime.date(2020, 1, 1), 2895)
(datetime.date(2020, 1, 1), 2864)
(datetime.date(2020, 1, 1), 2835)
(datetime.date(2020, 1, 1), 2804)
(datetime.date(2020, 1, 1), 2774)
(datetime.date(2020, 1, 1), 2743)
>>> for x in range(1, 7): # doctesttag: +TAG=1_dia_mes_proper
... print(dia_mes_proper(l1, date(2012+3*x, 12, 31)))
(datetime.date(2020, 10, 28), 1763)
(datetime.date(2020, 10, 28), 667)
(datetime.date(2022, 2, 25), 56)
(datetime.date(2024, 6, 15), 199)
(datetime.date(2030, 1, 24), 755)
(datetime.date(2030, 6, 27), 187)
Tests per a Motxilla¶
>>> import motxilla
>>> m = motxilla.Motxilla(3)
>>> m.nespais, m.objectes # doctesttag: +TAG=2_motxilla
(3, {})
>>> len(m) # doctesttag: +TAG=2_motxilla
0
>>> m.afegir(7, 'pedra')
>>> m.objectes # doctesttag: +TAG=2_motxilla
{'pedra': 7}
>>> m.nombre_objectes(), len(m) # doctesttag: +TAG=2_motxilla
(7, 1)
>>> m.afegir(100, 'herba')
>>> m.nombre_objectes(), len(m) # doctesttag: +TAG=2_motxilla
(107, 2)
>>> for x in ['pedra', 'sorra', 'herba', 'diamant']: # doctesttag: +TAG=2_motxilla
... print(m[x], end=',')
7,0,100,0,
>>> m.afegir(1000, 'pedra')
>>> m['pedra'] # doctesttag: +TAG=2_motxilla
1007
>>> m.afegir(100, 'sorra')
>>> m.afegir(13, 'sorra')
>>> m['sorra'] # doctesttag: +TAG=2_motxilla
113
>>> m.nombre_objectes(), len(m) # doctesttag: +TAG=2_motxilla
(1220, 3)
>>> m.afegir(11, 'mongeta')
>>> m.afegir(59, 'roca')
>>> m.nombre_objectes(), len(m) # doctesttag: +TAG=2_motxilla
(1220, 3)
>>> for x in ['pedra', 'sorra', 'herba', 'diamant', 'mongeta', 'roca']:
... print(m[x], end=',') # doctesttag: +TAG=2_motxilla
1007,113,100,0,0,0,
>>> m.treure('pedra')
>>> m.afegir(30, 'diamant')
>>> len(m), m.nombre_objectes() # doctesttag: +TAG=2_motxilla
(3, 243)
>>> for x in ['pedra', 'sorra', 'herba', 'diamant', 'mongeta', 'roca']:
... print(m[x], end=',') # doctesttag: +TAG=2_motxilla
0,113,100,30,0,0,
>>> m.treure('diamant')
>>> m.treure('herba')
>>> m.treure('sorra')
>>> m.treure('mongeta')
>>> len(m), m.nombre_objectes() # doctesttag: +TAG=2_motxilla
(0, 0)
Tests per a MotxillaLimit¶
>>> from motxilla_limit import MotxillaLimit
>>> m = MotxillaLimit(4, 20)
>>> m.nespais, len(m), m.nombre_objectes() # doctesttag: +TAG=3_motxillaLimit
(4, 0, 0)
>>> m.afegir(10, 'canya')
>>> m.espai('canya') # doctesttag: +TAG=3_motxillaLimit
10
>>> m.espai('tornavís') # doctesttag: +TAG=3_motxillaLimit
20
>>> m.afegir(12, 'tornavís')
>>> m.afegir(8, 'tornavís')
>>> len(m), m.nombre_objectes() # doctesttag: +TAG=3_motxillaLimit
(2, 30)
>>> m.espai('tornavís') # doctesttag: +TAG=3_motxillaLimit
0
>>> m.afegir(13, 'canya')
>>> m.espai('canya') # doctesttag: +TAG=3_motxillaLimit
10
>>> for x in ['tornavís', 'sorra', 'canya', 'diamant', 'roca']:
... print(m[x], m.espai(x), end=',') # doctesttag: +TAG=3_motxillaLimit
20 0,0 20,10 10,0 20,0 20,
>>> m.afegir(23, 'sorra')
>>> m['sorra'], len(m) # doctesttag: +TAG=3_motxillaLimit
(0, 2)
>>> m.afegir(10, 'mongeta')
>>> m.afegir(59, 'roca')
>>> m.afegir(8, 'diamant')
>>> len(m), m.nombre_objectes(), m.espai('patata') # doctesttag: +TAG=3_motxillaLimit
(4, 48, 0)
>>> for x in ['tornavís', 'sorra', 'canya', 'diamant', 'mongeta', 'roca']:
... print(m[x], m.espai(x), end=',') # doctesttag: +TAG=3_motxillaLimit
20 0,0 0,10 10,8 12,10 10,0 0,
>>> m.treure('tornavís')
>>> m['tornavís'], len(m), m.espai('tornavís')
(0, 3, 20)
>>> m.afegir(9, 'roca')
>>> m.treure('patata')
>>> m.treure('canya')
>>> m.afegir(25, 'diamant')
>>> for x in ['tornavís', 'sorra', 'canya', 'diamant', 'mongeta', 'roca', 'patata']:
... print(m[x], m.espai(x), end=',') # doctesttag: +TAG=3_motxillaLimit
0 20,0 20,0 20,8 12,10 10,9 11,0 20,
>>> len(m), m.nombre_objectes() # doctesttag: +TAG=3_motxillaLimit
(3, 27)
>>> m.treure('tornavís')
>>> m.afegir(15, 'marbre')
>>> m.afegir(8, 'or')
>>> m.afegir(10, 'plata')
>>> m.afegir(2, 'fusta')
>>> m.objectes == {'mongeta': 10, 'diamant': 8, 'roca': 9, 'marbre': 15} # doctesttag: +TAG=3_motxillaLimit
True