Beginner and first time asker here! I’ve run into a problem with my first project.
I’m trying to write a class method that adds an hour on to the current time for every 180 within a big number.
I’m only testing a basic version at the moment, but I cant get it to work, the hour stays the same despite incrementing the hour variable.
(e.g. if the time now was 1:00pm and the user typed 540 cases, it would return:
“360 should be remaining at: 2:00pm”
“180 should be remaining at
3:00pm” “0 should be remaining at 4:00pm”
What it actually does is:
“360 should be remaining at: 2:00pm”
“180 should be remaining at 2:00pm”
“0 should be remaining at 2:00pm”
def hourly_time_formula(self):
c = self.cases
hour = 1
nextHour = datetime.now() + timedelta(hours = hour)
neat_time = nextHour.strftime("%H:%M:%S")
if c > 180:
while c >= 180:
ihour += 1
c -= 180
print(f"{c - 180} should be remaining at {neat_time}")
Thanks in advance!
>Solution :
You’re not updating the neat_time variable. This is what you likely want:
def hourly_time_formula(self):
c = self.cases
hour = 0
if c > 180:
while c >= 180:
hour += 1
c -= 180
nextHour = datetime.now() + timedelta(hours = hour)
neat_time = nextHour.strftime("%H:%M:%S")
print(f"{c - 180} should be remaining at {neat_time}")