第二章 分支语句 最适宜运动心率
代码:
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
总结:
- 这个例子将Int,float,str三种类型都用上了;
- 在条件判断里面加上了字符串比较gender=="male"。

浙公网安备 33010602011771号