python 身高预测

  • Post author:
  • Post category:python


最近正在学这个,本实验主要是对孩子的身高进行预测 ,如有错误请指出。

工具:jupyter

语言:python


题目:

身高预测公式为:

  • 男性成人时身高=(父亲身高+母亲身高)*0.54
  • 女性成人时身高=(父亲身高*0.923+母亲身高)/2

    • 如果经常进行体育锻炼,那么可以增加2%
    • 如果有良好的饮食习惯,那么可以增加1.5%


代码部分:

father_h = float(input(“父亲的身高:”))

motrher_h = float(input(“母亲的身高:”))

child=input(“是男孩还是女孩?男/女”)

sport=input(“是否经常运动?是/否 :”)

diet=input(“是否饮食规律?是/否 :”)

if child ==  “男”:

child_h=(father_h+motrher_h)*0.54

if sport == “是”:

child_h=child_h*1.2

if sport == “是”:

child_h=child_h*1.15

else:

child_h=(father_h*0.923+motrher_h)/2

if sport == “是”:

child_h=child_h*1.2

if sport == “是”:

child_h=child_h*1.15

print(child_h)


运行结果截图:

这道题主要是根据题目要求,进行多个条件判断。所以当中有多个if,要注意语句的顺序对齐,不然也有可能出现错误哦。



版权声明:本文为weixin_47314602原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。