fork download
  1. # 定义身高变量
  2. height = 1.75
  3. # 定义体重变量
  4. weight = 75
  5. # 定义用户名变量
  6. username = '小明'
  7. # 求体质指数
  8. bmi = weight / height**2
  9. # 打印体质指数
  10. print(f'{username}您好,您的体质指数为{round(bmi, 1)}')
  11. # your code goes here
  12. # 验证
  13. if bmi <= 18.5:
  14. print(f'{username}您好,您的体质偏瘦')
  15. elif bmi <= 24.9:
  16. print(f'{username}您好,您的体质正常')
  17. elif bmi <= 29.9:
  18. print(f'{username}您好,您的体质超重')
  19. else:
  20. print(f'{username}您好,您的体质肥胖')
  21. # 定义列表数据
  22. score_list = [65, 92, 78, 90, 45, 83, 57, 96]
  23. # 先要定义好字典的键值对
  24. score_dict = {
  25. 'high': [],
  26. 'middle': [],
  27. 'low': []
  28. }
  29. # 循环遍历
  30. for score in score_list:
  31. # 验证
  32. if score >= 90:
  33. score_dict['high'].append(score)
  34. elif score >= 60:
  35. score_dict['middle'].append(score)
  36. else:
  37. score_dict['low'].append(score)
  38.  
  39. # 打印字典
  40. print(score_dict)
Success #stdin #stdout 0.07s 7920KB
stdin
Standard input is empty
stdout
小明您好,您的体质指数为24.5
小明您好,您的体质正常
{'high': [92, 90, 96], 'middle': [65, 78, 83], 'low': [45, 57]}