python根据出生日期计算年龄的代码,运行后会提醒用户输出出生的年月日,然后输出年龄,可以改写为一个通用函数

from time import *

#a function to find your age

def age():

print "Enter Your Date of Birth"

d=input("Day:")

m=input("Month:")

y=input("Year:")

#get the current time in tuple format

a=gmtime()

#difference in day

dd=a[2]-d

#difference in month

dm=a[1]-m

#difference in year

dy=a[0]-y

#checks if difference in day is negative

if dd<0:

dd=dd+30

dm=dm-1

#checks if difference in month is negative when difference in day is also negative

if dm<0:

dm=dm+12

dy=dy-1

#checks if difference in month is negative when difference in day is positive

if dm<0:

dm=dm+12

dy=dy-1

print "Your current age is %s Years %s Months & %s Days"%(dy,dm,dd)

age()

python输入出生年份、输出年龄_python根据出生日期计算年龄的代码相关推荐

  1. python输入出生日期和当前日期计算年龄_python根据出生日期计算年龄的代码

    python根据出生日期计算年龄的代码,运行后会提醒用户输出出生的年月日,然后输出年龄,可以改写为一个通用函数 from time import * #a function to find your ...

  2. python根据生日求年龄_python根据出生日期计算年龄的代码

    python根据出生日期计算年龄的代码,运行后会提醒用户输出出生的年月日,然后输出年龄,可以改写为一个通用函数 from time import * #a function to find your ...

  3. python输入十个数输出最大值_python输入十个数如何输出最大值

    python输入十个数输出最大值的方法:1.如果是整数的话,使用函数[a, b, c = map(int, input().split())]:2.使用函数[X=input().split()]. 相 ...

  4. java根据生日精确计算年龄_java根据出生日期计算年龄(精确到天)

    @根据出生日期计算年龄(精确到天) 代码块 public class CountAgeUtil { public static String countAge(String from){ String ...

  5. python输入三个数输出最小值_python之输入一系列整数输出最大值

    在python学习中,我们经常会遇到:编写一个程序,输入若干整数或者是在一串字符中,输出最大值(数)的问题.那么在这里,我给出了几种常见的,也是几种比较常用的方法,希望能给大家的学习带来一定的帮助. ...

  6. 如何用python计算年龄_python根据出生日期返回年龄的方法

    本文实例讲述了python根据出生日期返回年龄的方法.分享给大家供大家参考.具体实现方法如下: def CalculateAge(self, Date): '''Calculates the age ...

  7. java 计算年龄 Java 根据出生日期计算年龄

    1.把出生日期字符串转换为日期格式. public static Date parse(String strDate) throws ParseException {SimpleDateFormat ...

  8. python输入一个数输出绝对值_python如何使用绝对值

    python如何使用绝对值?下面给大家介绍三种求绝对值的方法:import math def abs_value1(): a = float(input('1.请输入一个数字:')) if a > ...

  9. js生日计算年龄_js 根据出生日期计算年龄

    function getAge(str){ var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})/); if(r==null)return f ...

最新文章

  1. (传送门) Ubuntu随身系统
  2. VMware中装Win2012并配置Hyper-v
  3. linux tar打包、压缩、解压到指定目录
  4. 英特尔物联网产业的布局中,优势和劣势都在哪?
  5. java8 垃圾 不同_【不同的Java垃圾回收器的比较】
  6. =空值返回空值_@ParameterizedTest在@CvsSource中具有空值
  7. 谷歌生物医学专用翻译_实用技能 | 知云文献翻译
  8. 计算机上无开根号功能 怎么计算机,攻略:2019年中级会计师无纸化考试 计算器怎么开根号?...
  9. Android上传图片的方式
  10. 复制csdn或者博客园文章时,图片无法直接粘贴过来解决办法
  11. 什么是HyperText Transfer Protocol 超文本传输协议
  12. 58VIP账号发贴器
  13. 关于瑞星杀毒软件对浏览器速度的影响
  14. chrome安装crx文件
  15. 一、JSX语法的基本使用
  16. 【掘金使用技巧7】如何从通达信等迁移到掘金
  17. 数据库服务器搭建系统,服务器系统搭建SQL数据库
  18. oracle分区表复制,Oracle分区表(Partition Table)
  19. PARKER派克电磁换向阀D1VW002CNTW
  20. 基于Verilog使用Quartus设计数字秒表和数字时钟

热门文章

  1. python 批量excel导入到mysql中
  2. 高利润赚钱行业有哪些?300的利润使人疯狂
  3. Tableau笔记(16)创建和使用集
  4. Java小程序:根据年份,月份来判断大小月
  5. 不懂商业就别谈数据 --- 车品觉
  6. HALCON已知平面两点图像坐标和对应机械坐标求仿射变换矩阵
  7. 系统分析--详细描述
  8. 【OpenCV】9th-关于argc
  9. 网页自动获取题目匹配题库答案填充(原创1.0)
  10. 阿达的esp01s单路通电器