当前位置:   article > 正文

python练习必备4小题_fum_bmi(list_w,list_m)

fum_bmi(list_w,list_m)

01输出bmi值

  1. def fun_bmi_upgrade(*peson):
  2. for list_person in peson:
  3. for item in list_person:
  4. peson = item[0]
  5. height =item[1]
  6. weight =item[2]
  7. print("\n" + "="*13,peson,"="*13)
  8. print("身高:" +str(height)+"米\t 体重:"+str(weight) +"千克")
  9. bmi=weight/(height*height)
  10. print("bmi指数:"+str(bmi))
  11. if bmi<18.5:
  12. print("您的体重过轻")
  13. if bmi>=18.5:
  14. print("正常范围,注意保持")
  15. if bmi>=24.9 and bmi<29.9:
  16. print("您是体重过重")
  17. if bmi>=29.9:
  18. print("肥胖")
  19. list_w =[("小明",1.70,65),("小红",1.78,50),("小兰",1.72,65)]
  20. list_m =[("小花",1.80,78),("小一",1.74,79)]
  21. fun_bmi_upgrade(list_w, list_m)

02输出拍腿游戏

  1. total = 999 # 记录拍腿次数的变量
  2. for number in range(1,1000): # 创建一个从1100(不包括)的循环
  3. if number % 7 ==0: # 判断是否为7的倍数
  4. continue # 继续下一次循环
  5. else:
  6. string = str(number) # 将数值转换为字符串
  7. if string.endswith('7'): # 判断是否以数字7结尾
  8. continue # 继续下一次循环
  9. total -= 1 # 可拍腿次数-1
  10. print("方法1(参考):从1数到99共拍腿",total,"次。") # 显示拍腿次数

03定义ascll值的输出:

  1. num="0"
  2. while ord(num)!=57:
  3. instr =input("请输入一个字母或数字:")
  4. if len(instr)==1:
  5. if ord((num)in range(65,91)or ord(num)in range(97,123)or ord(num)in range(48,58)):
  6. print(ord(instr))
  7. else:
  8. print("输入数字不合法,退出程序!")
  9. break
  10. else:
  11. print("输入长度超过一个字符,重新输入")
  12. instr="0"

04输出一个万年历

  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. # 万年历
  4. # 1900110
  5. # 条件:190011日是星期1
  6. # 要求输入一个1900年以后的年份和月份,打印当月的日历
  7. # 输入年份是否是闰年
  8. # 计算190011日到20201231日间间隔了多少天。
  9. # 计算输入月份和日期是当年的第几天
  10. # 确定输入的月份1号是周几
  11. # 总天数%7结果是几代表当月1日就是周几
  12. year = int(input("输入年份"))
  13. moth = int (input("输入月份"))
  14. day = 0
  15. run= 0
  16. rnu =0
  17. yearday = 0
  18. for n in range(1900,year):
  19. rnu+=1
  20. if n%4==0 and n%100!=0 or n%400==0:
  21. run+=1
  22. ping = rnu - run
  23. yearday = run * 366 + ping * 365
  24. nru =0
  25. moths = [31,28,31,30,31,30,31,31,30,31,30,31]
  26. if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
  27. moths[1] = 29
  28. index1 = range(moth-1)
  29. for i in index1 :
  30. day = moths[i] + day
  31. else:
  32. index1 = range(moth-1)
  33. for i in index1:
  34. day = moths[i] + day
  35. zongtianshu = day + yearday
  36. xingqi =((zongtianshu)%7)
  37. print("一\t二\t三\t四\t五\t六\t日",)
  38. x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]
  39. x1 = ""
  40. if (year%4==0 and year%100!=0) or year%400==0:
  41. x1 = [31,29,31,30,31,30,31,31,30,31,30,31]
  42. for n in range(xingqi):
  43. print(" \t", end="")
  44. for m in range(x1[moth - 1]):
  45. print(str(x[m]) + " \t", end="")
  46. if (m + xingqi + 1) % 7 == 0:
  47. print()
  48. else:
  49. x1=[31,28,31,30,31,30,31,31,30,31,30,31]
  50. for n in range(xingqi):
  51. print(" \t", end="")
  52. for m in range(x1[moth - 1]):
  53. print(str(x[m])+" \t", end="")
  54. if (m + xingqi + 1) % 7 == 0:
  55. print()
  56. # x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]
  57. # s = range(30)
  58. # l=2
  59. # for o in range(0,l):
  60. # print(" ","p",end="")
  61. # for i in s :
  62. # f= " "
  63. # if (i+l+1)%7==0 :
  64. # f = "\n"
  65. # print(x[i],f,end="")

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号