python6

一、输出每日一贴

def function_tips():
'''功能;每天输出一条励志文字'''
import datetime
mot=["今天是星期一:\n坚持下去不是因为我很坚强,而是因为我别无选择",
"今天是星期二:\n含泪播种的人一定能笑着收获",
"今天是星期三:\n做对的事情比把事情做对更重要",
"今天是星期四:\n命运给予我们的不是失望之酒,而是机会之杯",
"今天是星期五:\n不用等到明天,明天太遥远,今天就行动",
"今天是星期六:\n求知若饥,虚心若愚",
"今天是星期日:\n成功将属于那些从不说“不可能”的人"]
day=datetime.datetime.now().weekday()
print(mot[day])
function_tips()

二、根据身高、体重计算BMI指数

def fun_bni(person,heigth,weight):
'''功能:根据身高和体重计算BMI指数
person:姓名
height:身高,单位:米
weightt:体重,单位:千克
'''
print(person+"的身高:"+str(heighgt)+"米\t 体重:"+str(weight)+"千克")
bmi=weight/(height*height)
print(person+"的BMI指数为:"+str(bmi))
if bmi<18.5:
print("您的体重过轻\n")
if bmi>=18.5 and bmi<24.9:
print("正常范围,注意保持\n")
if bmi>=24.9 and bmi<29.9:
print("您的体重过重\n")
if bmi>=29.9:
print("肥胖\n")
fun_bmi("路人甲",1.83,60)
fun_bmi("路人乙",1.60,50)

三、根据身高、体重计算BMI指数

def fun_bmi_upggrade(*person):
'''功能:根据身高和体重计算BMI指数
*person:可变参数该参数中需要传递带3个元素的列表,
分别为姓名、身高(单位:米)和体重(单位:千克)
'''
for list_person in person:
for item in list_person:
person=item[0]
height=item[1]
weight=item[2]
print("\n"+"="*13,person,"="*13)
print("身高:"+str(height)+"米\t 体重:"+str(weight)+"千克")
bmi=weight/(height*height)
print("BMI指数:"+str(bmi))
if bmi<18.5:
print("您的体重过轻")
if bmi>=18.5 and bmi<24.9:
print("正常范围,注意保持")
if bmi>=24.9 and bmi<29.9:
print("您的体重过重")
if bmi>=29.9:
print("肥胖")

四、模拟结账功能,计算实付金额

def fun_chekout(money):
'''功能:计算商品合计金额并进行折扣处理
money:保存商品金额的列表
返回商品的合计金额和折扣后的金额
'''
money_old=sum(money)
money_new=money_old
if 500<=money_old<1000:
money_new='{:,2f}'.format(money_old*0.9)
elif 1000<=money_old<=2000:
money_new='{:,2f}'.format(money_old*0.8)
elif 2000<=money_old<=3000:
money_new='{:,2f}'.format(money_old*0.7)
elif money_old>=3000:
money_new='{:,2f}'.format(money_old*0.6)
return money_old,money_new
print("\n开始结算\n")
list_money=[]

五、一棵松树的梦

pinetree='我是一棵松树'
def fun_christmastree():
'''功能:一个梦
无返回值
'''
pinetree='挂上彩灯、礼物……我变成一棵圣诞树\n'
print(pinetree)
print('\n下雪了……\n')
print('===============开始做梦……==============\n')
fun_christmastree()
print('===============梦醒了……================\n')
pinetree='我身上落满飞雪,'+pinetree+'-_-'
print(pinetree)

六、应用lambda实现对爬取到的秒杀商品信息进行排序

bookinfo=[('不一样的卡梅拉(全套),22.50,120),('零基础学Android',65.10,89.80),
('摆渡人',23.40,36.00),('福摩斯探索全集8册',22.50,128)]
print('爬取到的商品信息:\n',bookinfo,'\n')
bookinfo.sort(key=lambda x:(x[1],x[1]/x[2]))
print('排序后的商品信息:\n',bookinfo)

实战3、根据生日判断生日

def xz(a,b):
c=('摩羯座','水瓶座','双鱼座','白羊座','金牛座','双子座','巨蟹座','狮子座','处女座','天秤座','天蝎座','射手座','摩羯座')
d=(20,19,21,20,21,22,23,23,23,24,23,22)
if b<d[a-1]:
return c[a-1]
else:
return c[a]
a=input("请输入月份(例如:5):")
b=input("请输入日期(例如:17):")
print(str(a)+'月'+str(b)+'日'+'星座为:'+xz(int(a),int(b)))

 

posted @ 2022-10-20 11:58  倪文林  阅读(143)  评论(0)    收藏  举报