首页 > 其他分享 >函数

函数

时间:2022-12-16 01:33:37浏览次数:27  
标签:函数 money bmi list height fun print

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

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)

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)

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])

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

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

标签:函数,money,bmi,list,height,fun,print
From: https://www.cnblogs.com/whc123/p/16986369.html

相关文章

  • 5.python-函数式编程
    函数式编程(1)定义:用一系列函数解决问题。--函数可以赋值给变量,赋值后变量绑定函数。--允许将函数作为参数传入另一个函数。(2)高阶函数:将函数作为参数或返回值的函数......
  • C#内联函数 特性 MethodImplOptions.AggressiveInlining)
    https://www.cnblogs.com/cdaniu/p/15900255.htmlImpl:implement的缩写内联函数在计算机科学中,内联函数(有时称作在线函数或编译时期展开函数)是一种编程语言结构,用来建议......
  • python-函数
    python-函数函数的作用封装代码,提高代码的重用性函数的使用函数的使用方法:先定义在调用函数的定义把代码封装到函数的内部函数的调......
  • C语言中将二维数组作为函数参数来传递
    c语言中经常需要通过函数传递二维数组,有三种方法可以实现,如下:方法一, 形参给出第二维的长度。例如:#include<stdio.h>voidfunc(intn,char str[][5]){ inti; f......
  • [Glib] GObject 的 dispose 和 finalize 成员函数的各自作用
    ​​GObject学习教程---第十一章8本文是学习学习他人的博客的心得(具体详见“楼主见解”),如果源网站可访问的话,建议直接访问源网站:楼主见解:主要讲解析构为什么需要2个函数来实......
  • <九>函数对象
    函数对象=》C语言中的函数指针函数对象尽管函数指针被广泛用于实现函数回调,但C++还提供了一个重要的实现回调函数的方法,那就是函数对象。函数对象(也称“函数符”)是重载......
  • P2085 最小函数值
    P2085最小函数值题目简述对于n个函数\(f_i(x)\),在x均为正整数情况下,求这些函数值中最小的m个思路大水题,裸的堆,主要记录一下重载运算符写法以及结构体套优先队列......
  • C++学习---cstdio的源码学习分析05-打开文件函数fopen
    cstdio中的文件访问函数stdio.h中定义了一系列文件访问函数(fopen,fclose,fflush,freopen,setbuf,setvbuf),接下来我们一起来分析一下fopen对应的源码实现。fopen:打开文件fclose:关......
  • mian函数中代码执行顺序
    /**自己写程序最好是参照下面的书写过程**/1//程序主入口函数----------------------------------2intmain(intargc,char*const*argv)3{5//(0......
  • Mysql 一些函数的使用
    Mysql一些函数的使用if函数SELECTIF(500<1000,"YES","NO");SELECTIF(500<1000,1,0);数字会一直叠加sum函数round函数四舍五入结合项目中做报表的时候查......