猫史档案馆


【Python作品分享】算年龄【教程贴】

用户:敏感的疾风雀BP5t敏感的疾风雀BP5t查看:0 回复:1 评论:0 创建时间:2020-03-13T21:53:56


【作品展示】

center_image

 

【作品介绍】

几个模块不能用

 

【作品源代码】

import datetime


imyear = input('年份:')
nowyear = datetime.datetime.now().year
age = (nowyear - int(imyear))
print('您的年龄为:’+str(age)+‘岁')
if (age < 18):
    print('您现在为未成年人 ~@_@~')
if (age >= 18 and age < 66):
    print('您现在为成年人 (-_-)')
if (age >= 66 and age < 80):
    print('您现在为中年人 ~@_@~')
if (age > 80):
    print('您现在老年人 *-_-*')

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
superstar_pengsuperstar_peng

print('您的年龄为:’+str(age)+‘岁')

错了,应为:

print('您的年龄为:', str(age), '岁')

总体为:

import datetime


imyear = input('年份:')
nowyear = datetime.datetime.now().year
age = (nowyear - int(imyear))
print('您的年龄为:', str(age), '岁')
if (age < 18):
    print('您现在为未成年人 ~@_@~')
if (age >= 18 and age < 66):
    print('您现在为成年人 (-_-)')
if (age >= 66 and age < 80):
    print('您现在为中年人 ~@_@~')
if (age > 80):
    print('您现在老年人 *-_-*')

点赞0


评论