克里斯保罗
发表于 2019-8-25 11:56:40
def LearYear(year):
if (year%4==0 and year%100!=0) or year%400 == 0:
return True
else:
return False
year=int(input('请输入年份:'))
mouth = int(input('请月份:'))
days = int(input('请输入日期:'))
day_list0 =
day_list1 =
temp = 0
if LearYear(year):
for i in range(mouth-1):
temp += day_list0
temp += days
else:
for i in range(mouth-1):
temp += day_list1
temp += days
print('这一天是这一年的第%d天' %temp)
克里斯保罗
发表于 2019-8-25 13:33:42
import datetime as dt
year,mouth,day =
date1 = dt.datetime(year,mouth,day)
date2 = dt.datetime(year-1,12,31)
date3 = date1-date2
print('这一天是这一年的第'+str(date3.days)+'天')
Jung
发表于 2019-11-21 12:57:04
def CountDays():
M =
DaysinM =
DaysinMleap =
YMD = input('please input Year-Month-Day like format 2019-11-22:')
Year = int(YMD.split('-'))
Month = int(YMD.split('-'))
Day = int(YMD.split('-'))
CountDays = 0
if(Year%400 == 0):
for i in range(Month-1):
CountDays += DaysinMleap
CountDays += Day
elif(Year%4 == 0):
for i in range(Month-1):
CountDays += DaysinMleap
CountDays += Day
else:
for i in range(Month-1):
CountDays += DaysinM
CountDays += Day
print('The day in the %d th of year.'%(CountDays))
天下一统2014
发表于 2019-12-1 20:29:05
def years(a):
year = a.split("年")
month = year.split("月")
day = month.split("日")
months =
d = int(year)
days = 0
if d % 400 == 0 or (d % 4 == 0 and d % 100 != 0):
f = 29
days += f
else:
f = 28
days += f
if 0<int(month)<13 :
if0< int(day) < 32:
days +=int(day)
if int(month) in months and int(month)>2:
days += ((int(month)-1)/2)*31
days += ((int(month) - 1) / 2 -1) * 30
else:
days -= f
days +=(int(month)-1)*31
return days
else:
return "天数错误"
else:
return "月份错误"
a = input("请输入年月日;")
b = ["年","月","日"]
c =
while c :
a = input("请重新输入:")
c =[]
e = years(a)
if type(e) == str :
print(e)
else:
print("这是这个月的第%s天"%int(e))
bestkfx
发表于 2020-1-6 19:42:39
# coding=gbk
year1=int(input("请输入年份:"))
month1=int(input("请输入月份:"))
day1=int(input("请输入日期:"))
list1=
if(year1%4==0):
print("这是"+str(year1)+"年的第"+str(list1+1+day1)+"天")
else:
print("这是"+str(year1)+"年的第"+str(list1+day1)+"天")
bestkfx
发表于 2020-1-6 19:51:16
前面的解答有误,重新发一个
# coding=gbk
year1=int(input("请输入年份:"))
month1=int(input("请输入月份:"))
day1=int(input("请输入日期:"))
list1=
if(year1%4==0&year1%100!=0&month1>2):
print("这是"+str(year1)+"年的第"+str(list1+1+day1)+"天")
else:
print("这是"+str(year1)+"年的第"+str(list1+day1)+"天")
bestkfx
发表于 2020-1-6 19:58:05
上一条回复没有考虑世纪闰年再来一发
# coding=gbk
year1=int(input("请输入年份:"))
month1=int(input("请输入月份:"))
day1=int(input("请输入日期:"))
list1=
if(year1%4==0 and year1%100!=0 and month1>2 or year1%400==0 and month1>2):
print("这是"+str(year1)+"年的第"+str(list1+1+day1)+"天")
else:
print("这是"+str(year1)+"年的第"+str(list1+day1)+"天")
ka233siji
发表于 2020-1-16 10:10:07
year=int(input('year:'))
month = int(input('month:'))
day = int(input('day:'))
if not year%400 or (not year%4 and year%100) :
year = 1
else:
year = 0
if month == 12 :
day += 30
month = 11
if month == 11 :
day += 31
month = 10
if month == 10 :
day += 30
month = 9
if month == 9 :
day += 31
month = 8
if month == 8 :
day += 31
month = 7
if month == 7 :
day += 30
month = 6
if month == 6 :
day += 31
month = 5
if month == 5 :
day += 30
month = 4
if month == 4 :
day += 31
month = 3
if month == 3 :
day += 28+year
month = 2
if month == 2 :
day += 31
month = 1
if month == 1 :
print(day)
Python学好
发表于 2020-1-16 18:00:45
year = int(input('请输入年份: '))
mouth = int(input('请输入月份: '))
day = int(input('请输入天数: '))
mouth_days = []
index =
for i in range(12):
i = i + 1
if i in index:
mouth_days.append(31)
elif (i == 2) and (year % 400 == 0):
mouth_days.append(29)
elif (i == 2) and (year % 400 != 0):
mouth_days.append(28)
else:
mouth_days.append(30)
sum_day = 0
for i in range(mouth - 1):
sum_day += mouth_days
sum_day += day
print('%d.%d.%d是这一年的第 %d 天' % (year, mouth, day, sum_day))
天涯过客
发表于 2020-2-14 17:01:37
def number4(year,month,day):
a=[]
numbermonth =
if (year%4==0) and (year%100 !=0) or (year%400==0):
numbermonth.insert(1,29)
else:
numbermonth.insert(1,28)
for i in range(month-1):
a.append(numbermonth)
sum1 = sum(a) + day
return sum1
year=int(input("请输入年份:"))
month = int(input("请输入月份:"))
day = int(input("请输入天:"))
print("这是这一年的第{}天".format(number4(year,month,day)))
君子好逑
发表于 2020-2-24 23:13:41
number=
temp=input('请输入日期(格式如:2000.02.08):')
temp=list(temp)
temp.reverse()
year=''
month=''
day=''
while temp[-1]!='.':
year+=str(temp.pop())
temp.pop()
while temp[-1]!='.':
month+=str(temp.pop())
temp.pop()
month=int(month)
print(month)
while temp:
day+=str(temp.pop())
year=int(year)
month=int(month)
day=int(day)
if (year%100==0)and(year%100==0):
flag=1
elif (year%4==0)and(year%100!=0):
flag=1
else :
flag=0
i=range(month)
if month<=2:
num=0
for each in i:
num+=number
num+=day
elif (2<month<=12):
num=flag
for each in i:
num+=number
num+=day
print("%d月%d日是%d年的第%d天"%(month,day,year,num))
xiaofan1228
发表于 2020-2-29 16:06:24
其实应该把输入合法性先做验证,本来应该把这个模块做个函数独立出来,懒了。。。
def feb_switch(x):
if x%4 == 0 :
return 1
else:
return 0
while 1:
date = input('Please input date in format YYYY.month.day\n')
x = date.split('.',3)
day = 0
big =
feb =
if feb_switch(int(x)) == 0 and int(x) ==2 and int(x) >28:
print("不是闰年,输入错误!!!")
elif feb_switch(int(x)) == 1 and int(x) ==2 and int(x) >29:
print("二月份哪有那么多天!!!")
elif int(x) not in big and int(x) >30:
print("当前月份只有30天!!!")
elif int(x) in big and int(x) >31:
print("当前月份只有31天!!!")
else:
for i in range(int(x) - 1):
if i + 1 in big:
day += 31
elif i + 1 == 2:
day += feb))]
else:
day += 30
day += int(x)
print(day)
十月故里
发表于 2020-4-1 19:40:02
import datetime
time=input('yyyy,mm,dd')
a=time.split(',')
day1=datetime.datetime(int(a),int(a),int(a))
day2=datetime.datetime(int(a),1,1)
delayday=(day1-day2).days+1
print('这是一年中的第%d天'%delayday)
1412849797
发表于 2020-4-9 10:53:43
num = 0
while num < 3 :
DataTest = eval(input("输入某年:"))
DataTest01 = eval(input("输入某月:"))
DataTest02 = eval(input("输入某日:"))
for i in range(1,13):
ifDataTest01 in :
if i == 1 :
DataNo = DataTest02
# print("这一天是这一年的第%d" % DataTest)
elif i== 2 :
DataNo = DataTest02 + 31
# print("这一天是这一年的第%d" % DataNo)
elif i == 3 :
DataNo = DataTest02+59
# print("这一天是这一年的第%d" % DataNo)
elif i == 4 :
DataNo = DataTest02 + 91
# print("这一天是这一年的第%d" % DataNo)
elif i == 5 :
DataNo = DataTest02 + 121
# print("这一天是这一年的第%d" % DataNo)
elif i == 6 :
DataNo = DataTest02 + 152
# print("这一天是这一年的第%d" % DataNo)
elif i == 7 :
DataNo = DataTest02 + 183
# print("这一天是这一年的第%d" % DataNo)
elif i == 8 :
DataNo = DataTest02 + 214
# print("这一天是这一年的第%d" % DataNo)
elif i == 9 :
DataNo = DataTest02 + 244
# print("这一天是这一年的第%d" % DataNo)
elif i == 10 :
DataNo = DataTest02 + 275
# print("这一天是这一年的第%d" % DataNo)
elif i == 11 :
DataNo = DataTest02 + 305
# print("这一天是这一年的第%d" % DataNo)
elif i == 12 :
DataNo = DataTest02 + 335
# print("这一天是这一年的第%d" % DataNo)
if DataTest % 4 == 0 or DataTest % 400 == 0:
print("这一天是这一年的第%d" % (DataNo+1))
else:print("这一天是这一年的第%d" % DataNo)
num = num + 1
san1412
发表于 2020-4-22 10:53:43
year = int(input('year:'))
month = int(input('month:'))
day = int(input('day:'))
month_day =
days = 0
for i in range(month-1):
days += month_day
if year % 4 == 0 and month > 2:
print(year,'年',month,'月',day,'日是这一年的第',days + day +1 ,'天')
else:
print(year,'年',month,'月',day,'日是这一年的第',days + day,'天')
土二奇
发表于 2020-4-22 13:55:59
return True if (n % 4 == 0 and n % 100 != 0) or n % 400 == 0 else False
这句为什么不是直接return Ture if (n%4==0)
尔东方
发表于 2020-4-27 10:34:37
s=[]
year=int(input("请输入年:"))
month=int(input("请输入月:"))
day1=int(input("请输入日:"))
day=
if year%400==0 or (year%4==0 and year%100!=0):
day=29
for i in range(month-1):
s.append(day)
print(int(sum(s))+day1)
ForPorsche
发表于 2020-5-22 17:51:52
datetime = input('输入某年某月某日(例:20140228):')
year = int(datetime[:4])
month = int(datetime)
day = int(datetime)
a =
b =
count1, count2 = 0, 0
day2, day3 = 0, 0
if month < 10:
month = '%02d' % month
else:
month = '%d' % month
for i in range(int(month)):
if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):
if i == 2:
day2 = 29
else:
if i == 2:
day2 = 28
if i in a:
count1 += 1
elif i in b:
count2 += 1
day3 = count1 * 31 + count2 * 30
print('这一天是这一年的第%d天' % (day + day2 + day3))
nononoyes
发表于 2020-5-28 14:54:22
#定义变量year:接受输入的年份
year = int(input("请输入年份:"))
#定义变量month:接收输入的月份
month = int(input("请输入月份:"))
#定义天数的list
listDay =
#定义变量day:接收输入的日期
day = int(input("请输入日期:"))
#定义theDay来存放是这一年的第几天
theDay = 0
ifmonth == 2:
theDay = 31 + day
print("%d年%d月%d日是这一年的第%d天"%(year,month,day,theDay))
elif month == 1:
theDay = day
print("%d年%d月%d日是这一年的第%d天"%(year,month,day,theDay))
elif month>2:
if year%4 == 0 and year%100 != 0 or year%400 == 0:
for i in range(1,month):
theDay += listDay
print("%d年%d月%d日是这一年的第%d天"%(year,month,day,theDay+1+day))
else:
for i in range(1,month):
theDay += listDay
print("%d年%d月%d日是这一年的第%d天" % (year, month, day, theDay + day))
鲨鱼辣椒1
发表于 2020-7-20 11:21:46
本帖最后由 鲨鱼辣椒1 于 2020-7-20 16:25 编辑
list1 =
list2 =
month = 0
def judge_date():
a = eval(input("请输入年份:"))
if ((a % 4 == 0) and (a % 100 != 0)) or ((a % 400 == 0) and (a % 100 == 0)): # 如果是闰年
count_date(list1)
else:
count_date(list2)
def count_date(t):
b = eval(input("请输入月份:"))
for i in range(b - 1):
global month
month = month + t
c = eval(input("请输入日期:"))
result = month + c
print(result)
judge_date()