请设计一个函数,方便筛选

img

那也得检查性别吧

img


import datetime
#定义筛选方法
def screen(number, height,weight ):
    #验证身高
    if height>173 or height<165:
        return "不符合标准-身高:"+str(height)+"身高超出173cm或低于165"
    #计算BMI
    bmi = float(float(weight)/(float(height/100)**2))
    #验证BMI
    if bmi>23 or bmi<19:
        return "不符合标准-bmi:"+bmi+" bmi超出23或低于19"

    #计算年龄
    birthday=str(number)[6:14]#出生年月日
    birth_year=birthday[0:4]#前四位
    age_number=datetime.datetime.now().year-int(birth_year)
    age_standard=datetime.datetime.now().year-int(1982)
    #验证年龄
    if age_standard>age_number+5 or age_standard<age_number-3:
        return "不符合标准-年龄:"+str(age_number)+" 年龄超出"+str(age_number+5)+" 或低于"+str(age_number-3)
    return "符合标准!"

#接收参数
number = int(input('请输入身份证号:'))
height = int(input('请输入身高(CM):'))
weight = int(input('请输入体重(KG):'))

#调用输出算选结果
print(screen(number,height,weight))
# coding=UTF-8
import datetime

class GetInformation(object):

     def __init__(self,id):
         self.id = id
         self.birth_year = int(self.id[6:10])
         self.birth_month = int(self.id[10:12])
         self.birth_day = int(self.id[12:14])

     def get_birthday(self):
         """通过身份证号获取出生日期"""
         birthday = "{0}-{1}-{2}".format(self.birth_year, self.birth_month, self.birth_day)
         return birthday

     def get_sex(self):
         """男生:1 女生:2"""
         num = int(self.id[16:17])
         if num % 2 == 0:
             return 2
         else:
             return 1

     def get_age(self):
         """通过身份证号获取年龄"""
         now = (datetime.datetime.now() + datetime.timedelta(days=1))
         year = now.year
         month = now.month
         day = now.day

         if year == self.birth_year:
             return 0
         else:
             if self.birth_month > month or (self.birth_month == month and self.birth_day > day):
                 return year - self.birth_year - 1
             else:
                 return year - self.birth_year


if __name__=='__main__':
    print('富婆、饿饿、饭饭')
    
    height=float(input("请输入身高(米):"))
    weight=float(input("请输入体重\(公斤):"))
    idNum=input('输入身份证号:')
    
    if height<=1.73 and height>=1.65:
        bmi=weight/pow(height,2)
        print("BMI数值为:{}".format(bmi))
        if bmi>=19 and bmi<=23:
            girlBirthday = GetInformation("000000198204230000").get_age()
            boyBirthday = GetInformation(idNum).get_age()
            offset=girlBirthday-boyBirthday
            print("年龄相差:{}".format(offset))
            if offset>=-3 and offset<=5:
                print('筛选通过')

需要提前安装下日期模块 pip install python-dateutil


# -*- coding:utf-8 -*-
# pip install python-dateutil

from datetime import datetime
from dateutil.relativedelta import relativedelta

# 1、云南人,身高在 165 ~ 173 之间,BMI指 在 19~23 之间
# 2、年龄不能大于5 岁以上,不能小于 3 岁以下,女老板生日 1982年4月23日
# 体质指数 BMI=体重÷身高^2。(体重单位:千克;身高单位:米。)

def filterInfo():
    idCard = input('请输入对方的身份证号码:').strip()
    height = int(input('请输入对方的身高(单位是cm[厘米]):').strip())
    weight = float(input('请输入对方的体重(单位是kg[千克]):').strip())

    print('\n\n开始核验年龄是否符合要求。。。。。')
    # 云南省身份证号以53开头,身份证号倒数第二位是奇数的为男性
    bossBirthday = datetime(1982, 4, 23)
    if idCard.startswith('53') and int(idCard[-2:-1]) % 2:
        year = int(idCard[6:10])
        month = int(idCard[10:12])
        day = int(idCard[12:14])
        birthday = datetime(year, month, day)
        print(birthday,birthday - relativedelta(years=+5),birthday + relativedelta(years=+3))
        if birthday - relativedelta(years=+5) < bossBirthday < birthday + relativedelta(years=+3) :
            print('年龄是:{}年{}月{}日,符合要求,下面开始核验身高。。。。。'.format(str(year), str(month), str(day)))

            # 判断身高是否符合要求
            if 165 < height < 173:
                print('身高是 {} cm,符合要求,下面开始核验BMI(体质指数)。。。。。'.format(str(height)))

                ##判断BMI是否符合要求
                bmi = round(weight / pow(height / 100,2),2)
                if 19 < bmi < 23:
                    print('核验完毕,此人符合征婚要求')
                else:
                    print('核验完毕,此人不符合征婚要求')

            else:
                print('身高不符合要求')
        else:
            print('年龄不符合要求')
    else:
        print('不是云南人')


if __name__ == '__main__':
    filterInfo()



import datetime


def get_age(birthday: str):
    now = datetime.datetime.now().strftime('%Y-%m-%d')
    b1 = birthday.split("-")
    n1 = now.split("-")
    age = int(n1[0]) - int(b1[0])
    if int(''.join(n1[1::])) < int(''.join(b1[1::])):
        age -= 1
    return age


def screen_object(ID: str, high: int, weight: int) -> bool:
    address = ID[0:2]
    if int(address) != 53:
        return False
    if not 165 <= high <= 173:
        return False
    BMI = weight / ((high / 100) ** 2)
    if not 21 <= BMI <= 23:
        return False
    boss_age = get_age("1982-4-23")
    ob_birthday = ID[6:10] + '-' + ID[10:12] + '-' + ID[12:14]
    ob_age = get_age(ob_birthday)
    if not -3 <= int(ob_age - boss_age) <= 5:
        return False
    return True