赞
踩
- def fun_bmi_upgrade(*peson):
- for list_person in peson:
- for item in list_person:
- peson = item[0]
- height =item[1]
- weight =item[2]
- print("\n" + "="*13,peson,"="*13)
- print("身高:" +str(height)+"米\t 体重:"+str(weight) +"千克")
- bmi=weight/(height*height)
- print("bmi指数:"+str(bmi))
- if bmi<18.5:
- print("您的体重过轻")
- if bmi>=18.5:
- print("正常范围,注意保持")
- if bmi>=24.9 and bmi<29.9:
- print("您是体重过重")
- if bmi>=29.9:
- print("肥胖")
- list_w =[("小明",1.70,65),("小红",1.78,50),("小兰",1.72,65)]
- list_m =[("小花",1.80,78),("小一",1.74,79)]
- fun_bmi_upgrade(list_w, list_m)
02输出拍腿游戏
- total = 999 # 记录拍腿次数的变量
- for number in range(1,1000): # 创建一个从1到100(不包括)的循环
- if number % 7 ==0: # 判断是否为7的倍数
- continue # 继续下一次循环
- else:
- string = str(number) # 将数值转换为字符串
- if string.endswith('7'): # 判断是否以数字7结尾
- continue # 继续下一次循环
- total -= 1 # 可拍腿次数-1
- print("方法1(参考):从1数到99共拍腿",total,"次。") # 显示拍腿次数
03定义ascll值的输出:
- num="0"
- while ord(num)!=57:
- instr =input("请输入一个字母或数字:")
- if len(instr)==1:
- if ord((num)in range(65,91)or ord(num)in range(97,123)or ord(num)in range(48,58)):
- print(ord(instr))
- else:
- print("输入数字不合法,退出程序!")
- break
- else:
- print("输入长度超过一个字符,重新输入")
- instr="0"
-
04输出一个万年历
- #!/usr/bin/env python
- # -*- coding:utf-8 -*-
-
- # 万年历
- # 1900年1月10
- # 条件:1900年1月1日是星期1
- # 要求输入一个1900年以后的年份和月份,打印当月的日历
- # 输入年份是否是闰年
- # 计算1900年1月1日到2020年12月31日间间隔了多少天。
- # 计算输入月份和日期是当年的第几天
- # 确定输入的月份1号是周几
- # 总天数%7结果是几代表当月1日就是周几
- year = int(input("输入年份"))
- moth = int (input("输入月份"))
- day = 0
- run= 0
- rnu =0
- yearday = 0
- for n in range(1900,year):
- rnu+=1
- if n%4==0 and n%100!=0 or n%400==0:
- run+=1
- ping = rnu - run
- yearday = run * 366 + ping * 365
- nru =0
- moths = [31,28,31,30,31,30,31,31,30,31,30,31]
- if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
- moths[1] = 29
- index1 = range(moth-1)
- for i in index1 :
- day = moths[i] + day
- else:
- index1 = range(moth-1)
- for i in index1:
- day = moths[i] + day
- zongtianshu = day + yearday
- xingqi =((zongtianshu)%7)
- print("一\t二\t三\t四\t五\t六\t日",)
- 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]
- x1 = ""
- if (year%4==0 and year%100!=0) or year%400==0:
- x1 = [31,29,31,30,31,30,31,31,30,31,30,31]
- for n in range(xingqi):
- print(" \t", end="")
-
- for m in range(x1[moth - 1]):
-
- print(str(x[m]) + " \t", end="")
-
- if (m + xingqi + 1) % 7 == 0:
- print()
- else:
- x1=[31,28,31,30,31,30,31,31,30,31,30,31]
- for n in range(xingqi):
- print(" \t", end="")
- for m in range(x1[moth - 1]):
- print(str(x[m])+" \t", end="")
-
- if (m + xingqi + 1) % 7 == 0:
- print()
-
- # 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]
- # s = range(30)
- # l=2
- # for o in range(0,l):
- # print(" ","p",end="")
- # for i in s :
- # f= " "
- # if (i+l+1)%7==0 :
- # f = "\n"
- # print(x[i],f,end="")
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。