Blue Bridge Cup Python Group - Running Exercise

Blue Bridge Cup Python Group - Running Exercise

Topic description

This question is a fill-in-the-blank question. After calculating the result, use the output statement in the code to output the filled result.
Xiaolan exercises every day.
Under normal circumstances, Xiaolan runs 11 kilometers a day. If a day is Monday or the beginning of the month (11th), in order to motivate himself, Xiaolan has to run 22 kilometers. If it is Monday or the beginning of the month at the same time, Xiaolan also runs 22 kilometers.
Xiaolan has been running for a long time, from Saturday, November 11, 20002000 (inclusive) to Thursday, October 11, 2020, 2020 (inclusive). How many kilometers did Xiaolan run in total during this time?

Running limit
Maximum running time: 1s
Maximum running memory: 128M

import os
import sys
import datetime
a=datetime.date(2000,1,1)
b=datetime.date(2020,10,1)
ans=0
while a<=b:
    if a.isoweekday()==1 or a.day==1:# 是周一或者月初就跑两千米
        ans+=2
    else:
        ans+=1
    a+=datetime.timedelta(days=1)
print(ans)

The answer is 8879

Notice:

isoweekday() # returns 1-7, representing Monday to Sunday
weekday() # returns 0-6, representing Monday to Sunday

Thank you for your support. Your one-click three-connection is the biggest driving force for Ganggang students!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324322608&siteId=291194637