1. 定义一个函数,用于求2017年1月到今天的总天数,打印总天数
def is_leapyear(year):
if year % 400 == 0:
return True
else:
return False
def allyear_days(year):
if is_leapyear(year):
return 366
else:
return 365
def total_days(year, month, day):
count = 0
leap_dict = {
1: 31, 2: 29, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}
noleap_dict = {
1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}
for i in range(2017, year):
s = allyear_days(i)
count += s
for j in range(month - 1):
if is_leapyear(year):
count += leap_dict[j+1]
else:
count += noleap_dict[j+1]
count += (day-1)
print(count)
2.定义一个函数,实现判断参数传入的是否全部是数字,返回值是True或者False(不使用isdigit)
def isdigit(n):
length = len(n)
count = 0
l1 = ['0','1',