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

代码:

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"。
上一篇:Java语言程序设计与数据结构(基础篇)第十一章 继承和多态 学习笔记(持续更新中)


下一篇:facebook like 按钮代码