Weekend counter
Weekend counter
Sofia has given you a schedule and two dates and told you she needs help planning her weekends. She has asked you to count each day of rest (Saturday and Sunday) starting from the initial date to final date. You should count the initial and final dates if they fall on a Saturday or Sunday.
The dates are given as datetime.date (Read about this module here). The result is an integer.
Input: Start and end date as datetime.date.
Output: The quantity of the rest days as an integer.
原题链接: http://www.checkio.org/mission/weekend-counter/
题目大义: 数一段日期间内的周六周日数
from datetime import date def checkio(from_date, to_date):
"""
Count the days of rest
"""
rel = 0
while from_date <= to_date:
if from_date.weekday() == 5 or from_date.weekday() == 6:
rel += 1
from_date += date.resolution return rel
date.resolution(day + 1)是时间步进1, 日+1
观摩veky的代码
def checkio(d1, d2):
w1, w2 = d1.weekday(), d2.weekday()
count = (d2 - d1).days // 7 * 2
while True:
count += w2 > 4
if w1 == w2: return count
w2 = (w2 - 1) % 7
思路不错, 首先计算两个日期间的天数, 地板除7, 再乘2; 再处理其他的天数, 第五行, 或许加个括号更好理解count += (w2 > 4)
Weekend counter的更多相关文章
- UNITY自带的PACKAGE的UTILITY 里面有一个自带的FPS COUNTER
UNITY自带的PACKAGE的UTILITY 里面有一个自带的FPS COUNTER 可用,但是脚本是保密的?
- [LeetCode] Design Hit Counter 设计点击计数器
Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...
- collections 模块(namedtuple, deque, Counter )
基本介绍 我们都知道,Python拥有一些内置的数据类型,比如str, int, list, tuple, dict等, collections模块在这些内置数据类型的基础上,提供了几个额外的数据类型 ...
- Performance Monitor2:Peformance Counter
Performance Counter 是量化系统状态或活动的一个数值,Windows Performance Monitor在一定时间间隔内(默认的取样间隔是15s)获取Performance Co ...
- Python_Day_05 计数器(counter),有序字典(OrderDict),默认字典(defaultdict),可命名元祖(namedtuple),双向队列(deque),单项队列(deuqe.Queue)
Counter(计数器) 是一个字典的子类,存储形式同样为字典,其中存储的键为字典的元素,值为元素出现的次数,在使用之前我们需要先导入文件 import collections 初始化一个计数器 im ...
- 利用CSS计数函数counter()实现计数
要实现li列表计数比较简单,直接设置list-style-type即可,但是要实现非li列表计数该怎么办呢,counter()可以轻松实现 body{counter-reset:section 0 s ...
- 计数器(counter),有序字典(OrderDict),默认字典(defaultdict),可命名元祖(namedtuple),双向队列(deque),单项队列(deuqe.Queue)
Python_Day_05 计数器(counter),有序字典(OrderDict),默认字典(defaultdict),可命名元祖(namedtuple),双向队列(deque),单项队列(deuq ...
- LeetCode Design Hit Counter
原题链接在这里:https://leetcode.com/problems/design-hit-counter/. 题目: Design a hit counter which counts the ...
- CacheManager COUNTER
CacheClient.AddOrUpdate("COUNTER", 0, v => Convert.ToInt32(v) + 1);
- codeforces 495A. Digital Counter 解题报告
题目链接:http://codeforces.com/problemset/problem/495/A 这个题目意思好绕好绕~~好绕~~~~~,昨天早上做得 virtual 看不懂,晚上继续看还是,差 ...
随机推荐
- BZOJ1671: [Usaco2005 Dec]Knights of Ni
1671: [Usaco2005 Dec]Knights of Ni Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 175 Solved: 107[Su ...
- linq 跨库查询
可以用多个DBContext,例如有DBContext1和DBContext2,但是不能将两个DBContext用在同一个查询中,可以分开,先用一个查出结果集1,再在第二个查询中使用结果集1就可以了
- 页面onclick()中传值问题
html中onclick()里面传变量到javascript中的问题,小小的记录下: 传变量的话一定要加 '' <span onclick="sellGoods('${session ...
- Unity怎样在Editor下运行协程(coroutine)
在处理Unity5新的AssetBundle的时候,我有一个需求,须要在Editor下(比方一个menuitem的处理函数中,游戏没有执行.也没有MonoBehaviour)载入AssetBundle ...
- c/c++ 复习基础要点01-const指针、指针函数 函数指针、new/delete与malloc/free区别与联系
1. 引用本身是有指针实现的:引用为只读指针 例子: int d=123; int& e=d; //引用 int * const e=d; //只读指针,e指向d,不可修改e指 ...
- [Redux] Extracting Presentational Components -- TodoApp
Finally, I just noticed that the to-do app component doesn't actually have to be a class. I can turn ...
- Ubuntu 14.04根据系统,休眠后不能启动要解决的问题
简介: 提升Ubuntu制度14.04之后,当系统进入休眠,我们不能再次启动,直接崩溃,凡出了问题? 1. 问题纳入 Ubuntu升级系统14.04之后.通过系统的Power设置休眠时间,在系统进 ...
- IOS开发之格式化日期时间
IOS开发之格式化日期时间(转) 在开发iOS程序时,有时候需要将时间格式调整成自己希望的格式,这个时候我们可以用NSDateFormatter类来处理. 例如: //实例化一个NSDateFor ...
- Gson源码分析之Json结构抽象和注解使用
github上的博客地址: http://chuyun923.github.io/blog/2015/01/06/gsonyuan-ma-fen-xi/ XML和Json作为最常用的两种网络传输格式而 ...
- kvm 启动libvirtd市出现错误
kvm 启动libvirtd市出现错误: /etc/init.d/libvirtd start启动 libvirtd 守护进程:libvirtd: relocation error: libvirtd ...