硕士生
逆向小白
 
- 金币
- 2680
- 好评
- 55
- 信誉
- 168
    
|
本帖最后由 笑 于 2025-10-5 19:53 编辑
用Python写的,可以计算身高、体重还有年龄
- def age_calculator():
- gender = input("性别(男/女): ").strip()
- age = int(input("年龄: "))
- if gender == "男":
- print(f"你的年龄是:{age}岁")
- elif gender == "女":
- if age < 18:
- print(f"你的年龄是:{age}岁")
- else:
- print("永远18岁!")
- else:
- print("你输的啥性别?重来!")
- def weight_calculator():
- gender = input("性别(男/女): ").strip()
- weight = float(input("体重(斤): "))
- if gender == "男":
- print(f"你的体重是:{weight}斤")
- elif gender == "女":
- if weight < 80:
- print("你的体重是:80来斤")
- elif weight < 100:
- rounded = int((weight // 10) * 10)
- print(f"你的体重是:{rounded}来斤")
- else:
- print("你的体重是:100来斤")
- else:
- print("性别输错了!只支持男/女!")
- def height_calculator():
- gender = input("性别(男/女): ").strip()
- height = float(input("身高(米): "))
- if gender == "男":
- if height < 1.5:
- print(f"你的身高是:{height}米")
- elif height < 1.6:
- print("你的身高是:1.6米")
- elif height < 1.7:
- print("你的身高是:1.7米")
- elif height < 2.0:
- print("你的身高是:1.8米")
- else:
- print("以你的身高堪称当代姚明!")
- elif gender == "女":
- if height < 1.6:
- print("你的身高是:1.5米")
- elif height < 1.7:
- print("你的身高是:1.6米")
- else:
- print(f"你的身高是:{height}米")
- else:
- print("你这性别是外星人?重输!")
- def main():
- print("1. 年龄计算器")
- print("2. 体重计算器")
- print("3. 身高计算器")
- choice = input("选择模式(1/2/3): ").strip()
-
- try:
- if choice == "1":
- age_calculator()
- elif choice == "2":
- weight_calculator()
- elif choice == "3":
- height_calculator()
- else:
- print("无效选项!")
- except ValueError:
- print("让你输数字,浮点数或者整数!")
- if __name__ == "__main__":
- main()
复制代码 |
|