张大哈 发表于 2018-6-7 11:01:40

year=int(input("请输入年份:"))
month=int(input("请输入月份:"))
day=int(input("请输入日"))
days=
sum=0
for i in range(0,month-1):
    sum=sum+days
if year%400==0 or (year%4==0 and year%100!=0) and month>2:
    sum=sum+day+1
else :
    sum=sum+day
print("这一天是第%s年的第%s天!"%(year,sum))

jy765190789 发表于 2018-6-27 11:50:19

def fun_1(month,days):
    month_days =
    result = 0
    for i in range(12):
      month = month - 1
      result = result+month_days
      if month == 0:
            break
    result = result + days

    return result

print("请输入日期(年月日),年月日用回车隔开")
year = int(input())
month = int(input())
days = int(input())
if (year%4 == 0 and year%100 != 0) or (year%400 == 0):   #判断是闰年
    month_days = 29
result = fun_1(month,days)
print("这是第",result,"天")

892427369 发表于 2018-7-17 15:47:37

Y = int(input("请输入年份:"))
M = int(input("请输入月份:"))
D = int(input("请输入日期:"))
t = (M-1)*31-M//2-2+D
if Y % 4 == 0 and Y % 100 != 0 or Y % 400 == 0:
    t += 1
if M <= 2:
    t=(M-1)*31+D
print("这一天是这一年的第",t,"天。",sep="")

CC柴 发表于 2018-7-19 19:38:58

又长又臭year = int(input("请输入某年:"))
month = int(input("请输入某月:"))
day = int(input("请输入某日:"))
run =
ping =
d = 0
i = 0
if ((year%4 ==0) and (year%100 !=0)) or year%400 ==0:
    for i in range(month-1):
      d += run
      i +=1
    d = d+day
    print("%d年%d月%d日是%d年中的第%d天!"%(year,month,day,year,d))
else:
    for i in range(month-1):
      d +=ping
      i +=1
    d = d+day
    print("%d年%d月%d日是%d年中的第%d天!" % (year, month, day, year, d))

DavidCowboy 发表于 2018-8-1 12:02:18

year = int(input('請輸入西元年份:'))
month = int(input('請輸入月份:'))
day = int(input('請輸入日:'))

common_year =
leap_year =
days = 0

if (year % 4 == 0 and year % 100 != 0) or year %400 == 0:
    while month:
      days += leap_year
      month -= 1
else:
    while month:
      days += common_year
      month -= 1

answer = day + days
print(answer)

uilUVUBWP 发表于 2018-8-5 10:43:26

新手·ing 发表于 2017-3-26 07:37
我的解答!

如果我输入的天数高于31天,你的程序仍然会照常执行,但是这并不符合正常的逻辑

澄绿哥 发表于 2018-8-7 22:39:46

献丑

本帖最后由 澄绿哥 于 2018-8-7 22:58 编辑

献丑了

jack1412 发表于 2018-8-9 21:41:18

可以这么玩

import datetime as dt
temp1 = int(input('year: '))
temp2 = int(input('month: '))
temp3 = int(input('day: '))
x = dt.datetime(temp1,temp2,temp3)-dt.datetime(temp1-1,12,31)
print (x)

小龙145 发表于 2018-8-9 22:20:45

{:10_245:}{:10_245:}

jluzhpanda 发表于 2018-8-12 14:04:05

def date(x, y, z):
    list1 =
    list2 =
    if (x % 4 == 0) and (x % 100 != 0):
      L =list1
    elif x % 400 == 0:
      L =list1
    else:
      L =list2
    list3 = L
    n = z + sum(list3)
    return n
x = int(input('input year:'))
y = int(input('input month:'))
z = int(input('input day:'))
print date(x, y, z)

一步半个脚印 发表于 2018-8-21 22:31:17

year=int(input('input year:'))
month=int(input('input month:'))
day=int(input('input day:'))
Setmonth =
sum=0

if year%4 ==0 and year%100 !=0 and year%400 ==0:
    for i in range(1, month):
      sum = sum + Setmonth
    print('This is No.:',sum+day,'day')
else:
    for i in range(1, month):
      sum = sum + Setmonth
    print('This is No.:',sum+day,'day')

终于憋出来了。。。。。。

acgods 发表于 2018-8-23 14:33:57

本帖最后由 acgods 于 2018-8-23 15:13 编辑

year = int(input("请输入年:"))
month = int(input("请输入月:"))
day = int(input("请输入日:"))

def dayCount(year,month,day):
    if ((year % 4 == 0) and (year % 100 !=0)) or (year % 400 == 0):
      februrayDays = 29
    else:
      februrayDays = 28
    list1 =
    dayCount = 0      
    for i in range(1,month):
      dayCount += list1
    dayCount += day
    return dayCount

print("您输入的日期是今年的第%d天" % dayCount(year,month,day))



修改后的代码

import datetime

year = int(input("请输入年:"))
month = int(input("请输入月:"))
day = int(input("请输入日:"))
days = datetime.date(year,month,day) - datetime.date(year-1,12,31)
days1 = int(days.days)
print("您输入的日期是今年的第%d天" % days1)

乔乔在哪 发表于 2018-8-27 21:37:09

版主高明,继续学习

_玛莎_ 发表于 2018-9-14 17:09:25

print('请根据提示输入要查询的日期')
a = int(input('请输入年:'))
b = int(input('请输入月:'))
c = int(input('请输入日:'))
day =
for n in range(1, b):
    if(((a % 4 == 0 and a % 100 != 0) or a % 400 == 0) and b>2):
      result = day + c + 1
    else:
      result =day + c
print('您输入的日期是今年的第%d天' % result)

Hxiaoping 发表于 2018-9-18 19:58:00

time = (input('请输入年月日:'))
#time = '2018,2,3'
mothlsit =
year = int(time.split(','))
moth = int(time.split(','))
day =int(time.split(','))

if moth in range(1, 13) :
    for i in range(1, moth) :
      day = day + mothlsit   

else:
    print('请输入1-12月')
   
if year % 400 == 0 or year % 4 == 0 and year % 100!= 0 :
    print('该年是闰年')   #二月 29天
    print(day)
else :
   
    print('改年是平年')#二月 28天
    if moth > 2 :
      print(day-1)
    else :
      print(day)

练习下,

Hxiaoping 发表于 2018-9-18 19:59:31

Hxiaoping 发表于 2018-9-18 19:58
time = (input('请输入年月日:'))
#time = '2018,2,3'
mothlsit =

思路比较清晰,代码不复杂,很容易看懂

吃鱼的虾 发表于 2018-10-11 10:28:07

dict1={1:31,2:28,3:31,4:30,5:31,6:30,7:31,8:10,9:30,10:31,11:30,12:31}
days=0
def judgment_year(year):
    if (year % 4) == 0:
      if (year % 100) == 0:
            if (year % 400) == 0:
                return True
            else:
                return False
      else:
            return True
    else:
      return False


year=int(input('请您输入年份:'))

if judgment_year(year):
    mouth=int(input('请您输入月份:'))
    if mouth > 2:
      day=int(input('请您输入%d月几号' % mouth))
      for i in range(1,mouth):
            days += dict1
      print(days+day+1)
    else:
      day=int(input('请您输入%d月几号' % mouth))
      for i in range(1,mouth):
            days += dict1
      print(days+day)
   
else:
    mouth=int(input('请您输入月份:'))
    day=int(input('请您输入%d月几号' % mouth))
    for i in range(1,mouth):
      days += dict1
    print(days+day)
   

Roc乘风 发表于 2018-10-15 22:26:30

抑痒指 发表于 2017-6-9 16:37


赞,初学者学习了

Roc乘风 发表于 2018-10-15 22:35:28

感觉我写的不咋样!daylist =

year = int(input("请输入年:"))
mouth = int(input("请输入月:"))
day = int(input("请输入天:"))
dayth = 0

if mouth == 1 :
    print(dayth + day)
else:

    if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
      daylist2 = daylist
      daylist2 = 29
      for index in range(1,mouth):
            dayth =dayth + daylist2
      print(dayth +day)
    else:
      for index in range(1,mouth):
            dayth =dayth + daylist
      print(dayth + day)

看了各位鱼油的代码! 学习了
1.datetime 计算日期之差
2.list Unpacking操作和 list的牛百写法year, month, day =
3.拆分功能点,尽量联系函数和类的使用

zhangjk19841984 发表于 2018-10-18 15:50:09

import math
your_birthday1=int(input('您出生的月份:'))
your_birthday2=int(input('您出生的日子:'))
d=0
month_days=

for i in range(your_birthday1-1):
    d+=month_days
    day=d+your_birthday2

print('生日是第{}天。'.format(day))
页: 1 2 3 [4] 5 6 7
查看完整版本: Python:每日一题 4