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(person,height,weight):
'''功能:根据身高和体重计算BMI指数
person:姓名
height:身高,单位:米
weight:体重,单位:千克
'''
print(person + "的身高" + str(height) + "米 \t 体重:" + str(weight) + "千克")
bmi = weight/(height*height)
print(person + "的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):
'''功能:根据身高和体重计算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**2
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 = [('绮梦',1.70,65),('零语',1.78,50),('黛兰',1.72,66)]
list_m = [('子轩',1.80,75),('冷伊一',1.75,70)]
fun_bmi_upgrade(list_w,list_m)
def fun_checkout(money):
'''功能:计算商品合计金额并进行折扣处理
money:保存商品金额的列表
返回商品的合计金额和折扣后的金额
'''
money_old = sum(money) # 计算合计金额
money_new = money_old
if 500 <= money_old < 1000: # 满500可享受9折优惠
money_new = '{:.2f}'.format(money_old * 0.9)
elif 1000 <= money_old <= 2000: # 满1000可享受8折优惠
money_new = '{:.2f}'.format(money_old * 0.8)
elif 2000 <= money_old <= 3000: # 满2000可享受7折优惠
money_new = '{:.2f'.format(money_old * 0.7)
elif money_old >= 3000: # 满3000可享受6折优惠
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('\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), ('福尔摩斯探索全集8册', 22.50, 128)]
print('爬取到的商品信息:\n',bookinfo, '\n')
bookinfo.sort(key=lambda x:(x[1],x[1]/x[2])) # sort默认为升序,按指定规则进行排序,先按x[1]升序排,再按x[1]/x[2]排
print('排序后的商品信息:\n', bookinfo)
def juben(a):
print(a+"开始参演这个剧本")
character = input("导演选定的主角是:")
juben(character)
def food(a,b,c):
print(a+"13元",'\n'+b+"9.9元",'\n'+c+"20元")
first = "考神套餐"
second = "单人套餐"
third = "情侣套餐"
print("米线店套餐如下: 1."+first,"2."+second,"3."+third)
food(first,second,third)
list = ['摩羯座','水瓶座','双鱼座','白羊座','金牛座','双子座',
'巨蟹座','狮子座','处女座','天秤座','天蝎座','射手座','摩羯座']
# 1、白羊座:3月21日~4月19日 2、金牛座:4月20日~5月20日
# 3、双子座:5月21日~6月21日 4、巨蟹座:6月22日~7月22日
# 5、狮子座:7月23日~8月22日 6、处女座:8月23日~9月22日
# 7、天秤座:9月23日~10月23日 8、天蝎座:10月24日~11月22日
# 9、射手座:11月23日~12月21日 10、摩羯座:12月22日~1月19日
# 11、水瓶座:1月20日~2月18日 12、双鱼座:2月19日~3月20日
# 日期
d = [20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22]
def starSign(month, day):
if day < d[month-1]:
return list[month-1]
else:
return list[month]
month = int(input("请输入月份:"))
day = int(input("请输入日期:"))
print(str(month) + "月" + str(day) + "日星座为:" + starSign(month, day))
a = int(input("请输入要转换的美元金额:"))
result = lambda a:a*6.28
print("转换后的人民币金额是:{0:.1f}".format(result(a)))
标签:23,python,money,bmi,list,第六周,person,print
From: https://www.cnblogs.com/rweiq/p/16854268.html