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

方法1:

import time

test_time = input("请输入日期(年-月-日):")
time_struct = time.strptime(test_time, "%Y-%m-%d")
time_year = time_struct.tm_year
time_yday = time_struct.tm_yday
print("{}是{}年这一年中的第{}天".format(test_time, time_year, time_yday))

方法2:

import datetime

date_time = input("请输入日期(年-月-日):")
datetime_struct = datetime.datetime.strptime(date_time, "%Y-%m-%d")
time_year = datetime_struct.timetuple().tm_year
time_yday = datetime_struct.timetuple().tm_yday
print("{}是{}年这一年中的第{}天".format(date_time, time_year, time_yday))

方法3:

def get_daynum():
year = input("请输入年份:")
month = input("请输入月份:")
day = input("请输入天:")
date1 = datetime.date(year=int(year), month=int(month), day=int(day))
date2 = datetime.date(year=int(year), month=1, day=1)
return ((date1 - date2).days + 1) if __name__ == '__main__':
print(get_daynum())

Python 3.X 练习集100题 04的更多相关文章

  1. Python 3.X 练习集100题 02

    企业发放的奖金根据利润提成.利润(I):低于或等于10万元时,奖金可提10%:高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%:20万到40万之间时,高 ...

  2. Python 3.X 练习集100题 03

    一个整数,它加上 100 后是一个完全平方数,再加上 168 又是一个完全平方数,请问该数是多少? import math for i in range(10000): n1 = math.sqrt( ...

  3. Python 3.X 练习集100题 01

    有以下几个数字:1.2.3.4.5,能组成多少个互不相同且无重复数字的三位数?都是多少? 方法1: import itertools from functools import reduce lyst ...

  4. Python 3.X 练习集100题 05

    用 *号输出字母 C的图案 方法1: print(" ***** ") print(" ** * ") print(" ** ") prin ...

  5. Python练习100题

    Python练习100题 题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? #Filename:001.py cnt = 0#count the sum of res ...

  6. Python练习题 026:求100以内的素数

    [Python练习题 026] 求100以内的素数. ------------------------------------------------- 奇怪,求解素数的题,之前不是做过了吗?难道是想 ...

  7. Go面试题精编100题

    Golang精编100题 选择题 1.   [初级]下面属于关键字的是()A. funcB. defC. structD. class 参考答案:AC 2.   [初级]定义一个包内全局字符串变量,下 ...

  8. bzoj 前100题计划

    bzoj前100题计划 xz布置的巨大的坑.. 有空填题解... 1002 轮状病毒 用python手动matrixtree打表. #include<bits/stdc++.h> #def ...

  9. 各位大佬Python的第一部分道基础题已经整理好了,希望大家面试的时候能用的上。

    Python的第一部分道基础题,希望大家面试的时候能用的上. 1.为什么学习Python? Python是目前市面上,我个人认为是最简洁.最优雅.最有前途.最全能的编程语言,没有之一. 2.通过什么途 ...

随机推荐

  1. @Async源码探究

    1. @Async源码探究 1.1. 上代码 @SpringBootApplication @EnableAsync public class SpringbootLearnApplication { ...

  2. 【转载】Gradle学习 第九章:Groovy快速入门

    转载地址:http://ask.android-studio.org/?/article/17 To build a Groovy project, you use the Groovy plugin ...

  3. 个人项目-WC (java实现)

    一.Github地址:https://github.com/734635746/WC 二.PSP表格 PSP2.1 Personal Software Process Stages 预估耗时(分钟) ...

  4. qtcreator VLD内存检测

    简介 Visual Leak Detector是一款用于Visual C++的免费的内存泄露检测工具.相比较其它的内存泄露检测工具,它在检测到内存泄漏的同时,还具有如下特点: 可以得到内存泄漏点的调用 ...

  5. 面向对象(三)--多态、封装、property装饰器

    一.多态与多态性 1.什么是多态 多态指的是同一种类/事物的不同形态 class Animal: def speak(self): pass class People(Animal): def spe ...

  6. Linux 批量查找并替换文件夹下所有文件的内容

    1.批量查找某个目下文件的包含的内容 cd etc grep -rn "查找的内容" ./ 2.批量替换某个目下所有包含的文件的内容 cd etc sed -i "s/查 ...

  7. JfreeChart 乱码问题处理

    在前面之间加上下面这段代码即可. //创建主题样式 StandardChartTheme standardChartTheme=new StandardChartTheme("CN" ...

  8. node_promise

    学习链接 http://liubin.org/promises-book/#__5

  9. ubuntu16.04深度学习环境配置

    https://www.lizenghai.com/archives/14651.html https://blog.csdn.net/qq_40936141/article/details/8119 ...

  10. 排序算法-归并排序(Java)

    package com.rao.sort; import java.util.Arrays; /** * @author Srao * @className MergeSort * @date 201 ...