How do I add another input function where if the current day is Monday and we add 4 dates, the day to be returned is Friday? Been clueless for 2-3 hours now, it's frustrating as hell already
import operator
class DayOfTheWeek:
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
def __init__(self,day_name):
day_name = day_name.lower().capitalize()
if day_name not in self.days:
raise ValueError("Invalid day name.")
self.day = day_name
def __repr__(self):
return self.day
def _arithmetic_helper(self,other,operation):
if isinstance(other,int):
cur_day_index = self.days.index(self.day)
after_calc = operation(cur_day_index,other)
target_day_index = after_calc % len(self.days)
return type(self)(self.days[target_day_index])
else:
return NotImplemented
def __add__(self,other):
return self._arithmetic_helper(other,operator.add)
def __sub__(self,other):
return self._arithmetic_helper(other,operator.sub)
day = DayOfTheWeek(input("What day is it? "))
for i in range(1,5):
print(f"Day {i} days ago was {day - i}.")
for i in range(1,5):
print(f"Day {i} days from today will be {day + i}.")