zoukankan      html  css  js  c++  java
  • Python练习实例004

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

    #! /usr/bin/env python3
    # -*- coding:utf-8 -*-
    
    # Author   : Ma Yi
    # Blog     : http://www.cnblogs.com/mayi0312/
    # Date     : 2020-06-18
    # Name     : demo004
    # Software : PyCharm
    # Note     : 输入某年某月某日,判断这一天是这一年的第几天?
    
    
    # 入口函数
    if __name__ == '__main__':
        s_date = input("Please input teh date(YYYYMMDD):")
        year = int(s_date[0: 4])   #
        month = int(s_date[4: 6])  #
        day = int(s_date[6:8])     #
        # 每月的天数
        month_day = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        count = 0
        if year % 100 == 0 and year % 400 == 0:
            # 润年(2月有29天)
            month_day[1] = 29
        elif year % 4 == 0 and year % 100 != 0:
            # 润年(2月有29天)
            month_day[1] = 29
        if (day > month_day[month - 1]) or (month > 12):
            # 输入的日期有误
            print("Input Date Error.")
            exit()
        for m in range(month - 1):
            count += month_day[m]
        count += day
    
        print("%s is %dth day." % (s_date, count))

    运行结果:

    Please input teh date(YYYYMMDD):20200618
    2020 6 18
    20200618 is 170 th day.
  • 相关阅读:
    前端开发 Vue -3axios
    前端开发 Vue -2npm
    前端开发 Vue -1windows环境搭建Vue Node开发环境
    前端开发 Vue -0前言
    linux
    java 框架-缓冲-Redis 2Jedis操作
    java 框架-缓冲-Redis 1概述
    微软银光 silverlight简介
    bs模型与cs模型
    安装vs2010
  • 原文地址:https://www.cnblogs.com/mayi0312/p/13158168.html
Copyright © 2011-2022 走看看