其他分享
首页 > 其他分享> > 第二章 分支语句 最适宜运动心率

第二章 分支语句 最适宜运动心率

作者:互联网

代码:

age=int(input("Your age is:"))
HRrest=float(input("Your HRrest is:"))
gender=str(input ("Your gender is:"))
if gender=="male":
    n=220
else:
    n=210
low=(n-age-HRrest)*0.6+HRrest
high=(n-age-HRrest)*0.8+HRrest
print("Your suit HRrest is between ",low,"~",high)

效果:

[root@localhost 2]# python p2_hrrest.py
Your age is:16
Your HRrest is:71
Your gender is:male
Your suit HRrest is between  150.8 ~ 177.4
[root@localhost 2]# python p2_hrrest.py
Your age is:16
Your HRrest is:71
Your gender is:famale
Your suit HRrest is between  144.8 ~ 169.4

总结:

  1. 这个例子将Int,float,str三种类型都用上了;
  2. 在条件判断里面加上了字符串比较gender=="male"。

标签:语句,HRrest,gender,age,心率,suit,input,第二章,Your
来源: https://www.cnblogs.com/scholarly/p/15427410.html