aggiunge esercizio 40
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
class WeekDayError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class Weeker:
|
||||
__GIORNI = ['lun', 'mar', 'mer', 'gio', 'ven', 'sab', 'dom']
|
||||
|
||||
def __init__(self, day):
|
||||
if day not in Weeker.__GIORNI:
|
||||
raise WeekDayError("Giorno non valido: " + day)
|
||||
self.__day_index = Weeker.__GIORNI.index(day)
|
||||
|
||||
def __str__(self):
|
||||
return Weeker.__GIORNI[self.__day_index].capitalize()
|
||||
|
||||
def add_days(self, n):
|
||||
self.__day_index = (self.__day_index + n) % 7
|
||||
|
||||
def subtract_days(self, n):
|
||||
self.__day_index = (self.__day_index - n) % 7
|
||||
|
||||
|
||||
# --- TEST ---
|
||||
try:
|
||||
weekday = Weeker('lun')
|
||||
print(weekday)
|
||||
|
||||
weekday.add_days(15)
|
||||
print(weekday)
|
||||
|
||||
weekday.subtract_days(23)
|
||||
print(weekday)
|
||||
|
||||
weekday = Weeker('lunedì')
|
||||
except WeekDayError:
|
||||
print("Mi dispiace, non posso soddisfare la sua richiesta.")
|
||||
Reference in New Issue
Block a user