python输入出生年份、输出年龄_python根据出生日期计算年龄的代码
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根据出生日期计算年龄的代码相关推荐
- python输入出生日期和当前日期计算年龄_python根据出生日期计算年龄的代码
python根据出生日期计算年龄的代码,运行后会提醒用户输出出生的年月日,然后输出年龄,可以改写为一个通用函数 from time import * #a function to find your ...
- python根据生日求年龄_python根据出生日期计算年龄的代码
python根据出生日期计算年龄的代码,运行后会提醒用户输出出生的年月日,然后输出年龄,可以改写为一个通用函数 from time import * #a function to find your ...
- python输入十个数输出最大值_python输入十个数如何输出最大值
python输入十个数输出最大值的方法:1.如果是整数的话,使用函数[a, b, c = map(int, input().split())]:2.使用函数[X=input().split()]. 相 ...
- java根据生日精确计算年龄_java根据出生日期计算年龄(精确到天)
@根据出生日期计算年龄(精确到天) 代码块 public class CountAgeUtil { public static String countAge(String from){ String ...
- python输入三个数输出最小值_python之输入一系列整数输出最大值
在python学习中,我们经常会遇到:编写一个程序,输入若干整数或者是在一串字符中,输出最大值(数)的问题.那么在这里,我给出了几种常见的,也是几种比较常用的方法,希望能给大家的学习带来一定的帮助. ...
- 如何用python计算年龄_python根据出生日期返回年龄的方法
本文实例讲述了python根据出生日期返回年龄的方法.分享给大家供大家参考.具体实现方法如下: def CalculateAge(self, Date): '''Calculates the age ...
- java 计算年龄 Java 根据出生日期计算年龄
1.把出生日期字符串转换为日期格式. public static Date parse(String strDate) throws ParseException {SimpleDateFormat ...
- python输入一个数输出绝对值_python如何使用绝对值
python如何使用绝对值?下面给大家介绍三种求绝对值的方法:import math def abs_value1(): a = float(input('1.请输入一个数字:')) if a > ...
- js生日计算年龄_js 根据出生日期计算年龄
function getAge(str){ var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})/); if(r==null)return f ...
最新文章
- (传送门) Ubuntu随身系统
- VMware中装Win2012并配置Hyper-v
- linux tar打包、压缩、解压到指定目录
- 英特尔物联网产业的布局中,优势和劣势都在哪?
- java8 垃圾 不同_【不同的Java垃圾回收器的比较】
- =空值返回空值_@ParameterizedTest在@CvsSource中具有空值
- 谷歌生物医学专用翻译_实用技能 | 知云文献翻译
- 计算机上无开根号功能 怎么计算机,攻略:2019年中级会计师无纸化考试 计算器怎么开根号?...
- Android上传图片的方式
- 复制csdn或者博客园文章时,图片无法直接粘贴过来解决办法
- 什么是HyperText Transfer Protocol 超文本传输协议
- 58VIP账号发贴器
- 关于瑞星杀毒软件对浏览器速度的影响
- chrome安装crx文件
- 一、JSX语法的基本使用
- 【掘金使用技巧7】如何从通达信等迁移到掘金
- 数据库服务器搭建系统,服务器系统搭建SQL数据库
- oracle分区表复制,Oracle分区表(Partition Table)
- PARKER派克电磁换向阀D1VW002CNTW
- 基于Verilog使用Quartus设计数字秒表和数字时钟