每日一题

2021-06-06

题目:输入某年某月某日,判断这一天是这一年的第几天?

解题:

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

#闰年:能被4整除,不能被100整除,能被400整除,平年2月28,闰年2月29

sum= 0
feb = 0
if year %4 == 0 and year %100 !=  0 and year % 400 == 0:
    feb = 28
else:
    feb = 29
    #135781012
moths = [0,31,feb,31,30,31,30,31,31,30,31,30,31]
for i in range(moth):
    sum +=  moths[i]
sum = sum + day
print("您输入的日期是当年的第{}天".format(sum))

2021年6月9号

已知一个由数字组成的列表,请将列表中的所有0移到右侧。
例如 move_zeros([1, 0, 1, 2, 0, 1, 3]) ,预期返回结果: [1, 1, 2, 1, 3, 0, 0]。

解题:

move_zeros = [1,0,1,2,0,1,3]

for i in range(len(move_zeros)):
    if move_zeros[i] == 0:
        zero_list = move_zeros.pop(i)
        # print(zero_list)
        move_zeros.append(zero_list)
print(move_zeros)
原文地址:https://www.cnblogs.com/hantongxue/p/15715983.html