克里斯保罗
发表于 2019-8-31 11:35:29
import datetime
if __name__ =='__main__':
date= input('请输入入职日期:')
old_date = datetime.datetime.strptime(date,format('%Y-%m-%d'))
new_date = datetime.datetime.now()
days =new_date-old_date
days = str(days).split('d')
print('您一共入职了%s天'%days)
janeari
发表于 2019-9-10 14:08:01
学习了
华一仙
发表于 2020-2-23 09:54:11
# 即使 60 退休,入职期间也只有 4 年一届的闰年
def is_leap_year(year):
return year % 4 == 0
def days_in_year(month, day):
months = # Dec. 用不上
return sum(months[:month]) + day
# 因为每天要写,所以全年无休
def f24(year, month, day):
if year < 2014:
return -1
elif year == 2014:
if month < 8 or (month == 8 and day < 18):
return -1
else:
return days_in_year(month, day) - days_in_year(8, 17)
else:
res = 365 - days_in_year(8, 17)
for y in range(2015, year):
res += 365
if is_leap_year(y):
res += 1
res += days_in_year(month, day)
if (month == 2 and day == 29) or (month > 2 and is_leap_year(year)):
res += 1
return res
夏日之巅
发表于 2020-2-23 10:54:00
感谢分享
youngorc
发表于 2020-4-17 09:23:11
import numpy as np
def count_days(date):
date=np.datetime64(date)
start_date=np.datetime64('2017-04-19')
datediff=date-start_date
return datediff
date=input('请输入当天日期,格式为YYYY-MM-DD:')
datediff=count_days(date).astype('int')
print("今天是小陆上班的第%s天"%(datediff))
san1412
发表于 2020-5-22 13:27:23
print("请输入今天的日期")
years2 = int(input("年:"))
months2 = int(input("月:"))
days2 = int(input("日:"))
years = 2014
months = 8
days = 18
n = 1
while years <= years2 :
#判断是否为闰年
month_day =
if years % 4 != 0: month_day = 28
elif years % 4 == 0: month_day = 29
while days <= month_day:
print("%d年%2d月%2d日,入职第%d天-小陆"%(years,months,days,n))
n += 1
if years < years2: days += 1
elif months < months2: days += 1
elif days < days2: days += 1
else: break
if days > month_day:
days = 1
if months < 12 and years < years2: months += 1
elif months < months2 and years == years2: months += 1
else:break
years += 1
months = 1
days = 1
if years > years2: print("现在是%d年%d月%d日,小陆上班%d天了"%(years2,months2,days2,n-1))
请输入今天的日期
年:2017
月:4
日:19
2014年 8月18日,入职第1天-小陆
2014年 8月19日,入职第2天-小陆
2014年 8月20日,入职第3天-小陆
……
2017年 4月18日,入职第975天-小陆
2017年 4月19日,入职第976天-小陆
现在是2017年4月19日,小陆上班976天了
nononoyes
发表于 2020-6-5 14:29:24
'''
小陆每天要写一份工作日报,日报标准是“入职第X天-小陆”,对于“入职第几天”,小陆现在每次需要对上次写的日报标题里的天数+1。
请你写一段程序,帮小陆自动完成这件事。
提供写日期当天的年月日,算出已入职的天数(假定小陆的入职时间是 2014年8月18日)。
现在是2017年4月19日,问小陆上班几天了?
要求:不能使用时间,日期相关的库函数。
'''
#定义一个方法,来判断这一天是这一年的第几天:
def fun(year,month,day):
# 定义天数的list
listDay =
# 定义theDay来存放是这一年的第几天
theDay = 0
ifmonth == 2:
theDay = 31 + day
elif month == 1:
theDay = day
elif month>2:
if year%4 == 0 and year%100 != 0 or year%400 == 0:
for i in range(1,month):
theDay += listDay
theDay = theDay+1+day
else:
for i in range(1,month):
theDay += listDay
theDay =theDay+day
return theDay
day = fun(2015,12,31)+fun(2016,12,31)+fun(2017,4,19)+fun(2014,12,31)-fun(2014,8,18)+1
print(day)
谢啾啾
发表于 2020-11-4 17:05:22
date1 = input('请输入入职日期(用‘-’进行分隔):')
date2 = input('请输入目前日期(用‘-’进行分隔):')
year1 = int(date1.split('-'))
month1 = int(date1.split('-'))
day1 = int(date1.split('-'))
year2 = int(date2.split('-'))
month2 = int(date2.split('-'))
day2 = int(date2.split('-'))
month_day =
days_1 = 0
days_2 = 0
sums = 0
def calc_year2():
global days_2
if (year2%4==0 and year2%100!=0) or year2%400==0:
if month2 > 2:
days_2 = sum(month_day[:month2 - 1]) + day2 + 1
else:
days_2 = sum(month_day[:month2 - 1]) + day2
else:
days_2 = sum(month_day[:month2-1]) + day2
def calc_year1():
global days_1
if (year1%4==0 and year1%100!=0) or year1%400==0:
if month1 > 2:
days_1 = 366-(sum(month_day[:month1 - 1]) + day1 + 1)
else:
days_1 = 366-(sum(month_day[:month1 - 1]) + day1)
else:
days_1 = 365-(sum(month_day[:month1-1]) + day1)
def calc_interval(n):
global sums
for i in range(1, n):
if ((year1+i) % 4 == 0 and (year1+i) % 100 != 0) or (year1+i) % 400 == 0:
sums += 366
else:
sums += 365
calc_year1()
calc_year2()
calc_interval(year2-year1)
total_day = days_1 + days_2 + sums
print('入职第%d天-小陆'%total_day)
利用了一下前面学的天数计算的方法{:10_264:}(拿来主义hhhhhh)
aironeng
发表于 2020-11-27 08:55:46
学习
896654661
发表于 2020-11-29 15:09:01
这题我不会...学习了
sanchuan555
发表于 2020-12-25 20:47:24
start_year=2014
start_month=8
start_day=18
end_year=2017
end_month=4
end_day=19
count=0
month1_day={1:31,2:28,3:31,4:30,5:31,6:30,7:31,
8:31,9:30,10:31,11:30,12:31}
month2_day={1:31,2:29,3:31,4:30,5:31,6:30,7:31,
8:31,9:30,10:31,11:30,12:31}
count=count+end_day
end_month=end_month-1
while end_month > 0:
day = month1_day
count = count + day
end_month -= 1
for year in range(start_year+1,end_year):
month=12
if year%4==0:
while month>0:
day = month2_day
month -= 1
count = count + day
else:
while month>0:
day = month1_day
month = month - 1
count = count + day
month=12
while month>start_month:
day = month1_day
month = month - 1
count = count + day
count=count+(month1_day-start_day)
print(count)
大体框架已经弄好了,有点急,就不搞那么细了