研究表明,人的身高与遗传因素有一定的关系。可以按照下面的公式,预测遗传身高(不考虑后天因素)。请据此设计一套身高预测系统,要求配有系统界面,可以支持用户选择性别。 男性成人时身高=(fa_Height + mo_Height)×0.54 cm 女性成人时身高=(fa_Height×0.923 + mo_Height) / 2 cm 这里fa_Height和mo_Height分别表示父亲和母亲的身高,单位均为cm。 以下为程序的运行结果示例1: ************************************* * Welcome to Use Height Prediction System * ************************************* Please choose the sex: 1.Female 2.Male Your choice is: 1↙ May I know your Surname? Ma↙ Hi, Miss Ma! Could you please input your mother’s height(cm): 153↙ Could you please input your father’s height(cm): 169↙ Your predicted height is 154cm Thank you for use our “Height Prediction System”!
时间: 2023-08-16 19:08:57 浏览: 155
身高预测程序
以下是一个Python实现的身高预测系统:
```python
def predict_height(sex, fa_height, mo_height):
if sex == 1:
height = (fa_height * 0.923 + mo_height) / 2
elif sex == 2:
height = (fa_height + mo_height) * 0.54
else:
return "Invalid input!"
return round(height, 1)
print("*************************************")
print("* Welcome to Use Height Prediction System *")
print("*************************************")
sex = int(input("Please choose the sex: 1.Female 2.Male "))
if sex == 1:
surname = input("May I know your Surname? ")
print("Hi, Miss " + surname + "!")
elif sex == 2:
surname = input("May I know your Surname? ")
print("Hi, Mr. " + surname + "!")
else:
print("Invalid input!")
exit(0)
fa_height = float(input("Could you please input your father’s height(cm): "))
mo_height = float(input("Could you please input your mother’s height(cm): "))
predicted_height = predict_height(sex, fa_height, mo_height)
print("Your predicted height is " + str(predicted_height) + "cm")
print("Thank you for use our 'Height Prediction System'!")
```
运行结果示例:
```
*************************************
* Welcome to Use Height Prediction System *
*************************************
Please choose the sex: 1.Female 2.Male 1
May I know your Surname? Ma
Hi, Miss Ma!
Could you please input your father’s height(cm): 175
Could you please input your mother’s height(cm): 160
Your predicted height is 155.5cm
Thank you for use our 'Height Prediction System'!
```
阅读全文