唼喋菁藻
后端开发
·2 天前
Day 11 🧭行动:开始学习所有编程语言中最重要的部分--核心语法--函数 🤓体会:在学习过C语言后这部分还是简单的,可能对初学者来说难以理解形参,实参以及参数的作用范围。重新理解了一下返回值的概念,之前一直不清楚return的作用 🧑‍💻代码: # def circle_area(r): # area = 3.14 * r ** 2 # return area # area = circle_area(10) # print(area) # def calc_score(score_list): # max_s = max(score_list) # min_s = min(score_list) # avg_s = round(sum(score_list)/len(score_list),1) # return max_s, min_s, avg_s # # s_list = [111,134,454,665,523,463,356,245] # max_score, min_score, avg_score = calc_score(s_list) # print(f"最小值:{min_score},最大值:{max_score},平均值:{avg_score}") # def add (a,b): # return a+b # # def subtract (a,b): # return a-b # # def calc (a,b,oper): # return oper(a,b) # result = calc(5,4,add) # print(result) def calc_order_cost(*args,coupon = 0,score = 0,express = 0.0): # 计算商品总价格 total_price = [goods[1] * goods[2] for goods in args] total_cost = sum(total_price) #计算优惠券 if total_cost >=5000 and coupon <= total_cost: total_cost -= coupon #计算积分抵扣 if total_cost >= 5000 and score // 100 <= total_cost: total_cost -= score // 100 #计算运费 total_cost += express #返回值 return total_cost total = calc_order_cost(("A", 1000, 2), ("B", 2000, 2),express=20) print(total)
0个评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
下载 APP