python学习(一)

#!/usr/bin/python
# -*- coding: utf-8 -*-

def is_leap_year(year):
    if year % 4 == 0 and year % 400 == 0:
        return True
    elif year % 100 == 0 and year % 400 == 0:
        return True
    else:
        return False

def get_month_days(year, month):
    days = 31
    if month == 2:
        if is_leap_year(year):
            days = 29
        else:
            days = 28
    elif month in[4, 6, 9, 11]:
        days = 30
    return days

def get_total_days(year, month):
    total_days = 1
    for i in list(range(1900, year)):
        if is_leap_year(year):
            total_days += 366
        else:
            total_days += 365
    for i in list(range(1, month)):
        total_days += get_month_days(year, month)
    return total_days
if __name__ == '__main__':
    while True:
        print("**************日历**************")
        year = input("请输入年份(:1990):")
        month = input("请输入月份:")
        try:
            year = int(year)
            month = int(month)
            if month < 1 or month > 12:
                print("输入错误!!!请重新输入")
                continue
            break
        except:
            print("输入错误!!!请重新输入")
            continue
        break

    if is_leap_year(year):
        print("%s是闰年"% year)
    else:
        print("%s是平年"% year)
    print("%s月份共有%s天"% (month, get_month_days(year, month)))
    print("一共多少天%s"% (get_total_days(year, month)))
    print("日\t\t\t\t\t\t六")
    i_count = 0     #计数器判断是否换行
    # a = get_total_days(year, month)/7
    # print(a)
    for i in list(range(1, int(get_total_days(year, month-1)/7)+1)):
        i_count += 1
    a = i_count % 7
    print(a)
    for i in list(range(0, a)):
        print(" ", "\t", end="")
    for i in list(range(0, get_month_days(year, month))):
        # print(i, '\t', end="")
        i_count += 1
        i += 1
        if i_count % 7 == 0:
            print(i)
        else:
            print(i, '\t', end="")
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值