Python 连续增加一个值,如果日期更改,则将变量设置为零

Python 连续增加一个值,如果日期更改,则将变量设置为零,python,Python,但是如果日期发生变化,x的值应该变为零,并且需要再次开始递增。那么我的输出应该如下 from datetime import datetime, date import time x = 0 def main(): global x while(1): x = x+1 print(x) today_date = date.today() print(today_date) time.sleep(10)

但是如果日期发生变化,x的值应该变为零,并且需要再次开始递增。那么我的输出应该如下

from datetime import datetime, date
import time
x = 0
def main():
    global x
    while(1):
        x = x+1
        print(x)
        today_date = date.today()
        print(today_date)
        time.sleep(10)

main()

有人能帮我吗

1
2020-05-06
2
2020-05-06
.
.
1
2020 -05-07
2
2020-05-07
.
.
.
from datetime import datetime, date
import time
x = 0
last_date = date.today()
def main():
    global x
    while(1):
        x = x+1
        print(x)
        today_date = date.today()
        if last_date != today_date:
            x = 0
            last_date = today_date   
        print(today_date)
        time.sleep(10)

main()
import time
from datetime import date
def Cnt():
     cur = date.today()
     old = None
     x = 0
     while True:
         old, cur = cur, date.today()
         if cur != old:
             x = 1
         else:
             x += 1
         yield str(cur), str(x)

 cnt = Cnt()
 while True:
     print('\n'.join(next(cnt))
     time.sleep(10)