首页 > 其他分享 >第六章

第六章

时间:2022-12-14 19:44:55浏览次数:34  
标签:fun money bmi list print 第六章 def

实例01--输出每日一贴

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

 

 

实例02--根据身高、体重计算BMI指数

def fun_bmi(name,height,weight):
   print(name+'的身高:'+str(height)+'米\t体重:'+str(weight)+'千克')
   bmi=weight/(height*height)
   print(name+'的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("肥胖 ^@_@^")
fun_bmi('路人甲',1.83,60)
fun_bmi('路人乙',1.60,50)

 

 实例03--根据身高、体重计算BMI指数(升级版)

def fun_bmi_upgrade(*person):
    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("肥胖 ^@_@^")
list_w=[('crz',1.70,65),('pxy',1.78,50),('gyl',1.72,66)]
list_m=[('gzz',1.80,45),('bgy',1.67,45)]
fun_bmi_upgrade(list_w,list_m)

 

 

实例04--模拟结账功能(计算实付金额)

def fun_checkout(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=[]
while True:
    inmoney=float(input('输入商品金额(输入0表示输入完毕)'))
    if int(inmoney)==0:
        break
    else:
        list_money.append(inmoney)
money=fun_checkout(list_money)
print('合计金额:',money[0],'应付金额:',money[1])

 

 

 实例05--一棵松树的梦

pinetree='我是一颗松树'
def fun_christmastree():
    pinetree='挂上彩灯,礼物....我变成一颗圣诞树@^.^@\n'
    print(pinetree)
print('\n下雪了....\n')
print('-----------开始做梦----------\n')
fun_christmastree()
print('==========梦醒了======\n')
pinetree='我身上落满雪花,'+pinetree+'-_-'
print(pinetree)

 

 

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

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

 

 

实战一:导演为剧本选主角

def act(actor):  #定义函数
    print(actor+"开始参演这个剧本")       
A = input("导演选定的角色是:")
act(A) #调用函数

 

 实战二:模拟美团外卖商家的套餐

def taocan(a,b,c,d,e,f):        
    print('米线店套餐如下:1.'+ a + '2.' + c + '3.' +e)
    print(a+b)
    print(c+d)
    print(e+f)
taocan('考神套餐','13元','单人套餐','9.9元','情侣套餐','20元')

 

 

实战三:根据生日判断星座

# 星座
m = ('摩羯座','水瓶座','双鱼座','白羊座','金牛座','双子座',
     '巨蟹座','狮子座','处女座','天秤座','天蝎座','射手座','摩羯座')
# 日期
d = (20,19,21,20,21,22,23,23,23,24,23,22)
def xingzuo(month,day):
    if day < d[month-1]:
        return m[month-1]
    else:
        return m[month]
M = int(input("请输入月份:"))
D = int(input("请输入日期:"))
print(str(M)+"月"+str(D)+"日星座为:"+xingzuo(M,D))

 

 实战四:将美元转换为人民币

def change(dollar):
    RMB = dollar * 6.28
    return RMB
dollar = float(input("请输入要转换的美元金额:"))
print("转换后人民币金额是:" , change(dollar))

 

标签:fun,money,bmi,list,print,第六章,def
From: https://www.cnblogs.com/xwb123/p/16983354.html

相关文章

  • 第六章 执行期语意学
    第六章执行期语意学classY{public:Y();~Y();booloperator==(constY&)const;};classX{public:X();~X();operatorY()const;XgetValue(......
  • 第六章 系统管理
    第六章系统管理6.1Linux中的进程和服务计算机中,一个正在执行的程序或命令,被叫做“进程”(process)。启动之后一只存在、常驻内存的进程,一般被称作“服务”(service)。......
  • C++课本的练习题及答案(第六章)
    第六章练习题一、选择题1.下列类的定义中正确的是(   )。(A)classa{intx=0;inty=1;}          (B)classb{intx=0;inty=1;};(C)classc{intx;inty;}     ......
  • 第六章实战
    defact(actor):#定义函数print(actor+"开始参演这个剧本")A=input("导演选定的角色是:")act(A)#调用函数  deftaocan(a,b,c,d,e,f):......
  • 第六章实例与实战
    实例01:输出每日一帖(共享版) 在IDLE中创建一个名称为function_tips.py的文件,然后在该文件中创建一个名称为function_tips的函数,在该函数中,从励志文字列表中获取一......
  • 第六章:bootstrap基础
    bootstrap简介该框架已经帮你写好了很多的页面样式,你如果需要使用,只需要下载对应的文件,之后直接cv拷贝即可在使用bootstrap的时候所有的页面样式都只需要通过class来调节......
  • 第六章练习题
    16、软件验收测试的合格通过准则是(ABCD)。你的答案A软件需求分析说明书中定义的所有功能已全部实现,性能指标全部达到要求。√正确B所有测试项没有残余一级、二级和三级......
  • GXT之旅:第六章:Templates(2)——XTemplate(1)
    XTemplateXTemplate比Template更为有用,除了拥有Template相同的功能之外,还具有更多有用的功能——提供使用更多的<tpl>标记来满足自己需要的html显示效果。为了下面例子的引......
  • GXT之旅:第六章:Templates(1)——Template(1)
    第六章:Templates本章我们要了解Templates,以及学习他们是如何方便我们去自定义数据的格式化和显示。我们也会详细了解XTemplates的丰富功能本章,我们会涉及到如下GXt功能集Tem......
  • 线上服务异常的定位、处理与优化的探索 - 第六章 监控与自动运维平台
    监控与自动运维平台 Zabbix简介 Zabbix是一个开源的监控平台,基于C/S方式采集数据,并使用B/S的Web方式展示数据。具有主机性能、数据库性能、Web应用、CPU、IO状态、硬......