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,要注意语句的顺序对齐,不然也有可能出现错误哦。 

 

文章知识点与官方知识档案匹配,可进一步学习相关知识Python入门技能树首页概览214790 人正在系统学习中

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年6月3日
下一篇 2022年6月3日

相关推荐