第二章 分支語句 最適宜運動心率


代碼:

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"。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM