# -*- coding: utf-8 -*-
# @Time : 2019/1/2 16:35
# @Author : Endless-cloud
# @Site :
# @File : 课后作业.py
# @Software: PyCharm
'''
# 1.写函数,接收n个数字,求这些参数数字的和。(动态传参)
'''
# def fun1 (*args):
# sun = 0
# for i in args:
#
# sun =sun+int(i)
# print(sun)
# fun1(1,2,3,4,5,6,7,8,9,10)
'''
2.读代码,回答:代码中,打印出来的值a,b,c分别是什么?为什么?
# a=10
# b=20
# def test5(a,b):
# print(a,b)
# c = test5(b,a)
# print(c)
'''
# 20 10
# 20,10 #None 没有返回值
# a=10
# b=20
# def test5(a,b):
# print(a,b)
# c = test5(b,a)
# print(c)
'''
# 3.读代码,回答:代码中,打印出来的值a,b,c分别是什么?为什么?
# a=10
# b=20
# def test5(a,b):
# a=3
# b=5
# print(a,b)
# c = test5(b,a)
# print(c)
'''
# 3 ,5
# None
# a=10
# b=20
# def test5(a,b):
# a=3
# b=5
# print(a,b)
# c = test5(b,a)
# print(c)
'''
# 4.传入函数中多个列表和字典,如何将每个列表的每个元素依次添加到函数的动态参数args里面?
如何将每个字典的所有键值对依次添加到kwargs里面?
'''
# 利用* 的魔性用法
# def func2(*args,**kwargs):
# print(args)
# print(kwargs)
# l1 =(1,2,3,4,7,5)
# l2 =['a','b','c','d']
# func2(*l1,*l2,**{'name':'alex'},**{'like':'python'})
'''
# 5.下面代码成立么?如果不成立为什么报错?怎么解决?
# 5.1
# a = 2
# def wrapper():
# print(a)
# wrapper()
#
# 5.2
# a = 2
# def wrapper():
# a += 1
# print(a)
# wrapper()
# 5.3
# def wrapper():
# a = 1
# def inner():
# print(a)
# inner()
# wrapper()
# 5.4
# def wrapper():
# a = 1
# def inner():
# a += 1
# print(a)
# inner()
# wrapper()
'''
#D
# a = 2
# def wrapper():
# print(a)
# wrapper()
# 5.2
#C 因为如果不加global 变量不允许改变,只能引用
# a = 2
# def wrapper():
# # global a
# a =a+1
# print(a)
# wrapper()
# 5.3
# C 没有返回值
# def wrapper():
# a = 1
# def inner():
# print(a)
# inner()
# wrapper()
# 没有nolable
# def wrapper():
# a =1
# def inner():
# a+=1
# print(a)
# inner()
# wrapper()
'''
# 6.写函数,传入n个数,返回字典{‘max’:最大值,’min’:最小值}
# 例如:min_max(2,5,7,8,4) 返回:{‘max’:8,’min’:2}(此题用到max(),min()内置函数)
'''
# def func3(lis):
# max1 =max(lis)
# min1 =min(lis)
# print(max1)
# print(min1)
# lis =(1,2,3,4,5)
# func3(lis)
'''
# 7.写函数,传入一个参数n,返回n的阶乘
# 例如:cal(7) 计算7*6*5*4*3*2*1
'''
# def func4(num):
# sun =1
# for i in range(1,num):
# sun =num*sun
# num = num - 1
# return sun
# print(func4(3))
'''
# 8.写函数,返回一个扑克牌列表,里面有52项,每一项是一个元组
# 例如:[(‘红心’,2),(‘草花’,2), …(‘黑桃’,‘A’)]
'''
# huase =['红心','黑心','草花','方片']
# hao =['A',2,'3','4','5','6','7','8','9','10','J','Q','K']
# wang =['大王','小王']
# lis =[]
# lis23=[]
# # dic ={}
# def func5():
#
# for se in huase:
# for i in hao:
# dic1={}
# dic1[se]=i
# lis.append(dic1)
#
# # lis.append([i+j for i ,j in dic1.items()])
# for j in lis:
# l2 =[]
# l2.insert(0,[i for i in j][0])
# l2.insert(1,[i for i in j.values()][0])
# lis23.append(tuple(l2))
# print(lis23)
# func5()
# 9.有如下函数:
# def wrapper():
# def inner():
# print(666)
# wrapper()
'''
# 9.有如下函数:
# def wrapper():
# def inner():
# print(666)
# wrapper()
# 你可以任意添加代码,用两种或以上的方法,执行inner函数.
'''
# def wrapper():
# def inner():
# print('777')
# return inner()def wrapper():
# def inner():
# print('777')
# return inner
# wrapper()
# wrapper()()
'''
# 10 相关面试题(先从纸上写好答案,然后在运行):
# def calc(a, b, c, d=1, e=2):
# return (a + b) * (c - d) + e
#
# 请分别写出下列标号代码的输出结果,如果出错请写出Error。
# print(calc(1, 2, 3, 4, 5))
# _____
# print(calc(1, 2))
# ____
# print(calc(e=4, c=5, a=2, b=3))
# ___
# print(calc(1, 2, 3))
# _____
# print(calc(1, 2, 3, e=4))
# ____
# print(calc(1, 2, 3, d=5, 4))
# _____
#
# 下面代码打印的结果分别是_________, ________, ________.
#
# 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)
'''
# def calc(a, b, c, d=1, e=2):
# return (a + b) * (c - d) + e
# print(calc(1, 2, 3, 4, 5))
# 2
# print(calc(1, 2))
#报错,缺少数据
# print(calc(e=4, c=5, a=2, b=3))
#24
# print(calc(1, 2, 3))
# 8
# print(calc(1, 2, 3, d=5, 4))
# 形参顺序错了
'''
# 11 写代码完成99乘法表.(升级题)
'''
# for i in range(9,0,-1):
# # print(type(i))
# print(' ')
# for j in range(1,i+1) :
# # print(j,end='')
# print(str(j)+"*"+str(i)+'='+str(i*j),end=' ')
[print(str(i) +'*'+str(j)+'='+str(i*j),end= ' ') for i in range(1,10) for j in range(1,i+1) ]
# 1.什么是闭包。
# 2.迭代器的好处。
# 3.名称空间的加载顺序,取值顺序。
# 4.解释一下什么是global,什么是nonlocal。
# 5.用while循环模拟for循环(写具体代码)。