1141429506
发表于 2018-1-25 18:36:00
jerryxjr1220 发表于 2017-3-26 12:55
python的强大就在于有非常多好用的库,有现成的解决方案就不要重复造轮子了
要达到看到一个问题就能反映上来可以直接用哪个库里现成的方法来解决是要把所有的库都过一遍?
z1446773686
发表于 2018-2-7 15:01:30
def M_T(spare = 0 , M = 1 , day = 20):
count = 0
for each_day in range(0,(M - 1)):
if((M - 1) > 0):
count += today
if(spare == 0):
count += day
print('这是这年的第%d天' % count)
elif(spare == 1):
count += day + 1
print('这是这年的第%d天' % count)
elif(M - 1) == 0:
print('这是这年的第%d天' % day)
{:10_266:}可以放到闰年里了
>>> M_T()
这是这年的第20天
>>>
凌九霄
发表于 2018-2-13 11:17:32
本帖最后由 凌九霄 于 2018-2-13 11:55 编辑
#Python强大的地方就是各种模块齐全,直接调用,不用考虑繁杂的细节
import datetime
Y, M, D =
day1 = datetime.date(Y, 1, 1)
day2 = datetime.date(Y, M, D)
print("输入的日期是{0}年中的第{1}天".format(Y, day2.__sub__(day1).days + 1))
#更简单的实现
import time
day = input("请输入日期(YYYYMMDD):")
struct_time = time.strptime(day, "%Y%m%d")
print("输入日期为{0}年中的第{1}天 :".format(struct_time.tm_year, struct_time.tm_yday))
ultraji
发表于 2018-2-19 11:19:15
month_day = (0,31,28,31,30,31,30,31,31,30,31,30,31)
def isRun(x):
if x%400 == 0 or (x%100 != 0 and x%4 == 0):
return True
return False
tim = str(input())
year,month,date = int(tim),int(tim),int(tim)
day = 0
for i in range(0,month):
day += month_day
day += date
if isRun(year) and month > 2:
day += 1
print (day)
victor.xu
发表于 2018-3-2 11:18:16
def leap(n):
if (n % 4 == 0 and n % 100 != 0) or (n % 400 == 0):
return 1
else:
return 0
print('日期格式为:YYYY-MM-DD')
date = input('请输入日期:\n')
day =
lis = date.split('-')
Year = int(lis)
Month = int(lis)
Day = int(lis)
Flag = leap(Year)
count = Month - 1
if Month > 2:
result = sum(day) + Flag + Day
else:
result = sum(day)
print(result)
瞬秒爆加速
发表于 2018-3-3 15:56:39
pn =
def mtest(m):
if 0<m<=12:
return m
def dtest(d):
if m in :
if 0<d<=31:
return d
elif m in :
if 0<d<=30:
return d
elif m == 2 and (y% 4 == 0 or (y % 400 == 0 and y % 100 != 0)):
pn = 29
if 0<d<=pn:
return d
elif m == 2:
if 0<d<=pn:
return d
y = int(input("年 "))
m = int(input("月 "))
d = int(input("日 "))
print(sum(pn[:mtest(m)-1])+dtest(d))
benzhj
发表于 2018-3-8 11:04:55
新手·ing 发表于 2017-3-26 07:37
我的解答!
判读润年有误.:)
(年能整除4且不能整除100)或 (年能整除 400 ) 是润年!
benzhj
发表于 2018-3-8 11:19:35
#生成有效的年份及日期列表
y =
d =
#粗判断输入日期是否正确
while 1 :
a = input ("请输入年月日YYYYMMDD:")
year = int (a[:4])
month = int (a)
day = int(a)
if year in y and 0 < month < 13 andday in d:
break
else:
print ("输入错误!!!")
days = 0
monthday =
if month == 2:
days += 31
elif month >2:
for i in range (month-1):
days += monthday
days += day
#判断是否为润年
if ((year % 4 == 0 and year % 100 != 0) or year % 400 == 0) and month > 2:
days += 1
print ("这是本年第{}天".format(days))
tusumili
发表于 2018-3-11 19:38:37
import datetime
years = int(input('请输入哪年:'))
months = int(input('请输入哪月:'))
days = int(input('请输入哪日:'))
a = datetime.date(years,1,1)
b = datetime.date(years,months,days)
print((a.__rsub__(b).days)+1)
romell
发表于 2018-3-18 21:16:02
import calendar
def mdays(date):
year = int(date[:4])
month = int(date)
datetime = int(date)
days = 0
for i in range(1, month):
if month == 1:
days = datetime
print("今天是今年的第%d天" % days)
else:
monthdays = calendar.monthrange(year, i)
days += monthdays
if i == month - 1:
print("今天是今年的第%d天" % (days + datetime))
date = input("请按以下格式输入年月日(20160916):")
mdays(date)
zlfy1982
发表于 2018-3-23 09:38:39
m = input("请输入一个日期:")
a = m.split(m)
year = int(a)
month = int(a)
day = int(a)
days = 0
moth =
for i in range(1,month):
days =days+moth
if month> 2 and (year%4 ==0 or (year%100==0 and year%400)):
days = days +day+1
else:
days=days+day
print("这是%d年的%d天"%(year,days))
124646646
发表于 2018-3-26 01:10:05
def isyear(year):#闰年
if year%400 == 0 or (year%100 != 0and year%4 ==0):
return 1
else:
return 0
def day_year(month,days):#判断第几天
day =
if isyear(year):
add_day = 0
for eachin range(month):
add_day += day
return add_day+1
else:
add_day = 0
for eachin range(month):
add_day += day
return add_day
year = int(input("请输入年份:"))
month = int(input("请输入月份:"))
days = int(input("请输入天:"))
add_day1 = day_year(month,days)
print("这是%d年得第%d天。"%(year,add_day1))
124646646
发表于 2018-3-26 01:26:28
def isyear(year):#闰年
if year%400 == 0 or (year%100 != 0and year%4 ==0):
return 1
else:
return 0
def day_year(month,days):#判断第几天
day =
if isyear(year):
add_day = 0
for eachin range(month-1):
add_day += day
return add_day+1
else:
add_day = 0
for eachin range(month-1):
add_day += day
return add_day
while True:
print("是否继续(Y/N)")
if input("") == "Y":
year = int(input("请输入年份:"))
month = int(input("请输入月份:"))
days = int(input("请输入天:"))
if (0<month <=12) and (0<days<=31):
add_day1 = day_year(month,days)
print("这是%d年得第%d天。"%(year,add_day1))
else:
print("日期格式不对,\n一年只有十二个月,\n一月最多有三十一天。")
print("请新输入日期格式。")
continue
else:
break
小Gui
发表于 2018-4-4 17:17:23
year = input('pleses input years:')
while not year.isdigit():
year = input('输入错误,请输入整数')
yue = input('plese input yue:')
while not yue.isdigit()or 1 > int(yue) or int(yue) > 12:
yue = input('输入错误,请输入1-12的整数')
day = input('plese input day')
while not day.isdigit() or 1 > int(day) or int(day) > 31:
day = input('输入错误,请输入1-31之间的整数')
yue = int(yue)
day = int(day)
year = int(year)
months =
l = yue - 1
sun = months
sun = sun + day
if (year%4==0 or year%400==0)and yue > 2:
sun +=1
print(sun)
tsembrace
发表于 2018-4-6 23:57:34
'''
输入某年某月某日,判断这一天是这一年的第几天?
'''
def isLpy(year):
if ((year%4==0)and(year%100!=0))or(year%400==0):
return 1
else:
return 0
def cdays(year,month,date):
dayslist=
days=dayslist
if isLpy(year) and month>2:
days=days+1
days=days+date
return days
if __name__=='__main__':
year=int(input("请输入年份数:\n"))
month=int(input("请输入月份数:\n"))
date=int(input("请输入日期数:\n"))
print('%d年%d月%d号是%d年的第%d天。'%(year,month,date,year,cdays(year,month,date)))
天天学习$
发表于 2018-4-20 09:01:55
def year_days(year):
'''判断是否为闰年,1代表闰年,0代表平年'''
if (year%100) == 0:
if (year%400) == 0:
return 1
else:
return 0
elif (year%4) == 0:
return 1
else:
return 0
year =int(input('输入年:'))
month = int(input('输入月:'))
day = int(input('输入日:'))
month_list =
month_days_leap =
month_days_nonleap =
if year_days(year) == 1:
for i in month_list:
if month == i:
month_days_leap_temp = month_days_leap[:(i-1)]
print('这是%d年的第%d天' %(year,(sum(month_days_leap_temp) + day)))
else :
for i in month_list:
if month == i:
month_days_nonleap_temp = month_days_nonleap[:(i-1)]
print('这是%d年的第%d天' %(year,(sum(month_days_nonleap_temp) + day)))
树树
发表于 2018-4-24 17:42:11
temp1 = input("请输入年:")
temp2 = input("请输入月:")
temp3 = input("请输入日:")
s = 0
list1 =
list2 =
year = int(temp1)
month = int(temp2)
day = int(temp3)
if 0 < month <= 12 and 0< year and (day < list1) or (day < list2):
print("当前输入日期为%s年%s月%s日" %(temp1,temp2,temp3))
print('***' * 16)
if (year%4 == 0 and year%100 != 0) or (year%400 == 0):
s = sum(list2[:month-1]) + day
print("这一天是这一年的第%s天." %(s))
else:
s = sum(list1[:month-1]) + day
print("这一天是这一年的第%s天." %(s))
else:
print("数据错误,请重新输入!")
print("月份应小于等于12,日期应小于等于31,注意2月份最多只有29天!")
小强工作室
发表于 2018-5-7 16:18:29
本帖最后由 小强工作室 于 2018-5-7 16:23 编辑
import datetime
year,month,day=int(input("请输入年:")),int(input("请输入月:")),int(input("请输入日:"))
print(list(datetime.datetime(year,month,day).timetuple())[-2])
2行代码解决
萧丹夜
发表于 2018-5-8 15:00:02
date = input('请输入年-月-日:')
year,month,day = date.split('-')
#print(year,month,day)
year = int(year)
month = int(month)
day = int(day)
ping =
run =
i = 0
days = 0
if year % 400 == 0 or ( year % 100 != 0 and year % 4 == 0 ) :
while i < (month - 1) :
days += run
i += 1
days += day
else :
while i < (month - 1) :
days += ping
i += 1
days += day
print(days)
BISHIQIUQIUI
发表于 2018-5-9 10:49:35
#未做日期输入错误判断
year = int(input("年:\n"))
month = int(input("月:"))
day = int(input("日:"))
montharr =
montharr2 =
if (year%100!=0 and year%4!=0) or (year%100==0 and year%400!=0):
i= montharr+day
else:
i = montharr2 + day
print("这天是一年中的第%d天"%i)