1

I have three variables

a = 1

b = 2

c = 3

Every day, I need to add 1 to each variable

a = a + 1 (so a=2)

b = b + 1

c = c + 1

But I need that when tomorrow I run the script, to add 1 unit more:

a = a + 2 (so tomorrow a=3, after 2 days a = 4....)

b = b + 2

c = c + 2

And so on...I need every day to add +1.

Any ideas?

Pren Ven
  • 177
  • 1
  • 10
  • 2
    What happens if you forget to run the script one day? Have you considered storing the date when the script was first run so that you can figure things out subsequently. Also, it's highly likely that most people reading this will know that 1+1==2 but thanks for the reminder – DarkKnight May 21 '22 at 12:03
  • I think this link has your answer: https://stackoverflow.com/questions/6871016/adding-days-to-a-date-in-python – Ali May 21 '22 at 12:05

1 Answers1

2

Choose some fixed reference date, and when the code runs, calculate the number of days from the reference date, adjust by some constant offset, and add that to your variables. So, maybe I choose 1/1/2022 as my reference date and an offset of 100 days. This means on 100 days after 1/1/2022 the variables don't get increased at all, 101 days after 1/1/2022 the variables are greater by 1, and so on.

If you need to only increase if the script actually ran on a date, keep a log file of days the script actually ran, or for that matter, save the increments directly!

Patrick87
  • 27,682
  • 3
  • 38
  • 73