Python全栈学习_day011作业
1,写函数,传入n个数,返回字典{‘max’:最大值,’min’:最小值}
例如:min_max(2,5,7,8,4) 返回:{‘max’:8,’min’:2}(此题用到max(),min()内置函数)
def min_max(*args):
dic = {}
dic['max'] = max(args)
dic['min'] = min(args)
return dic
2,写函数,传入一个参数n,返回n的阶乘
例如:cal(7) 计算7*6*5*4*3*2*1
def cal(n):
if n == 1:
return 1
return n * cal(n - 1)
3,写函数,返回一个扑克牌列表,里面有52项,每一项是一个元组
例如:[(‘红桃’,2),(‘梅花’,2), …(‘黑桃’,‘A’)]
def playingcard():
card = []
card_nums = ['A', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K']
card_class = ['红桃', '梅花', '黑桃', '方块']
for i in card_class:
for j in card_nums:
card.append((i, j))
return card
4,有如下函数:
def wrapper():
def inner():
print(666)
wrapper()
你可以任意添加代码,用两种或以上的方法,执行inner函数.
第一种:
def wrapper():
def inner():
print(666)
inner()
wrapper()
第二种:
def wrapper():
def inner():
print(666)
return inner
ret = wrapper()
ret()
5,相关面试题(先从纸上写好答案,然后在运行):
5.1,有函数定义如下:
def calc(a,b,c,d=1,e=2):
return (a+b)*(c-d)+e
请分别写出下列标号代码的输出结果,如果出错请写出Error。
print(calc(1,2,3,4,5))_____2
print(calc(1,2))____Error
print(calc(e=4,c=5,a=2,b=3))___24
print(calc(1,2,3))_____8
print(calc(1,2,3,e=4))____10
print(calc(1,2,3,d=5,4))_____Error
5.2,下面代码打印的结果分别是_list1=[10, 'a'],list2=[123],list3=[10, 'a'].
def extendList(val,list=[]):
list.append(val)
return list
list1 = extendList(10)
list2 = extendList(123,[])
list3 = extendList('a')
print('list1=%s'%list1)
print('list2=%s'%list2)
print('list3=%s'%list3)
5.3,写代码完成99乘法表.(升级题)
1 * 1 = 1
2 * 1 = 2 2 * 2 = 4
3 * 1 = 3 3 * 2 = 6 3 * 3 = 9
......
9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81
def nine_nine():
first = 1
two = 1
while 1:
print(first, '*', two, '=', first*two, end=' ')
if first == 9 and two == 9:
break
elif first == two:
print()
first += 1
two = 1
else:
two += 1
明日默写:
1,什么是闭包。
2,迭代器的好处。
3,用while循环模拟for循环(写具体代码)。
Python全栈学习_day011作业的更多相关文章
- Python全栈学习_day006作业
Day6作业及默写 ,使用循环打印以下效果: : * ** *** **** ***** : ***** **** *** ** * : * *** ***** ******* ********* . ...
- Python全栈学习_day001作业
Day1作业及默写 1.简述变量命名规范 1. 必须以字母.数字.下划线命名,且不能以数字开头 2. 不能是python的关键字 3. 不能以中文或者拼音作为变量名 4. 命名格式推荐以驼峰式或者下划 ...
- Python全栈学习_作业集锦(持续更新)
python基础 day1 python初识 . 计算机基础(cpu,内存,硬盘,操作系统) . Python出生于应用 . python发展史 . 编程语言分类 . python优缺点 . pyth ...
- Python全栈学习_day007作业
Day7作业及默写 .把列表中所有姓周的人的信息删掉(升级题:此题有坑, 请慎重): 第一种方法:lst = ['周老二', '周星星', '麻花藤', '周扒皮'] # 结果: lst = ['麻花 ...
- Python全栈学习_day003作业
day3作业及默写 1,有变量name = "aleX leNb" 完成如下操作: 1) 移除 name 变量对应的值两边的空格,并输出处理结果 print(name.strip( ...
- Python全栈学习_day002作业
Day2作业及默写 1.判断下列逻辑语句的True,False. 1)1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 & ...
- Python全栈学习_day010作业
1,继续整理函数相关知识点,写博客. 2,写函数,接收n个数字,求这些参数数字的和.(动态传参)def MySum(*args): sum = 0 for i in range(len(args)): ...
- Python全栈学习_day004作业
,写代码,有如下列表,按照要求实现每一个功能 li = ["alex", "WuSir", "ritian", "barry&qu ...
- Python全栈学习_day005作业
,有如下变量(tu是个元祖),请实现要求的功能 tu = (, , {,,)}, ]) a. 讲述元祖的特性 b. 请问tu变量中的第一个元素 "alex" 是否可被修改? c. ...
随机推荐
- consul服务注册与发现
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- LeNet,AlexNet,GoogleLeNet,VggNet等网络对比
CNN的发展史 上一篇回顾讲的是2006年Hinton他们的Science Paper,当时提到,2006年虽然Deep Learning的概念被提出来了,但是学术界的大家还是表示不服.当时有流传的段 ...
- [算法专题] Binary Tree
1 Same Tree https://leetcode.com/problems/same-tree/ Given two binary trees, write a function to che ...
- wpf使用FFMEPG录制屏幕
Simple function of recording screen based on ffmpeg Using WPF环境 Visual Studio 2017,dotNet Framework ...
- 背水一战 Windows 10 (72) - 控件(控件基类): UIElement - UIElement 的位置, UIElement 的布局, UIElement 的其他特性
[源码下载] 背水一战 Windows 10 (72) - 控件(控件基类): UIElement - UIElement 的位置, UIElement 的布局, UIElement 的其他特性 作者 ...
- Array.prototype.slice.call引发的思考
概述 今天在看书的时候看到Array.prototype.slice.call(arguments),有点看不懂,所以认真研究了一下,记录下来,供以后开发时参考,相信对其他人也有用. call 每一个 ...
- 详解 leetcode 猜数字大小 II
375. 猜数字大小 II 原题链接375. 猜数字大小 II 题目下方给出了几个提示: 游戏的最佳策略是减少最大损失,这引出了 Minimax 算法,见这里,和这里 使用较小的数开始(例如3),看看 ...
- USB插入电脑的硬件检测和枚举流程
USB协议定义了设备的6种状态,仅在枚举过程种,设备就经历了4个状态的迁移:上电状态(Powered),默认状态(Default),地址状态(Address)和配置状态(Configured)(其他两 ...
- 列表list切片
list1 = [1, 2, 3, 4, 5, 6] list1[::-1] >>>[6, 5, 4, 3, 2, 1] list1[:3:-1] >>>[6, 5 ...
- python(30)——【random模块】【if __name__ =='__main__'】【os模块】
一.random模块(随机模块) 1.random 常用模块介绍 import random print(random.random()) #返回[0,1)之间的随机浮点数 print(random. ...